
Hertz Controle
Dependencies: USBDevice USBHost mbed
main.cpp@0:82ac305b273e, 2018-04-15 (annotated)
- Committer:
- ABuche
- Date:
- Sun Apr 15 17:11:14 2018 +0000
- Revision:
- 0:82ac305b273e
Initial Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ABuche | 0:82ac305b273e | 1 | #include "mbed.h" |
ABuche | 0:82ac305b273e | 2 | #include "USBHostSerial.h" |
ABuche | 0:82ac305b273e | 3 | |
ABuche | 0:82ac305b273e | 4 | DigitalOut led(LED1); |
ABuche | 0:82ac305b273e | 5 | Serial pc(USBTX, USBRX); |
ABuche | 0:82ac305b273e | 6 | |
ABuche | 0:82ac305b273e | 7 | void serial_task(void const*) { |
ABuche | 0:82ac305b273e | 8 | USBHostSerial serial; |
ABuche | 0:82ac305b273e | 9 | |
ABuche | 0:82ac305b273e | 10 | while(1) { |
ABuche | 0:82ac305b273e | 11 | |
ABuche | 0:82ac305b273e | 12 | // try to connect a serial device |
ABuche | 0:82ac305b273e | 13 | while(!serial.connect()) |
ABuche | 0:82ac305b273e | 14 | Thread::wait(500); |
ABuche | 0:82ac305b273e | 15 | |
ABuche | 0:82ac305b273e | 16 | // in a loop, print all characters received |
ABuche | 0:82ac305b273e | 17 | // if the device is disconnected, we try to connect it again |
ABuche | 0:82ac305b273e | 18 | while (1) { |
ABuche | 0:82ac305b273e | 19 | |
ABuche | 0:82ac305b273e | 20 | // if device disconnected, try to connect it again |
ABuche | 0:82ac305b273e | 21 | if (!serial.connected()) |
ABuche | 0:82ac305b273e | 22 | break; |
ABuche | 0:82ac305b273e | 23 | |
ABuche | 0:82ac305b273e | 24 | // print characters received |
ABuche | 0:82ac305b273e | 25 | while (serial.available()) { |
ABuche | 0:82ac305b273e | 26 | printf("%c", serial.getc()); |
ABuche | 0:82ac305b273e | 27 | } |
ABuche | 0:82ac305b273e | 28 | |
ABuche | 0:82ac305b273e | 29 | Thread::wait(50); |
ABuche | 0:82ac305b273e | 30 | } |
ABuche | 0:82ac305b273e | 31 | } |
ABuche | 0:82ac305b273e | 32 | } |
ABuche | 0:82ac305b273e | 33 | |
ABuche | 0:82ac305b273e | 34 | int main() { |
ABuche | 0:82ac305b273e | 35 | Thread serialTask(serial_task, NULL, osPriorityNormal, 256 * 4); |
ABuche | 0:82ac305b273e | 36 | while(1) { |
ABuche | 0:82ac305b273e | 37 | led=!led; |
ABuche | 0:82ac305b273e | 38 | Thread::wait(500); |
ABuche | 0:82ac305b273e | 39 | } |
ABuche | 0:82ac305b273e | 40 | } |