David Rodriguez Douglas Gonzalez

Dependencies:   MMA8451Q TSI USBDevice WakeUp mbed

Fork of labusb by Douglas Gonzalez

Files at this revision

API Documentation at this revision

Comitter:
dglmgc
Date:
Wed Jun 22 13:51:06 2016 +0000
Parent:
1:2bdcfc75ee32
Commit message:
Proyecto 2-David Rodriguez/Douglas Gonzalez-Universidad Galileo

Changed in this revision

WakeUp.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 2bdcfc75ee32 -r da744dca7faf WakeUp.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WakeUp.lib	Wed Jun 22 13:51:06 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/Sissors/code/WakeUp/#49ca85e8822f
diff -r 2bdcfc75ee32 -r da744dca7faf main.cpp
--- a/main.cpp	Thu Jun 09 01:22:12 2016 +0000
+++ b/main.cpp	Wed Jun 22 13:51:06 2016 +0000
@@ -1,123 +1,54 @@
 #include "mbed.h"
-#include "USBKeyboard.h"
+#include "USBMouse.h"
 #include "MMA8451Q.h"
 #include "TSISensor.h"
+#include "WakeUp.h"
 
 #define MMA8451_I2C_ADDRESS (0x1d<<1)
 
-USBKeyboard teclado;
-Serial pc(USBTX, USBRX); // tx, rx
+USBMouse raton;
+DigitalOut myled(LED2);
+InterruptIn boton(PTD4);
+
+bool dormido = false;
+
+void dormir() {
+    dormido = !dormido;
+    myled = !myled;
+}
 
 int main()
 {
-    float click =0;
-    float clickant = 0;
-    int16_t x = 0;
-    int16_t y = 0;
-    TSISensor tsi;
+    //TSISensor tsi;
     MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
-
-    while (1) {
-        x = -10*acc.getAccY();
-        y = 10*acc.getAccX();
+    AnalogIn   potx(A0);
+    AnalogIn   poty(A1);
+    boton.rise(&dormir);
+    
+    float velx = 0;
+    float vely = 0;
+    
+    float x = 0;
     
-        click=tsi.readPercentage();
-        //pc.printf("%f\n",click);
-        if(click < (clickant - 0.10) || click > (clickant + 0.10)) {
-            if(x>0 && y > 0){                
-                if (click>0.80)
-                    teclado._putc(99);
-                    
-                if((click<0.30)&&(click>0))
-                    teclado._putc(97);
-                    
-                if((click<0.80)&&(click>0.30))
-                    teclado._putc(98);
-            }
-            if(x<0 && y > 0){                
-                if (click>0.80)
-                    teclado._putc(102);
-                    
-                if((click<0.30)&&(click>0))
-                    teclado._putc(100);
-                    
-                if((click<0.80)&&(click>0.30))
-                    teclado._putc(101);
-            }
-            if(x<0 && y < 0){                
-                if (click>0.80)
-                    teclado._putc(105);
-                    
-                if((click<0.30)&&(click>0))
-                    teclado._putc(103);
-                    
-                if((click<0.80)&&(click>0.30))
-                    teclado._putc(104);
-            }
-            if(x>0 && y < 0){                
-                if (click>0.80)
-                    teclado._putc(108);
-                    
-                if((click<0.30)&&(click>0))
-                    teclado._putc(106);
-                    
-                if((click<0.80)&&(click>0.30))
-                    teclado._putc(107);
-            }
-            if(x==0 && y < 0){                
-                if (click>0.80)
-                    teclado._putc(111);
-                    
-                if((click<0.30)&&(click>0))
-                    teclado._putc(109);
-                    
-                if((click<0.80)&&(click>0.30))
-                    teclado._putc(110);
-            }
-            if(x==0 && y > 0){                
-                if (click>0.80)
-                    teclado._putc(114);
-                    
-                if((click<0.30)&&(click>0))
-                    teclado._putc(112);
-                    
-                if((click<0.80)&&(click>0.30))
-                    teclado._putc(113);
-            }
-            if(x==0 && y == 0){                
-                if (click>0.80)
-                    teclado._putc(117);
-                    
-                if((click<0.30)&&(click>0))
-                    teclado._putc(115);
-                    
-                if((click<0.80)&&(click>0.30))
-                    teclado._putc(116);
-            }
-            if(x>0 && y == 0){                
-                if (click>0.80)
-                    teclado._putc(120);
-                    
-                if((click<0.30)&&(click>0))
-                    teclado._putc(118);
-                    
-                if((click<0.80)&&(click>0.30))
-                    teclado._putc(119);
-            }
-            if(x<0 && y == 0){                
-                if (click>0.80)
-                    teclado._putc(123);
-                    
-                if((click<0.30)&&(click>0))
-                    teclado._putc(121);
-                    
-                if((click<0.80)&&(click>0.30))
-                    teclado._putc(122);
-            }
-        }
-        
-        wait(0.001);
-        clickant = click;
-       
+    while (1) {
+        if(dormido) {
+            sleep();
+        } else {
+            x = -10*acc.getAccY();
+            
+            velx = potx*20 - 16;
+            vely = poty*20 - 15;
+            
+            raton.move(velx, vely);
+            
+            if (x>5)
+                raton.press(MOUSE_LEFT);
+            else
+                raton.release(MOUSE_LEFT);
+            if(x<-5)
+                raton.press(MOUSE_RIGHT);
+            else
+                raton.release(MOUSE_RIGHT);
+        }  
     }
-}
\ No newline at end of file
+}