aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-01-08 19:30:59 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-01-08 19:30:59 +0100
commit9c3ff3ca4ac5eb076fd6add2e5f14c294e915567 (patch)
tree73d625c3e835e7700e7d42a09dd5f6e57cc9c70d
parent08f269afd4926edca9cdfd00c3d15d419e6c87a4 (diff)
downloadtrygvisio_soil_moisture-9c3ff3ca4ac5eb076fd6add2e5f14c294e915567.tar.gz
trygvisio_soil_moisture-9c3ff3ca4ac5eb076fd6add2e5f14c294e915567.tar.bz2
trygvisio_soil_moisture-9c3ff3ca4ac5eb076fd6add2e5f14c294e915567.tar.xz
trygvisio_soil_moisture-9c3ff3ca4ac5eb076fd6add2e5f14c294e915567.zip
o Implementing reading of values from the real thing.
-rw-r--r--app.cpp39
-rw-r--r--app.h3
-rw-r--r--trygvisio_soil_moisture.ino4
3 files changed, 39 insertions, 7 deletions
diff --git a/app.cpp b/app.cpp
index 19d7285..606864d 100644
--- a/app.cpp
+++ b/app.cpp
@@ -11,15 +11,17 @@
// See http://redbearlab.com/blendmicro/ for pins.
struct sm_sensor {
- uint8_t pin;
+ uint8_t a_pin;
+ uint8_t d1_pin;
+ uint8_t d2_pin;
uint8_t value;
uint16_t warning_value;
uint16_t update_interval;
uint8_t name_length;
uint8_t name[SENSOR_NAME_LEN];
} sensors[SENSOR_COUNT] = {
- // Pin, Value, Warning Value, Update Interval, Length of Name, Name
- { 9, 0, 10, 0, 9, 'sensor #1'},
+ // A Pin, D1 Pin, D2 Pin, Value, Warning Value, Update Interval, Length of Name, Name
+ { 8, 3, 5, 0, 10, 0, 9, 'sensor #1'},
};
static unsigned long next_update[SENSOR_COUNT];
@@ -31,15 +33,42 @@ void sm_on_connect() {
}
}
-void sm_on_loop() {
+void sm_setup() {
+ for (int i = 0; i < SENSOR_COUNT; i++) {
+ struct sm_sensor s = sensors[i];
+
+ pinMode(s.a_pin, INPUT);
+ pinMode(s.d1_pin, OUTPUT);
+ pinMode(s.d2_pin, OUTPUT);
+ }
+}
+
+void sm_loop() {
static unsigned long last = 0, now;
static uint8_t x = 10;
now = millis();
+
+ if (now - last > 3000) {
+ last = now;
+ for (int i = 0; i < SENSOR_COUNT; i++) {
+ struct sm_sensor& s = sensors[i];
+
+ digitalWrite(s.d1_pin, HIGH);
+ digitalWrite(s.d2_pin, LOW);
+
+ s.value = analogRead(s.a_pin);
+ Serial.print("#");
+ Serial.print(i, DEC);
+ Serial.print(" = ");
+ Serial.print(s.value, DEC);
+ Serial.println();
+ }
+ }
// TODO: implement proper notification
- if (false || now - last > 3000) {
+ if (false && now - last > 3000) {
last = now;
struct sm_res res;
diff --git a/app.h b/app.h
index ee9c1cd..5039c0e 100644
--- a/app.h
+++ b/app.h
@@ -106,8 +106,9 @@ struct sm_res {
};
};
+void sm_loop();
+void sm_setup();
void sm_on_connect();
-void sm_on_loop();
//boolean tx_soil_moisture(struct sm_res& res);
void notify_soil_moisture(const struct sm_res& res, uint8_t body_len);
diff --git a/trygvisio_soil_moisture.ino b/trygvisio_soil_moisture.ino
index ecadbdf..f908e4a 100644
--- a/trygvisio_soil_moisture.ino
+++ b/trygvisio_soil_moisture.ino
@@ -97,6 +97,8 @@ static void setup_rf() {
// 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"));
+
+ sm_setup();
}
static boolean rf_started = false;
@@ -331,7 +333,7 @@ void loop() {
}
}
- sm_on_loop();
+ sm_loop();
}
static void show_pipes() {