This is a very simple guide, reviewing the steps required to get Blinky working on an Mbed OS platform.

Dependencies:   RemoteIR

Revision:
121:450f119863a7
Parent:
120:a1dd83d9c036
Child:
122:2c65a61b756d
--- a/main.cpp	Fri Apr 17 16:32:02 2020 +0000
+++ b/main.cpp	Fri Apr 17 16:46:38 2020 +0000
@@ -1,12 +1,8 @@
 #include "mbed.h"
 #include <string.h>
 
-//RawSerial pc(USBTX, USBRX);
-//RawSerial pc(D2, D8,115200);
-//RawSerial pc(PA10, PA9, 115200); // USART2
-
-//RawSerial pc(D8, D2,115200);
-RawSerial pc(PA_9, PA_10, 9600); // USART2
+RawSerial pc(PA_2, PA_3,115200);
+RawSerial phone(PA_9, PA_10, 9600); // USART2
 
 DigitalOut rLed(D3);
 DigitalOut gLed(D4);
@@ -14,73 +10,121 @@
 char buf[256];
 int index = 0;
 
-void rx_handler(void) {
+void pc_rx_handler(void) {
     int ch = pc.getc();
-//    phone.putc(ch);
+    
+    if(ch == 0x0D) {
+                while(!pc.writeable());
+                
+                pc.putc(0x0A);
+                phone.putc(0x0A);
+                
+                if(strcmp(buf,"Rled on") == 0) {
+                    rLed = 1;
+                    pc.printf("Rled status: %s\r\n", "on");
+                    phone.printf("Rled status: %s\r\n", "on");
+                    
+                } else if(strcmp(buf,"Rled off") == 0){
+                    rLed = 0;
+                    pc.printf("Rled status: %s\r\n", "off");
+                    phone.printf("Rled status: %s\r\n", "off");
+                    
+                } else if(strcmp(buf,"Rled status") == 0){
+                    pc.printf("Rled status: %s\r\n", rLed? "on" : "off");
+                    phone.printf("Rled status: %s\r\n", rLed? "on" : "off");
+                    
+                } else if(strcmp(buf,"Gled on") == 0) {
+                    gLed = 1;
+                    pc.printf("Gled status: %s\r\n", "on");
+                    phone.printf("Gled status: %s\r\n", "on");
+                    
+                } else if(strcmp(buf,"Gled off") == 0){
+                    gLed = 0;
+                    pc.printf("Gled status: %s\r\n", "off");
+                    phone.printf("Gled status: %s\r\n", "off");
+                    
+                } else if(strcmp(buf,"Gled status") == 0){
+                    pc.printf("Gled status: %s\r\n", gLed? "on" : "off");
+                    phone.printf("Gled status: %s\r\n", gLed? "on" : "off");
+                    
+                } else {
+                    pc.printf("Undefined command\r\n");
+                    phone.printf("Undefined command\r\n");
+                }
+                for(int i = 0; i < index; i++) buf[i] = '\0';
+                index = 0;
+    } else {
+    
+        pc.putc(ch);
+        phone.putc(ch);
+        buf[index] = ch;
+        index ++;
+    }
+}
+
+void phone_rx_handler(void) {
+    int ch = phone.getc();
     
     if(ch == 0x0D) {
                 while(!pc.writeable());
                 
                 pc.putc(0x0A);
-//                phone.putc(0x0A);
-                
-//                pc.printf("buf: %s\r\n",buf);
+                phone.putc(0x0A);
                 
                 if(strcmp(buf,"Rled on") == 0) {
                     rLed = 1;
                     pc.printf("Rled status: %s\r\n", "on");
-//                    phone.printf("Rled status: %s\r\n", "on");
+                    phone.printf("Rled status: %s\r\n", "on");
                     
                 } else if(strcmp(buf,"Rled off") == 0){
                     rLed = 0;
                     pc.printf("Rled status: %s\r\n", "off");
-//                    phone.printf("Rled status: %s\r\n", "off");
+                    phone.printf("Rled status: %s\r\n", "off");
                     
                 } else if(strcmp(buf,"Rled status") == 0){
                     pc.printf("Rled status: %s\r\n", rLed? "on" : "off");
-//                    phone.printf("Rled status: %s\r\n", rLed? "on" : "off");
+                    phone.printf("Rled status: %s\r\n", rLed? "on" : "off");
                     
                 } else if(strcmp(buf,"Gled on") == 0) {
                     gLed = 1;
                     pc.printf("Gled status: %s\r\n", "on");
-//                    phone.printf("Gled status: %s\r\n", "on");
+                    phone.printf("Gled status: %s\r\n", "on");
                     
                 } else if(strcmp(buf,"Gled off") == 0){
                     gLed = 0;
                     pc.printf("Gled status: %s\r\n", "off");
-//                    phone.printf("Gled status: %s\r\n", "off");
+                    phone.printf("Gled status: %s\r\n", "off");
                     
                 } else if(strcmp(buf,"Gled status") == 0){
                     pc.printf("Gled status: %s\r\n", gLed? "on" : "off");
-//                    phone.printf("Gled status: %s\r\n", gLed? "on" : "off");
+                    phone.printf("Gled status: %s\r\n", gLed? "on" : "off");
                     
                 } else {
                     pc.printf("Undefined command\r\n");
-//                    phone.printf("Undefined command\r\n");
+                    phone.printf("Undefined command\r\n");
                 }
                 for(int i = 0; i < index; i++) buf[i] = '\0';
-//                pc.printf("cleaned buf: '%s'\r\n", buf);
                 index = 0;
     } else if(ch != 10){
     
         pc.putc(ch);
-//        pc.printf("%d",ch);
+        phone.putc(ch);
         buf[index] = ch;
         index ++;
     }
-            
 }
+
 int main() {
     
     strcpy(buf,"");
     
-    pc.attach(&rx_handler);
+    pc.attach(&pc_rx_handler);
     pc.printf("\r\n Welcome to UART Lab_3_4!\r\n");
     pc.printf("Enter 'Rled/Gled on/off/status'\r\n");
     
-//    phone.attach(&rx_handler);
-//    phone.printf("\r\n Welcome to UART Lab_3_4!\r\n");
-//    phone.printf("Enter 'Rled/Gled on/off/status'\r\n");
+    phone.attach(&phone_rx_handler);
+    phone.printf("\r\n Welcome to UART Lab_3_4!\r\n");
+    phone.printf("Enter 'Rled/Gled on/off/status'\r\n");
     
     while(true) {
     }