36 #include "lib/sensors.h" 37 #include "button-sensor.h" 38 #include <AppHardwareApi.h> 46 #define PRINTF(...) printf(__VA_ARGS__) 53 #if SENSOR_BOARD_DR1199 63 #define APP_PORT_BUTTON_SW0 (8) 64 #if SENSOR_BOARD_DR1199 65 #define APP_PORT_BUTTON_SW1 (11) 66 #define APP_PORT_BUTTON_SW2 (12) 67 #define APP_PORT_BUTTON_SW3 (17) 68 #define APP_PORT_BUTTON_SW4 (1) 72 #if SENSOR_BOARD_DR1199 73 #define APP_BUTTONS_DIO_MASK ((1 << APP_PORT_BUTTON_SW0) | \ 74 (1 << APP_PORT_BUTTON_SW1) | \ 75 (1 << APP_PORT_BUTTON_SW2) | \ 76 (1 << APP_PORT_BUTTON_SW3) | \ 77 (1 << APP_PORT_BUTTON_SW4)) 79 #define APP_BUTTONS_DIO_MASK (1 << APP_PORT_BUTTON_SW0) 82 #define KEY_SAMPLE_TIME (CLOCK_SECOND / 20) 85 BUTTONS_STATUS_NOT_INIT = 0,
87 BUTTONS_STATUS_NOT_ACTIVE = BUTTONS_STATUS_INIT,
95 volatile static buttons_status_t buttons_status = BUTTONS_STATUS_NOT_INIT;
96 static int key_value = 0;
97 static uint8 key_map[] = { APP_PORT_BUTTON_SW0,
98 #if SENSOR_BOARD_DR1199 109 PROCESS(key_sampling,
"Key sample");
110 static int get_key_value(
void);
116 configure(
int type,
int value)
118 if(type == SENSORS_HW_INIT) {
121 vAHI_DioSetDirection(APP_BUTTONS_DIO_MASK, 0);
123 vAHI_DioSetPullup(APP_BUTTONS_DIO_MASK, 0);
124 PRINTF(
"HW_INIT BUTTONS (0x%x)\n", APP_BUTTONS_DIO_MASK);
126 buttons_status = BUTTONS_STATUS_INIT;
129 }
else if(type == SENSORS_ACTIVE) {
130 if(buttons_status != BUTTONS_STATUS_NOT_INIT) {
133 PRINTF(
"BUTTONS ACTIVATED\n");
134 buttons_status = BUTTONS_STATUS_ACTIVE;
137 PRINTF(
"BUTTONS DE-ACTIVATED\n");
138 buttons_status = BUTTONS_STATUS_NOT_ACTIVE;
140 process_post(&key_sampling, PROCESS_EVENT_MSG, (
void *)&buttons_status);
144 PRINTF(
"ERROR: NO HW_INIT BUTTONS\n");
156 if(type == SENSORS_ACTIVE) {
157 return buttons_status == BUTTONS_STATUS_ACTIVE;
158 }
else if(type == SENSORS_READY) {
159 return buttons_status != BUTTONS_STATUS_NOT_INIT;
178 int io_value = ~u32AHI_DioReadInput() & APP_BUTTONS_DIO_MASK;
182 while(k < APP_E_BUTTON_NUM) {
183 if(io_value & (1 << key_map[k])) {
196 static int previous_key_value = 0;
197 static char debounce_check = 0;
198 int current_key_value;
203 if(ev == PROCESS_EVENT_TIMER) {
205 PRINTF(
"Key sample\n");
206 current_key_value = get_key_value();
207 if(debounce_check != 0) {
209 if(previous_key_value == current_key_value) {
211 key_value = current_key_value;
215 previous_key_value = current_key_value;
219 if(current_key_value != previous_key_value) {
220 previous_key_value = current_key_value;
226 if(*(buttons_status_t *)data == BUTTONS_STATUS_NOT_ACTIVE) {
229 }
else if((*(buttons_status_t *)data == BUTTONS_STATUS_ACTIVE)) {
SENSORS & button_sensor
Exports global symbols for the sensor API.
#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.