Dreamforce 2015 BLE-based mDS HeartRate Monitor Endpoint

Dependencies:   GroveEarbudSensor mbed mbedConnectorInterface mbedEndpointNetwork_BLE

Revision:
0:6b414fe5f8db
Child:
1:3ad5d55e1cc7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbedEndpointResources/HeartrateResource.h	Thu Mar 05 18:24:04 2015 +0000
@@ -0,0 +1,75 @@
+/**
+ * @file    HeartrateResource.h
+ * @brief   mbed CoAP Endpoint Heartrate resource (Grove Earbud) supporting CoAP GET and PUT
+ * @author  Doug Anson
+ * @version 1.0
+ * @see
+ *
+ * Copyright (c) 2014
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __HEARTRATE_RESOURCE_H__
+#define __HEARTRATE_RESOURCE_H__
+
+// Base class
+#include "DynamicResource.h"
+
+// Grove Earbud Sensor
+#include "GroveEarbudSensor.h"
+extern RawSerial pc;            // declared in main.cpp for logger... just reference here...
+InterruptIn __sensor(D2);
+GroveEarbudSensor __earbud(&__sensor,&pc);
+
+// HRM sensor value
+string __hrm = string("<off>");
+
+// Heartrate callback (Earbud)
+void __hrm_callback(float heartrate,void *data) {
+    char buf[10];
+    memset(buf,0,10);
+    sprintf(buf,"%.1f",heartrate);
+    __hrm = string(buf);
+    
+    // DEBUG
+    pc.printf("HRM: %s\r\n",__hrm.c_str());
+}
+
+/** HeartrateResource class
+ */
+class HeartrateResource : public DynamicResource
+{
+
+public:
+    /**
+    Default constructor
+    @param logger input logger instance for this resource
+    @param name input the Light resource name
+    @param observable input the resource is Observable (default: FALSE)
+    */
+    HeartrateResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Heartrate",SN_GRS_GET_ALLOWED,observable) {
+        // finish setup of the earbud sensor
+        __earbud.registerCallback(__hrm_callback);
+    }
+
+    /**
+    Get the value of the Heartrate sensor
+    @returns string containing the heartrate in bpm
+    */
+    virtual string get() {
+       return __hrm;
+    }
+};
+
+#endif // __HEARTRATE_RESOURCE_H__