// P/Invoke CreateEvent and WaitForSingleObject private void GPIO_Open() //get handle for gpio private void GPIO_Output() //output pin declaration private void button1_Click(object sender, EventArgs e) {
Interrupt_Setup();
} private void Interrupt_Setup() {
hGPIO = GPIOapi.GpioOpenHandle(); //returns a handle to the gpio GIPO_ON = true; Debug.WriteLine("Driver open \n" + hGPIO); GPIO_Output(); //set output pins GPIO_Interrupt(Trigger); //configure interrupt
hGPIO = GPIOapi.GpioOpenHandle(); //returns a handle to the gpio
GIPO_ON = true;
Debug.WriteLine("Driver open \n" + hGPIO);
GPIO_Output(); //set output pins
GPIO_Interrupt(Trigger); //configure interrupt
} private void GPIO_Interrupt(string trigger) {
bool ok; _Main(); //INTERRUPT DECALRATION ok = GPIOapi.GpioSetupInterruptPin(hGPIO, port6, 4, GPIOapi.INT_TRIGGER_MODE.TRIGGER_MODE_EDGE, GPIOapi.INT_TRIGGER_POLARITY.TRIGGER_POL_HIGH_RISING, trigger, true); if (!ok)
bool ok;
_Main();
//INTERRUPT DECALRATION
ok = GPIOapi.GpioSetupInterruptPin(hGPIO, port6, 4, GPIOapi.INT_TRIGGER_MODE.TRIGGER_MODE_EDGE,
GPIOapi.INT_TRIGGER_POLARITY.TRIGGER_POL_HIGH_RISING, trigger, true);
if (!ok)
Debug.WriteLine("NO interrupt");
else
Debug.WriteLine("Interrupt set for:" + port6 + "04" + " at " + hGPIO);
} public static string Trigger = "InputProcessUpdateHandler"; private static InputProcessor inputProcessor = null; private void _Main() {
public static IntPtr handle = CreateEvent(IntPtr.Zero, false, false, Trigger); //used P/Invoke try {
if (WaitForSingleObject(handle, 0xFFFFFFFF) == false)
label2.BackColor = Color.Red;
} catch(Exception e) {Debug.WriteLine("exception: "+e);}
inputProcessor = new InputProcessor(); ShowToggle showToggle = new ShowToggle(inputProcessor); inputProcessor.Process(label1);
inputProcessor = new InputProcessor();
ShowToggle showToggle = new ShowToggle(inputProcessor);
inputProcessor.Process(label1);
}
private InputProcessor _inputProcessor = null; public ShowToggle(InputProcessor inputProcessor) {
_inputProcessor = inputProcessor; _inputProcessor.updateHandledBy += InputProcessUpdateHandler;
_inputProcessor = inputProcessor;
_inputProcessor.updateHandledBy += InputProcessUpdateHandler;
} private void InputProcessUpdateHandler(Label label) {
label.BackColor = Color.Yellow; Debug.Write("execute");
label.BackColor = Color.Yellow;
Debug.Write("execute");
public delegate void InputProcessUpdateHandler(Label label); public event InputProcessUpdateHandler updateHandledBy = null; public void Process(Label label) {
if (updateHandledBy != null) updateHandledBy(label);
if (updateHandledBy != null)
updateHandledBy(label);