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
OnBoardLED.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 __LED_RESOURCE_H__ 00024 #define __LED_RESOURCE_H__ 00025 00026 00027 // Base class 00028 #include "DynamicResource.h" 00029 00030 // our Light 00031 DigitalOut LED_red(LED1); 00032 DigitalOut LED_green(LED2); 00033 DigitalOut LED_blue(LED3); 00034 00035 static char * LED_color_value = {"0000000"}; //RRGGBBII 00036 00037 void LED_set_color(char * color_string) 00038 { 00039 static uint8_t red, green, blue, index; 00040 int color_int; 00041 00042 sscanf(color_string, "%X", &color_int); 00043 00044 index = color_int & 255; 00045 blue = color_int >> 8 & 255; 00046 green = color_int >> 16 & 255; 00047 red = color_int >> 24 & 255; 00048 00049 if(index == 0) { 00050 LED_red = !(red & 1); 00051 LED_green = !(green & 1); 00052 LED_blue = !(blue & 1); 00053 } 00054 } 00055 00056 /** LightResource class 00057 */ 00058 class LEDResource : public DynamicResource 00059 { 00060 00061 public: 00062 /** 00063 Default constructor 00064 @param logger input logger instance for this resource 00065 @param name input the Light resource name 00066 @param observable input the resource is Observable (default: FALSE) 00067 */ 00068 LEDResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"OnBoardLED",SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED,observable) { 00069 LED_set_color("00000000"); 00070 wait(0.5); 00071 LED_set_color("FF000000"); 00072 wait(0.5); 00073 LED_set_color("00FF0000"); 00074 wait(0.5); 00075 LED_set_color("0000FF00"); 00076 wait(0.5); 00077 LED_set_color(LED_color_value); 00078 } 00079 00080 /** 00081 Get the value of the LED 00082 @returns string containing the last setting 00083 */ 00084 virtual string get() { 00085 return(LED_color_value); 00086 } 00087 00088 /** 00089 Set the value of the LED 00090 @param string input the string containing the desired setting 00091 */ 00092 virtual void put(const string value) { 00093 if( sizeof(value) == sizeof(LED_color_value) ){ 00094 LED_color_value = (char *)value.c_str(); 00095 LED_set_color(LED_color_value); 00096 } 00097 } 00098 }; 00099 00100 #endif // __LED_RESOURCE_H__
Generated on Tue Jul 12 2022 20:37:45 by
1.7.2
