From 5e855e95761b936ddba1c964c329c15219f59afd Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 3 May 2016 19:44:47 +0200 Subject: added external lib PJON - not working yet.. --- usb-pjon/Makefile | 5 ++--- usb-pjon/usb-pjon.cpp | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) (limited to 'usb-pjon') diff --git a/usb-pjon/Makefile b/usb-pjon/Makefile index 2848646..e9aecc2 100644 --- a/usb-pjon/Makefile +++ b/usb-pjon/Makefile @@ -21,12 +21,11 @@ ## NAME := usb-pjon -BOARD_TYPE := minimus32 +BOARD_TYPE := teensy2 CXX_OBJ := $(NAME).o LIBS := util led lufa-descriptor-usbserial usbio CXX_LIBS := arduino-stub -EXTERNAL_LIBS := lufa -#EXTERNAL_LIBS := lufa pjon +EXTERNAL_LIBS := lufa pjon SPREADAVR_PATH := .. PJON_PATH := $(SPREADAVR_PATH)/contrib/PJON 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(); } } -- cgit v1.2.3