if i have:
button1.OnInterrupt += new NativeEventHandler(button1_OnInterrupt);
The event fires, but only once. Is there a way to reset the button event again?
(apologies again for this basic question...
  | ||||||||||||||
Button OnInterrupt Reset
Started by Doug Rathbone, Dec 16 2011 12:51 AM
5 replies to this topic
#1Posted 16 December 2011 - 12:51 AM
This is a very beginner question i know, but i can't seem to find an answer easily trough google.
if i have: button1.OnInterrupt += new NativeEventHandler(button1_OnInterrupt); The event fires, but only once. Is there a way to reset the button event again? (apologies again for this basic question... #2Posted 16 December 2011 - 04:46 AM
Hello Doug.
I'm not sure to understand the problem...are you saying that even pressing many times the button, the event is called only once?
Or maybe are you expecting many event firing while holding the button down?
Biggest fault of Netduino? It runs by electricity.
#3Posted 16 December 2011 - 07:43 AM
Just out of curiosity, where have you defined button1? If it is like
... public static void Main() { var button1 = new InterruptPort(...); button1.OnInterrupt += button1_OnInterrupt; // ... }and you have a lot of other possibly memory intensive code in your application, the button1 may be disposed during garbage collection. Try making it a class member: ... private static InterruptPort button1 = new InterruptPort(...); ... public static void Main() { button1.OnInterrupt += button1_OnInterrupt; // ... } If it does not help, you'd probably need to show us the rest of your code...
#4Posted 19 December 2011 - 03:04 AM
The behavior depends on what Port.InterruptMode you use. If you use one of the level-based ones, you have to call ClearInterrupt each time. I'd suggest trying Port.InterruptMode.InterruptEdgeLow. #5Posted 19 December 2011 - 10:18 PM
As i was using the on board switch i got it working by doing the following: public static InterruptPort button1; public static void Main() { button1 = new InterruptPort(Pins.ONBOARD_SW1, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLevelLow); WaitForButtonPress(); } private static void WaitForButtonPress() { Debug.Print("Waiting for button press..."); button1.ClearInterrupt(); button1.OnInterrupt += new NativeEventHandler(button1_OnInterrupt); while (true) { Thread.Sleep(15); } } private static void button1_OnInterrupt(uint data1, uint data2, DateTime time) { Debug.Print("Onboard button pressed"); WaitForButtonPress(); } #6Posted 22 December 2011 - 07:44 AM
This might be of interest - a general purpose button class. http://nerduino.word...1/02/24/button/ (derived from http://geekswithblog.../09/142211.aspx ) 0 user(s) are reading this topic0 members, 0 guests, 0 anonymous users | ||||||||||||||
|
||||||||||||||
This webpage is licensed under a Creative Commons Attribution-ShareAlike License. | ||||||||||||||