adapted for new sensor APIs
This commit is contained in:
parent
e0c0808767
commit
071a9eaa6b
1 changed files with 11 additions and 38 deletions
|
@ -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.4 2007/04/02 14:14:28 fros4943 Exp $
|
* $Id: button-sensor.c,v 1.5 2010/01/14 16:13:45 joxe Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lib/sensors.h"
|
#include "lib/sensors.h"
|
||||||
|
@ -41,38 +41,6 @@ static struct timer debouncetimer;
|
||||||
char simButtonChanged;
|
char simButtonChanged;
|
||||||
char simButtonIsDown;
|
char simButtonIsDown;
|
||||||
char simButtonIsActive;
|
char simButtonIsActive;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
init(void)
|
|
||||||
{
|
|
||||||
simButtonIsActive = 1;
|
|
||||||
timer_set(&debouncetimer, 0);
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static int
|
|
||||||
irq(void)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
activate(void)
|
|
||||||
{
|
|
||||||
simButtonIsActive = 1;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
deactivate(void)
|
|
||||||
{
|
|
||||||
simButtonIsActive = 0;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static int
|
|
||||||
active(void)
|
|
||||||
{
|
|
||||||
return simButtonIsActive;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static unsigned int
|
static unsigned int
|
||||||
value(int type)
|
value(int type)
|
||||||
|
@ -81,22 +49,28 @@ value(int type)
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
configure(int type, void *c)
|
configure(int type, int c)
|
||||||
{
|
{
|
||||||
|
if(type == SENSORS_ACTIVE) {
|
||||||
|
simButtonIsActive = c;
|
||||||
|
} else if(type == SENSORS_HW_INIT) {
|
||||||
|
simButtonIsActive = 1;
|
||||||
|
timer_set(&debouncetimer, 0);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void *
|
static int
|
||||||
status(int type)
|
status(int type)
|
||||||
{
|
{
|
||||||
return 0;
|
return (type == SENSORS_ACTIVE) ? simButtonIsActive : 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
doInterfaceActionsBeforeTick(void)
|
doInterfaceActionsBeforeTick(void)
|
||||||
{
|
{
|
||||||
// Check if button value has changed
|
// Check if button value has changed
|
||||||
if (simButtonChanged && simButtonIsActive && simButtonIsDown) {
|
if(simButtonChanged && simButtonIsActive && simButtonIsDown) {
|
||||||
if(timer_expired(&debouncetimer)) {
|
if(timer_expired(&debouncetimer)) {
|
||||||
timer_set(&debouncetimer, CLOCK_SECOND / 10);
|
timer_set(&debouncetimer, CLOCK_SECOND / 10);
|
||||||
sensors_changed(&button_sensor);
|
sensors_changed(&button_sensor);
|
||||||
|
@ -116,5 +90,4 @@ SIM_INTERFACE(button_interface,
|
||||||
doInterfaceActionsAfterTick);
|
doInterfaceActionsAfterTick);
|
||||||
|
|
||||||
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR,
|
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR,
|
||||||
init, irq, activate, deactivate, active,
|
|
||||||
value, configure, status);
|
value, configure, status);
|
||||||
|
|
Loading…
Reference in a new issue