PES 4 - Smart Medication Dispenser / PES4_ProgrammeforDesignReview2

Dependencies:   SDFileSystem mbed

Fork of PES4_Programme by PES 4 - Smart Medication Dispenser

Revision:
40:b5e533e1e033
Parent:
35:a9bf045dc014
Child:
41:f054a83f9556
--- a/source/main.cpp	Tue Mar 27 16:05:00 2018 +0000
+++ b/source/main.cpp	Tue Mar 27 16:24:59 2018 +0000
@@ -1,11 +1,14 @@
 #include "main.h"
 
 
-int state = 46;
+int state = 47;
 int old_state;
 
 Serial pc(USBTX, USBRX); // tx, rx
-char buf[100];
+
+/* PWM Test Tool */
+int channel;
+int dutyCycle;
 
 int main()
 {
@@ -20,7 +23,7 @@
         switch (state) {
             case 0:
                 printf("Hello World");
-                state = 1;
+                state = 47;
                 break;
             case 1:
                 break;
@@ -60,7 +63,10 @@
             case 38:
                 break;
 
-                /* Time test tool */
+                /**************************************************************/
+                /* Test Zone */
+
+                /* Time test tool: set Time */
             case 45:
                 s_time time;
                 time.second     =   30;
@@ -73,20 +79,56 @@
                 pc.printf("set now time\r\n");
                 setTime(&time);
                 pc.printf("read time: %02d:%02d:%02d, %02d.%02d.20%02d, weekday: %d\r\n",time.hour, time.minute, time.second, time.day, time.month, time.year, time.weekday);
-                state = 46;
+                state = 47;
                 pc.printf("change state to: %d\r\n",state);
                 break;
+
+                /* Time test tool: get Time */
             case 46:
                 wait(5);
                 time = getTime();
                 pc.printf("read time: %02d:%02d:%02d, %02d.%02d.20%02d, weekday: %d\r\n",time.hour, time.minute, time.second, time.day, time.month, time.year, time.weekday);
-                state = 46;
+                state = 47;
+                break;
+
+                /* Console State Switch */
+            case 47:
+                pc.printf("State Switch: Enter next State: \n\r");
+                pc.printf("45\tset Time\n\r46\tread Time\n\r47\tState Switch\n\r48\tServo Board Test Tool\n\t49\tempty\n\r50\tempty\n\r");
+                pc.scanf("%d", &state);
+                pc.printf("Switch to State %d\n\r",state);
+                fflush(stdin);
                 break;
+
+                /* Servo-Board Test Tool */
             case 48:
+                pc.printf("Servo-Board Test Tool\n\rEnter Channel Number and then Duty Cycle\n\r");
+                pc.printf("for exit, enter Channel > 15");
+                channel = 0;
+                while (channel < 16) {
+                    pc.printf("Channel Number: ");
+                    pc.scanf("%d", &channel);
+                    pc.printf("\r\nDuty Cycle 0..100: ");
+                    pc.scanf("%d", &dutyCycle);
+                    setPWM((char)channel, (char)dutyCycle);
+                    fflush(stdin);
+                }
+                pc.printf("leave Servo-Board Test Tool\n\r");
+                state = 47;
+                break;
+
+            case 49:
+                state = 47;
                 break;
 
 
             case 50:
+
+                state = 47;
+                break;
+
+            default:
+                state = 47; /* Go to State Switch */
                 break;
         }
     }