Sorfware for Lexy ( Hexapode )

Dependencies:   mbed BLE_API X_NUCLEO_IDB0XA1 MODSERIAL

Revision:
4:49b5cde0aecc
Parent:
3:13bd725bd47b
--- a/main.cpp	Sat Aug 20 18:24:21 2016 +0000
+++ b/main.cpp	Sat Aug 20 19:19:43 2016 +0000
@@ -1,20 +1,19 @@
 #include "mbed.h"
 #include "COM/SSC-32.h"
 #include "COM/LOGGER.h"
+#include "COM/Event.h"
 #include "LIB/Hexapod.h"
 
 static Logger *Ordi = Logger::Instance();
+static event *evnt = event::Instance();
 int main()
 {
-    //0.declaration des ressources    
+    //0.declaration des ressources
 
     int ii, ij, ik, ix, iy, size, ind;
     int cx, cy, attempts;
     //serial ser;
-    packet *pack, *pack2, *pack_ask, *pack_data;
-    packet *pack_enable, *pack_disable;
     hexapod hex;
-    data_chunk *d;
     //logger log;
     //SDL_Surface *screen;
     //SDL_Event event;
@@ -41,16 +40,14 @@
     time = 0.0;
     lasttime = time.read();
     hex.safeStand();
-    while (hex.ssrunning)
-    {
+    while (hex.ssrunning) {
         dt = (time.read() - lasttime);
         lasttime = time.read();
         hex.step(dt);
         // package positions
-        for (ii=0; ii<18; ii++)
-        {
+        for (ii=0; ii<18; ii++) {
             ser.add(ii,hex.servoangle[ii]);
-            
+
         }
         ser.send();
         wait_us(20*1000);
@@ -62,56 +59,47 @@
     wait_us(20*1000);
 
     quit = false;
-    while (!quit)
-    {
+    while (!quit) {
         dt = (time.read() - lasttime);
         time += dt;
         lasttime = time.read();
         hex.step(dt);
         // package positions
-        for (ii=0; ii<18; ii++)
-        {
+        for (ii=0; ii<18; ii++) {
             ser.add(ii, hex.servoangle[ii]);
         }
         ser.send();
-        // ask for data?        
-        
-        while (Ordi->buffer_has_recived()!=false)
-        {
-            switch (event.type)
-            {
-                case SDL_JOYBUTTONDOWN:
-                    if (event.jbutton.button == 7) quit = true;
-                    break;
-                case SDL_JOYAXISMOTION:
-                    joyval = -event.jaxis.value/32767.;
-                    if (event.jaxis.axis == 1) // L stick, yaxis
-                    {
-                        if (joyval > 0.1) hex.speed = 0.5*(joyval - 0.1);
-                        else if (joyval < -0.1) hex.speed = 0.5*(joyval + 0.1);
-                        else hex.speed = 0.0;
-                    }
-                    if (event.jaxis.axis == 2) // R stick, xaxis
-                    {
-                        if (joyval > 0.1) hex.turning = (joyval-0.1);
-                        else if (joyval < -0.1) hex.turning = (joyval+0.1);
-                        else hex.turning = 0.0;
-                    }
-                    if (event.jaxis.axis == 3) // R stick, yaxis
-                    {
-                        if (joyval > 0.1) hex.standheight = (joyval-0.1)*2.0;
-                        else if (joyval < -0.1) hex.standheight = (joyval+0.1)*2.0;
-                        else hex.standheight = 0.0;
-                    }
-                    break;
+        // ask for data?
+
+        while (evnt->has_new_event()) {
+
+            if (evnt->has_button_presed()) {
+                if (evnt->get_val_B()=='7') quit = true;
+            }
+            if (evnt->has_J_pressed()) { // J stick, yaxis
+                joyval = evnt->get_val_J();
+                if (joyval > 0.1) hex.speed = 0.5*(joyval - 0.1);
+                else if (joyval < -0.1) hex.speed = 0.5*(joyval + 0.1);
+                else hex.speed = 0.0;
             }
+            if (evnt->has_T_pressed()) { // T stick, xaxis
+                joyval = evnt->get_val_T();
+                if (joyval > 0.1) hex.turning = (joyval-0.1);
+                else if (joyval < -0.1) hex.turning = (joyval+0.1);
+                else hex.turning = 0.0;
+            }
+            if (evnt->has_R_pressed()) { // R stick, yaxis
+                joyval = evnt->get_val_R();
+                if (joyval > 0.1) hex.standheight = (joyval-0.1)*2.0;
+                else if (joyval < -0.1) hex.standheight = (joyval+0.1)*2.0;
+                else hex.standheight = 0.0;
+            }
+
         }
-        SDL_Delay(20);
+        wait_us(20);
     }
 
     Ordi->log( "Quitting.." );
-    ser.send(pack_disable);
     ser.close();
     return 0;
-    }
-    
\ No newline at end of file
+}