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: Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork
Fork of IoT_LED_demo by
LightResource.h
00001 /** 00002 * @file LightResource.h 00003 * @brief mbed CoAP Endpoint Light resource supporting CoAP GET and PUT 00004 * @author Doug Anson, Michael Koster 00005 * @version 1.0 00006 * @see 00007 * 00008 * Copyright (c) 2014 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); 00011 * you may not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, 00018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 */ 00022 00023 #ifndef __LIGHT_RESOURCE_H__ 00024 #define __LIGHT_RESOURCE_H__ 00025 00026 00027 // Base class 00028 #include "DynamicResource.h" 00029 00030 // our Light 00031 #include "ChainableLED.h" 00032 #define LED_COUNT 1 00033 00034 ChainableLED led_chain(D4, D5, LED_COUNT); 00035 00036 static char * led_value = {"0000000"}; //RRGGBBII 00037 00038 void set_led_array(char * color_string) 00039 { 00040 static uint8_t red, green, blue, index; 00041 int color_int; 00042 00043 sscanf(color_string, "%X", &color_int); 00044 00045 index = color_int & 255; 00046 blue = color_int >> 8 & 255; 00047 green = color_int >> 16 & 255; 00048 red = color_int >> 24 & 255; 00049 00050 if(index > 0 and index <= LED_COUNT) { 00051 led_chain.setColorRGB(index-1, red, green, blue); 00052 } 00053 else if(index == 0){ 00054 for(int i = 0; i < LED_COUNT; i++){ 00055 led_chain.setColorRGB(i, red, green, blue); 00056 } 00057 } 00058 } 00059 00060 /** LightResource class 00061 */ 00062 class LightResource : public DynamicResource 00063 { 00064 00065 public: 00066 /** 00067 Default constructor 00068 @param logger input logger instance for this resource 00069 @param name input the Light resource name 00070 @param observable input the resource is Observable (default: FALSE) 00071 */ 00072 LightResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Light",SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED,observable) { 00073 set_led_array("00000000"); 00074 wait(0.5); 00075 set_led_array("FF000000"); 00076 wait(0.5); 00077 set_led_array("00FF0000"); 00078 wait(0.5); 00079 set_led_array("0000FF00"); 00080 wait(0.5); 00081 set_led_array(led_value); 00082 } 00083 00084 /** 00085 Get the value of the Light 00086 @returns string containing either "0" (light off) or "1" (light on) 00087 */ 00088 virtual string get() { 00089 return(led_value); 00090 } 00091 00092 /** 00093 Set the value of the Light 00094 @param string input the string containing "0" (light off) or "1" (light on) 00095 */ 00096 virtual void put(const string value) { 00097 if( sizeof(value) == sizeof(led_value) ){ 00098 led_value = (char *)value.c_str(); 00099 set_led_array(led_value); 00100 } 00101 } 00102 }; 00103 00104 #endif // __LIGHT_RESOURCE_H__
Generated on Tue Jul 12 2022 20:37:45 by
1.7.2
