confidential

Dependencies:   Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork

Revision:
1:73f962479f1a
Parent:
0:02b8d440ded3
Child:
2:0382d0c13a51
--- a/mbedEndpointResources/Touch.h	Sat May 09 17:32:02 2015 +0000
+++ b/mbedEndpointResources/Touch.h	Sat May 09 20:25:40 2015 +0000
@@ -28,54 +28,84 @@
 // Base class
 #include "DynamicResource.h"
 #include "mbed.h"
-
-DigitalIn button(D2);
-
-
-int count = 0;
+#include "MMA7660.h"
 
 
-void touch_thread(void const *args) {
+DigitalIn button(D2);
+MMA7660 accelemeter;
+
+int reps[50];
+int idx = 0;
+
+char result[200];
+
+void touch_thread(void const *args)
+{
+    float ax, ay, az;
+    accelemeter.init();
+    bool up = false;
+    int rep = 0;
+    for (i = 0; i < 50; i++)
+        reps[i] = -1;
     while(1) {
-        if (button) {
-            printf("touch detected\n");
+        if (!button) {
+            printf("touch detected\n\r");
             count++;
             LED_set_color("0000FF00");
-            wait(1.0);
+            while(!button) {
+                accelemeter.getAcceleration(&ax,&ay,&az);
+                printf("Accleration of X=%2.2fg, Y=%2.2fg, Z=%2.2fg\n\r",ax,ay,az);
+                if (ay < 0.7f) {
+                    up = true;
+                }
+                if (ay > 0.9f) {
+                    if (up)
+                        rep++;
+                    up = false;
+                }
+            }
+
             LED_set_color("00000000");
-            while(button);
+            printf("Reps = %d\n\r", rep);
+            reps[idx++] = rep;
+            rep = 0;
         }
-        
-        Thread::wait(500);
     }
 }
-    
-/** LightResource class
- */
-class TouchResource : public DynamicResource
-{
+
+    /** LightResource class
+     */
+    class TouchResource : 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)
+        */
+        TouchResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Touch",SN_GRS_GET_ALLOWED,observable) {
+        }
 
-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)
-    */
-    TouchResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Touch",SN_GRS_GET_ALLOWED,observable) {
-    }
+        /**
+        Get the value of the LED
+        @returns string containing the last setting
+        */
+        virtual string get() {
+            int i = 0;
+            memset(result, 0, 200);
+            
+            for (i = 0; i < idx; i++)
+            sprintf(result+(i*4), "%2d, ", reps[idx]);
 
-    /**
-    Get the value of the LED
-    @returns string containing the last setting
-    */
-    virtual string get() {
-        char result[10];
-        sprintf(result, "%d", count);
-        count = 0;
-        return(result);
-    }
-};
+            for (i = 0; i < 50; i++)
+                reps[i] = -1;
+            idx = 0;
+            
+            return(result);
+        }
+    };
 
 #endif // __TOUCH_RESOURCE_H__