SLCAN/CAN-USB implementation for mbed targets
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include <mbed.h> 00002 #include <USBSerial.h> 00003 #include "slcan.h" 00004 00005 static const uint16_t VID = 0x1209; 00006 static const uint16_t PID = 0x0001; 00007 static const uint16_t VERSION = 0x0001; 00008 00009 00010 CAN can1(D9, D10); 00011 USBSerial virtualUART(VID, PID, VERSION, false); 00012 USBSLCAN slcan(virtualUART, can1); 00013 00014 //Serial hwUART(USBTX, USBRX); 00015 //SerialSLCAN slcan(hwUART, can1); 00016 00017 Timer timer; 00018 DigitalOut led(LED1); 00019 DigitalOut led2(LED2); 00020 00021 int main() { 00022 virtualUART.connect(false); 00023 //hwUART.baud(115200); 00024 00025 led = 0; 00026 led2 = 1; 00027 while(1) { 00028 bool active = false; 00029 //active = slcan.update(); 00030 00031 if (virtualUART.configured()) { 00032 led2 = 0; 00033 active = slcan.update(); 00034 } else { 00035 led2 = 1; 00036 virtualUART.connect(false); 00037 } 00038 00039 if (active) { 00040 timer.reset(); 00041 timer.start(); 00042 } 00043 00044 if (timer.read_ms() > 100) { 00045 led = 0; 00046 timer.stop(); 00047 } else { 00048 led = 1; 00049 } 00050 } 00051 }
Generated on Sun Jul 24 2022 20:02:47 by
1.7.2