a

Dependencies:   LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI

Revision:
2:8788d711db7e
Parent:
1:42a82d41947f
Child:
3:6fc7976cc5bf
--- a/main.cpp	Sat May 09 08:55:15 2020 +0000
+++ b/main.cpp	Wed May 20 15:42:07 2020 +0000
@@ -1,26 +1,65 @@
 #include "mbed.h"
+#include "string.h"
 
+#define BUFFER_SIZE 100
+
+Serial MySerial(USBTX, USBRX);
 DigitalOut led_green(LED1);
 DigitalOut led_red(LED2);
 
-//Marcin
+char gets(char *pStr, unsigned char ucSize){
+    unsigned char ucStrPtr = 0;
+    while(ucStrPtr < ucSize) {
+        pStr[ucStrPtr] = MySerial.getc();
+        if(pStr[ucStrPtr] == '\r') {
+            pStr[ucStrPtr] = NULL;
+            return 0;
+        }
+        ucStrPtr ++;    
+    }
+    return 1;
+}
 
-DigitalIn user_button(USER_BUTTON);
-
-float delay = 0.5;
+char puts(char *pStr, unsigned char ucSize){   
+    unsigned char ucNullPtr;
+    for(ucNullPtr = 0; ucNullPtr <= ucSize; ucNullPtr++){
+        if(pStr[ucNullPtr] == NULL) {
+            break;
+        }
+        else {}
+    }
+    if (ucNullPtr == ucSize) {
+        return 1;
+    }
 
-int main()
-{   
-    while(1) {
-        
-        if(user_button){
-            led_red = 0;
-            led_green = !led_green;
+    for(unsigned char ucIdx = 0; ucIdx < ucNullPtr; ucIdx ++) {
+        MySerial.putc(pStr[ucIdx]);
+    }
+    MySerial.putc('\r');
+    return 0;
+}
+
+
+int main() {
+    char cTablica[BUFFER_SIZE];
+    extern struct Token asToken[];
+    extern unsigned char ucTokenCnt;
+   
+    while(1){
+        if(!gets(cTablica, BUFFER_SIZE)){        
+          DecodeMsg(cTablica);
+          if ((asToken[0].eType == KEYWORD) & (ucTokenCnt != 0)){
+            switch (asToken[0].uValue.eKeyword){
+              case (CLB):
+                led_green = !led_green;
+                break;
+              case (GT):
+                led_red = !led_red;
+                break;
+              default:
+                break;
+            }
+          }
         }
-        else{
-            led_green = 0;
-            led_red = !led_red;
-        }
-        wait(delay);
     }
 }