aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Debug.h6
-rw-r--r--app.cpp363
-rw-r--r--app.h10
-rw-r--r--config.h68
-rw-r--r--trygvisio_soil_moisture.ino96
-rw-r--r--uncrustify.cfg18
6 files changed, 287 insertions, 274 deletions
diff --git a/Debug.h b/Debug.h
index 1fee5db..455b6db 100644
--- a/Debug.h
+++ b/Debug.h
@@ -40,7 +40,7 @@ template<typename T>
inline
void DebugImpl<enable>::print(const T *t) {
if (enable) {
- Serial.print(t);
+ Serial.print(t);
}
}
@@ -58,7 +58,7 @@ template<typename T>
inline
void DebugImpl<enable>::println(const T *t) {
if (enable) {
- Serial.println(t);
+ Serial.println(t);
}
}
@@ -66,7 +66,7 @@ template<bool enable>
inline
void DebugImpl<enable>::println() {
if (enable) {
- Serial.println();
+ Serial.println();
}
}
diff --git a/app.cpp b/app.cpp
index bb5ad9c..76d2653 100644
--- a/app.cpp
+++ b/app.cpp
@@ -76,8 +76,8 @@ void sm_on_connect() {
next_update[i] = now + sensors[i].update_interval;
}
- connected = true;
- blink = true;
+ connected = true;
+ blink = true;
digitalWrite(LED_PIN, HIGH);
last_blink = millis();
}
@@ -126,9 +126,9 @@ void sm_loop() {
Debug::print(s.value, DEC);
struct sm_res res;
- res.code = SM_CMD_GET_VALUE;
+ res.code = SM_CMD_GET_VALUE;
res.get_value.sensor = i;
- res.get_value.value = s.value;
+ res.get_value.value = s.value;
notify_soil_moisture(res, sizeof(sm_get_value_res));
}
@@ -141,109 +141,109 @@ void sm_loop() {
#ifdef SM_DEBUG == 1
static void write_name(uint8_t const* name, uint8_t len) {
- for(int i = 0; i < len; i++) {
+ for (int i = 0; i < len; i++) {
Debug::print((char)name[i]);
}
}
-void write_req(struct sm_req const& req) {
+void write_req(struct sm_req const &req) {
Debug::print(">> ");
- switch(req.code) {
- case 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);
- 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);
- 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);
- 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=");
- 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");
- 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);
- break;
-
- default:
- Debug::print("Unknown command: ");
- Debug::print(req.code);
+ switch (req.code) {
+ case 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);
+ 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);
+ 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);
+ 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=");
+ 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");
+ 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);
+ break;
+
+ default:
+ Debug::print("Unknown command: ");
+ Debug::print(req.code);
}
Debug::println();
}
-void write_res(struct sm_res const& res) {
+void write_res(struct sm_res const &res) {
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);
- 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);
- break;
-
- case 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);
- break;
-
- case 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=");
- 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");
- break;
-
- default:
- Debug::print("Unknown command: ");
- Debug::print(res.code);
+ 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);
+ 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);
+ break;
+
+ case 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);
+ break;
+
+ case 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=");
+ 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");
+ break;
+
+ default:
+ Debug::print("Unknown command: ");
+ Debug::print(res.code);
}
Debug::println();
}
@@ -272,86 +272,86 @@ void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) {
res.code = SM_CMD_FAIL;
// TODO: use len_op(len, sizeof(sm_XX_req)) to check that each request's size is ok.
- 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;
-
- case SM_CMD_GET_VALUE:
- body_len = sizeof(sm_get_value_res);
- 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 {
- res.code = SM_CMD_FAIL;
- }
- break;
-
- case SM_CMD_SET_WARNING_VALUE:
- body_len = sizeof(sm_set_warning_value_res);
- 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;
- }
- break;
-
- case SM_CMD_GET_WARNING_VALUE:
- body_len = sizeof(sm_get_warning_value_res);
- 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;
- }
- break;
-
- case SM_CMD_SET_SENSOR_NAME:
- body_len = sizeof(sm_set_sensor_name_res);
- 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 {
- res.code = SM_CMD_FAIL;
- }
- break;
-
- case SM_CMD_GET_SENSOR_NAME:
- body_len = sizeof(sm_get_sensor_name_res);
- 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 {
- res.code = SM_CMD_FAIL;
- }
- break;
-
- case SM_CMD_SET_UPDATE_INTERVAL:
- body_len = sizeof(sm_set_update_interval_res);
- sensor = req->set_update_interval.sensor;
-
- if (sensor < SENSOR_COUNT) {
- sensors[sensor].update_interval = req->set_update_interval.interval_in_seconds;
- } else {
- res.code = SM_CMD_FAIL;
- }
- break;
+ 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;
+
+ case SM_CMD_GET_VALUE:
+ body_len = sizeof(sm_get_value_res);
+ 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 {
+ res.code = SM_CMD_FAIL;
+ }
+ break;
+
+ case SM_CMD_SET_WARNING_VALUE:
+ body_len = sizeof(sm_set_warning_value_res);
+ 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;
+ }
+ break;
+
+ case SM_CMD_GET_WARNING_VALUE:
+ body_len = sizeof(sm_get_warning_value_res);
+ 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;
+ }
+ break;
+
+ case SM_CMD_SET_SENSOR_NAME:
+ body_len = sizeof(sm_set_sensor_name_res);
+ 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 {
+ res.code = SM_CMD_FAIL;
+ }
+ break;
+
+ case SM_CMD_GET_SENSOR_NAME:
+ body_len = sizeof(sm_get_sensor_name_res);
+ 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 {
+ res.code = SM_CMD_FAIL;
+ }
+ break;
+
+ case SM_CMD_SET_UPDATE_INTERVAL:
+ body_len = sizeof(sm_set_update_interval_res);
+ sensor = req->set_update_interval.sensor;
+
+ if (sensor < SENSOR_COUNT) {
+ sensors[sensor].update_interval = req->set_update_interval.interval_in_seconds;
+ } else {
+ res.code = SM_CMD_FAIL;
+ }
+ break;
}
if (res.code == SM_CMD_FAIL) {
@@ -372,7 +372,7 @@ static int store_string(int index, uint8_t len, char *chars) {
return 1 + len;
}
-static int load_string(int index, const uint8_t max_length, uint8_t& length, char *chars) {
+static int load_string(int index, const uint8_t max_length, uint8_t &length, char *chars) {
length = EEPROM.read(index++);
uint8_t len = min(length, max_length);
@@ -387,7 +387,7 @@ static int load_string(int index, const uint8_t max_length, uint8_t& length, cha
* Returns true if the settings was successfully read.
*/
static boolean load_settings() {
- int index = 0;
+ int index = 0;
uint8_t magic = EEPROM.read(index++);
// Check to see if the EEPROM contains a magic byte indicating if we have written anything before.
@@ -398,9 +398,9 @@ static boolean load_settings() {
for (int i = 0; i < SENSOR_COUNT; i++) {
struct sm_sensor s = sensors[i];
- s.warning_value = EEPROM.read(index++);
+ s.warning_value = EEPROM.read(index++);
s.warning_value += EEPROM.read(index++) << 8;
- index += load_string(index, SENSOR_NAME_LEN, s.name_length, s.name);
+ index += load_string(index, SENSOR_NAME_LEN, s.name_length, s.name);
}
return true;
@@ -433,7 +433,7 @@ static void setup_settings() {
Debug::print("Sensor #");
Debug::print(i, DEC);
- struct sm_sensor& s = sensors[i];
+ struct sm_sensor &s = sensors[i];
// Debug::print(", name len=");
// Debug::print(s.name_length, DEC);
@@ -452,7 +452,8 @@ static void setup_settings() {
Debug::println("setup_settings: done");
}
#else
-static void setup_settings() {}
+static void setup_settings() {
+}
#endif // PERSISTENT_CONFIGURATION_SUPPORT
// vim: set ft=arduino:
diff --git a/app.h b/app.h
index 26e52cb..25f834f 100644
--- a/app.h
+++ b/app.h
@@ -37,12 +37,12 @@ struct sm_get_value_req {
* This includes the sensor id because it can be used as a notification too
*/
struct sm_get_value_res {
- uint8_t sensor;
+ uint8_t sensor;
uint16_t value;
};
struct sm_set_warning_value_req {
- uint8_t sensor;
+ uint8_t sensor;
uint16_t warning_value;
};
@@ -121,14 +121,14 @@ void sm_on_connect();
void sm_on_disconnect();
//boolean tx_soil_moisture(struct sm_res& res);
-void notify_soil_moisture(const struct sm_res& res, uint8_t body_len);
+void notify_soil_moisture(const struct sm_res &res, uint8_t body_len);
void notify_battery_level(uint8_t value);
void on_soil_moisture_ctrl(uint8_t *data, uint8_t len);
#if SM_DEBUG == 1
-void write_req(struct sm_req const& req);
-void write_res(struct sm_res const& res);
+void write_req(struct sm_req const &req);
+void write_res(struct sm_res const &res);
#endif
#endif
diff --git a/config.h b/config.h
index 52e6751..7ab5ac8 100644
--- a/config.h
+++ b/config.h
@@ -2,33 +2,33 @@
#define CONFIG_H
/*
-
-TL; DR; If you are using Arduino IDE, you have to configure this file.
-See the first section.
-
-This file controls how the sketch work so this is where your should
-start to adjust settings. If you are using Arduino-Makefile you can
-set these values by editing the EXTRA_FLAGS Makefile variable.
-
-If you are using the Arduino IDE and want to set a configuration
-value, change the lines that look like this:
-
-// #define FOO ...
-
-to
-
-#define FOO 1
-
-*/
+ *
+ * TL; DR; If you are using Arduino IDE, you have to configure this file.
+ * See the first section.
+ *
+ * This file controls how the sketch work so this is where your should
+ * start to adjust settings. If you are using Arduino-Makefile you can
+ * set these values by editing the EXTRA_FLAGS Makefile variable.
+ *
+ * If you are using the Arduino IDE and want to set a configuration
+ * value, change the lines that look like this:
+ *
+ * // #define FOO ...
+ *
+ * to
+ *
+ * #define FOO 1
+ *
+ */
/*
-
-Configuration Section
-
-If you are using the Arduino IDE, change stuff in this section. All
-values are commented out, but some have default values
-
-*/
+ *
+ * Configuration Section
+ *
+ * If you are using the Arduino IDE, change stuff in this section. All
+ * values are commented out, but some have default values
+ *
+ */
///////////////////////////////////////////////////////////////////////////////
// Board version
@@ -85,15 +85,13 @@ 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
-
-Do not touch stuff in this section, it only sets default values.
-
-*/
+ *
+ * Default Values Section
+ *
+ * Do not touch stuff in this section, it only sets default values.
+ *
+ */
#ifndef WAIT_FOR_SERIAL_BEFORE_STARING
#define WAIT_FOR_SERIAL_BEFORE_STARING 1
@@ -111,8 +109,4 @@ 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 59b0cf6..7306c05 100644
--- a/trygvisio_soil_moisture.ino
+++ b/trygvisio_soil_moisture.ino
@@ -15,15 +15,16 @@ static void setup_rf();
static void show_pipes();
static services_pipe_type_mapping_t services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT;
-static const hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] PROGMEM = SETUP_MESSAGES_CONTENT;
+static const hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] PROGMEM = SETUP_MESSAGES_CONTENT;
+// Pipes
static const uint8_t sm_pipe_set = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_SET;
-static const uint8_t sm_pipe_tx = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_TX;
-static const uint8_t sm_pipe_rx = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_RX_ACK_AUTO;
+static const uint8_t sm_pipe_tx = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_TX;
+static const uint8_t sm_pipe_rx = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_RX_ACK_AUTO;
static struct aci_state_t aci_state;
static hal_aci_evt_t aci_data;
-static boolean timing_change_done = false;
+static boolean timing_change_done = false;
void __ble_assert(const char *file, uint16_t line)
{
@@ -32,7 +33,7 @@ void __ble_assert(const char *file, uint16_t line)
Debug::print(": ");
Debug::print(line);
Debug::print("\n");
- while(1);
+ while (1) {};
}
#if defined(__AVR_ATmega32U4__)
@@ -50,7 +51,7 @@ void setup() {
// As the F_CPU = 8000000UL, the USB core make the PLLCSR = 0x02
// But the external xtal is 16000000Hz, so correct it here.
PLLCSR |= 0x10; // Need 16 MHz xtal
- while (!(PLLCSR & (1<<PLOCK))); // wait for lock pll
+ while (!(PLLCSR & (1<<PLOCK))) {} // wait for lock pll
#elif defined(BLEND_MICRO_16MHZ)
// The CPU clock in bootloader is 8MHz, change to 16MHz for sketches to run (i.e. overclock running at 3.3v).
CLKPR = 0x80;
@@ -63,8 +64,7 @@ void setup() {
// 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 (!Serial) {}
delay(1000);
#elif defined(__PIC32MX__)
@@ -86,9 +86,9 @@ static void setup_rf() {
else {
aci_state.aci_setup_info.services_pipe_type_mapping = NULL;
}
- aci_state.aci_setup_info.number_of_pipes = NUMBER_OF_PIPES;
- aci_state.aci_setup_info.setup_msgs = (hal_aci_data_t*)setup_msgs;
- aci_state.aci_setup_info.num_setup_msgs = NB_SETUP_MESSAGES;
+ aci_state.aci_setup_info.number_of_pipes = NUMBER_OF_PIPES;
+ aci_state.aci_setup_info.setup_msgs = (hal_aci_data_t*)setup_msgs;
+ aci_state.aci_setup_info.num_setup_msgs = NB_SETUP_MESSAGES;
// Tell the ACI library, the MCU to nRF8001 pin connections.
// The Active pin is optional and can be marked UNUSED
@@ -118,7 +118,7 @@ static void setup_rf() {
Debug::println(F("lib_aci_init done"));
}
-static bool rf_started = false;
+static bool rf_started = false;
static bool setup_required = false;
static void aci_loop() {
@@ -130,7 +130,7 @@ static void aci_loop() {
aci_evt_t * aci_evt;
aci_evt = &aci_data.evt;
- switch(aci_evt->evt_opcode) {
+ switch (aci_evt->evt_opcode) {
case ACI_EVT_DEVICE_STARTED:
Debug::println(F("ACI_EVT_DEVICE_STARTED"));
aci_state.data_credit_total = aci_evt->params.device_started.credit_available;
@@ -138,10 +138,10 @@ static void aci_loop() {
Debug::print(F("aci_state.data_credit_total="));
Debug::println(aci_state.data_credit_total, DEC);
- switch(aci_evt->params.device_started.device_mode) {
+ switch (aci_evt->params.device_started.device_mode) {
case ACI_DEVICE_SETUP:
Debug::println(F("ACI_DEVICE_SETUP"));
- rf_started = true;
+ rf_started = true;
setup_required = true;
break;
@@ -151,7 +151,7 @@ static void aci_loop() {
delay(20); // Magic number used to make sure the HW error event is handled correctly.
}
else {
- lib_aci_connect(180/* in seconds */, 0x0050 /* advertising interval 50ms*/);
+ lib_aci_connect(180 /* in seconds */, 0x0050 /* advertising interval 50ms*/);
// 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);
@@ -213,18 +213,18 @@ static void aci_loop() {
// bit 3-7: reserved
// Reference: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature_measurement.xml
struct {
- uint8_t flags;
+ uint8_t flags;
uint32_t value;
// time stamp
// temperature type
} temperature_measurement = {
- 0,
- exponent | (t & 0x00FFFFFF)
+ 0,
+ exponent | (t & 0x00FFFFFF)
};
lib_aci_set_local_data(&aci_state, PIPE_SOIL_MOISTURE_INTERMEDIATE_TEMPERATURE_SET,
- (uint8_t *) &temperature_measurement,
- sizeof(temperature_measurement));
+ (uint8_t *) &temperature_measurement,
+ sizeof(temperature_measurement));
}
break;
@@ -256,7 +256,7 @@ static void aci_loop() {
case ACI_EVT_DISCONNECTED:
Debug::println(F("ACI_EVT_DISCONNECTED"));
- lib_aci_connect(180/* in seconds */, 0x0100 /* advertising interval 100ms*/);
+ lib_aci_connect(180 /* in seconds */, 0x0100 /* advertising interval 100ms*/);
Debug::println(F("Advertising started"));
sm_on_disconnect();
@@ -301,11 +301,11 @@ static void aci_loop() {
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++) {
+ 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::println();
- lib_aci_connect(180/* in seconds */, 0x0050 /* advertising interval 50ms*/);
+ lib_aci_connect(180 /* in seconds */, 0x0050 /* advertising interval 50ms*/);
Debug::println(F("Advertising started"));
break;
@@ -365,7 +365,7 @@ void loop() {
last = now;
if (!rf_started) {
- static int count = 0;
+ static int count = 0;
static bool reset_attempted = false;
count++;
@@ -412,30 +412,30 @@ static void show_pipes() {
}
}
/*
-boolean tx_moisture(sm_res *res) {
- static const uint8_t pipe = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_TX;
- uint8_t *data = (uint8_t *)res;
- uint8_t len = 2 + res->len;
- boolean status = false;
-
- 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);
-
- if (available && aci_state.data_credit_available > 0) {
+ boolean tx_moisture(sm_res *res) {
+ static const uint8_t pipe = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_TX;
+ uint8_t *data = (uint8_t *)res;
+ uint8_t len = 2 + res->len;
+ boolean status = false;
+
+ 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);
+
+ if (available && aci_state.data_credit_available > 0) {
status = lib_aci_send_data(pipe, data, len);
if (status) {
aci_state.data_credit_available--;
}
- }
- return status;
-}
-*/
+ }
+ return status;
+ }
+ */
void notify_battery_level(uint8_t value) {
static const uint8_t pipe = PIPE_BATTERY_BATTERY_LEVEL_SET;
@@ -447,10 +447,10 @@ void notify_battery_level(uint8_t value) {
lib_aci_send_data(pipe, &value, 1);
}
-void notify_soil_moisture(const struct sm_res& res, uint8_t body_len) {
+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;
+ uint8_t len = SM_RES_HEADER_SIZE + body_len;
// Debug::print(F("notify_soil_moisture, code="));
// Debug::print(res.code, DEC);
@@ -473,7 +473,7 @@ void notify_soil_moisture(const struct sm_res& res, uint8_t body_len) {
}
#if SM_DEBUG == 1
-Debug::println("write_res");
+ Debug::println("write_res");
write_res(res);
#endif
diff --git a/uncrustify.cfg b/uncrustify.cfg
new file mode 100644
index 0000000..ec393b0
--- /dev/null
+++ b/uncrustify.cfg
@@ -0,0 +1,18 @@
+# http://uncrustify.sourceforge.net/config.txt
+
+indent_columns = 2
+indent_continue = 4
+indent_with_tabs = 0
+indent_class = True
+
+indent_switch_case = 0
+
+align_var_struct_span = 1
+
+sp_before_sparen = add
+sp_sparen_brace = add
+
+sp_before_byref = add
+sp_after_byref = remove
+
+align_assign_span = 2