aboutsummaryrefslogtreecommitdiff
path: root/app.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'app.cpp')
-rw-r--r--app.cpp129
1 files changed, 72 insertions, 57 deletions
diff --git a/app.cpp b/app.cpp
index a46734e..2d84700 100644
--- a/app.cpp
+++ b/app.cpp
@@ -4,6 +4,14 @@
#include <EEPROM.h>
#include <HardwareSerial.h>
+#if SM_BOARD_VERSION == 1
+#define SENSOR_COUNT 2
+#elif SM_BOARD_VERSION == 2
+#define SENSOR_COUNT 4
+#else
+#error "SM_BOARD_VERSION must be set. See config.h"
+#endif
+
// http://bleaklow.com/2010/09/05/progmem_and_gcc_bug_34734.html
#undef PROGMEM
#define PROGMEM __attribute__((section(".progmem.data")))
@@ -22,17 +30,13 @@ struct sm_sensor {
uint16_t update_interval;
uint8_t name_length;
char name[SENSOR_NAME_LEN];
-
-#define PROTOTYPE_VERSION 2
-#define SENSOR_COUNT 4
-
} sensors[SENSOR_COUNT] = {
// A Pin, D1 Pin, D2 Pin, Value, Warning Value, Update Interval, Length of Name, Name
-#if PROTOTYPE_VERSION == 1
+#if SM_BOARD_VERSION == 1
{ 8, 3, 5, 0, 10, 0, 9, "Sensor #1"},
{ 10, 11, 12, 0, 10, 0, 9, "Sensor #2"},
-#elif PROTOTYPE_VERSION == 2
+#elif SM_BOARD_VERSION == 2
{ A0, 1, 2, 0, 10, 0, 3, "wat"},
{ A1, 3, 5, 0, 10, 0, 4, "woot"},
{ A2, 8, 10, 0, 10, 0, 3, "foo"},
@@ -48,62 +52,17 @@ static boolean connected;
static boolean blink;
static unsigned long last_blink;
+#if PERSISTENT_CONFIGURATION_SUPPORT == 1
+static boolean setup_settings();
static boolean load_settings();
static void store_settings();
static void set_default_settings();
+#endif
void sm_setup() {
- /*
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 16; j++) {
- uint8_t value = EEPROM.read(i * 16 + j);
- Serial.print(value, HEX);
- Serial.print(" ");
- Serial.print((char)value);
- Serial.print(" ");
- }
- Serial.println();
- }
-
- for (int i = 0; i < SENSOR_COUNT; i++) {
- struct sm_sensor s = sensors[i];
-
- Serial.print("name len=");
- Serial.print(s.name_length, DEC);
- Serial.print(": ->");
- Serial.write((const uint8_t*) s.name, s.name_length);
- Serial.print("<-");
- Serial.println();
- }
-*/
-// set_default_settings();
- /*
- if (!load_settings()) {
- Serial.println("setting default settings");
- set_default_settings();
-
- Serial.println("saving settings");
- store_settings();
- } else {
- Serial.println("Settings loaded");
- }
- /**/
-/**/
- for (int i = 0; i < SENSOR_COUNT; i++) {
- Serial.print("XX: i=");
- Serial.print(i, DEC);
-
- struct sm_sensor& s = sensors[i];
-
- Serial.print(", name len=");
- Serial.print(s.name_length, DEC);
- Serial.print(": ->");
- Serial.write(s.name, s.name_length);
- Serial.print("<-");
- Serial.println();
- }
- /**/
- Serial.println("done!!");
+#if PERSISTENT_CONFIGURATION_SUPPORT == 1
+ setup_settings();
+#endif
for (int i = 0; i < SENSOR_COUNT; i++) {
struct sm_sensor s = sensors[i];
@@ -133,6 +92,7 @@ void sm_on_disconnect() {
digitalWrite(LED_PIN, LOW);
}
+#if PERSISTENT_CONFIGURATION_SUPPORT == 1
static int store_string(int index, uint8_t len, char* chars) {
EEPROM.write(index++, len);
@@ -210,6 +170,60 @@ static void store_settings() {
Serial.println("Settings saved");
}
+static void setup_settings() {
+ /*
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 16; j++) {
+ uint8_t value = EEPROM.read(i * 16 + j);
+ Serial.print(value, HEX);
+ Serial.print(" ");
+ Serial.print((char)value);
+ Serial.print(" ");
+ }
+ Serial.println();
+ }
+
+ for (int i = 0; i < SENSOR_COUNT; i++) {
+ struct sm_sensor s = sensors[i];
+
+ Serial.print("name len=");
+ Serial.print(s.name_length, DEC);
+ Serial.print(": ->");
+ Serial.write((const uint8_t*) s.name, s.name_length);
+ Serial.print("<-");
+ Serial.println();
+ }
+*/
+// set_default_settings();
+/*
+ if (!load_settings()) {
+ Serial.println("setting default settings");
+ set_default_settings();
+
+ Serial.println("saving settings");
+ store_settings();
+ } else {
+ Serial.println("Settings loaded");
+ }
+*/
+ for (int i = 0; i < SENSOR_COUNT; i++) {
+ Serial.print("XX: i=");
+ Serial.print(i, DEC);
+
+ struct sm_sensor& s = sensors[i];
+
+ Serial.print(", name len=");
+ Serial.print(s.name_length, DEC);
+ Serial.print(": ->");
+ Serial.write((const uint8_t*) s.name, s.name_length);
+ Serial.print("<-");
+ Serial.println();
+ }
+ /**/
+ Serial.println("done");
+}
+#endif // PERSISTENT_CONFIGURATION_SUPPORT
+
void sm_loop() {
static unsigned long last = 0, now;
@@ -480,3 +494,4 @@ void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) {
}
// vim: set ft=arduino:
+