Dreamforce 2015 BLE-based mDS HeartRate Monitor Endpoint

Dependencies:   GroveEarbudSensor mbed mbedConnectorInterface mbedEndpointNetwork_BLE

Committer:
ansond
Date:
Mon Sep 07 04:52:10 2015 +0000
Revision:
53:d22af3b91e4c
Parent:
45:425c86379f12
updates and tweaks for static location option and android 5.x

Who changed what in which revision?

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