Devan Lai
/
SLCAN
SLCAN/CAN-USB implementation for mbed targets
main.cpp
- Committer:
- devanlai
- Date:
- 2016-06-04
- Revision:
- 0:f2565808eea5
- Child:
- 1:3644b10bce2f
File content as of revision 0:f2565808eea5:
#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; } } }