Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface PololuLedStripx mbed-rtos mbed nanoservice_client_1_12_X
Fork of LPC1768_LWM2M_Client by
Revision 2:4166c3e5b321, committed 2014-09-27
- Comitter:
- michaeljkoster
- Date:
- Sat Sep 27 23:58:43 2014 +0000
- Parent:
- 1:09a525977925
- Child:
- 3:e3aa908cbb51
- Commit message:
- Added LED control
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PololuLedStrip.lib Sat Sep 27 23:58:43 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/DavidEGrayson/code/PololuLedStrip/#77e743378104
--- a/main.cpp Sat Sep 27 21:53:28 2014 +0000
+++ b/main.cpp Sat Sep 27 23:58:43 2014 +0000
@@ -5,6 +5,12 @@
// Include resources
#include "light.h"
+#include "PololuLedStrip.h"
+PololuLedStrip ledStrip(P0_4);
+#define LED_COUNT 60
+//#define LED_COUNT 120
+rgb_color colors[LED_COUNT];
+
Serial pc(USBTX, USBRX); // tx, rx
// ****************************************************************************
@@ -95,8 +101,8 @@
memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s));
// Static resources
- nsdl_create_static_resource(resource_ptr, sizeof("dev/mfg")-1, (uint8_t*) "dev/mfg", 0, 0, (uint8_t*) "Sensinode", sizeof("Sensinode")-1);
- nsdl_create_static_resource(resource_ptr, sizeof("dev/mdl")-1, (uint8_t*) "dev/mdl", 0, 0, (uint8_t*) "NSDL-C mbed device", sizeof("NSDL-C mbed device")-1);
+ nsdl_create_static_resource(resource_ptr, sizeof("dev/mfg")-1, (uint8_t*) "dev/mfg", 0, 0, (uint8_t*) "ARMDEMO", sizeof("ARMDEMO")-1);
+ nsdl_create_static_resource(resource_ptr, sizeof("dev/mdl")-1, (uint8_t*) "dev/mdl", 0, 0, (uint8_t*) "LED-STRIP", sizeof("LED-STRIP")-1);
// Dynamic resources
create_light_resource(resource_ptr);
@@ -114,11 +120,47 @@
return 1;
}
+void set_led_color(char *color_string)
+{
+static uint8_t red, green, blue, index ;
+int color_int ;
+int num ;
+
+ //pc.printf("set_led_color: %s\r\n", color_string);
+ // convert string to uint8 tuple
+ num = sscanf(color_string, "%X", &color_int);
+ //pc.printf("color_int: %d %x\r\n", num, color_int);
+
+ index = color_int & 255;
+ blue = color_int >> 8 & 255;
+ green = color_int >> 16 & 255;
+ red = color_int >> 24 & 255;
+
+ //pc.printf("index: %x\r\n", index);
+ //pc.printf("red: %x\r\n", red);
+ //pc.printf("green: %x\r\n", green);
+ //pc.printf("blue: %x\r\n", blue);
+
+ if(index > 0 and index <= LED_COUNT)
+ {
+ colors[index-1] = (rgb_color) {red,green,blue} ;
+ ledStrip.write(colors, LED_COUNT);
+ }
+ else if(index == 0)
+ {
+ for(int i = 0; i < LED_COUNT; i++)
+ colors[i] = (rgb_color) {red,green,blue} ;
+ ledStrip.write(colors, LED_COUNT);
+ }
+}
+
+
// ****************************************************************************
// Program entry point
int main()
{
+
NSDL_DEBUG("mbed NanoService Example App 0.1\n");
// Initialize Ethernet interface first
--- a/resources/light.cpp Sat Sep 27 21:53:28 2014 +0000
+++ b/resources/light.cpp Sat Sep 27 23:58:43 2014 +0000
@@ -9,12 +9,14 @@
extern Serial pc;
char led_color[] = {"00000000"};
+extern void set_led_color(char* led_color);
+
/* Only GET and PUT method allowed */
static uint8_t light_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto)
{
sn_coap_hdr_s *coap_res_ptr = 0;
- pc.printf("LED Strip callback\r\n");
+ //pc.printf("LED Strip callback\r\n");
if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET)
{
@@ -26,7 +28,7 @@
}
else if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT)
{
- pc.printf("PUT: %d bytes\r\n", received_coap_ptr->payload_len);
+ //pc.printf("PUT: %d bytes\r\n", received_coap_ptr->payload_len);
if(received_coap_ptr->payload_len == 8)
{
memcpy(led_color, (char *)received_coap_ptr->payload_ptr, received_coap_ptr->payload_len);
@@ -35,6 +37,7 @@
pc.printf("PUT: %s\r\n",led_color);
//call LED strup update function here
+ set_led_color(led_color);
coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED);
sn_nsdl_send_coap_message(address, coap_res_ptr);
