Initial Commit

Dependencies:   mbed HC05 QEI MODSERIAL SWSPI mbed-rtos

Revision:
2:0f80c8a1c236
Child:
3:d1197b5ea68a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/shell/bt_shell.cpp	Sun Oct 12 13:33:19 2014 +0000
@@ -0,0 +1,86 @@
+#include "bt_shell.h"
+//#include "keybindings.h"
+//the following functions are for the python interface
+
+//save a struct that indicates which data is to be returned
+Timer tt;
+interface iface;
+int linear_velocity_value ;
+int linear_velocity_direction;
+int rotational_velocity_value ;
+int rotational_velocity_direction;
+int bit_size=20;
+int thetha1=300;
+int thetha=0;
+int stall=0;
+int bump=1;
+int Lspeed=1;
+int Rspeed=1;
+int k=0;
+int char_received=0;
+DigitalOut myreset(PTA20);
+Timeout reset_pgm;
+//mandatory tiny shell output function
+void print_all()
+{
+    bt.lock();
+    stdio_mutex.lock();
+    heading=heading*11.375;
+    bt.printf(">>D%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
+              dx/256,dx%256,dy/256,dy%256,\
+              (heading)/256,(heading)%256,\
+              stall, bump,\
+              UL_rR/256,UL_rR%256,\
+              UL_R/256,UL_R%256, \
+              UL_F/256,UL_F%256,\
+              UL_L/256,UL_L%256,\
+              UL_rL/256,UL_rL%256,\
+              UL_B/256,UL_B%256);
+    dx=0;
+    dy=0;
+    stdio_mutex.unlock();
+    bt.unlock();
+}
+void bt_shell_run()
+{
+    char buffer[12];
+    bt.lock();
+    if(bt.readable()) {
+        bt.gets(buffer,5);
+        char_received=buffer[2];
+        bt.unlock();
+        if(buffer[3]=='R') {
+            bt.gets(buffer,char_received);
+            linear_velocity_value = buffer[0]<<8|buffer[1];
+            linear_velocity_direction= buffer[2];
+            rotational_velocity_value = buffer[3]<<8|buffer[4];
+            rotational_velocity_direction= buffer[5];
+            if( linear_velocity_direction==0x01) 
+            {
+                 Lspeed=-lMotor;
+                Rspeed=-rMotor;
+            } else if( linear_velocity_direction==0x10) {
+                Lspeed=+lMotor;
+                Rspeed=+rMotor;
+            }
+            if( rotational_velocity_direction==0x01 && rotational_velocity_value !=0) {
+                motor_control(Lspeed*60,Rspeed*0);
+               
+            } else if( rotational_velocity_direction==0x10 && rotational_velocity_value !=0) {
+               motor_control(Lspeed*0,Rspeed*60);
+            } else{
+                motor_control((Lspeed*linear_velocity_value/4),(Rspeed*linear_velocity_value/4));
+                
+                }
+        } else if(buffer[0] == 'P'  && buffer[1]== 'O') {
+          software_interuupt=1;
+            myreset=0;
+        }
+        else
+        {
+            bt.rxBufferFlush();
+        }
+    }
+    bt.unlock();
+    print_all();
+}
\ No newline at end of file