mbedConnectorInterface sample endpoint utilizing 3g cellular radio as the underlying connection transport.

Dependencies:   LM75B mbed mbedConnectorInterface mbedEndpointNetwork_Ublox

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LightResource.h Source File

LightResource.h

Go to the documentation of this file.
00001 /**
00002  * @file    LightResource.h
00003  * @brief   mbed CoAP Endpoint Light resource supporting CoAP GET and PUT
00004  * @author  Doug Anson
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 // Base class
00027 #include "DynamicResource.h"
00028 
00029 // our Light sensor
00030 DigitalOut  __light(LED3);
00031 
00032 // possible Light states
00033 #define OFF             "1"
00034 #define ON              "0"
00035 
00036 /** LightResource class
00037  */
00038 class LightResource : public DynamicResource
00039 {
00040 
00041 public:
00042     /**
00043     Default constructor
00044     @param logger input logger instance for this resource
00045     @param name input the Light resource name
00046     @param observable input the resource is Observable (default: FALSE)
00047     */
00048     LightResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Light",SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED,observable) {
00049     }
00050 
00051     /**
00052     Get the value of the Light
00053     @returns string containing either "0" (light off) or "1" (light on)
00054     */
00055     virtual string get() {
00056         string result(OFF);
00057         if (__light) result = ON;
00058         return result;
00059     }
00060 
00061     /**
00062     Set the value of the Light
00063     @param string input the string containing "0" (light off) or "1" (light on)
00064     */
00065     virtual void put(const string value) {
00066         if (value.compare(string(OFF)) == 0) __light = 0;
00067         else __light = 1;
00068     }
00069 };
00070 
00071 #endif // __LIGHT_RESOURCE_H__