Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Button OnInterrupt Reset


  • Please log in to reply
5 replies to this topic

#1 Doug Rathbone

Doug Rathbone

    Member

  • Members
  • PipPip
  • 11 posts

Posted 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...

#2 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 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.

#3 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 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...

#4 EricGu

EricGu

    New Member

  • Members
  • Pip
  • 1 posts

Posted 19 December 2011 - 03:04 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...


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.

#5 Doug Rathbone

Doug Rathbone

    Member

  • Members
  • PipPip
  • 11 posts

Posted 19 December 2011 - 10:18 PM

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.


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();
}


#6 lesmondo

lesmondo

    Member

  • Members
  • PipPip
  • 24 posts

Posted 22 December 2011 - 07:44 AM

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();
}



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 topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.