Cortex Challenge Team / Mbed 2 deprecated Nucleo_read_logic_probe

Dependencies:   mbed

Revision:
0:786207d961f4
Child:
1:533ef4c5f7ab
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Mar 13 03:33:26 2015 +0000
@@ -0,0 +1,119 @@
+#include "mbed.h"
+
+PortIn myIOs(PortC, 0xFFFF); // PC_all
+
+Serial pc(SERIAL_TX, SERIAL_RX);
+
+Ticker toggle_ticker;
+
+DigitalOut led(LED1);
+
+int pin =0;
+int vypis =0;
+
+bool start = true;
+
+void toggle()
+{
+    int meas,z;
+    meas=myIOs.read();
+
+    led= !led;
+    if (meas == pin ) {
+        start = true;
+    }
+    if(start) {
+        if(vypis==1) {
+            while(!pc.writeable());
+            for (z =32768; z > 0; z >>= 1) {
+                while(!pc.writeable());
+                printf(((meas & z) == z) ? "1" : "0");
+            }
+            while(!pc.writeable());
+            printf("\n");
+        } else if(vypis==2) {
+            while(!pc.writeable());
+            printf("%d\n", meas);
+        } else if(vypis==3) {
+            while(!pc.writeable());
+            printf("%o\n", meas);
+        } else if(vypis==4) {
+            while(!pc.writeable());
+            printf("%x\n", meas);
+        } else {
+            while(!pc.writeable());
+            printf("DEC: %d, HEX: %x, OCT: %o, BIN: ", meas,meas,meas);
+            for (z =32768; z > 0; z >>= 1) {
+                while(!pc.writeable());
+                printf(((meas & z) == z) ? "1" : "0");
+            }
+            while(!pc.writeable());
+            printf("\n");
+        }
+    }
+}
+
+void flushSerialPort()
+{
+    while(pc.readable())
+        pc.getc();
+    return;
+}
+
+
+int main()
+{
+    myIOs.mode(PullNone); // PullDown PullUp PullNone OpenDrain
+
+
+
+    int prijData=0;
+    int Data1=0;
+    float Data2=0;
+    pc.baud(115200);
+    toggle_ticker.detach();
+    toggle_ticker.attach(&toggle, 0.01);
+    printf("\nLogic sond.\n");
+
+    while(1) {
+        prijData=pc.scanf("%d %f",&Data1,&Data2);
+        if(prijData==2) {
+            //pc.printf()
+            if(Data1==1) {
+                toggle_ticker.detach();
+                toggle_ticker.attach(&toggle, Data2);
+            } else if(Data1==2) {
+                toggle_ticker.detach();
+            } else if(Data1==3) {
+                pin=(int)Data2;
+                start = false;
+            } else if(Data1==4) {
+                vypis=(int)Data2;
+            }
+        } else {
+            toggle_ticker.detach();
+
+            while(!pc.writeable());
+            printf("HELP - MENU\n");
+            while(!pc.writeable());
+            printf("Data send to PC is in dec format.\n");
+            while(!pc.writeable());
+            printf("Set data exactly.\n");
+            while(!pc.writeable());
+            printf("Write to console: \"xx yy\", where xx is a code of seting and yy his value.\n");
+            while(!pc.writeable());
+            printf("01 y.yyy - set period[s] to send data to PC and start reading value, example:01 0.01\n");
+            while(!pc.writeable());
+            printf("02 0 - stop reading value, example:02 0\n");
+            while(!pc.writeable());
+            printf("03 yyyy - Wait for pin to get to log.1. yyyy write in dec example:03 2000\n");
+            while(!pc.writeable());
+            printf("04 yy - print yy: 00-default all, 01-bin, 02-dec, 03-oct, 04-hex, example:04 00\n");
+            while(!pc.writeable());
+            printf("end HELP\n");
+            flushSerialPort();
+
+        }
+        // wait(0.2); // 200 ms
+    }
+}