Demo project for IoT World Hackathon
Dependencies: Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork
mbedEndpointResources/LightResource.h
- Committer:
- michaeljkoster
- Date:
- 2015-05-12
- Revision:
- 0:a9025db1ac76
File content as of revision 0:a9025db1ac76:
/** * @file LightResource.h * @brief mbed CoAP Endpoint Light resource supporting CoAP GET and PUT * @author Doug Anson, Michael Koster * @version 1.0 * @see * * Copyright (c) 2014 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __LIGHT_RESOURCE_H__ #define __LIGHT_RESOURCE_H__ // Base class #include "DynamicResource.h" // our Light #include "ChainableLED.h" #define LED_COUNT 1 ChainableLED led_chain(D3, D4, LED_COUNT); static char * led_value = {"00000"}; //RRGGBB void set_led_array(char * color_string) { int color_int; sscanf(color_string, "%X", &color_int); led_chain.setColorRGB(0, (color_int >> 16 & 255), (color_int >> 8 & 255), (color_int & 255) ); } /** LightResource class */ class LightResource : public DynamicResource { public: /** Default constructor @param logger input logger instance for this resource @param name input the Light resource name @param observable input the resource is Observable (default: FALSE) */ LightResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Light",SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED,observable) { set_led_array("000000"); wait(0.5); set_led_array("FF0000"); wait(0.5); set_led_array("00FF00"); wait(0.5); set_led_array("0000FF"); wait(0.5); set_led_array(led_value); } /** Get the value of the Light @returns string containing either "0" (light off) or "1" (light on) */ virtual string get() { return(led_value); } /** Set the value of the Light @param string input the string containing "0" (light off) or "1" (light on) */ virtual void put(const string value) { if( sizeof(value) == sizeof(led_value) ){ led_value = (char *)value.c_str(); set_led_array(led_value); } } }; #endif // __LIGHT_RESOURCE_H__