Red Hat Summit 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
Revision 30:cab9f0800471, committed 2014-04-28
- Comitter:
- sam_grove
- Date:
- Mon Apr 28 23:49:50 2014 +0000
- Parent:
- 27:d898b3a8c769
- Commit message:
- Updates to mbed house as sent for the show
Changed in this revision
--- a/main.cpp Sun Apr 27 17:03:22 2014 +0000 +++ b/main.cpp Mon Apr 28 23:49:50 2014 +0000 @@ -9,6 +9,7 @@ #include "gps.h" #include "relay.h" #include "rgb.h" +#include "input.h" static C12832_LCD lcd; Serial pc(USBTX, USBRX); // tx, rx @@ -139,6 +140,7 @@ create_temperature_resource(resource_ptr); create_light_resource(resource_ptr); create_gps_resource(resource_ptr); + create_input_resource(resource_ptr); //create_relay_resource(resource_ptr); #ifdef USE_RGBLED
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/resources/input.cpp Mon Apr 28 23:49:50 2014 +0000 @@ -0,0 +1,46 @@ +// Light resource implementation + +#include "mbed.h" +#include "nsdl_support.h" +#include "input.h" + +#define INPUT_RES_ID "/200/0/5502" + +extern Serial pc; +static InterruptIn in1(p9); +static DigitalOut out1(p22); + +static void inputHandler(void) +{ + out1 = !in1; +} + + +/* Only GET and PUT method allowed */ +static uint8_t input_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; + uint8_t input_state = (in1.read() > 0) ? '0' : '1'; + + pc.printf("input callback\r\n"); + + coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); + + coap_res_ptr->payload_len = 1; + coap_res_ptr->payload_ptr = &input_state; + sn_nsdl_send_coap_message(address, coap_res_ptr); + + sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); + return 0; +} + +int create_input_resource(sn_nsdl_resource_info_s *resource_ptr) +{ + nsdl_create_dynamic_resource(resource_ptr, sizeof(INPUT_RES_ID)-1, (uint8_t*)INPUT_RES_ID, 0, 0, 0, &input_resource_cb, SN_GRS_GET_ALLOWED); + + in1.mode(PullUp); + in1.fall(&inputHandler); + in1.rise(&inputHandler); + out1 = !in1; + return 0; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/resources/input.h Mon Apr 28 23:49:50 2014 +0000 @@ -0,0 +1,10 @@ +// Input resource implementation + +#ifndef INPUT_H +#define INPUT_H + +#include "nsdl_support.h" + +int create_input_resource(sn_nsdl_resource_info_s *resource_ptr); + +#endif
--- a/resources/light.cpp Sun Apr 27 17:03:22 2014 +0000 +++ b/resources/light.cpp Mon Apr 28 23:49:50 2014 +0000 @@ -7,7 +7,7 @@ #define LIGHT_RES_ID "311/0/5851" extern Serial pc; -static PwmOut led2(LED2); +static PwmOut led2(p21); static PwmOut led3(LED3);