Jan Kamidra
/
CANLoop_EventQueue
CAN-BUS loop back with EventQueue
Revision 0:d31fd55babb2, committed 2019-04-13
- Comitter:
- JohnnyK
- Date:
- Sat Apr 13 19:39:14 2019 +0000
- Commit message:
- Release
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed-os.lib | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r d31fd55babb2 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Apr 13 19:39:14 2019 +0000 @@ -0,0 +1,37 @@ +#include "mbed.h" + +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +CAN can2(PB_8, PB_9); +CAN can1(PB_12, PB_13); +EventQueue queue(32 * EVENTS_EVENT_SIZE); +Thread t; + +char counter = 0; + +void send() { + printf("send()\n"); + if(can1.write(CANMessage(1337, &counter, 1))) { + counter++; + printf("Message sent: %d\n", counter); + led3 = !led3; + } +} + +int main() { + + t.start(callback(&queue, &EventQueue::dispatch_forever)); + queue.call_every(1000, send); + + CANMessage msg; + while(1) { + if(can2.read(msg)) { + printf("Message received: %d\n", msg.data[0]); + led2 = !led2; + } + wait(0.2); + led1 = !led1; + } + +}
diff -r 000000000000 -r d31fd55babb2 mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Sat Apr 13 19:39:14 2019 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#0063e5de32fc575f061244c96ac60c41c07bd2e6