Alan Simms / Mbed 2 deprecated threeAxisTable

Dependencies:   mbed threeAxis mbed-rtos 4DGL-uLCD-SE

Revision:
13:8231d6cce099
Parent:
12:2bc6047d219b
Child:
14:d6c8724a69e8
--- a/main.cpp	Wed Dec 15 00:02:35 2021 +0000
+++ b/main.cpp	Wed Dec 15 01:18:03 2021 +0000
@@ -35,6 +35,7 @@
 uLCD_4DGL uLCD(p9,p10,p11);
 DigitalOut actualLED(LED1);
 Mutex LCD;
+Mutex blue;
 /*
 volatile int currX;
 volatile int currY;
@@ -46,29 +47,18 @@
 Thread thread;
 Thread thread2;
 
-
-void parseCoords(std::string coords){
-
-    int start = 0;
-    int end = coords.find(',');
-
-    float tempX = atof(coords.substr(start, end-start).c_str());
-
-    start = end + 1;
-    end = coords.find(',', start);
-
-    float tempY = atof(coords.substr(start, end-start).c_str());
-
-    start = end + 1;
-    end = coords.length();
-    float tempZ = atof(coords.substr(start, end-start).c_str());
-    
-    table.goTo(tempX, tempY, tempZ);
-    LCD.lock();
-    uLCD.printf("\n");
-    uLCD.printf("%d, %d, %d", tempX,tempY,tempZ);
-    LCD.unlock();
-    
+void raiseLimit(DigitalOut* arg){
+        while(1){
+            if(bluetooth.readable()){
+                char temp;
+                while(bluetooth.readable()){
+                    temp = bluetooth.getc();
+                }
+                //bluetoothFlush();
+                *arg = 1;
+                break;
+            }
+        }
 }
 
 void bluetoothFlush(){
@@ -78,6 +68,29 @@
     }
 }
 
+void parseCoords(std::string coords){
+    
+    
+    int start = 0;
+    int end = coords.find(',');
+    
+
+    float tempX = atof(coords.substr(start, end-start).c_str());
+
+    
+    start = end + 1;
+    end = coords.find(',', start);
+
+    float tempY = atof(coords.substr(start, end-start).c_str());
+    
+    start = end + 1;
+    end = coords.length();
+    float tempZ = atof(coords.substr(start, end-start).c_str());
+
+    table.goTo(tempX, tempY, tempZ);
+    
+}
+
 void bluetooth_thread(){
      
     //char bnum=0;
@@ -121,6 +134,7 @@
     //Y axis direction inverted from others to get behavior that makes me happy (rewards = negative, forward = positive)
     table.invertY();
     table.invertZ();
+    table.setWait(3);
     uLCD.baudrate(300000);
     wait(0.5);
     
@@ -143,16 +157,10 @@
     uLCD.printf("Enter anything to stop");
     LCD.unlock();
     
+    thread2.start(raiseLimit,&xLimit);
+    Thread::wait(50);
     table.zeroX();
-    uLCD.printf("Running!");
-    while(1){
-        if(bluetooth.readable()){
-            bluetoothFlush();
-            xLimit = 1;
-            break;
-        }
-    }
-    
+
     LCD.lock();
     uLCD.cls();    
     uLCD.printf("Enter null value to begin Y zero, anything else to skip");
@@ -170,14 +178,9 @@
     uLCD.printf("Enter anything to stop");
     LCD.unlock();
     
+    thread2.start(raiseLimit,&yLimit);
+    Thread::wait(50);
     table.zeroY();
-    while(1){
-        if(bluetooth.readable()){
-            bluetoothFlush();
-            yLimit = 1;
-            break;
-        }
-    }
     
     LCD.lock();
     uLCD.cls();    
@@ -196,15 +199,12 @@
     uLCD.printf("Enter anything to stop");
     LCD.unlock();
     
+    
+    thread2.start(raiseLimit,&zLimit);
+    Thread::wait(50);
     table.zeroZ();
-        while(1){
-        if(bluetooth.readable()){
-            bluetoothFlush();
-            zLimit = 1;
-            break;
-        }
-    }
     
+    thread2.terminate();
     LCD.lock();
     uLCD.cls();
     
@@ -216,6 +216,8 @@
     uLCD.printf("Waiting...");
     LCD.unlock();
     
+    bluetoothFlush();
+    
     thread.start(bluetooth_thread);
     
     while(1);