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 DHT LED_Bar mbed mbedConnectorInterface mbedEndpointNetwork_mjk_regfix
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(D3, D4, LED_COUNT); 00035 00036 static char * led_value = {"00000"}; //RRGGBB 00037 00038 void set_led_array(char * color_string) 00039 { 00040 int color_int; 00041 00042 sscanf(color_string, "%X", &color_int); 00043 00044 led_chain.setColorRGB(0, (color_int >> 16 & 255), (color_int >> 8 & 255), (color_int & 255) ); 00045 } 00046 00047 /** LightResource class 00048 */ 00049 class LightResource : public DynamicResource 00050 { 00051 00052 public: 00053 /** 00054 Default constructor 00055 @param logger input logger instance for this resource 00056 @param name input the Light resource name 00057 @param observable input the resource is Observable (default: FALSE) 00058 */ 00059 LightResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Light",SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED,observable) { 00060 set_led_array("000000"); 00061 wait(0.5); 00062 set_led_array("FF0000"); 00063 wait(0.5); 00064 set_led_array("00FF00"); 00065 wait(0.5); 00066 set_led_array("0000FF"); 00067 wait(0.5); 00068 set_led_array(led_value); 00069 } 00070 00071 /** 00072 Get the value of the Light 00073 @returns string containing either "0" (light off) or "1" (light on) 00074 */ 00075 virtual string get() { 00076 return(led_value); 00077 } 00078 00079 /** 00080 Set the value of the Light 00081 @param string input the string containing "0" (light off) or "1" (light on) 00082 */ 00083 virtual void put(const string value) { 00084 if( sizeof(value) == sizeof(led_value) ){ 00085 led_value = (char *)value.c_str(); 00086 set_led_array(led_value); 00087 } 00088 } 00089 }; 00090 00091 #endif // __LIGHT_RESOURCE_H__
Generated on Wed Jul 13 2022 19:30:15 by
1.7.2