Alexander Rakhman / Mbed 2 deprecated MaxSonarTTL2Flash

Dependencies:   SDFileSystem mbed

Files at this revision

API Documentation at this revision

Comitter:
shtirlitz
Date:
Sat Apr 02 21:37:01 2016 +0000
Parent:
2:a5ea1929e545
Commit message:
Excluded bullshit

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Mar 17 22:32:39 2016 +0000
+++ b/main.cpp	Sat Apr 02 21:37:01 2016 +0000
@@ -3,80 +3,61 @@
 
 SDFileSystem sd(PA_7, PA_6, PA_5, PA_4, "sd");  //mosi, miso, sck, cs
 
-Serial pc(PA_2, PA_3);               // This is USB tx, rx
-Serial sensor_uart(PA_9, PA_10);        // This is USART2 tx, rx
-
-DigitalOut myled(PC_13);             // This is USER LED
-DigitalOut myled2(PB_11);             // This is USER LED
-DigitalIn Button(PB_12);   // This is Blue-Button
+Serial pc_uart(PA_2, PA_3);          // This is USART1 tx, rx
+Serial sensor_uart(PA_9, PA_10);     // This is USART2 tx, rx
 
-#define Pressed 0
-#define NotPressed 1
+DigitalOut led_read(PC_13);          // This is reading LED indicator
+DigitalOut led_write(PB_11);         // This is writing LED indicator
+DigitalIn button(PB_12);             // This is STOP button
 
-int USBByte='\0';
-int GaugeByte='\0';
-int n=0;
-int readgauge = 0;
 Timer t;
-char buf[32];
-char str[32];
-char str2[32];
+char buf[5];
+char reading_str[32];
+char writing_str[32];
 uint8_t writeflag = 0;
-long millis = 0;
 
-void PC_INT()  // USART2 used for Debug
-{
-    // Note: you need to actually read from the serial to clear the RX interrupt
-    pc.putc(pc.getc());
-    myled = (myled)?(0):(1);
-}
-
-void SENSOR_USART_INT()  // SENSOR_USART
+void SENSOR_USART_INT()  // sensor uart interrupt
 {
     if (sensor_uart.getc() == 'R') {
-        myled = (myled)?(0):(1);
-        sprintf(str, "%d; %s;", t.read_ms(), sensor_uart.gets(buf, 5));
+        led_read = 1;
+        sprintf(reading_str, "%d; %s;", t.read_ms(), sensor_uart.gets(buf, 5));
         writeflag = 1;
-        //pc.printf("%s\r\n", str);
     }
 }
 
 int main()
 {
-    myled = 0;
-
-    // SetUp the baud rate
-    pc.baud(115200);
-    sensor_uart.baud(9600);
+    pc_uart.baud(115200);   //set baudrate of pc port
+    sensor_uart.baud(9600); //set baudrate of sensorport
 
     mkdir("/sd/ultrasonic", 0777);
 
     FILE *fp = fopen("/sd/ultrasonic/test.csv", "w");
     if(fp == NULL) {
-        pc.printf("Could not open file for write\n");
+        pc_uart.printf("Could not open file for write\n");
     }
     fprintf(fp, "timestamp;value;\n");
     //fclose(fp);
 
-    pc.printf("\n\r\n\r|||||START MAIN|||||\n\r");
+    pc_uart.printf("\n\r\n\r|||||START_MAIN|||||\n\r");
     t.start();
     sensor_uart.attach(&SENSOR_USART_INT);
-    pc.attach(&PC_INT);
 
     while(1) {
-        if (Button)
+        if (button)
             fclose(fp);
         if (writeflag) {
-            myled2 = (myled2)?(0):(1);
-            memcpy(str2, str, 32);
-            fprintf(fp, "%s\n", str2);
+            led_write = 1;
+            memcpy(writing_str, reading_str, 32);
+            fprintf(fp, "%s\n", writing_str);
             writeflag = 0;
-            fprintf(pc, "%s\r\n", str2);
-            }
-        else
-        {
-            myled2 = (myled2)?(0):(1);
+            fprintf(pc_uart, "%s\r\n", writing_str);
+        }
+        else {
+            led_write = 1;
             wait (0.07);
         }
+        led_read = 0;
+        led_write = 0;
     }
 }
\ No newline at end of file