Proof of concept for distance and temperature monitoring

Dependencies:   mbed mbedConnectorInterface mbedEndpointNetwork

Committer:
coyotebush
Date:
Sat May 02 01:10:55 2015 +0000
Revision:
3:b51fcb5fd114
add LED resource

Who changed what in which revision?

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