A small library that's provide helpers for programmers

Dependents:   PYRN

Revision:
1:ee7a5f05513d
Child:
2:6cc4c56940af
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MySensor.cpp	Tue Feb 17 11:55:34 2015 +0000
@@ -0,0 +1,48 @@
+
+#include "MySensor.h"
+
+MySensor::MySensor(const char* sName, uint8_t t, uint32_t idle): MyThread(sName) {
+    resultsMutex = new Mutex();
+    sensorType = t;
+    idleTime = idle;
+}
+
+MySensor::~MySensor() {
+    delete(resultsMutex);
+}
+
+const char *MySensor::GetSensorName() {
+    return tName;
+}
+
+uint8_t MySensor::GetSensorType() {
+    return sensorType;
+}
+
+void MySensor::SetIdleTime(uint32_t idle) {
+    idleTime = idle;
+}
+
+void MySensor::Main() {
+    while(running){
+        Loop();
+        Wait(idleTime);
+    }
+}
+
+void MySensor::Capture(char *data, uint16_t *len) {
+    if(resultsMutex) {
+        // Warning here, lock have no timeout it could leads to deadlocks
+        if(results.start) {
+            resultsMutex->lock();
+            // Copy the results
+            memcpy(data,results.start,results.num);
+            *len = results.num;
+            // Reset the results struct
+            results.current = results.start;
+            results.num = 0;
+            resultsMutex->unlock();
+        }
+    } else
+        *len = 0;
+}
\ No newline at end of file