From 77e261f12089bd7db854d21fc81a42eaa60e0b67 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 25 Jul 2015 17:35:57 +0200 Subject: o Even better debug code. --- Debug.h | 129 +++++++++++++++++++++++------- app.cpp | 136 ++++++++++++++++---------------- config.h | 5 ++ trygvisio_soil_moisture.ino | 186 ++++++++++++++++++++++---------------------- 4 files changed, 267 insertions(+), 189 deletions(-) diff --git a/Debug.h b/Debug.h index 455b6db..a5b3134 100644 --- a/Debug.h +++ b/Debug.h @@ -3,77 +3,150 @@ #include "config.h" -template -class DebugImpl { +enum DebugSink { + DEBUG_SINK_SERIAL, + DEBUG_SINK_SOFTWARE_SERIAL, + DEBUG_SINK_VOID, +}; + +template +class Debug { public: + inline void begin(unsigned int baud_rate); + + inline operator bool(); + + inline bool available(); + + size_t write(uint8_t); + template - static inline + inline void print(T t, int format = DEC); - template - static inline - void print(const T *t); + inline + void print(const char *t); + + inline + void print(const __FlashStringHelper *t); template - static inline + inline void println(T t, int format = DEC); template - static inline + inline void println(const T *t); - static inline + inline + void println(const __FlashStringHelper *t); + + inline void println(); + + inline + void flush(); }; -template +template +inline void Debug::begin(unsigned int baud_rate) { + if (sink == DEBUG_SINK_SERIAL) { + Serial.begin(baud_rate); + } +} + +template +inline Debug::operator bool() { + if (sink == DEBUG_SINK_SERIAL) { + return Serial; + } + + return false; +} + +template +inline bool Debug::available() { + if (sink == DEBUG_SINK_SERIAL) { + return Serial.available(); + } + + return false; +} + +template +inline size_t Debug::write(uint8_t value) { + if (sink == DEBUG_SINK_SERIAL) { + return Serial.write(value); + } + + return 0; +} + +template template inline -void DebugImpl::print(T t, int format) { - if (enable) { +void Debug::print(T t, int format) { + if (sink == DEBUG_SINK_SERIAL) { Serial.print(t, format); } } -template -template +template inline -void DebugImpl::print(const T *t) { - if (enable) { +void Debug::print(const char *t) { + if (sink == DEBUG_SINK_SERIAL) { + Serial.print(t); + } +} +template +inline +void Debug::print(const __FlashStringHelper *t) { + if (sink == DEBUG_SINK_SERIAL) { Serial.print(t); } } -template +template template inline -void DebugImpl::println(T t, int format) { - if (enable) { +void Debug::println(T t, int format) { + if (sink == DEBUG_SINK_SERIAL) { Serial.println(t, format); } } -template +template template inline -void DebugImpl::println(const T *t) { - if (enable) { +void Debug::println(const T *t) { + if (sink == DEBUG_SINK_SERIAL) { + Serial.println(t); + } +} + +template +inline +void Debug::println(const __FlashStringHelper *t) { + if (sink == DEBUG_SINK_SERIAL) { Serial.println(t); } } -template +template inline -void DebugImpl::println() { - if (enable) { +void Debug::println() { + if (sink == DEBUG_SINK_SERIAL) { Serial.println(); } } -#if ENABLE_DEBUG_LOG == 1 -typedef DebugImpl Debug; +#if DEBUG_SINK == 1 +static Debug debug; +#elif DEBUG_SINK == 2 +static Debug debug; #else -typedef DebugImpl Debug; +#error Invalid value for DEBUG_SINK, must be one of 1 (for no output), 2 for serial port +// , or 3 for software serial. #endif #endif diff --git a/app.cpp b/app.cpp index 76d2653..e347b46 100644 --- a/app.cpp +++ b/app.cpp @@ -65,7 +65,7 @@ void sm_setup() { pinMode(2, OUTPUT); digitalWrite(2, HIGH); - Debug::println("sm_setup: done"); + debug.println("sm_setup: done"); } void sm_on_connect() { @@ -118,12 +118,12 @@ void sm_loop() { s.value = (uint16_t) analogRead(s.a_pin); if (count++ > 0) { - Debug::print(", "); + debug.print(", "); } - Debug::print("#"); - Debug::print(i, DEC); - Debug::print(" = "); - Debug::print(s.value, DEC); + debug.print("#"); + debug.print(i, DEC); + debug.print(" = "); + debug.print(s.value, DEC); struct sm_res res; res.code = SM_CMD_GET_VALUE; @@ -134,7 +134,7 @@ void sm_loop() { } if (count > 0) { - Debug::println(); + debug.println(); } } @@ -142,110 +142,110 @@ void sm_loop() { static void write_name(uint8_t const* name, uint8_t len) { for (int i = 0; i < len; i++) { - Debug::print((char)name[i]); + debug.print((char)name[i]); } } void write_req(struct sm_req const &req) { - Debug::print(">> "); + debug.print(">> "); switch (req.code) { case SM_CMD_GET_SENSOR_COUNT: - Debug::print("SM_CMD_GET_SENSOR_COUNT"); + debug.print("SM_CMD_GET_SENSOR_COUNT"); break; case SM_CMD_GET_VALUE: - Debug::print("SM_CMD_GET_VALUE"); - Debug::print(": sensor="); - Debug::print(req.get_value.sensor, DEC); + debug.print("SM_CMD_GET_VALUE"); + debug.print(": sensor="); + debug.print(req.get_value.sensor, DEC); break; case SM_CMD_SET_WARNING_VALUE: - Debug::print("SM_CMD_SET_WARNING_VALUE"); - Debug::print(": sensor="); - Debug::print(req.set_warning_value.sensor, DEC); - Debug::print(", warning_value="); - Debug::print(req.set_warning_value.warning_value, DEC); + debug.print("SM_CMD_SET_WARNING_VALUE"); + debug.print(": sensor="); + debug.print(req.set_warning_value.sensor, DEC); + debug.print(", warning_value="); + debug.print(req.set_warning_value.warning_value, DEC); break; case SM_CMD_GET_WARNING_VALUE: - Debug::print("SM_CMD_GET_WARNING_VALUE"); - Debug::print(": sensor="); - Debug::print(req.get_warning_value.sensor, DEC); + debug.print("SM_CMD_GET_WARNING_VALUE"); + debug.print(": sensor="); + debug.print(req.get_warning_value.sensor, DEC); break; case SM_CMD_SET_SENSOR_NAME: - Debug::print("SM_CMD_SET_SENSOR_NAME"); - Debug::print(": sensor="); - Debug::print(req.set_sensor_name.sensor, DEC); - Debug::print(", name="); + debug.print("SM_CMD_SET_SENSOR_NAME"); + debug.print(": sensor="); + debug.print(req.set_sensor_name.sensor, DEC); + debug.print(", name="); write_name(req.set_sensor_name.name, req.set_sensor_name.length); break; case SM_CMD_GET_SENSOR_NAME: - Debug::print("SM_CMD_GET_SENSOR_NAME"); + debug.print("SM_CMD_GET_SENSOR_NAME"); break; case SM_CMD_SET_UPDATE_INTERVAL: - Debug::print("SM_CMD_SET_UPDATE_INTERVAL"); - Debug::print(": interval_in_seconds="); - Debug::print(req.set_update_interval.interval_in_seconds, DEC); + debug.print("SM_CMD_SET_UPDATE_INTERVAL"); + debug.print(": interval_in_seconds="); + debug.print(req.set_update_interval.interval_in_seconds, DEC); break; default: - Debug::print("Unknown command: "); - Debug::print(req.code); + debug.print("Unknown command: "); + debug.print(req.code); } - Debug::println(); + debug.println(); } void write_res(struct sm_res const &res) { - Debug::print("<< "); + debug.print("<< "); switch (res.code) { case SM_CMD_GET_SENSOR_COUNT: - Debug::print("SM_CMD_GET_SENSOR_COUNT"); - Debug::print(": count="); - Debug::print(res.get_sensor_count.count, DEC); + debug.print("SM_CMD_GET_SENSOR_COUNT"); + debug.print(": count="); + debug.print(res.get_sensor_count.count, DEC); break; case SM_CMD_GET_VALUE: - Debug::print("SM_CMD_GET_VALUE"); - Debug::print(": sensor="); - Debug::print(res.get_value.sensor, DEC); - Debug::print(", value="); - Debug::print(res.get_value.value, DEC); + debug.print("SM_CMD_GET_VALUE"); + debug.print(": sensor="); + debug.print(res.get_value.sensor, DEC); + debug.print(", value="); + debug.print(res.get_value.value, DEC); break; case SM_CMD_SET_WARNING_VALUE: - Debug::print("SM_CMD_SET_WARNING_VALUE"); + debug.print("SM_CMD_SET_WARNING_VALUE"); break; case SM_CMD_GET_WARNING_VALUE: - Debug::print("SM_CMD_GET_WARNING_VALUE"); - Debug::print(": warning_value="); - Debug::print(res.get_warning_value.warning_value, DEC); + debug.print("SM_CMD_GET_WARNING_VALUE"); + debug.print(": warning_value="); + debug.print(res.get_warning_value.warning_value, DEC); break; case SM_CMD_SET_SENSOR_NAME: - Debug::print("SM_CMD_SET_SENSOR_NAME"); + debug.print("SM_CMD_SET_SENSOR_NAME"); break; case SM_CMD_GET_SENSOR_NAME: - Debug::print("SM_CMD_GET_SENSOR_NAME"); - Debug::print(": name="); + debug.print("SM_CMD_GET_SENSOR_NAME"); + debug.print(": name="); write_name(res.get_sensor_name.name, res.get_sensor_name.length); break; case SM_CMD_SET_UPDATE_INTERVAL: - Debug::print("SM_CMD_SET_UPDATE_INTERVAL"); + debug.print("SM_CMD_SET_UPDATE_INTERVAL"); break; default: - Debug::print("Unknown command: "); - Debug::print(res.code); + debug.print("Unknown command: "); + debug.print(res.code); } - Debug::println(); + debug.println(); } #endif // SM_DEBUG @@ -418,38 +418,38 @@ static void store_settings() { index += store_string(index, s.name_length, s.name); } - Debug::println("Settings saved"); + debug.println("Settings saved"); } static void setup_settings() { if (!load_settings()) { - Debug::println("Could not load settings, storing defaults"); + debug.println("Could not load settings, storing defaults"); store_settings(); } else { - Debug::println("Settings loaded"); + debug.println("Settings loaded"); } for (int i = 0; i < SENSOR_COUNT; i++) { - Debug::print("Sensor #"); - Debug::print(i, DEC); + debug.print("Sensor #"); + debug.print(i, DEC); struct sm_sensor &s = sensors[i]; -// Debug::print(", name len="); -// Debug::print(s.name_length, DEC); -// Debug::print(": ->"); -// Serial.write((const uint8_t*) s.name, s.name_length); -// Debug::print("<-"); +// debug.print(", name len="); +// debug.print(s.name_length, DEC); +// debug.print(": ->"); +// debug.write((const uint8_t*) s.name, s.name_length); +// debug.print("<-"); - Debug::print(": update_interval="); - Debug::print(s.update_interval, DEC); - Debug::print(", warning_value="); - Debug::print(s.warning_value, DEC); + debug.print(": update_interval="); + debug.print(s.update_interval, DEC); + debug.print(", warning_value="); + debug.print(s.warning_value, DEC); - Debug::println(); + debug.println(); } - Debug::println("setup_settings: done"); + debug.println("setup_settings: done"); } #else static void setup_settings() { diff --git a/config.h b/config.h index 7ab5ac8..7f9a235 100644 --- a/config.h +++ b/config.h @@ -109,4 +109,9 @@ #define LOW_POWER 0 #endif +// Default to Serial port. +#ifndef DEBUG_SINK +#define DEBUG_SINK 2 +#endif + #endif diff --git a/trygvisio_soil_moisture.ino b/trygvisio_soil_moisture.ino index 7306c05..53936e3 100644 --- a/trygvisio_soil_moisture.ino +++ b/trygvisio_soil_moisture.ino @@ -28,11 +28,11 @@ static boolean timing_change_done = false; void __ble_assert(const char *file, uint16_t line) { - Debug::print("ERROR "); - Debug::print(file); - Debug::print(": "); - Debug::print(line); - Debug::print("\n"); + debug.print("ERROR "); + debug.print(file); + debug.print(": "); + debug.print(line); + debug.print("\n"); while (1) {}; } @@ -58,13 +58,13 @@ void setup() { CLKPR = 0; #endif - Serial.begin((unsigned int)115200); + debug.begin((unsigned int)115200); #if WAIT_FOR_SERIAL_BEFORE_STARING == 1 // Wait until the serial port is available (useful only for the Leonardo) // As the Leonardo board is not reseted every time you open the Serial Monitor #if defined (__AVR_ATmega32U4__) - while (!Serial) {} + while (!debug) {} delay(1000); #elif defined(__PIC32MX__) @@ -78,7 +78,7 @@ void setup() { } static void setup_rf() { - Debug::println(F("setup_rf()")); + debug.println(F("setup_rf()")); // Point ACI data structures to the the setup data that the nRFgo studio generated for the nRF8001 if (NULL != services_pipe_type_mapping) { aci_state.aci_setup_info.services_pipe_type_mapping = &services_pipe_type_mapping[0]; @@ -115,7 +115,7 @@ static void setup_rf() { // then we initialize the data structures required to setup the nRF8001 // The second parameter is for turning debug printing on for the ACI Commands and Events so they be printed on the Serial lib_aci_init(&aci_state, false); - Debug::println(F("lib_aci_init done")); + debug.println(F("lib_aci_init done")); } static bool rf_started = false; @@ -132,21 +132,21 @@ static void aci_loop() { switch (aci_evt->evt_opcode) { case ACI_EVT_DEVICE_STARTED: - Debug::println(F("ACI_EVT_DEVICE_STARTED")); + debug.println(F("ACI_EVT_DEVICE_STARTED")); aci_state.data_credit_total = aci_evt->params.device_started.credit_available; - Debug::print(F("aci_state.data_credit_total=")); - Debug::println(aci_state.data_credit_total, DEC); + debug.print(F("aci_state.data_credit_total=")); + debug.println(aci_state.data_credit_total, DEC); switch (aci_evt->params.device_started.device_mode) { case ACI_DEVICE_SETUP: - Debug::println(F("ACI_DEVICE_SETUP")); + debug.println(F("ACI_DEVICE_SETUP")); rf_started = true; setup_required = true; break; case ACI_DEVICE_STANDBY: - Debug::println(F("ACI_DEVICE_STANDBY")); + debug.println(F("ACI_DEVICE_STANDBY")); if (aci_evt->params.device_started.hw_error) { delay(20); // Magic number used to make sure the HW error event is handled correctly. } @@ -155,7 +155,7 @@ static void aci_loop() { // lib_aci_broadcast(10/* in seconds */, 0x0100 /* advertising interval 100ms */); // ret = lib_aci_open_adv_pipe(PIPE_BATTERY_BATTERY_LEVEL_BROADCAST); // ret = lib_aci_open_adv_pipe(PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_BROADCAST); - Debug::println(F("Advertising started")); + debug.println(F("Advertising started")); } break; case ACI_DEVICE_INVALID: @@ -167,21 +167,21 @@ static void aci_loop() { break; case ACI_EVT_CMD_RSP: - // Debug::println(F("ACI_EVT_CMD_RSP")); - // Debug::print(F("aci_evt->params.cmd_rsp.cmd_opcode=")); - // Debug::println(aci_evt->params.cmd_rsp.cmd_opcode, HEX); - // Debug::print(F("aci_evt->params.cmd_rsp.cmd_status=")); - // Debug::println(aci_evt->params.cmd_rsp.cmd_status, HEX); + // debug.println(F("ACI_EVT_CMD_RSP")); + // debug.print(F("aci_evt->params.cmd_rsp.cmd_opcode=")); + // debug.println(aci_evt->params.cmd_rsp.cmd_opcode, HEX); + // debug.print(F("aci_evt->params.cmd_rsp.cmd_status=")); + // debug.println(aci_evt->params.cmd_rsp.cmd_status, HEX); //If an ACI command response event comes with an error -> stop if (aci_evt->params.cmd_rsp.cmd_status != ACI_STATUS_SUCCESS) { //ACI ReadDynamicData and ACI WriteDynamicData will have status codes of //TRANSACTION_CONTINUE and TRANSACTION_COMPLETE //all other ACI commands will have status code of ACI_STATUS_SCUCCESS for a successful command// - // Debug::print(F("ACI Command ")); - // Debug::println(aci_evt->params.cmd_rsp.cmd_opcode, HEX); - // Debug::print(F("Evt Cmd respone: Status ")); - // Debug::println(aci_evt->params.cmd_rsp.cmd_status, HEX); + // debug.print(F("ACI Command ")); + // debug.println(aci_evt->params.cmd_rsp.cmd_opcode, HEX); + // debug.print(F("Evt Cmd respone: Status ")); + // debug.println(aci_evt->params.cmd_rsp.cmd_status, HEX); } if (aci_evt->params.cmd_rsp.cmd_opcode == ACI_CMD_GET_DEVICE_VERSION) { //Store the version and configuration information of the nRF8001 in the Hardware Revision String Characteristic @@ -190,9 +190,9 @@ static void aci_loop() { // sizeof(aci_evt_cmd_rsp_params_get_device_version_t)); } if (aci_evt->params.cmd_rsp.cmd_opcode == ACI_CMD_GET_TEMPERATURE) { - Debug::print("aci_evt->params.cmd_rsp.params.get_temperature="); - Debug::print(aci_evt->params.cmd_rsp.params.get_temperature.temperature_value, DEC); - Debug::println(); + debug.print("aci_evt->params.cmd_rsp.params.get_temperature="); + debug.print(aci_evt->params.cmd_rsp.params.get_temperature.temperature_value, DEC); + debug.println(); int32_t t = aci_evt->params.cmd_rsp.params.get_temperature.temperature_value; @@ -201,7 +201,7 @@ static void aci_loop() { // Multiply t by 25 without having to include float support t = t * 16 + t * 8 + t; - uint32_t exponent = 2 << 24; + uint32_t exponent = ((uint32_t) 2) << 24; // example. reading=111. real temperature = 111 / 4 = 27.75 dec C // Calculation: t = 2775, exp = 2. formula: 10^exp * 0.t => 10^2 * 0.2775 = 27.75 @@ -229,11 +229,11 @@ static void aci_loop() { break; case ACI_EVT_CONNECTED: - Debug::println(F("ACI_EVT_CONNECTED")); + debug.println(F("ACI_EVT_CONNECTED")); timing_change_done = false; aci_state.data_credit_available = aci_state.data_credit_total; - Debug::print(F("aci_state.data_credit_available=")); - Debug::println(aci_state.data_credit_available, DEC); + debug.print(F("aci_state.data_credit_available=")); + debug.println(aci_state.data_credit_available, DEC); // Get the device version of the nRF8001 and store it in the Hardware Revision String. // This will trigger a ACI_CMD_GET_DEVICE_VERSION. @@ -245,19 +245,19 @@ static void aci_loop() { break; case ACI_EVT_PIPE_STATUS: - Debug::println(F("ACI_EVT_PIPE_STATUS")); + debug.println(F("ACI_EVT_PIPE_STATUS")); show_pipes(); break; case ACI_EVT_TIMING: - Debug::println(F("ACI_EVT_TIMING")); + debug.println(F("ACI_EVT_TIMING")); break; case ACI_EVT_DISCONNECTED: - Debug::println(F("ACI_EVT_DISCONNECTED")); + debug.println(F("ACI_EVT_DISCONNECTED")); lib_aci_connect(180 /* in seconds */, 0x0100 /* advertising interval 100ms*/); - Debug::println(F("Advertising started")); + debug.println(F("Advertising started")); sm_on_disconnect(); break; @@ -265,8 +265,8 @@ static void aci_loop() { case ACI_EVT_DATA_RECEIVED: pipe_number = aci_evt->params.data_received.rx_data.pipe_number; -// Debug::print(F("ACI_EVT_DATA_RECEIVED: pipe_number=")); -// Debug::println(pipe_number, DEC); +// debug.print(F("ACI_EVT_DATA_RECEIVED: pipe_number=")); +// debug.println(pipe_number, DEC); if (pipe_number == sm_pipe_rx) { on_soil_moisture_ctrl(aci_evt->params.data_received.rx_data.aci_data, aci_evt->len); @@ -274,19 +274,19 @@ static void aci_loop() { break; case ACI_EVT_DATA_CREDIT: - Debug::println(F("ACI_EVT_DATA_CREDIT")); + debug.println(F("ACI_EVT_DATA_CREDIT")); aci_state.data_credit_available = aci_state.data_credit_available + aci_evt->params.data_credit.credit; - Debug::print(F("aci_state.data_credit_available=")); - Debug::println(aci_state.data_credit_available, DEC); + debug.print(F("aci_state.data_credit_available=")); + debug.println(aci_state.data_credit_available, DEC); break; case ACI_EVT_PIPE_ERROR: - Debug::println(F("ACI_EVT_PIPE_ERROR")); + debug.println(F("ACI_EVT_PIPE_ERROR")); //See the appendix in the nRF8001 Product Specication for details on the error codes - Debug::print(F("ACI Evt Pipe Error: Pipe #:")); - Debug::print(aci_evt->params.pipe_error.pipe_number, DEC); - Debug::print(F(" Pipe Error Code: 0x")); - Debug::println(aci_evt->params.pipe_error.error_code, HEX); + debug.print(F("ACI Evt Pipe Error: Pipe #:")); + debug.print(aci_evt->params.pipe_error.pipe_number, DEC); + debug.print(F(" Pipe Error Code: 0x")); + debug.println(aci_evt->params.pipe_error.error_code, HEX); // Increment the credit available as the data packet was not sent. // The pipe error also represents the Attribute protocol Error Response sent from the peer and that should not be counted @@ -297,40 +297,40 @@ static void aci_loop() { break; case ACI_EVT_HW_ERROR: - Debug::println(F("ACI_EVT_HW_ERROR")); - Debug::print(F("HW error: ")); - Debug::println(aci_evt->params.hw_error.line_num, DEC); + debug.println(F("ACI_EVT_HW_ERROR")); + debug.print(F("HW error: ")); + debug.println(aci_evt->params.hw_error.line_num, DEC); for (uint8_t counter = 0; counter <= (aci_evt->len - 3); counter++) { - Serial.write(aci_evt->params.hw_error.file_name[counter]); //uint8_t file_name[20]; + debug.write(aci_evt->params.hw_error.file_name[counter]); //uint8_t file_name[20]; } - Debug::println(); + debug.println(); lib_aci_connect(180 /* in seconds */, 0x0050 /* advertising interval 50ms*/); - Debug::println(F("Advertising started")); + debug.println(F("Advertising started")); break; case ACI_EVT_INVALID: - Debug::println(F("ACI_EVT_INVALID")); + debug.println(F("ACI_EVT_INVALID")); break; case ACI_EVT_ECHO: - Debug::println(F("ACI_EVT_ECHO")); + debug.println(F("ACI_EVT_ECHO")); break; case ACI_EVT_BOND_STATUS: - Debug::println(F("ACI_EVT_BOND_STATUS")); + debug.println(F("ACI_EVT_BOND_STATUS")); break; case ACI_EVT_DATA_ACK: - Debug::println(F("ACI_EVT_DATA_ACK")); + debug.println(F("ACI_EVT_DATA_ACK")); break; case ACI_EVT_DISPLAY_PASSKEY: - Debug::println(F("ACI_EVT_DISPLAY_PASSKEY")); + debug.println(F("ACI_EVT_DISPLAY_PASSKEY")); break; case ACI_EVT_KEY_REQUEST: - Debug::println(F("ACI_EVT_KEY_REQUEST")); + debug.println(F("ACI_EVT_KEY_REQUEST")); break; } } else { - // Debug::println(F("No ACI Events available")); + // debug.println(F("No ACI Events available")); // No event in the ACI Event queue and if there is no event in the ACI command queue the arduino can go to sleep // Arduino can go to sleep now // Wakeup from sleep from the RDYN line @@ -342,8 +342,8 @@ static void aci_loop() { */ if (setup_required) { int ret = do_aci_setup(&aci_state); - Debug::print(F("do_aci_setup ret=")); - Debug::println(ret, DEC); + debug.print(F("do_aci_setup ret=")); + debug.println(ret, DEC); if (SETUP_SUCCESS == ret) { setup_required = false; } @@ -356,8 +356,8 @@ void loop() { aci_loop(); - if (Serial.available()) { - Serial.write(Serial.read()); + if (debug.available()) { + debug.write(Serial.read()); } now = millis(); @@ -372,7 +372,7 @@ void loop() { if (!reset_attempted) { if (count == 3) { reset_attempted = true; - Debug::println(F("RF did not start, resetting RF")); + debug.println(F("RF did not start, resetting RF")); // asm volatile ("jmp 0"); // lib_aci_pin_reset(); @@ -380,7 +380,7 @@ void loop() { count = 0; return; } else { - Debug::println(F("waiting for RF to start")); + debug.println(F("waiting for RF to start")); } } /**/ @@ -394,8 +394,8 @@ void loop() { #ifdef USE_LOW_POWER_MODE == 1 #ifdef SM_DEBUG == 1 - Debug::println(F("Sleeping...")); - Serial.flush(); + debug.println(F("Sleeping...")); + debug.flush(); #endif // SM_DEBUG go_to_sleep(); @@ -405,10 +405,10 @@ void loop() { static void show_pipes() { for (uint8_t i = 1; i <= NUMBER_OF_PIPES; i++) { uint8_t x = lib_aci_is_pipe_available(&aci_state, i); - Debug::print(F("pipe #")); - Debug::print(i, DEC); - Debug::print(F(", available=?")); - Debug::println(x, DEC); + debug.print(F("pipe #")); + debug.print(i, DEC); + debug.print(F(", available=?")); + debug.println(x, DEC); } } /* @@ -420,12 +420,12 @@ static void show_pipes() { boolean available = lib_aci_is_pipe_available(&aci_state, pipe); - Debug::print(F("tx_soil_moisture, len=")); - Debug::println(len, DEC); - Debug::print(F("aci_state.data_credit_available=")); - Debug::println(aci_state.data_credit_available, DEC); - Debug::print(F("available=")); - Debug::println(available, DEC); + debug.print(F("tx_soil_moisture, len=")); + debug.println(len, DEC); + debug.print(F("aci_state.data_credit_available=")); + debug.println(aci_state.data_credit_available, DEC); + debug.print(F("available=")); + debug.println(available, DEC); if (available && aci_state.data_credit_available > 0) { status = lib_aci_send_data(pipe, data, len); @@ -439,8 +439,8 @@ static void show_pipes() { void notify_battery_level(uint8_t value) { static const uint8_t pipe = PIPE_BATTERY_BATTERY_LEVEL_SET; - Debug::print(F("notify_battery_level, value=")); - Debug::println(value, DEC); + debug.print(F("notify_battery_level, value=")); + debug.println(value, DEC); value = value % 101; @@ -452,17 +452,17 @@ void notify_soil_moisture(const struct sm_res &res, uint8_t body_len) { uint8_t *data = (uint8_t *)&res; uint8_t len = SM_RES_HEADER_SIZE + body_len; -// Debug::print(F("notify_soil_moisture, code=")); -// Debug::print(res.code, DEC); -// Debug::print(F(", body_len=")); -// Debug::println(body_len, DEC); +// debug.print(F("notify_soil_moisture, code=")); +// debug.print(res.code, DEC); +// debug.print(F(", body_len=")); +// debug.println(body_len, DEC); -// Debug::print(F("aci_state.data_credit_available=")); -// Debug::println(aci_state.data_credit_available, DEC); +// debug.print(F("aci_state.data_credit_available=")); +// debug.println(aci_state.data_credit_available, DEC); bool available = lib_aci_is_pipe_available(&aci_state, sm_pipe_tx); -// Debug::print(F("pipe available=")); -// Debug::println(available, DEC); +// debug.print(F("pipe available=")); +// debug.println(available, DEC); // This should probably be an explicit part of the API, but for now it makes it easier to implement a synchronous interface. lib_aci_set_local_data(&aci_state, sm_pipe_set, (uint8_t *)&res, len); @@ -472,14 +472,14 @@ void notify_soil_moisture(const struct sm_res &res, uint8_t body_len) { return; } -#if SM_DEBUG == 1 - Debug::println("write_res"); +#if SM_DEBUG + debug.println("write_res"); write_res(res); #endif - if (aci_state.data_credit_available = 0) { -#if SM_DEBUG == 1 - Debug::println("Not enough credits to send notification."); + if (aci_state.data_credit_available == 0) { +#if SM_DEBUG + debug.println("Not enough credits to send notification."); #endif return; } @@ -488,8 +488,8 @@ void notify_soil_moisture(const struct sm_res &res, uint8_t body_len) { if (sent) { aci_state.data_credit_available--; } else { -#if SM_DEBUG == 1 - Debug::println("Sending failed"); +#if SM_DEBUG + debug.println("Sending failed"); #endif } } -- cgit v1.2.3