36 #include "lib/sensors.h" 37 #include "pot-sensor.h" 39 #include <GenericBoard.h> 47 #define PRINTF(...) printf(__VA_ARGS__) 53 POT_STATUS_NOT_INIT = 0,
55 POT_STATUS_NOT_ACTIVE = POT_STATUS_INIT,
60 #define DELTA_POT_VALUE 1 65 const struct sensors_sensor pot_sensor;
66 volatile static pot_status_t pot_status = POT_STATUS_NOT_INIT;
67 static int prev_pot_event_val = 0;
68 static int pot_value = 0;
79 configure(
int type,
int value)
81 if(type == SENSORS_HW_INIT) {
82 pot_status = POT_STATUS_INIT;
86 }
else if(type == SENSORS_ACTIVE) {
87 if(pot_status != POT_STATUS_NOT_INIT) {
91 prev_pot_event_val = 0;
93 PRINTF(
"POT ACTIVATED\n");
94 pot_status = POT_STATUS_ACTIVE;
95 process_post(&POTSampling, PROCESS_EVENT_MSG, (
void *)&pot_status);
99 PRINTF(
"POT DE-ACTIVATED\n");
100 pot_status = POT_STATUS_NOT_ACTIVE;
101 process_post(&POTSampling, PROCESS_EVENT_MSG, (
void *)&pot_status);
107 PRINTF(
"ERROR: NO HW_INIT POT\n");
119 if(type == SENSORS_ACTIVE) {
120 return pot_status == POT_STATUS_ACTIVE;
121 }
else if(type == SENSORS_READY) {
122 return pot_status != POT_STATUS_NOT_INIT;
148 if(ev == PROCESS_EVENT_TIMER) {
150 PRINTF(
"POT sample\n");
151 pot_value = u16ReadPotValue();
152 PRINTF(
"POT = %d\n", pot_value);
153 if(abs(pot_value - prev_pot_event_val) > DELTA_POT_VALUE) {
154 prev_pot_event_val = pot_value;
155 sensors_changed(&pot_sensor);
160 if(*(
int *)data == POT_STATUS_NOT_ACTIVE) {
163 }
else if((*(
int *)data == POT_STATUS_ACTIVE)) {
174 SENSORS_SENSOR(pot_sensor, POT_SENSOR, value, configure, status);
#define PROCESS(name, strname)
Declare a process.
void etimer_stop(struct etimer *et)
Stop a pending event timer.
void etimer_restart(struct etimer *et)
Restart an event timer from the current point in time.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define PROCESS_END()
Define the end of a process.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
#define CLOCK_SECOND
A second, measured in system clock time.
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
void etimer_reset(struct etimer *et)
Reset an event timer with the same interval as was previously set.
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
void process_start(struct process *p, process_data_t data)
Start a process.