From a1b9ba26309367bb9b53070423c07d52916177bb Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 25 Feb 2018 21:40:19 +0000 Subject: [PATCH] Migrate to LED HAL (IPSO Objects) --- examples/ipso-objects/example-ipso-objects.c | 5 +++-- os/services/ipso-objects/ipso-leds-control.c | 6 +++++- os/services/ipso-objects/ipso-objects.c | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/ipso-objects/example-ipso-objects.c b/examples/ipso-objects/example-ipso-objects.c index aa565603b..013c62205 100644 --- a/examples/ipso-objects/example-ipso-objects.c +++ b/examples/ipso-objects/example-ipso-objects.c @@ -46,6 +46,7 @@ #include "services/ipso-objects/ipso-objects.h" #include "services/ipso-objects/ipso-sensor-template.h" #include "services/ipso-objects/ipso-control-template.h" +#include "dev/leds.h" #define DEBUG DEBUG_NONE #include "net/ipv6/uip-debug.h" @@ -98,9 +99,9 @@ static lwm2m_status_t leds_set_val(ipso_control_t *control, uint8_t value) { if(value > 0) { - leds_on(LEDS_YELLOW); + leds_single_on(LEDS_LED1); } else { - leds_off(LEDS_YELLOW); + leds_single_off(LEDS_LED1); } return LWM2M_STATUS_OK; } diff --git a/os/services/ipso-objects/ipso-leds-control.c b/os/services/ipso-objects/ipso-leds-control.c index 8cfbdac41..2c64da328 100644 --- a/os/services/ipso-objects/ipso-leds-control.c +++ b/os/services/ipso-objects/ipso-leds-control.c @@ -56,11 +56,15 @@ #define PRINTF(...) #endif +#if LEDS_LEGACY_API #if LEDS_ALL & LEDS_BLUE || LEDS_ALL & LEDS_RED || LEDS_ALL & LEDS_BLUE #define LEDS_CONTROL_NUMBER (((LEDS_ALL & LEDS_BLUE) ? 1 : 0) + ((LEDS_ALL & LEDS_RED) ? 1 : 0) + ((LEDS_ALL & LEDS_GREEN) ? 1 : 0)) #else #define LEDS_CONTROL_NUMBER 1 #endif +#else /* LEDS_LEGACY_API */ +#define LEDS_CONTROL_NUMBER LEDS_COUNT +#endif /* LEDS_LEGACY_API */ typedef struct led_state { ipso_control_t control; @@ -72,7 +76,7 @@ static led_state_t leds_controls[LEDS_CONTROL_NUMBER]; static lwm2m_status_t set_value(ipso_control_t *control, uint8_t value) { -#if PLATFORM_HAS_LEDS +#if PLATFORM_HAS_LEDS || LEDS_COUNT led_state_t *state; state = (led_state_t *)control; diff --git a/os/services/ipso-objects/ipso-objects.c b/os/services/ipso-objects/ipso-objects.c index b1138ca09..f8538ee43 100644 --- a/os/services/ipso-objects/ipso-objects.c +++ b/os/services/ipso-objects/ipso-objects.c @@ -42,6 +42,7 @@ */ #include "contiki.h" +#include "dev/leds.h" #include "ipso-objects.h" /*---------------------------------------------------------------------------*/ void @@ -58,7 +59,7 @@ ipso_objects_init(void) #ifdef IPSO_LIGHT_CONTROL ipso_light_control_init(); -#elif PLATFORM_HAS_LEDS +#elif PLATFORM_HAS_LEDS || LEDS_COUNT ipso_leds_control_init(); #endif }