mbedConnectorInterface sample endpoint utilizing 3g cellular radio as the underlying connection transport.
Dependencies: LM75B mbed mbedConnectorInterface mbedEndpointNetwork_Ublox
mbedEndpointResources/LightResource.h@0:a507bbd93e47, 2015-04-28 (annotated)
- Committer:
- ansond
- Date:
- Tue Apr 28 05:04:20 2015 +0000
- Revision:
- 0:a507bbd93e47
initial checkin
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:a507bbd93e47 | 1 | /** |
ansond | 0:a507bbd93e47 | 2 | * @file LightResource.h |
ansond | 0:a507bbd93e47 | 3 | * @brief mbed CoAP Endpoint Light resource supporting CoAP GET and PUT |
ansond | 0:a507bbd93e47 | 4 | * @author Doug Anson |
ansond | 0:a507bbd93e47 | 5 | * @version 1.0 |
ansond | 0:a507bbd93e47 | 6 | * @see |
ansond | 0:a507bbd93e47 | 7 | * |
ansond | 0:a507bbd93e47 | 8 | * Copyright (c) 2014 |
ansond | 0:a507bbd93e47 | 9 | * |
ansond | 0:a507bbd93e47 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ansond | 0:a507bbd93e47 | 11 | * you may not use this file except in compliance with the License. |
ansond | 0:a507bbd93e47 | 12 | * You may obtain a copy of the License at |
ansond | 0:a507bbd93e47 | 13 | * |
ansond | 0:a507bbd93e47 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
ansond | 0:a507bbd93e47 | 15 | * |
ansond | 0:a507bbd93e47 | 16 | * Unless required by applicable law or agreed to in writing, software |
ansond | 0:a507bbd93e47 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
ansond | 0:a507bbd93e47 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ansond | 0:a507bbd93e47 | 19 | * See the License for the specific language governing permissions and |
ansond | 0:a507bbd93e47 | 20 | * limitations under the License. |
ansond | 0:a507bbd93e47 | 21 | */ |
ansond | 0:a507bbd93e47 | 22 | |
ansond | 0:a507bbd93e47 | 23 | #ifndef __LIGHT_RESOURCE_H__ |
ansond | 0:a507bbd93e47 | 24 | #define __LIGHT_RESOURCE_H__ |
ansond | 0:a507bbd93e47 | 25 | |
ansond | 0:a507bbd93e47 | 26 | // Base class |
ansond | 0:a507bbd93e47 | 27 | #include "DynamicResource.h" |
ansond | 0:a507bbd93e47 | 28 | |
ansond | 0:a507bbd93e47 | 29 | // our Light sensor |
ansond | 0:a507bbd93e47 | 30 | DigitalOut __light(LED3); |
ansond | 0:a507bbd93e47 | 31 | |
ansond | 0:a507bbd93e47 | 32 | // possible Light states |
ansond | 0:a507bbd93e47 | 33 | #define OFF "1" |
ansond | 0:a507bbd93e47 | 34 | #define ON "0" |
ansond | 0:a507bbd93e47 | 35 | |
ansond | 0:a507bbd93e47 | 36 | /** LightResource class |
ansond | 0:a507bbd93e47 | 37 | */ |
ansond | 0:a507bbd93e47 | 38 | class LightResource : public DynamicResource |
ansond | 0:a507bbd93e47 | 39 | { |
ansond | 0:a507bbd93e47 | 40 | |
ansond | 0:a507bbd93e47 | 41 | public: |
ansond | 0:a507bbd93e47 | 42 | /** |
ansond | 0:a507bbd93e47 | 43 | Default constructor |
ansond | 0:a507bbd93e47 | 44 | @param logger input logger instance for this resource |
ansond | 0:a507bbd93e47 | 45 | @param name input the Light resource name |
ansond | 0:a507bbd93e47 | 46 | @param observable input the resource is Observable (default: FALSE) |
ansond | 0:a507bbd93e47 | 47 | */ |
ansond | 0:a507bbd93e47 | 48 | LightResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Light",SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED,observable) { |
ansond | 0:a507bbd93e47 | 49 | } |
ansond | 0:a507bbd93e47 | 50 | |
ansond | 0:a507bbd93e47 | 51 | /** |
ansond | 0:a507bbd93e47 | 52 | Get the value of the Light |
ansond | 0:a507bbd93e47 | 53 | @returns string containing either "0" (light off) or "1" (light on) |
ansond | 0:a507bbd93e47 | 54 | */ |
ansond | 0:a507bbd93e47 | 55 | virtual string get() { |
ansond | 0:a507bbd93e47 | 56 | string result(OFF); |
ansond | 0:a507bbd93e47 | 57 | if (__light) result = ON; |
ansond | 0:a507bbd93e47 | 58 | return result; |
ansond | 0:a507bbd93e47 | 59 | } |
ansond | 0:a507bbd93e47 | 60 | |
ansond | 0:a507bbd93e47 | 61 | /** |
ansond | 0:a507bbd93e47 | 62 | Set the value of the Light |
ansond | 0:a507bbd93e47 | 63 | @param string input the string containing "0" (light off) or "1" (light on) |
ansond | 0:a507bbd93e47 | 64 | */ |
ansond | 0:a507bbd93e47 | 65 | virtual void put(const string value) { |
ansond | 0:a507bbd93e47 | 66 | if (value.compare(string(OFF)) == 0) __light = 0; |
ansond | 0:a507bbd93e47 | 67 | else __light = 1; |
ansond | 0:a507bbd93e47 | 68 | } |
ansond | 0:a507bbd93e47 | 69 | }; |
ansond | 0:a507bbd93e47 | 70 | |
ansond | 0:a507bbd93e47 | 71 | #endif // __LIGHT_RESOURCE_H__ |