diff options
-rw-r--r-- | Debug.h | 31 | ||||
-rw-r--r-- | trygvisio_soil_moisture.ino | 17 |
2 files changed, 13 insertions, 35 deletions
@@ -3,15 +3,9 @@ #include "config-check.h" -template<bool B, class T, class F> -struct conditional { typedef T type; }; +#include <AltSoftSerial.h> -template<class T, class F> -struct conditional<false, T, F> { typedef F type; }; - -#include <SoftwareSerial.h> - -#ifdef __AVR_ATtiny85__ +#ifdef ARDUINO_attiny class Serial { public: void begin(int); @@ -33,27 +27,14 @@ enum DebugSink { DEBUG_SINK_SOFTWARE_SERIAL, }; -struct DebugEmptyBase {}; -struct DebugSoftwareSerialBase { - // TODO: these should be customizable - static const int rx_pin = 1; - static const int tx_pin = 0; - -public: - SoftwareSerial ss; - - DebugSoftwareSerialBase() : ss(rx_pin, tx_pin) { - } -}; - -template <enum DebugSink sink_> -class Debug : public conditional<sink_ == DEBUG_SINK_SOFTWARE_SERIAL, DebugSoftwareSerialBase, DebugEmptyBase>::type +template <enum DebugSink sink_, int rx_pin = 1, int tx_pin = 0> +class Debug { - + AltSoftSerial ss; public: const enum DebugSink sink; - Debug() : sink(sink_) { + Debug() : ss(rx_pin, tx_pin), sink(sink_) { } inline void begin(const long baud_rate) { diff --git a/trygvisio_soil_moisture.ino b/trygvisio_soil_moisture.ino index 25baac0..929f220 100644 --- a/trygvisio_soil_moisture.ino +++ b/trygvisio_soil_moisture.ino @@ -7,8 +7,9 @@ #ifdef PERSISTENT_CONFIGURATION_SUPPORT #include <EEPROM.h> #endif -#include <SoftwareSerial.h> +#include <AltSoftSerial.h> #include <SPI.h> + #include <lib_aci.h> #include <aci_setup.h> #include <aci_evts.h> @@ -73,7 +74,7 @@ static hal_aci_evt_t aci_data; static boolean timing_change_done = false; void __ble_assert(const char *file, uint16_t line) -{ +{ debug.print("ERROR "); debug.print(file); debug.print(": "); @@ -84,7 +85,6 @@ void __ble_assert(const char *file, uint16_t line) static void go_to_sleep(); -extern SoftwareSerial ss; void setup() { #ifdef TXLED0 // An attempt to make sure that the RX and TX LEDs are turned off when running normally. @@ -105,11 +105,7 @@ void setup() { if (debug.sink == DEBUG_SINK_SERIAL) { debug.begin(115200); } else if (debug.sink == DEBUG_SINK_SOFTWARE_SERIAL) { - debug.begin(9600); - - while(true) { - debug.println("hello debug world!"); - } + debug.begin(9600); } #if WAIT_FOR_SERIAL_BEFORE_STARING @@ -148,7 +144,7 @@ static void setup_rf() { // SPI_CLOCK_DIV8 = 2MHz SPI speed // SPI_CLOCK_DIV16 = 1MHz SPI speed -#ifdef ARDUINO_BLEND_MICRO +#if defined(ARDUINO_BLEND_MICRO) aci_state.aci_pins.board_name = REDBEARLAB_SHIELD_V1_1; aci_state.aci_pins.reqn_pin = 6; aci_state.aci_pins.rdyn_pin = 7; @@ -163,7 +159,7 @@ static void setup_rf() { aci_state.aci_pins.interface_is_interrupt = false; aci_state.aci_pins.interrupt_number = 4; -#elif ARDUINO_AVR_LEONARDO +#elif defined(ARDUINO_AVR_LEONARDO) // Assumes OLIMEXINO-32U4 and UEXT aci_state.aci_pins.board_name = BOARD_DEFAULT; aci_state.aci_pins.reqn_pin = 2; @@ -179,6 +175,7 @@ static void setup_rf() { aci_state.aci_pins.interface_is_interrupt = false; // aci_state.aci_pins.interrupt_number = 4; +#elif defined(ARDUINO_attiny) #else #error unknown board type #endif |