ftf mbedos threads lab

Dependencies:   ST7567

Revision:
1:e7266223f1fa
Parent:
0:ead5ee0a33fa
--- a/main.cpp	Sat Nov 05 02:46:29 2016 +0000
+++ b/main.cpp	Sat Nov 05 23:27:09 2016 +0000
@@ -43,6 +43,12 @@
 void app1_task(void) {
     const char thread_message[] = {"app1_task now running! \0"};
     for(;;) {
+        /* each thread has the same behavior
+         * waits for a signal and when it asserted
+         * executes and keep sending a signal_set
+         * in order to suspend only when requested via
+         * terminal
+         */
         app1_thread.signal_wait(1);
         app1_thread.signal_set(1);
         glcd.locate((LCD_WIDTH - (FONT_WIDTH * sizeof(thread_message)))/2,
@@ -247,22 +253,36 @@
         if(pc_serial.readable()) {
             bool new_cmd = false;
             
-            
             /* get the incoming character */
             char c = pc_serial.getc();
-            pc_serial.putc(c);
-            
-            
-            /* is a enter ? */
+                       
             if( (c == '\n') || (c == '\r')) {
+                /* handle enter key */
                 new_cmd = true;
-                pc_serial.getc();
+                pc_serial.printf("\n\r");
+                
+            }else if( (c == 0x7F) || (c == 0x08)){
+                /* handle backspace and del keys */
+                pc_serial.printf("\033[1D");
+                pc_serial.putc(' ');
+                pc_serial.printf("\033[1D");
+                
+                read_ptr--;
+                if(read_ptr < -1) read_ptr = 1023;
+                serial_buffer[read_ptr] = ' ';
+
                 
             } else {
+                /* loopback the pressed key */
+                pc_serial.putc(c);
+                
+                /* store the incoming character on command circular buffer */
                 serial_buffer[read_ptr] = c;
                 read_ptr = (read_ptr + 1) % 1024;
             }
             
+            
+            
             if(new_cmd != false) {
                 /* command arrived, has other characters? */
                 if(read_ptr != 0) {
@@ -281,7 +301,7 @@
 }
 
 static void idle_hook(void) {
-        const char thread_message[] = {"No thread running! \0"};        
+        const char thread_message[] = {"No thread running!"};        
         glcd.locate((LCD_WIDTH - (FONT_WIDTH * sizeof(thread_message)))/2, 
                     (LCD_HEIGHT - FONT_HEIGHT) / 2);
         glcd.printf(thread_message);