From 49e6624d3817c87d71265790d774e0d34a47b8b4 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 24 Nov 2018 03:50:02 +0100 Subject: usb-lora example works now - but is not stable yet... --- contrib/radiohead.patch | 5 +++-- lib/arduino-stub.cpp | 35 +++++++++++++++++++++++++++++++++++ usb-lora/usb-lora.cpp | 12 +++++++----- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/contrib/radiohead.patch b/contrib/radiohead.patch index 3b154ee..a7040a6 100644 --- a/contrib/radiohead.patch +++ b/contrib/radiohead.patch @@ -1,6 +1,6 @@ diff -Nur RadioHead-orig/RadioHead.h RadioHead/RadioHead.h --- RadioHead-orig/RadioHead.h 2018-11-15 11:40:24.000000000 +0100 -+++ RadioHead/RadioHead.h 2018-11-23 13:20:02.014133482 +0100 ++++ RadioHead/RadioHead.h 2018-11-24 03:40:03.395279378 +0100 @@ -317,8 +317,6 @@ cd /tmp mkdir RadioHead @@ -10,7 +10,7 @@ diff -Nur RadioHead-orig/RadioHead.h RadioHead/RadioHead.h cp /usr/local/projects/arduino/libraries/RadioHead/examples/cc110/cc110_client/cc110_client.pde application.cpp \endcode - Edit application.cpp and comment out any \#include so it looks like: -@@ -1283,11 +1281,13 @@ +@@ -1283,11 +1281,14 @@ #elif (RH_PLATFORM == RH_PLATFORM_GENERIC_AVR8) #include #include @@ -22,6 +22,7 @@ diff -Nur RadioHead-orig/RadioHead.h RadioHead/RadioHead.h - #include + #include + #include ++ #define RH_ATTACHINTERRUPT_TAKES_PIN_NUMBER // For Steve Childress port to ARM M4 w/CMSIS with STM's Hardware Abstraction lib. // See ArduinoWorkarounds.h (not supplied) diff --git a/lib/arduino-stub.cpp b/lib/arduino-stub.cpp index 201962f..38bc168 100644 --- a/lib/arduino-stub.cpp +++ b/lib/arduino-stub.cpp @@ -1006,6 +1006,41 @@ void detachInterrupt(uint8_t interruptNum) { } } +#define IMPLEMENT_ISR(vect, interrupt) \ + ISR(vect) { \ + intFunc[interrupt](); \ + } + +#if defined(__AVR_ATmega32U4__) + +IMPLEMENT_ISR(INT0_vect, EXTERNAL_INT_0) +IMPLEMENT_ISR(INT1_vect, EXTERNAL_INT_1) +IMPLEMENT_ISR(INT2_vect, EXTERNAL_INT_2) +IMPLEMENT_ISR(INT3_vect, EXTERNAL_INT_3) +IMPLEMENT_ISR(INT6_vect, EXTERNAL_INT_4) + +#elif defined(EICRA) && defined(EICRB) + +IMPLEMENT_ISR(INT0_vect, EXTERNAL_INT_2) +IMPLEMENT_ISR(INT1_vect, EXTERNAL_INT_3) +IMPLEMENT_ISR(INT2_vect, EXTERNAL_INT_4) +IMPLEMENT_ISR(INT3_vect, EXTERNAL_INT_5) +IMPLEMENT_ISR(INT4_vect, EXTERNAL_INT_0) +IMPLEMENT_ISR(INT5_vect, EXTERNAL_INT_1) +IMPLEMENT_ISR(INT6_vect, EXTERNAL_INT_6) +IMPLEMENT_ISR(INT7_vect, EXTERNAL_INT_7) + +#else + +IMPLEMENT_ISR(INT0_vect, EXTERNAL_INT_0) +IMPLEMENT_ISR(INT1_vect, EXTERNAL_INT_1) + +#if defined(EICRA) && defined(ISC20) +IMPLEMENT_ISR(INT2_vect, EXTERNAL_INT_2) +#endif + +#endif + // ****************** // this is from Arduino's WMath.cpp diff --git a/usb-lora/usb-lora.cpp b/usb-lora/usb-lora.cpp index d56946f..561f543 100644 --- a/usb-lora/usb-lora.cpp +++ b/usb-lora/usb-lora.cpp @@ -37,8 +37,8 @@ RH_RF95 lora; void recv_lora_msg() { - uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]; - uint8_t len = sizeof(buf); + uint8_t buf[RH_RF95_MAX_MESSAGE_LEN+1]; + uint8_t len = sizeof(buf)-1; led2_on(); if(!lora.recv(buf, &len)) { @@ -46,10 +46,12 @@ void recv_lora_msg() led2_off(); return; } + buf[len] = 0; - printf("lora.recv() got message: SNR = %d, data = ", lora.lastSNR()); - for(uint8_t i = 0; i < len; ++i) printf("%s0x%02X", (i==0) ? "" : " ", buf[i]); - printf("\r\n"); + // printf("lora.recv() got message: SNR = %d, data = ", lora.lastSNR()); + // for(uint8_t i = 0; i < len; ++i) printf("%s0x%02X", (i==0) ? "" : " ", buf[i]); + // printf("\r\n"); + printf("lora.recv() got message: SNR = %d, data = %s\r\n", lora.lastSNR(), buf); led2_off(); } -- cgit v1.2.3