Updated to match the new sensors API
This commit is contained in:
parent
bca8104a86
commit
2a7ad011c5
6 changed files with 58 additions and 115 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.5 2010/01/14 16:13:45 joxe Exp $
|
* $Id: button-sensor.c,v 1.6 2010/01/14 19:12:31 nifi Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lib/sensors.h"
|
#include "lib/sensors.h"
|
||||||
|
@ -42,7 +42,7 @@ char simButtonChanged;
|
||||||
char simButtonIsDown;
|
char simButtonIsDown;
|
||||||
char simButtonIsActive;
|
char simButtonIsActive;
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static unsigned int
|
static int
|
||||||
value(int type)
|
value(int type)
|
||||||
{
|
{
|
||||||
return simButtonIsDown || !timer_expired(&debouncetimer);
|
return simButtonIsDown || !timer_expired(&debouncetimer);
|
||||||
|
@ -53,9 +53,11 @@ configure(int type, int c)
|
||||||
{
|
{
|
||||||
if(type == SENSORS_ACTIVE) {
|
if(type == SENSORS_ACTIVE) {
|
||||||
simButtonIsActive = c;
|
simButtonIsActive = c;
|
||||||
|
return 1;
|
||||||
} else if(type == SENSORS_HW_INIT) {
|
} else if(type == SENSORS_HW_INIT) {
|
||||||
simButtonIsActive = 1;
|
simButtonIsActive = 1;
|
||||||
timer_set(&debouncetimer, 0);
|
timer_set(&debouncetimer, 0);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,10 +26,9 @@
|
||||||
* 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: pir-sensor.c,v 1.1 2006/08/21 12:11:18 fros4943 Exp $
|
* $Id: pir-sensor.c,v 1.2 2010/01/14 19:12:31 nifi Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lib/sensors.h"
|
|
||||||
#include "dev/pir-sensor.h"
|
#include "dev/pir-sensor.h"
|
||||||
#include "lib/simEnvChange.h"
|
#include "lib/simEnvChange.h"
|
||||||
|
|
||||||
|
@ -41,53 +40,36 @@ char simPirChanged;
|
||||||
char simPirIsActive;
|
char simPirIsActive;
|
||||||
char simPirValue = 0;
|
char simPirValue = 0;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
init(void)
|
|
||||||
{
|
|
||||||
simPirIsActive = 1;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
irq(void)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
activate(void)
|
|
||||||
{
|
|
||||||
simPirIsActive = 1;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
deactivate(void)
|
|
||||||
{
|
|
||||||
simPirIsActive = 0;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static int
|
|
||||||
active(void)
|
|
||||||
{
|
|
||||||
return simPirIsActive;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static unsigned int
|
|
||||||
value(int type)
|
value(int type)
|
||||||
{
|
{
|
||||||
return simPirValue;
|
return simPirValue;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
configure(int type, void *c)
|
configure(int type, int c)
|
||||||
{
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_HW_INIT:
|
||||||
|
simPirIsActive = 0;
|
||||||
|
return 1;
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
simPirIsActive = c;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void *
|
static int
|
||||||
status(int type)
|
status(int type)
|
||||||
{
|
{
|
||||||
return NULL;
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return simPirIsActive;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
|
@ -95,7 +77,7 @@ doInterfaceActionsBeforeTick(void)
|
||||||
{
|
{
|
||||||
// Check if PIR value has changed
|
// Check if PIR value has changed
|
||||||
if (simPirIsActive && simPirChanged) {
|
if (simPirIsActive && simPirChanged) {
|
||||||
simPirValue = !simPirValue;
|
simPirValue++;
|
||||||
|
|
||||||
sensors_changed(&pir_sensor);
|
sensors_changed(&pir_sensor);
|
||||||
simPirChanged = 0;
|
simPirChanged = 0;
|
||||||
|
@ -113,5 +95,4 @@ SIM_INTERFACE(pir_interface,
|
||||||
doInterfaceActionsAfterTick);
|
doInterfaceActionsAfterTick);
|
||||||
|
|
||||||
SENSORS_SENSOR(pir_sensor, PIR_SENSOR,
|
SENSORS_SENSOR(pir_sensor, PIR_SENSOR,
|
||||||
init, irq, activate, deactivate, active,
|
|
||||||
value, configure, status);
|
value, configure, status);
|
||||||
|
|
|
@ -26,12 +26,14 @@
|
||||||
* 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: pir-sensor.h,v 1.1 2006/08/21 12:11:19 fros4943 Exp $
|
* $Id: pir-sensor.h,v 1.2 2010/01/14 19:12:31 nifi Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __PIR_H__
|
#ifndef __PIR_H__
|
||||||
#define __PIR_H__
|
#define __PIR_H__
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
|
||||||
extern const struct sensors_sensor pir_sensor;
|
extern const struct sensors_sensor pir_sensor;
|
||||||
|
|
||||||
#define PIR_SENSOR "PIR"
|
#define PIR_SENSOR "PIR"
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* @(#)$Id: radio-sensor.c,v 1.3 2007/05/29 12:27:00 fros4943 Exp $
|
* @(#)$Id: radio-sensor.c,v 1.4 2010/01/14 19:12:31 nifi Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lib/sensors.h"
|
#include "lib/sensors.h"
|
||||||
|
@ -40,54 +40,29 @@ const struct sensors_sensor radio_sensor;
|
||||||
|
|
||||||
extern int simSignalStrength;
|
extern int simSignalStrength;
|
||||||
|
|
||||||
// COOJA variables (none - no corresponding part in Java)
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
init(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
irq(void)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
activate(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
deactivate(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static int
|
|
||||||
active(void)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static unsigned int
|
|
||||||
value(int type)
|
value(int type)
|
||||||
{
|
{
|
||||||
return simSignalStrength;
|
return simSignalStrength;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
configure(int type, void *c)
|
configure(int type, int c)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void *
|
static int
|
||||||
status(int type)
|
status(int type)
|
||||||
{
|
{
|
||||||
return NULL;
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
SENSORS_SENSOR(radio_sensor, RADIO_SENSOR,
|
SENSORS_SENSOR(radio_sensor, RADIO_SENSOR,
|
||||||
init, irq, activate, deactivate, active,
|
|
||||||
value, configure, status);
|
value, configure, status);
|
||||||
|
|
|
@ -26,10 +26,9 @@
|
||||||
* 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: vib-sensor.c,v 1.1 2006/08/21 12:11:18 fros4943 Exp $
|
* $Id: vib-sensor.c,v 1.2 2010/01/14 19:12:31 nifi Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lib/sensors.h"
|
|
||||||
#include "dev/vib-sensor.h"
|
#include "dev/vib-sensor.h"
|
||||||
#include "lib/simEnvChange.h"
|
#include "lib/simEnvChange.h"
|
||||||
|
|
||||||
|
@ -41,53 +40,36 @@ char simVibChanged;
|
||||||
char simVibIsActive;
|
char simVibIsActive;
|
||||||
char simVibValue = 0;
|
char simVibValue = 0;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
init(void)
|
|
||||||
{
|
|
||||||
simVibIsActive = 1;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
irq(void)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
activate(void)
|
|
||||||
{
|
|
||||||
simVibIsActive = 1;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
deactivate(void)
|
|
||||||
{
|
|
||||||
simVibIsActive = 0;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static int
|
|
||||||
active(void)
|
|
||||||
{
|
|
||||||
return simVibIsActive;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static unsigned int
|
|
||||||
value(int type)
|
value(int type)
|
||||||
{
|
{
|
||||||
return simVibValue;
|
return simVibValue;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
configure(int type, void *c)
|
configure(int type, int c)
|
||||||
{
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_HW_INIT:
|
||||||
|
simVibIsActive = 0;
|
||||||
|
return 1;
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
simVibIsActive = c;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void *
|
static int
|
||||||
status(int type)
|
status(int type)
|
||||||
{
|
{
|
||||||
return NULL;
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return simVibIsActive;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
|
@ -95,7 +77,7 @@ doInterfaceActionsBeforeTick(void)
|
||||||
{
|
{
|
||||||
// Check if Vib value has changed
|
// Check if Vib value has changed
|
||||||
if (simVibIsActive && simVibChanged) {
|
if (simVibIsActive && simVibChanged) {
|
||||||
simVibValue = !simVibValue;
|
simVibValue++;
|
||||||
|
|
||||||
sensors_changed(&vib_sensor);
|
sensors_changed(&vib_sensor);
|
||||||
simVibChanged = 0;
|
simVibChanged = 0;
|
||||||
|
@ -113,5 +95,4 @@ SIM_INTERFACE(vib_interface,
|
||||||
doInterfaceActionsAfterTick);
|
doInterfaceActionsAfterTick);
|
||||||
|
|
||||||
SENSORS_SENSOR(vib_sensor, VIB_SENSOR,
|
SENSORS_SENSOR(vib_sensor, VIB_SENSOR,
|
||||||
init, irq, activate, deactivate, active,
|
|
||||||
value, configure, status);
|
value, configure, status);
|
||||||
|
|
|
@ -26,12 +26,14 @@
|
||||||
* 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: vib-sensor.h,v 1.1 2006/08/21 12:11:18 fros4943 Exp $
|
* $Id: vib-sensor.h,v 1.2 2010/01/14 19:12:31 nifi Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __VIB_H__
|
#ifndef __VIB_H__
|
||||||
#define __VIB_H__
|
#define __VIB_H__
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
|
||||||
extern const struct sensors_sensor vib_sensor;
|
extern const struct sensors_sensor vib_sensor;
|
||||||
|
|
||||||
#define VIB_SENSOR "Vibration sensor"
|
#define VIB_SENSOR "Vibration sensor"
|
||||||
|
|
Loading…
Reference in a new issue