I have a Fez Panda 2 with a simple switch wired into pin Di20. I have it declared as
static InputPort MySwitch = new InputPort((Cpu_Pin)FEZ_Pin.Digital.Di20, false, Port.ResistorMode.PullUp);
I have several threads in my program, one of which runs a while(true) block in which I want to use:
while(true)
{
if(MySwitch.Read()== false)
{
//put FEZ to sleep
LED.State = LED.LedState.Off; //I have an LED class to set LED on or off
}
else
{
//wake up FEZ
LED.State = LED.LedState.Off;
}
}
Any idea on how I could achieve this so that the Fez will 'hibernate' until this button is changed?
I have heard about allowing An interrupt Port, but I am unsure if this is useful/feasible in this situation. I have several COM ports connected, and want these connections to 'close' and so 'stop' all transmissions. It is due to these serial ports that it proves difficult to 'just use an interrupt port', as well I need to 'disable' the communications there (Serials are using COM1, COM3 and COM4, with regular data flowing).
Any suggestions as to how to go about this?
Low-Power-State example below taken from here: https://www.ghielectronics.com/docs/141/low-power
using Microsoft.SPOT.Hardware;
using System;
public class Program
{
public static void Main()
{
var interrupt = new InterruptPort(Cpu.Pin.GPIO_Pin0, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
interrupt.OnInterrupt += interrupt_OnInterrupt;
PowerState.Sleep(SleepLevel.DeepSleep, HardwareEvent.OEMReserved1);
///Continue on with your program here
}
private static void interrupt_OnInterrupt(uint data1, uint data2, DateTime time)
{
//Interrupted
}
}