More advanced NanoService Demo for LPC1768 App Board using OMA Lightweight Objects

Dependencies:   Beep C12832_lcd EthernetInterface LM75B MMA7660 mbed-rtos mbed nsdl_lib

Fork of LWM2M_NanoService_Ethernet by MBED_DEMOS

Files at this revision

API Documentation at this revision

Comitter:
sstark
Date:
Tue Apr 08 01:02:06 2014 +0000
Parent:
19:e5c0b6553c11
Commit message:
Properly use the RGB_LED define to exclude the creation of the RGB resource, and encapsulate the RGB PwmOut object in an RBG class to avoid having the pins activated when they were initialized statically.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
resources/rgb.cpp Show annotated file Show diff for this revision Revisions of this file
resources/rgb.h Show annotated file Show diff for this revision Revisions of this file
resources/temperature.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e5c0b6553c11 -r 84ee332ba360 main.cpp
--- a/main.cpp	Sun Apr 06 20:11:46 2014 +0000
+++ b/main.cpp	Tue Apr 08 01:02:06 2014 +0000
@@ -20,8 +20,8 @@
 /* Define this to enable DHCP, otherwise manual address configuration is used */
 #define DHCP 1
 
-// Change this to 1 to enable the RGB LED resource
-#define USE_RGBLED 0
+// Define this to enable the RGB LED resource
+//#define USE_RGBLED 1
 
 /* Manual IP configurations, if DHCP not defined */
 #define IP      "10.45.0.206"
@@ -140,13 +140,15 @@
     create_light_resource(resource_ptr);
     create_gps_resource(resource_ptr);
     create_relay_resource(resource_ptr);
+
 #ifdef USE_RGBLED
+    NSDL_DEBUG("Enabling RGB LED due to USE_RGBLED=%d\n", USE_RGBLED);
     create_rgb_resource(resource_ptr);
 #else
     NSDL_DEBUG("Skipped RGB LED resource, change USE_RGBLED to 1 in main.cpp to test");
 #endif
 
-        /* Register with NSP */
+    /* Register with NSP */
     endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr);
     if(sn_nsdl_register_endpoint(endpoint_ptr) != 0)
         pc.printf("NSP registering failed\r\n");
diff -r e5c0b6553c11 -r 84ee332ba360 resources/rgb.cpp
--- a/resources/rgb.cpp	Sun Apr 06 20:11:46 2014 +0000
+++ b/resources/rgb.cpp	Tue Apr 08 01:02:06 2014 +0000
@@ -8,11 +8,36 @@
 #define RGB_UNITS_RES_ID    "308/0/5701"
 
 extern Serial pc;
-static PwmOut rout(p23);
-static PwmOut gout(p24);
-static PwmOut bout(p25);
+
 static int rgb[] = {0, 0, 0};
 
+class RGB {
+public:
+    RGB();
+    void show(float r, float g, float b);
+
+private:
+    PwmOut rout;
+    PwmOut gout;
+    PwmOut bout;
+};
+RGB::RGB() : rout(p23), gout(p24), bout(p25) {
+    pc.printf("RGB.ctor()\r\n");
+    rout.period(0.001);
+    gout.period(0.001);
+    bout.period(0.001);
+}
+
+/*
+The RGB LED is common anode, so that "0" is on, and "1" is off. For PWM, the closer to 0.0 the brighter, the closer to 1.0 the dimmer. 
+This method uses (1.0 - rgb value) to invert.
+*/
+void RGB::show(float r, float g, float b) {
+    rout = 1 - r;
+    gout = 1 - g;
+    bout = 1 - b;
+}
+
 /*
 Convert the r|g|b string into the integer parts, each in the range [0,255]
 */
@@ -40,13 +65,12 @@
 */
 static void setRGB()
 {
+    static RGB rgbLed;
     pc.printf("Changing to RGB(%d,%d,%d)\r\n", rgb[0], rgb[1], rgb[2]);
     float r = rgb[0] * RGB_SCALE;
     float g = rgb[1] * RGB_SCALE;
     float b = rgb[2] * RGB_SCALE;
-    rout = 1 - r;
-    gout = 1 - g;
-    bout = 1 - b;
+    rgbLed.show(r, g, b);
 }
     
 /* Only GET and PUT method allowed */
@@ -89,4 +113,9 @@
     nsdl_create_static_resource(resource_ptr, sizeof(RGB_UNITS_RES_ID)-1, (uint8_t*) RGB_UNITS_RES_ID, 0, 0,  (uint8_t*) "(R|G|B)0-255", sizeof("(R|G|B)0-255")-1);
     setRGB();
     return 0;
-}
\ No newline at end of file
+}
+void zero_rgb()
+{
+    memset(rgb, 0, sizeof(rgb));
+    setRGB();
+}
diff -r e5c0b6553c11 -r 84ee332ba360 resources/rgb.h
--- a/resources/rgb.h	Sun Apr 06 20:11:46 2014 +0000
+++ b/resources/rgb.h	Tue Apr 08 01:02:06 2014 +0000
@@ -6,5 +6,6 @@
 #include "nsdl_support.h"
 
 int create_rgb_resource(sn_nsdl_resource_info_s *resource_ptr);
+void zero_rgb();
 
 #endif
diff -r e5c0b6553c11 -r 84ee332ba360 resources/temperature.cpp
--- a/resources/temperature.cpp	Sun Apr 06 20:11:46 2014 +0000
+++ b/resources/temperature.cpp	Tue Apr 08 01:02:06 2014 +0000
@@ -33,7 +33,7 @@
             if(sn_nsdl_send_observation_notification(obs_token_ptr, obs_token_len, (uint8_t*)temp_val, 5, &obs_number, 1, COAP_MSG_TYPE_NON_CONFIRMABLE, 0) == 0)
                 pc.printf("Observation sending failed\r\n");
             else
-                pc.printf("Observation\r\n");
+                pc.printf("Observation, temp=%s\r\n", temp_val);
         }
     }
 }