Julius Bernth / Mbed OS Cuvette_Centrifuge_Test_v1-2_ParallelMode

Dependencies:   QEI LIS3DH_spi

Revision:
13:32e1ae4221f7
Parent:
12:bc34f264e2f2
Child:
14:81d390496d4e
--- a/main.cpp	Thu Aug 12 15:47:50 2021 +0000
+++ b/main.cpp	Thu Aug 12 16:02:25 2021 +0000
@@ -328,13 +328,13 @@
         char spinState;
         pinLedRed = 1;
         //set up ticker to allow motor control thread to run periodically
-        
         encoder.reset();//reset encoder
         lastPulses = 0;//reset previous encoder reading
         encoderTimer.start();
         PrintThread.start(PrintTimeRemaining);
         printf("\r\n Test setup complete, State:%d \r\n", state);
         EN_FAULTA.write(1);
+
         //EN_FAULTB.write(1);
         if(state == STATE_RUNNING){
             //printf("\r\n running %d\r\n",state);
@@ -348,6 +348,18 @@
     semButton.release();
 }
 
+bool isSpinning(){
+    int pulses1 = encoder.getPulses();
+    wait(0.1);
+    int pulses2 = encoder.getPulses();
+    int difference = pulses2 - pulses1;
+    if (abs(difference) > 10){
+        return 1;
+    }else{
+        return 0;
+    }
+}
+
 void ReadButton()
 {
     int countThreashold = int(BUTTON_HOLD_TIME_S/BUTTON_READ_SAMPLETIME_S);
@@ -399,9 +411,13 @@
                     //printf("button released count = %d\r\n",count);
                     count = 0;
                     //CentrifugeTestThread.start(CentrifugeTest);
-                    semStartTest.release();
-                    tickerMotorControl.attach_us(&MotorControlRelease, SAMPLE_TIME_US);//set up signal for control frequency
-                    tickerPrint.attach(&PrintRelease,PRINT_TIME_S);
+                    if(!isSpinning()){
+                        semStartTest.release();
+                        tickerMotorControl.attach_us(&MotorControlRelease, SAMPLE_TIME_US);//set up signal for control frequency
+                        tickerPrint.attach(&PrintRelease,PRINT_TIME_S);
+                    }else{
+                        printf("Holder still spinning. Wait until it has stopped.\r\n");
+                    }
                 }else{
                     pinLedRed = 0;
                 }