Michael Koster / Mbed 2 deprecated ipso_interop_mbed1

Dependencies:   Chainable_RGB_LED DHT LED_Bar mbed mbedConnectorInterface mbedEndpointNetwork_mjk_regfix

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LedBarResource.h Source File

LedBarResource.h

Go to the documentation of this file.
00001 /**
00002  * @file    LedBarResource.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 __LEDBAR_RESOURCE_H__
00024 #define __LEDBAR_RESOURCE_H__
00025 
00026 
00027 // Base class
00028 #include "DynamicResource.h"
00029 
00030 // our LED Bar
00031 #include "LED_Bar.h"
00032 
00033 LED_Bar bar(D3, D2);
00034 
00035 static char * leds = {"0000000000"}; //GGGGGGGGYR
00036 
00037 
00038 void set_leds(char *leds)
00039 {
00040 int i;
00041     for (i=0; i<=9; i++) {
00042         if(leds[i] == '1')
00043             bar.setSingleLed((9-i),1);
00044         else if(leds[i] == '0')
00045             bar.setSingleLed((9-i),0);    
00046         }    
00047 }
00048 
00049 /** LedBarResource class
00050  */
00051 class LedBarResource : public DynamicResource
00052 {
00053 
00054 public:
00055     /**
00056     Default constructor
00057     @param logger input logger instance for this resource
00058     @param name input the Light resource name
00059     @param observable input the resource is Observable (default: FALSE)
00060     */
00061     LedBarResource(const Logger *logger,const char *name,const bool observable = false) : 
00062     DynamicResource(logger,name,"urn:X-ipso:actuator",SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED,observable) {
00063     }
00064 
00065     /**
00066     Get the value of the LED bar
00067     @returns string containing either "0" (light off) or "1" (light on) for each LED segment
00068     */
00069     virtual string get() {
00070         return(leds);
00071     }
00072 
00073     /**
00074     Set the value of the LED bar
00075     @param string input the string containing "0" (light off) or "1" (light on) per segment
00076     */
00077     virtual void put(const string value) {
00078         if( sizeof(value) == sizeof(leds) ){
00079             leds = (char *)value.c_str();
00080             set_leds(leds);
00081         }
00082     }
00083 };
00084 
00085 #endif // __LEDBAR_RESOURCE_H__