Devan Lai
/
SLCAN
SLCAN/CAN-USB implementation for mbed targets
Diff: main.cpp
- Revision:
- 0:f2565808eea5
- Child:
- 1:3644b10bce2f
diff -r 000000000000 -r f2565808eea5 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Jun 04 04:40:58 2016 +0000 @@ -0,0 +1,58 @@ +#include <mbed.h> +#include <USBSerial.h> +#include "slcan.h" + +static const uint16_t VID = 0x1209; +static const uint16_t PID = 0x0001; +static const uint16_t VERSION = 0x0001; + + +CAN can1(D9, D10); +/* +USBSerial virtualUART(VID, PID, VERSION, false); +USBSLCAN slcan(virtualUART, can1); +*/ + +Serial hwUART(USBTX, USBRX); +SerialSLCAN slcan(hwUART, can1); + +Timer timer; +DigitalOut led(LED1); +DigitalOut led2(LED2); + +int main() { + can1.mode(CAN::Reset); + //can1.frequency(500000); + //can1.mode(CAN::Silent); + + //virtualUART.connect(false); + hwUART.baud(115200); + + led = 0; + led2 = 1; + while(1) { + bool active = false; + active = slcan.update(); + /* + if (virtualUART.configured()) { + led2 = 0; + active = slcan.update(); + } else { + led2 = 1; + virtualUART.connect(false); + } + */ + + if (active) { + timer.reset(); + timer.start(); + } + + if (timer.read_ms() > 100) { + led = 0; + timer.stop(); + } else { + led = 1; + } + } +} \ No newline at end of file