aboutsummaryrefslogtreecommitdiff
path: root/trygvisio_soil_moisture.ino
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-07-25 17:35:57 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2015-07-25 18:00:42 +0200
commit77e261f12089bd7db854d21fc81a42eaa60e0b67 (patch)
treeb925284f465b97625f35f1d3a7a1dbeaf78f05e8 /trygvisio_soil_moisture.ino
parent29e624aaa14b98a45f0408e0b1925b60136871d3 (diff)
downloadtrygvisio_soil_moisture-77e261f12089bd7db854d21fc81a42eaa60e0b67.tar.gz
trygvisio_soil_moisture-77e261f12089bd7db854d21fc81a42eaa60e0b67.tar.bz2
trygvisio_soil_moisture-77e261f12089bd7db854d21fc81a42eaa60e0b67.tar.xz
trygvisio_soil_moisture-77e261f12089bd7db854d21fc81a42eaa60e0b67.zip
o Even better debug code.
Diffstat (limited to 'trygvisio_soil_moisture.ino')
-rw-r--r--trygvisio_soil_moisture.ino186
1 files changed, 93 insertions, 93 deletions
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
}
}