diff options
author | Christian Pointner <equinox@spreadspace.org> | 2016-05-03 19:44:47 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2016-05-03 19:44:47 +0200 |
commit | 5e855e95761b936ddba1c964c329c15219f59afd (patch) | |
tree | f32a595e28ee00503f9fea91d19bdae322cb875f /usb-pjon/usb-pjon.cpp | |
parent | add PJON source to contrib makefile (diff) |
added external lib PJON - not working yet..
Diffstat (limited to 'usb-pjon/usb-pjon.cpp')
-rw-r--r-- | usb-pjon/usb-pjon.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/usb-pjon/usb-pjon.cpp b/usb-pjon/usb-pjon.cpp index eb4e7f8..66d58e1 100644 --- a/usb-pjon/usb-pjon.cpp +++ b/usb-pjon/usb-pjon.cpp @@ -31,14 +31,36 @@ #include "usbio.h" #include "Arduino.h" -//#include "PJON.h" +#include "PJON.h" +PJON bus(5, 45); // Bus connection to pin 12, device id 45 + +void error_handler(uint8_t code, uint8_t data) { + if(code == CONNECTION_LOST) { + printf("Connection with device ID %d is lost.\r\n", data); + } + if(code == PACKETS_BUFFER_FULL) { + printf("Packet buffer is full, has now a length of %d\r\n", data); + printf("Possible wrong bus configuration!\r\n"); + printf("higher MAX_PACKETS in PJON.h if necessary.\r\n"); + } + if(code == MEMORY_FULL) { + printf("Packet memory allocation failed. Memory is full.\r\n"); + } + if(code == CONTENT_TOO_LONG) { + printf("Content is too long, length: %d\r\n", data); + } + if(code == ID_ACQUISITION_FAIL) { + printf("Can't acquire a free id %d\r\n", data); + } +} void handle_cmd(uint8_t cmd) { switch(cmd) { case '0': led_off(); break; case '1': led_on(); break; + case 's': bus.send(44, "hello", 5); break; case '!': reset2bootloader(); break; default: printf("error\r\n"); return; } @@ -55,6 +77,10 @@ int main(void) usbio_init(); sei(); + arduino_init(); + bus.begin(); + bus.set_error(error_handler); + for(;;) { int16_t BytesReceived = usbio_bytes_received(); while(BytesReceived > 0) { @@ -66,5 +92,6 @@ int main(void) } usbio_task(); + bus.update(); } } |