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