aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Debug.h79
-rw-r--r--app.cpp138
-rw-r--r--config.h6
-rw-r--r--trygvisio_soil_moisture.ino167
4 files changed, 240 insertions, 150 deletions
diff --git a/Debug.h b/Debug.h
new file mode 100644
index 0000000..1fee5db
--- /dev/null
+++ b/Debug.h
@@ -0,0 +1,79 @@
+#ifndef DEBUG_H
+#define DEBUG_H
+
+#include "config.h"
+
+template <bool enable>
+class DebugImpl {
+public:
+ template<typename T>
+ static inline
+ void print(T t, int format = DEC);
+
+ template<typename T>
+ static inline
+ void print(const T *t);
+
+ template<typename T>
+ static inline
+ void println(T t, int format = DEC);
+
+ template<typename T>
+ static inline
+ void println(const T *t);
+
+ static inline
+ void println();
+};
+
+template<bool enable>
+template<typename T>
+inline
+void DebugImpl<enable>::print(T t, int format) {
+ if (enable) {
+ Serial.print(t, format);
+ }
+}
+
+template<bool enable>
+template<typename T>
+inline
+void DebugImpl<enable>::print(const T *t) {
+ if (enable) {
+ Serial.print(t);
+ }
+}
+
+template<bool enable>
+template<typename T>
+inline
+void DebugImpl<enable>::println(T t, int format) {
+ if (enable) {
+ Serial.println(t, format);
+ }
+}
+
+template<bool enable>
+template<typename T>
+inline
+void DebugImpl<enable>::println(const T *t) {
+ if (enable) {
+ Serial.println(t);
+ }
+}
+
+template<bool enable>
+inline
+void DebugImpl<enable>::println() {
+ if (enable) {
+ Serial.println();
+ }
+}
+
+#if ENABLE_DEBUG_LOG == 1
+typedef DebugImpl<false> Debug;
+#else
+typedef DebugImpl<true> Debug;
+#endif
+
+#endif
diff --git a/app.cpp b/app.cpp
index d4f880d..bb5ad9c 100644
--- a/app.cpp
+++ b/app.cpp
@@ -1,4 +1,5 @@
#include "app.h"
+#include "Debug.h"
#include <EEPROM.h>
@@ -61,7 +62,10 @@ void sm_setup() {
pinMode(LED_PIN, OUTPUT);
- Serial.println("sm_setup: done");
+ pinMode(2, OUTPUT);
+ digitalWrite(2, HIGH);
+
+ Debug::println("sm_setup: done");
}
void sm_on_connect() {
@@ -114,12 +118,12 @@ void sm_loop() {
s.value = (uint16_t) analogRead(s.a_pin);
if (count++ > 0) {
- Serial.print(", ");
+ Debug::print(", ");
}
- Serial.print("#");
- Serial.print(i, DEC);
- Serial.print(" = ");
- Serial.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;
@@ -130,7 +134,7 @@ void sm_loop() {
}
if (count > 0) {
- Serial.println();
+ Debug::println();
}
}
@@ -138,110 +142,110 @@ void sm_loop() {
static void write_name(uint8_t const* name, uint8_t len) {
for(int i = 0; i < len; i++) {
- Serial.print((char)name[i]);
+ Debug::print((char)name[i]);
}
}
void write_req(struct sm_req const& req) {
- Serial.print(">> ");
+ Debug::print(">> ");
switch(req.code) {
case SM_CMD_GET_SENSOR_COUNT:
- Serial.print("SM_CMD_GET_SENSOR_COUNT");
+ Debug::print("SM_CMD_GET_SENSOR_COUNT");
break;
case SM_CMD_GET_VALUE:
- Serial.print("SM_CMD_GET_VALUE");
- Serial.print(": sensor=");
- Serial.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:
- Serial.print("SM_CMD_SET_WARNING_VALUE");
- Serial.print(": sensor=");
- Serial.print(req.set_warning_value.sensor, DEC);
- Serial.print(", warning_value=");
- Serial.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:
- Serial.print("SM_CMD_GET_WARNING_VALUE");
- Serial.print(": sensor=");
- Serial.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:
- Serial.print("SM_CMD_SET_SENSOR_NAME");
- Serial.print(": sensor=");
- Serial.print(req.set_sensor_name.sensor, DEC);
- Serial.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:
- Serial.print("SM_CMD_GET_SENSOR_NAME");
+ Debug::print("SM_CMD_GET_SENSOR_NAME");
break;
case SM_CMD_SET_UPDATE_INTERVAL:
- Serial.print("SM_CMD_SET_UPDATE_INTERVAL");
- Serial.print(": interval_in_seconds=");
- Serial.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:
- Serial.print("Unknown command: ");
- Serial.print(req.code);
+ Debug::print("Unknown command: ");
+ Debug::print(req.code);
}
- Serial.println();
+ Debug::println();
}
void write_res(struct sm_res const& res) {
- Serial.print("<< ");
+ Debug::print("<< ");
switch(res.code) {
case SM_CMD_GET_SENSOR_COUNT:
- Serial.print("SM_CMD_GET_SENSOR_COUNT");
- Serial.print(": count=");
- Serial.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:
- Serial.print("SM_CMD_GET_VALUE");
- Serial.print(": sensor=");
- Serial.print(res.get_value.sensor, DEC);
- Serial.print(", value=");
- Serial.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:
- Serial.print("SM_CMD_SET_WARNING_VALUE");
+ Debug::print("SM_CMD_SET_WARNING_VALUE");
break;
case SM_CMD_GET_WARNING_VALUE:
- Serial.print("SM_CMD_GET_WARNING_VALUE");
- Serial.print(": warning_value=");
- Serial.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:
- Serial.print("SM_CMD_SET_SENSOR_NAME");
+ Debug::print("SM_CMD_SET_SENSOR_NAME");
break;
case SM_CMD_GET_SENSOR_NAME:
- Serial.print("SM_CMD_GET_SENSOR_NAME");
- Serial.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:
- Serial.print("SM_CMD_SET_UPDATE_INTERVAL");
+ Debug::print("SM_CMD_SET_UPDATE_INTERVAL");
break;
default:
- Serial.print("Unknown command: ");
- Serial.print(res.code);
+ Debug::print("Unknown command: ");
+ Debug::print(res.code);
}
- Serial.println();
+ Debug::println();
}
#endif // SM_DEBUG
@@ -414,38 +418,38 @@ static void store_settings() {
index += store_string(index, s.name_length, s.name);
}
- Serial.println("Settings saved");
+ Debug::println("Settings saved");
}
static void setup_settings() {
if (!load_settings()) {
- Serial.println("Could not load settings, storing defaults");
+ Debug::println("Could not load settings, storing defaults");
store_settings();
} else {
- Serial.println("Settings loaded");
+ Debug::println("Settings loaded");
}
for (int i = 0; i < SENSOR_COUNT; i++) {
- Serial.print("Sensor #");
- Serial.print(i, DEC);
+ Debug::print("Sensor #");
+ Debug::print(i, DEC);
struct sm_sensor& s = sensors[i];
-// Serial.print(", name len=");
-// Serial.print(s.name_length, DEC);
-// Serial.print(": ->");
+// Debug::print(", name len=");
+// Debug::print(s.name_length, DEC);
+// Debug::print(": ->");
// Serial.write((const uint8_t*) s.name, s.name_length);
-// Serial.print("<-");
+// Debug::print("<-");
- Serial.print(": update_interval=");
- Serial.print(s.update_interval, DEC);
- Serial.print(", warning_value=");
- Serial.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);
- Serial.println();
+ Debug::println();
}
- Serial.println("setup_settings: done");
+ Debug::println("setup_settings: done");
}
#else
static void setup_settings() {}
diff --git a/config.h b/config.h
index 3f3271f..52e6751 100644
--- a/config.h
+++ b/config.h
@@ -85,6 +85,8 @@ values are commented out, but some have default values
// Default: 0
// #define USE_LOW_POWER_MODE ...
+#define USE_LOW_POWER_MODE 1
+
/*
Default Values Section
@@ -109,4 +111,8 @@ Do not touch stuff in this section, it only sets default values.
#define LOW_POWER 0
#endif
+#ifndef ENABLE_DEBUG_LOG
+#define ENABLE_DEBUG_LOG 1
+#endif
+
#endif
diff --git a/trygvisio_soil_moisture.ino b/trygvisio_soil_moisture.ino
index 4d5bc9c..59b0cf6 100644
--- a/trygvisio_soil_moisture.ino
+++ b/trygvisio_soil_moisture.ino
@@ -9,6 +9,7 @@
#include "config.h"
#include "services.h"
#include "app.h"
+#include "Debug.h"
static void setup_rf();
static void show_pipes();
@@ -26,11 +27,11 @@ static boolean timing_change_done = false;
void __ble_assert(const char *file, uint16_t line)
{
- Serial.print("ERROR ");
- Serial.print(file);
- Serial.print(": ");
- Serial.print(line);
- Serial.print("\n");
+ Debug::print("ERROR ");
+ Debug::print(file);
+ Debug::print(": ");
+ Debug::print(line);
+ Debug::print("\n");
while(1);
}
@@ -77,7 +78,7 @@ void setup() {
}
static void setup_rf() {
- Serial.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];
@@ -114,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);
- Serial.println(F("lib_aci_init done"));
+ Debug::println(F("lib_aci_init done"));
}
static bool rf_started = false;
@@ -131,21 +132,21 @@ static void aci_loop() {
switch(aci_evt->evt_opcode) {
case ACI_EVT_DEVICE_STARTED:
- Serial.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;
- Serial.print(F("aci_state.data_credit_total="));
- Serial.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:
- Serial.println(F("ACI_DEVICE_SETUP"));
+ Debug::println(F("ACI_DEVICE_SETUP"));
rf_started = true;
setup_required = true;
break;
case ACI_DEVICE_STANDBY:
- Serial.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.
}
@@ -154,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);
- Serial.println(F("Advertising started"));
+ Debug::println(F("Advertising started"));
}
break;
case ACI_DEVICE_INVALID:
@@ -166,21 +167,21 @@ static void aci_loop() {
break;
case ACI_EVT_CMD_RSP:
- // Serial.println(F("ACI_EVT_CMD_RSP"));
- // Serial.print(F("aci_evt->params.cmd_rsp.cmd_opcode="));
- // Serial.println(aci_evt->params.cmd_rsp.cmd_opcode, HEX);
- // Serial.print(F("aci_evt->params.cmd_rsp.cmd_status="));
- // Serial.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//
- // Serial.print(F("ACI Command "));
- // Serial.println(aci_evt->params.cmd_rsp.cmd_opcode, HEX);
- // Serial.print(F("Evt Cmd respone: Status "));
- // Serial.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
@@ -189,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) {
- Serial.print("aci_evt->params.cmd_rsp.params.get_temperature=");
- Serial.print(aci_evt->params.cmd_rsp.params.get_temperature.temperature_value, DEC);
- Serial.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;
@@ -228,11 +229,11 @@ static void aci_loop() {
break;
case ACI_EVT_CONNECTED:
- Serial.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;
- Serial.print(F("aci_state.data_credit_available="));
- Serial.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.
@@ -244,19 +245,19 @@ static void aci_loop() {
break;
case ACI_EVT_PIPE_STATUS:
- Serial.println(F("ACI_EVT_PIPE_STATUS"));
+ Debug::println(F("ACI_EVT_PIPE_STATUS"));
show_pipes();
break;
case ACI_EVT_TIMING:
- Serial.println(F("ACI_EVT_TIMING"));
+ Debug::println(F("ACI_EVT_TIMING"));
break;
case ACI_EVT_DISCONNECTED:
- Serial.println(F("ACI_EVT_DISCONNECTED"));
+ Debug::println(F("ACI_EVT_DISCONNECTED"));
lib_aci_connect(180/* in seconds */, 0x0100 /* advertising interval 100ms*/);
- Serial.println(F("Advertising started"));
+ Debug::println(F("Advertising started"));
sm_on_disconnect();
break;
@@ -264,8 +265,8 @@ static void aci_loop() {
case ACI_EVT_DATA_RECEIVED:
pipe_number = aci_evt->params.data_received.rx_data.pipe_number;
-// Serial.print(F("ACI_EVT_DATA_RECEIVED: pipe_number="));
-// Serial.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);
@@ -273,19 +274,19 @@ static void aci_loop() {
break;
case ACI_EVT_DATA_CREDIT:
- Serial.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;
- Serial.print(F("aci_state.data_credit_available="));
- Serial.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:
- Serial.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
- Serial.print(F("ACI Evt Pipe Error: Pipe #:"));
- Serial.print(aci_evt->params.pipe_error.pipe_number, DEC);
- Serial.print(F(" Pipe Error Code: 0x"));
- Serial.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
@@ -296,40 +297,40 @@ static void aci_loop() {
break;
case ACI_EVT_HW_ERROR:
- Serial.println(F("ACI_EVT_HW_ERROR"));
- Serial.print(F("HW error: "));
- Serial.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];
}
- Serial.println();
+ Debug::println();
lib_aci_connect(180/* in seconds */, 0x0050 /* advertising interval 50ms*/);
- Serial.println(F("Advertising started"));
+ Debug::println(F("Advertising started"));
break;
case ACI_EVT_INVALID:
- Serial.println(F("ACI_EVT_INVALID"));
+ Debug::println(F("ACI_EVT_INVALID"));
break;
case ACI_EVT_ECHO:
- Serial.println(F("ACI_EVT_ECHO"));
+ Debug::println(F("ACI_EVT_ECHO"));
break;
case ACI_EVT_BOND_STATUS:
- Serial.println(F("ACI_EVT_BOND_STATUS"));
+ Debug::println(F("ACI_EVT_BOND_STATUS"));
break;
case ACI_EVT_DATA_ACK:
- Serial.println(F("ACI_EVT_DATA_ACK"));
+ Debug::println(F("ACI_EVT_DATA_ACK"));
break;
case ACI_EVT_DISPLAY_PASSKEY:
- Serial.println(F("ACI_EVT_DISPLAY_PASSKEY"));
+ Debug::println(F("ACI_EVT_DISPLAY_PASSKEY"));
break;
case ACI_EVT_KEY_REQUEST:
- Serial.println(F("ACI_EVT_KEY_REQUEST"));
+ Debug::println(F("ACI_EVT_KEY_REQUEST"));
break;
}
}
else {
- // Serial.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
@@ -341,8 +342,8 @@ static void aci_loop() {
*/
if (setup_required) {
int ret = do_aci_setup(&aci_state);
- Serial.print(F("do_aci_setup ret="));
- Serial.println(ret, DEC);
+ Debug::print(F("do_aci_setup ret="));
+ Debug::println(ret, DEC);
if (SETUP_SUCCESS == ret) {
setup_required = false;
}
@@ -371,7 +372,7 @@ void loop() {
if (!reset_attempted) {
if (count == 3) {
reset_attempted = true;
- Serial.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();
@@ -379,7 +380,7 @@ void loop() {
count = 0;
return;
} else {
- Serial.println(F("waiting for RF to start"));
+ Debug::println(F("waiting for RF to start"));
}
}
/**/
@@ -393,7 +394,7 @@ void loop() {
#ifdef USE_LOW_POWER_MODE == 1
#ifdef SM_DEBUG == 1
- Serial.println(F("Sleeping..."));
+ Debug::println(F("Sleeping..."));
Serial.flush();
#endif // SM_DEBUG
@@ -404,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);
- Serial.print(F("pipe #"));
- Serial.print(i, DEC);
- Serial.print(F(", available=?"));
- Serial.println(x, DEC);
+ Debug::print(F("pipe #"));
+ Debug::print(i, DEC);
+ Debug::print(F(", available=?"));
+ Debug::println(x, DEC);
}
}
/*
@@ -419,12 +420,12 @@ boolean tx_moisture(sm_res *res) {
boolean available = lib_aci_is_pipe_available(&aci_state, pipe);
- Serial.print(F("tx_soil_moisture, len="));
- Serial.println(len, DEC);
- Serial.print(F("aci_state.data_credit_available="));
- Serial.println(aci_state.data_credit_available, DEC);
- Serial.print(F("available="));
- Serial.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);
@@ -438,8 +439,8 @@ boolean tx_moisture(sm_res *res) {
void notify_battery_level(uint8_t value) {
static const uint8_t pipe = PIPE_BATTERY_BATTERY_LEVEL_SET;
- Serial.print(F("notify_battery_level, value="));
- Serial.println(value, DEC);
+ Debug::print(F("notify_battery_level, value="));
+ Debug::println(value, DEC);
value = value % 101;
@@ -451,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;
-// Serial.print(F("notify_soil_moisture, code="));
-// Serial.print(res.code, DEC);
-// Serial.print(F(", body_len="));
-// Serial.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);
-// Serial.print(F("aci_state.data_credit_available="));
-// Serial.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);
-// Serial.print(F("pipe available="));
-// Serial.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,23 +473,23 @@ void notify_soil_moisture(const struct sm_res& res, uint8_t body_len) {
}
#if SM_DEBUG == 1
-Serial.println("write_res");
+Debug::println("write_res");
write_res(res);
#endif
if (aci_state.data_credit_available = 0) {
#if SM_DEBUG == 1
- Serial.println("Not enough credits to send notification.");
+ Debug::println("Not enough credits to send notification.");
#endif
return;
}
- boolean sent = lib_aci_send_data(pipe_tx, data, len);
+ boolean sent = lib_aci_send_data(sm_pipe_tx, data, len);
if (sent) {
aci_state.data_credit_available--;
} else {
#if SM_DEBUG == 1
- Serial.println("Sending failed");
+ Debug::println("Sending failed");
#endif
}
}