thread pointers

Dependencies:   TextLCD mbed-rtos mbed

Fork of myStopwatch_threads by CIS541 Xueli Jon

Files at this revision

API Documentation at this revision

Comitter:
jfields
Date:
Fri Oct 03 20:18:22 2014 +0000
Parent:
1:38e744366b97
Commit message:
pointer threads!

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 38e744366b97 -r 9386c6f541bd main.cpp
--- a/main.cpp	Fri Oct 03 19:26:13 2014 +0000
+++ b/main.cpp	Fri Oct 03 20:18:22 2014 +0000
@@ -1,42 +1,72 @@
 #include "mbed.h"
 #include "rtos.h"
 #include "TextLCD.h"
-
+ 
 TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD16x2);
 Serial pc (USBTX, USBRX);
 DigitalOut myled(LED1);
  
-
+ 
 // global vars 
 int mm [] = {0, 0};
 int ss [] = {0, 0};
 int MM [] = {0, 0};
-
+ 
 // functions
 void update_display(void const *args);
 void update_mm(void const *args);
 void update_ss(void const *args);
 void update_MM(void const *args);
-
+ 
 int main() {
     
     Thread thread_display(update_display);
-    Thread thread_mm(update_mm);
-    Thread thread_ss(update_ss);
-    Thread thread_MM(update_MM);
+    Thread * mmptr;
+    Thread * ssptr; 
+    Thread * MMptr;    
+ 
+    char input = 'z';
+    int run_status = 0;
     
-    while (true) {
+    while(1) {
+        
+        if ( input == 's') { 
+            if (run_status==0) {
+                mmptr = new Thread(update_mm);
+                ssptr = new Thread(update_ss);
+                MMptr = new Thread(update_MM);
+                run_status = 1;
+            }
+        }
+        if ( input == 'p') {
+            if (run_status==1) {
+                delete mmptr;
+                delete ssptr;
+                delete MMptr;
+                run_status = 0;
+            }
+        }
+        if ( input == 'r') {
+            if (run_status == 0) {
+                mm[0] = mm[1] = 0;
+                ss[0] = ss[1] = 0;
+                MM[0] = MM[1] = 0;
+            }
+        }
+        
+        input = pc.getc();
 
     }
+    
 }
-
+ 
 void update_display(void const *args) {
     while (1) {
         lcd.printf("%d%d:%d%d:%d%d\n\n", MM[1], MM[0],ss[1],ss[0],mm[1],mm[0]);
         Thread::wait(10);
     }
 }
-
+ 
 void update_mm(void const *args) {
     while (1) {
         Thread::wait(10);
@@ -51,7 +81,7 @@
         }
     }
 }
-
+ 
 void update_ss(void const *args) {
     while (1) {
         Thread::wait(1000);
@@ -66,7 +96,7 @@
         }
     }
 }
-
+ 
 void update_MM(void const *args) {
     while (1) {
         Thread::wait(60000);
@@ -81,3 +111,4 @@
         }
     }
 }
+ 
\ No newline at end of file