Change Zoul examples to use the button HAL

This commit is contained in:
George Oikonomou 2017-11-05 22:09:48 +00:00
parent a5ea8d44e9
commit 0445275825
2 changed files with 13 additions and 21 deletions

View File

@ -34,7 +34,7 @@
#include "ipv6/ip64-addr.h" #include "ipv6/ip64-addr.h"
#include "dev/leds.h" #include "dev/leds.h"
#include "net/routing/routing.h" #include "net/routing/routing.h"
#include "dev/button-sensor.h" #include "dev/button-hal.h"
#include <stdio.h> #include <stdio.h>
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static struct http_socket s; static struct http_socket s;
@ -138,15 +138,12 @@ PROCESS_THREAD(http_example_process, ev, data)
while(1) { while(1) {
PROCESS_YIELD(); PROCESS_YIELD();
if((ev == sensors_event) && (data == &button_sensor)) { if(ev == button_hal_release_event) {
if(button_sensor.value(BUTTON_SENSOR_VALUE_TYPE_LEVEL) ==
BUTTON_SENSOR_PRESSED_LEVEL) {
leds_on(LEDS_GREEN); leds_on(LEDS_GREEN);
printf("Button pressed! sending a POST to IFTTT\n"); printf("Button pressed! sending a POST to IFTTT\n");
http_socket_post(&s, url_buffer, NULL, 0, NULL, callback, NULL); http_socket_post(&s, url_buffer, NULL, 0, NULL, callback, NULL);
} }
} }
}
PROCESS_END(); PROCESS_END();
} }

View File

@ -47,7 +47,7 @@
#include <stdio.h> #include <stdio.h>
#include "contiki.h" #include "contiki.h"
#include "dev/rgb-bl-lcd.h" #include "dev/rgb-bl-lcd.h"
#include "dev/button-sensor.h" #include "dev/button-hal.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define SCROLL_PERIOD (CLOCK_SECOND / 6) #define SCROLL_PERIOD (CLOCK_SECOND / 6)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -104,20 +104,15 @@ PROCESS_THREAD(remote_lcd_process, ev, data)
printf("Counter: %05u\n", counter); printf("Counter: %05u\n", counter);
counter++; counter++;
etimer_restart(&et); etimer_restart(&et);
} else if(ev == sensors_event) { } else if(ev == button_hal_press_event) {
if(data == &button_sensor) {
if(button_sensor.value(BUTTON_SENSOR_VALUE_TYPE_LEVEL) ==
BUTTON_SENSOR_PRESSED_LEVEL) {
printf("Button pressed!!\n"); printf("Button pressed!!\n");
lcd_set_cursor(0, LCD_RGB_1ST_ROW); lcd_set_cursor(0, LCD_RGB_1ST_ROW);
lcd_write("Button pressed!!"); lcd_write("Button pressed!!");
} else { } else if(ev == button_hal_release_event) {
lcd_set_cursor(0, LCD_RGB_1ST_ROW); lcd_set_cursor(0, LCD_RGB_1ST_ROW);
lcd_write("Press the button!"); lcd_write("Press the button!");
} }
} }
}
}
PROCESS_END(); PROCESS_END();
} }