aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-07-23 15:37:39 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2015-07-23 15:37:39 +0200
commitdea9cb49271631d4def70d21db42a85d1d58f269 (patch)
tree77f8b281190818d0bde23c2535d845abe6d98258
parent678dfb7e93f1d613fb9a513d60a685d5e3c1c3b3 (diff)
downloadtrygvisio_soil_moisture-dea9cb49271631d4def70d21db42a85d1d58f269.tar.gz
trygvisio_soil_moisture-dea9cb49271631d4def70d21db42a85d1d58f269.tar.bz2
trygvisio_soil_moisture-dea9cb49271631d4def70d21db42a85d1d58f269.tar.xz
trygvisio_soil_moisture-dea9cb49271631d4def70d21db42a85d1d58f269.zip
o Fixing a bug where the reponse code wasn't properly set.
-rw-r--r--.gitignore1
-rw-r--r--app.cpp8
-rw-r--r--config.h29
-rw-r--r--trygvisio_soil_moisture.ino35
4 files changed, 62 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore
index 414487d..7e86e35 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
build-*/
+config.h
diff --git a/app.cpp b/app.cpp
index cadcc30..d4f880d 100644
--- a/app.cpp
+++ b/app.cpp
@@ -134,7 +134,7 @@ void sm_loop() {
}
}
-#ifdef SM_DEBUG
+#ifdef SM_DEBUG == 1
static void write_name(uint8_t const* name, uint8_t len) {
for(int i = 0; i < len; i++) {
@@ -271,6 +271,7 @@ void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) {
switch(req->code) {
case SM_CMD_GET_SENSOR_COUNT:
body_len = sizeof(sm_get_sensor_count_res);
+ res.code = req->code;
res.get_sensor_count.count = SENSOR_COUNT;
break;
@@ -279,6 +280,7 @@ void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) {
sensor = req->get_value.sensor;
if (sensor < SENSOR_COUNT) {
+ res.code = req->code;
// TODO: update the sensor's value
res.get_value.value = sensors[sensor].value;
} else {
@@ -291,6 +293,7 @@ void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) {
sensor = req->set_warning_value.sensor;
if (sensor < SENSOR_COUNT) {
+ res.code = req->code;
sensors[sensor].warning_value = req->set_warning_value.warning_value;
} else {
res.code = SM_CMD_FAIL;
@@ -302,6 +305,7 @@ void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) {
sensor = req->get_warning_value.sensor;
if (sensor < SENSOR_COUNT) {
+ res.code = req->code;
res.get_warning_value.warning_value = sensors[sensor].warning_value;
} else {
res.code = SM_CMD_FAIL;
@@ -313,6 +317,7 @@ void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) {
sensor = req->set_sensor_name.sensor;
if (sensor < SENSOR_COUNT) {
+ res.code = req->code;
sensors[sensor].name_length = min(req->set_sensor_name.length, SENSOR_NAME_LEN);
memcpy(sensors[sensor].name, req->set_sensor_name.name, sensors[sensor].name_length);
} else {
@@ -325,6 +330,7 @@ void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) {
sensor = req->get_sensor_name.sensor;
if (sensor < SENSOR_COUNT) {
+ res.code = req->code;
res.get_sensor_name.length = sensors[sensor].name_length;
memcpy(res.get_sensor_name.name, sensors[sensor].name, SENSOR_NAME_LEN);
} else {
diff --git a/config.h b/config.h
index 6ad7fb6..3f3271f 100644
--- a/config.h
+++ b/config.h
@@ -30,6 +30,9 @@ values are commented out, but some have default values
*/
+///////////////////////////////////////////////////////////////////////////////
+// Board version
+//
// You have to set this to match your board. The build will fail if
// you don't set it.
//
@@ -39,8 +42,12 @@ values are commented out, but some have default values
//
// Default: not set, you have to set it
// #define SM_BOARD_VERSION ...
-#define SM_BOARD_VERSION 2
+#define SM_BOARD_VERSION 1
+
+///////////////////////////////////////////////////////////////////////////////
+// Wait for serial before starting
+//
// If enabled the code won't start until you open the serial port
// monitor or otherwise connect to the serial port.
//
@@ -54,6 +61,9 @@ values are commented out, but some have default values
// Default: 1
// #define WAIT_FOR_SERIAL_BEFORE_STARING ...
+///////////////////////////////////////////////////////////////////////////////
+// Persistent configuration
+//
// If enabled the settings for each sensor will be persisted in EEPROM
//
// Values:
@@ -62,6 +72,19 @@ values are commented out, but some have default values
// Default: 0
// #define PERSISTENT_CONFIGURATION_SUPPORT ...
+///////////////////////////////////////////////////////////////////////////////
+// Use low power mode
+//
+// If enabled the device will try to use as little power as possible.
+//
+// Not fully functional yet so it is disabled by default.
+//
+// Values:
+// 0: disabled
+// 1: enabled
+// Default: 0
+// #define USE_LOW_POWER_MODE ...
+
/*
Default Values Section
@@ -82,4 +105,8 @@ Do not touch stuff in this section, it only sets default values.
#define SM_DEBUG 1
#endif
+#ifndef LOW_POWER
+#define LOW_POWER 0
+#endif
+
#endif
diff --git a/trygvisio_soil_moisture.ino b/trygvisio_soil_moisture.ino
index 8185754..729f5da 100644
--- a/trygvisio_soil_moisture.ino
+++ b/trygvisio_soil_moisture.ino
@@ -225,8 +225,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);
+// Serial.print(F("ACI_EVT_DATA_RECEIVED: pipe_number="));
+// Serial.println(pipe_number, DEC);
if (pipe_number == pipe_rx) {
on_soil_moisture_ctrl(aci_evt->params.data_received.rx_data.aci_data, aci_evt->len);
@@ -352,12 +352,14 @@ void loop() {
sm_loop();
-#ifdef SM_DEBUG
+#ifdef USE_LOW_POWER_MODE == 1
+#ifdef SM_DEBUG == 1
Serial.println(F("Sleeping..."));
Serial.flush();
#endif // SM_DEBUG
go_to_sleep();
+#endif // USE_LOW_POWER_MODE
}
static void show_pipes() {
@@ -425,14 +427,29 @@ void notify_soil_moisture(const struct sm_res& res, uint8_t body_len) {
// 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, pipe_set, (uint8_t *)&res, len);
- if (available && aci_state.data_credit_available > 0) {
- boolean sent = lib_aci_send_data(pipe_tx, data, len);
- if (sent) {
- aci_state.data_credit_available--;
+ // There is no need to lod messages that won't be sent.
+ if (!available) {
+ return;
+ }
#if SM_DEBUG == 1
- write_res(res);
+Serial.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.");
+#endif
+ return;
+ }
+
+ boolean sent = lib_aci_send_data(pipe_tx, data, len);
+ if (sent) {
+ aci_state.data_credit_available--;
+ } else {
+#if SM_DEBUG == 1
+ Serial.println("Sending failed");
#endif
- }
}
}