testing

Dependencies:   mbed tinyshell X_NUCLEO_IHM02A1

Revision:
31:ebd464b0d0d8
Parent:
30:a23204ee2be2
--- a/main.cpp	Thu Apr 01 22:20:55 2021 +0000
+++ b/main.cpp	Fri Apr 02 16:01:18 2021 +0000
@@ -21,7 +21,7 @@
 #define PHASE_RES_OHMS              12.0
 #define MOTOR_INITIAL_SPEED_SPS     1000.0
 #define MOTOR_ACCEL_SPS2            1000.0
-#define MOTOR_MAX_SPEED_SPS         2000.0
+#define MOTOR_MAX_SPEED_SPS         1000.0
 #define FULL_STEP_TH_SPS            602.7
 #define DUMMY_KVAL_V                3.06
 #define BEMF_ICPT_SPS               61.52
@@ -123,7 +123,7 @@
 void set_gosteps_flag(int argc, char **argv)
 {    
     if (argc < 3 || argc > 4) {
-        printf("\r\nIncorrect number of arguments for: gosteps dir steps (axis).\r\n");
+        printf("\r\nIncorrect number of arguments for: gosteps dir steps (axis)\r\n");
         return;
     }
     
@@ -145,7 +145,7 @@
 void set_run_flag(int argc, char **argv)
 {
     if (argc < 3 || argc > 4) {
-        printf("\r\nIncorrect number of arguments for: run dir steps (axis).\r\n");
+        printf("\r\nIncorrect number of arguments for: run dir steps (axis)\r\n");
         return;
     }
 
@@ -154,16 +154,12 @@
     if (argv[1] == std::string("bwd")) dir_fwd = false;
     speed_sps = atoi(argv[2]);
 
-    //printf("\r\nParsing 'run'[%d], %s %s %s", argc, argv[1], argv[2], argv[3]);
     if (argc == 3) {
-        // both axes
         cmd_both = true;
-        //printf("\r\nUsing both axes\r\n");
     } else {
         cmd_both = false;
         which_axis = 0;
         if (argv[3] == std::string("y")) which_axis = 1;
-        //printf("\r\nUsing axis %s (%d)\r\n", argv[3], which_axis);
     }
 }
 
@@ -171,7 +167,7 @@
 void set_stop_flag(int argc, char **argv)
 {
     if (argc > 2) {
-        printf("\r\nIncorrect number of arguments for: stop (axis).\r\n");
+        printf("\r\nIncorrect number of arguments for: stop (axis)\r\n");
         return;
     }
     
@@ -190,16 +186,16 @@
 // parent cmd (0 for top) cmd input name, help string, usage string, 
 //   function to launch, arg when called, next (0 at init), child (0 at init)
 tinysh_cmd_t print_status_cmd = {0, "status", 
-    "\r\nPrint content of status registers.\r\n", 
+    "\r\nPrint content of status registers\r\n", 
     "[no args]", set_status_flag,0,0,0};
 tinysh_cmd_t go_steps_cmd = {0, "gosteps", 
-    "\r\n'Go n steps', dir = 'fwd' for CW or 'bwd' for CCW, steps = n steps, axis = 'x' or 'y' (omit for both).\r\n", 
+    "\r\n'Go n steps', dir = 'fwd' for CW or 'bwd' for CCW, steps = n steps, axis = 'x' or 'y' (omit for both)\r\n", 
     "[dir, steps, (axis)]", set_gosteps_flag,0,0,0};
 tinysh_cmd_t run_cmd = {0, "run", 
-    "\r\nRun motor, dir = 'fwd' for CW or 'bwd' for CCW, speed in steps per second, axis = 'x' or 'y' (omit for both).\r\n", 
+    "\r\nRun motor, dir = 'fwd' for CW or 'bwd' for CCW, speed in steps per second, axis = 'x' or 'y' (omit for both)\r\n", 
     "[dir, speed, (axis)]", set_run_flag,0,0,0};
 tinysh_cmd_t stop_cmd = {0, "stop", 
-    "\r\nStop motor, optional axis = 'x' or 'y'; both stopped if omitted.\r\n", 
+    "\r\nStop motor, optional axis = 'x' or 'y'; both stopped if omitted\r\n", 
     "[(axis)]", set_stop_flag,0,0,0};
 
 /* mandatory tiny shell output function */
@@ -260,13 +256,12 @@
             }
             x_nucleo_ihm02a1->perform_prepared_actions();
         
-            printf("\r\nReached limit.\r\n");
+            printf("\r\nReached limit\r\n");
+            /* force prompt display by generating empty command */
+            tinysh_char_in('\r');
         }
-        
-        /* 2: Fetch new chars for Tinyshell ----------------------------------*/
-        tinysh_char_in(pc.getc());
-        
-        /* 3: Handle Commands ------------------------------------------------*/
+                
+        /* 2: Handle Commands ------------------------------------------------*/
         if (go_steps) {
             // Stop first
             if (cmd_both) {
@@ -290,7 +285,9 @@
                 else motors[which_axis]->move(StepperMotor::BWD, go_steps);
             }
  
-            printf("\r\nGoing %s %d steps.\r\n", dir_fwd ? "Forward" : "Backward", go_steps);
+            printf("\r\nGoing %s %d steps\r\n", dir_fwd ? "Forward" : "Backward", go_steps);
+            /* force prompt display by generating empty command */
+            tinysh_char_in('\r');
             
             // Clear flags
             go_steps = 0;
@@ -321,7 +318,9 @@
                 else motors[which_axis]->run(StepperMotor::BWD, speed_sps);
             }
 
-            printf("\r\nRunning.\r\n");
+            printf("\r\nRunning\r\n");
+            /* force prompt display by generating empty command */
+            tinysh_char_in('\r');
 
             // Clear flags
             run_flag = false;
@@ -330,7 +329,9 @@
 
         if (stop_flag) {
 
-            printf("\r\nStopping.\r\n");
+            printf("\r\nStopping\r\n");
+            /* force prompt display by generating empty command */
+            tinysh_char_in('\r');
 
             // Hard stop 
             if (cmd_both) {
@@ -398,11 +399,15 @@
                 printf(status_bytes[m] & 0x0002 ? "SET\r\n" : "NOT SET\r\n");
                 printf("    HI_Z:                  ");
                 printf(status_bytes[m] & 0x0001 ? "SET\r\n" : "NOT SET\r\n");
-                printf("\r\n\n");
             }
             // clear flag
             status_flag = false;
+            /* force prompt display by generating empty command */
+            tinysh_char_in('\r');
         }
         
+        /* 3: Fetch new chars for Tinyshell ----------------------------------*/
+        tinysh_char_in(pc.getc());
+        
     } // end main loop
 }
\ No newline at end of file