added debounce timer to button sensor
OBS removed sensor changed notification when button released!
This commit is contained in:
parent
f3e5126a8c
commit
87219929b7
@ -26,7 +26,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: button-sensor.c,v 1.1 2006/08/21 12:11:19 fros4943 Exp $
|
* $Id: button-sensor.c,v 1.2 2006/10/05 11:51:51 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lib/sensors.h"
|
#include "lib/sensors.h"
|
||||||
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
const struct simInterface button_interface;
|
const struct simInterface button_interface;
|
||||||
const struct sensors_sensor button_sensor;
|
const struct sensors_sensor button_sensor;
|
||||||
|
static struct timer debouncetimer;
|
||||||
|
|
||||||
// COOJA variables
|
// COOJA variables
|
||||||
char simButtonChanged;
|
char simButtonChanged;
|
||||||
@ -46,6 +47,7 @@ static void
|
|||||||
init(void)
|
init(void)
|
||||||
{
|
{
|
||||||
simButtonIsActive = 1;
|
simButtonIsActive = 1;
|
||||||
|
timer_set(&debouncetimer, 0);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
@ -75,7 +77,7 @@ active(void)
|
|||||||
static unsigned int
|
static unsigned int
|
||||||
value(int type)
|
value(int type)
|
||||||
{
|
{
|
||||||
return simButtonIsDown;
|
return simButtonIsDown || !timer_expired(&debouncetimer);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
@ -94,10 +96,13 @@ static void
|
|||||||
doInterfaceActionsBeforeTick(void)
|
doInterfaceActionsBeforeTick(void)
|
||||||
{
|
{
|
||||||
// Check if button value has changed
|
// Check if button value has changed
|
||||||
if (simButtonChanged && simButtonIsActive) {
|
if (simButtonChanged && simButtonIsActive && simButtonIsDown) {
|
||||||
|
if(timer_expired(&debouncetimer)) {
|
||||||
|
timer_set(&debouncetimer, CLOCK_SECOND / 4);
|
||||||
sensors_changed(&button_sensor);
|
sensors_changed(&button_sensor);
|
||||||
simButtonChanged = 0;
|
simButtonChanged = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user