aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-07-31 20:34:29 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2015-07-31 20:34:29 +0200
commit930b9e23ab981251e0cbd839c5a2f3a769c3fb47 (patch)
tree010f8a93acf9ab8d4694a5a567fe53de3f3dfb38
parent9b086f8c4b5e96b46a3904c3bcfe11af39347b80 (diff)
downloadtrygvisio_soil_moisture-930b9e23ab981251e0cbd839c5a2f3a769c3fb47.tar.gz
trygvisio_soil_moisture-930b9e23ab981251e0cbd839c5a2f3a769c3fb47.tar.bz2
trygvisio_soil_moisture-930b9e23ab981251e0cbd839c5a2f3a769c3fb47.tar.xz
trygvisio_soil_moisture-930b9e23ab981251e0cbd839c5a2f3a769c3fb47.zip
o Even better Debug for the ATtiny85 implementation.h.
-rw-r--r--Debug.h24
-rw-r--r--config-check.h8
-rw-r--r--trygvisio_soil_moisture.ino2
3 files changed, 33 insertions, 1 deletions
diff --git a/Debug.h b/Debug.h
index 2de911b..83eb43f 100644
--- a/Debug.h
+++ b/Debug.h
@@ -3,6 +3,22 @@
#include "config-check.h"
+#ifdef __AVR_ATtiny85__
+class Serial {
+public:
+ void begin(int);
+ void write(uint8_t);
+ int read();
+ void print(...);
+ void println(...);
+ operator bool();
+ bool available();
+ void flush();
+};
+
+extern Serial Serial;
+#endif
+
enum DebugSink {
DEBUG_SINK_SERIAL,
DEBUG_SINK_SOFTWARE_SERIAL,
@@ -30,6 +46,14 @@ public:
return false;
};
+ inline int read() const {
+ if (sink == DEBUG_SINK_SERIAL) {
+ return Serial.read();
+ }
+
+ return '\0';
+ };
+
size_t write(uint8_t value) const {
if (sink == DEBUG_SINK_SERIAL) {
Serial.write(value);
diff --git a/config-check.h b/config-check.h
index 45f1af0..63e9b95 100644
--- a/config-check.h
+++ b/config-check.h
@@ -101,6 +101,8 @@
* Values:
* 1: no logging, all logging is discarded
* 2: Use Serial. Uses the platforms default Serial port, usually the USB or hardware serial ports on your board.
+ *
+ * TODO: Change this to 0=no logging, 1=serial, 2=software serial
*/
#ifndef DEBUG_SINK
@@ -124,6 +126,12 @@
#undef USE_LOW_POWER_MODE
#endif
+#if DEBUG_SINK == 2
+#warning DEBUG_SINK must be 1 on ATTiny85 boards
+#undef DEBUG_SINK
+#define DEBUG_SINK 1
+#endif
+
#endif // __AVR_ATtiny85__
#endif
diff --git a/trygvisio_soil_moisture.ino b/trygvisio_soil_moisture.ino
index 183cb38..a43ea26 100644
--- a/trygvisio_soil_moisture.ino
+++ b/trygvisio_soil_moisture.ino
@@ -434,7 +434,7 @@ void loop() {
aci_loop();
if (debug.available()) {
- debug.write(Serial.read());
+ debug.write(debug.read());
}
now = millis();