confidential

Dependencies:   Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork

Committer:
dscrobonia
Date:
Sat May 09 21:00:59 2015 +0000
Revision:
2:0382d0c13a51
Parent:
0:02b8d440ded3
results csv info;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cjwu15 0:02b8d440ded3 1 /**
cjwu15 0:02b8d440ded3 2 * @file LightResource.h
cjwu15 0:02b8d440ded3 3 * @brief mbed CoAP Endpoint Light resource supporting CoAP GET and PUT
cjwu15 0:02b8d440ded3 4 * @author Doug Anson, Michael Koster
cjwu15 0:02b8d440ded3 5 * @version 1.0
cjwu15 0:02b8d440ded3 6 * @see
cjwu15 0:02b8d440ded3 7 *
cjwu15 0:02b8d440ded3 8 * Copyright (c) 2014
cjwu15 0:02b8d440ded3 9 *
cjwu15 0:02b8d440ded3 10 * Licensed under the Apache License, Version 2.0 (the "License");
cjwu15 0:02b8d440ded3 11 * you may not use this file except in compliance with the License.
cjwu15 0:02b8d440ded3 12 * You may obtain a copy of the License at
cjwu15 0:02b8d440ded3 13 *
cjwu15 0:02b8d440ded3 14 * http://www.apache.org/licenses/LICENSE-2.0
cjwu15 0:02b8d440ded3 15 *
cjwu15 0:02b8d440ded3 16 * Unless required by applicable law or agreed to in writing, software
cjwu15 0:02b8d440ded3 17 * distributed under the License is distributed on an "AS IS" BASIS,
cjwu15 0:02b8d440ded3 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
cjwu15 0:02b8d440ded3 19 * See the License for the specific language governing permissions and
cjwu15 0:02b8d440ded3 20 * limitations under the License.
cjwu15 0:02b8d440ded3 21 */
cjwu15 0:02b8d440ded3 22
cjwu15 0:02b8d440ded3 23 #ifndef __LED_RESOURCE_H__
cjwu15 0:02b8d440ded3 24 #define __LED_RESOURCE_H__
cjwu15 0:02b8d440ded3 25
cjwu15 0:02b8d440ded3 26
cjwu15 0:02b8d440ded3 27 // Base class
cjwu15 0:02b8d440ded3 28 #include "DynamicResource.h"
cjwu15 0:02b8d440ded3 29
cjwu15 0:02b8d440ded3 30 // our Light
cjwu15 0:02b8d440ded3 31 DigitalOut LED_red(LED1);
cjwu15 0:02b8d440ded3 32 DigitalOut LED_green(LED2);
cjwu15 0:02b8d440ded3 33 DigitalOut LED_blue(LED3);
cjwu15 0:02b8d440ded3 34
cjwu15 0:02b8d440ded3 35 static char * LED_color_value = {"0000000"}; //RRGGBBII
cjwu15 0:02b8d440ded3 36
cjwu15 0:02b8d440ded3 37 void LED_set_color(char * color_string)
cjwu15 0:02b8d440ded3 38 {
cjwu15 0:02b8d440ded3 39 static uint8_t red, green, blue, index;
cjwu15 0:02b8d440ded3 40 int color_int;
cjwu15 0:02b8d440ded3 41
cjwu15 0:02b8d440ded3 42 sscanf(color_string, "%X", &color_int);
cjwu15 0:02b8d440ded3 43
cjwu15 0:02b8d440ded3 44 index = color_int & 255;
cjwu15 0:02b8d440ded3 45 blue = color_int >> 8 & 255;
cjwu15 0:02b8d440ded3 46 green = color_int >> 16 & 255;
cjwu15 0:02b8d440ded3 47 red = color_int >> 24 & 255;
cjwu15 0:02b8d440ded3 48
cjwu15 0:02b8d440ded3 49 if(index == 0) {
cjwu15 0:02b8d440ded3 50 LED_red = !(red & 1);
cjwu15 0:02b8d440ded3 51 LED_green = !(green & 1);
cjwu15 0:02b8d440ded3 52 LED_blue = !(blue & 1);
cjwu15 0:02b8d440ded3 53 }
cjwu15 0:02b8d440ded3 54 }
cjwu15 0:02b8d440ded3 55
cjwu15 0:02b8d440ded3 56 /** LightResource class
cjwu15 0:02b8d440ded3 57 */
cjwu15 0:02b8d440ded3 58 class LEDResource : public DynamicResource
cjwu15 0:02b8d440ded3 59 {
cjwu15 0:02b8d440ded3 60
cjwu15 0:02b8d440ded3 61 public:
cjwu15 0:02b8d440ded3 62 /**
cjwu15 0:02b8d440ded3 63 Default constructor
cjwu15 0:02b8d440ded3 64 @param logger input logger instance for this resource
cjwu15 0:02b8d440ded3 65 @param name input the Light resource name
cjwu15 0:02b8d440ded3 66 @param observable input the resource is Observable (default: FALSE)
cjwu15 0:02b8d440ded3 67 */
cjwu15 0:02b8d440ded3 68 LEDResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"OnBoardLED",SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED,observable) {
cjwu15 0:02b8d440ded3 69 LED_set_color("00000000");
cjwu15 0:02b8d440ded3 70 wait(0.5);
cjwu15 0:02b8d440ded3 71 LED_set_color("FF000000");
cjwu15 0:02b8d440ded3 72 wait(0.5);
cjwu15 0:02b8d440ded3 73 LED_set_color("00FF0000");
cjwu15 0:02b8d440ded3 74 wait(0.5);
cjwu15 0:02b8d440ded3 75 LED_set_color("0000FF00");
cjwu15 0:02b8d440ded3 76 wait(0.5);
cjwu15 0:02b8d440ded3 77 LED_set_color(LED_color_value);
cjwu15 0:02b8d440ded3 78 }
cjwu15 0:02b8d440ded3 79
cjwu15 0:02b8d440ded3 80 /**
cjwu15 0:02b8d440ded3 81 Get the value of the LED
cjwu15 0:02b8d440ded3 82 @returns string containing the last setting
cjwu15 0:02b8d440ded3 83 */
cjwu15 0:02b8d440ded3 84 virtual string get() {
cjwu15 0:02b8d440ded3 85 return(LED_color_value);
cjwu15 0:02b8d440ded3 86 }
cjwu15 0:02b8d440ded3 87
cjwu15 0:02b8d440ded3 88 /**
cjwu15 0:02b8d440ded3 89 Set the value of the LED
cjwu15 0:02b8d440ded3 90 @param string input the string containing the desired setting
cjwu15 0:02b8d440ded3 91 */
cjwu15 0:02b8d440ded3 92 virtual void put(const string value) {
cjwu15 0:02b8d440ded3 93 if( sizeof(value) == sizeof(LED_color_value) ){
cjwu15 0:02b8d440ded3 94 LED_color_value = (char *)value.c_str();
cjwu15 0:02b8d440ded3 95 LED_set_color(LED_color_value);
cjwu15 0:02b8d440ded3 96 }
cjwu15 0:02b8d440ded3 97 }
cjwu15 0:02b8d440ded3 98 };
cjwu15 0:02b8d440ded3 99
cjwu15 0:02b8d440ded3 100 #endif // __LED_RESOURCE_H__