commit 644742a885cd010c3491f3142b6d1388deaa1367
parent a707a7dc4a735c310333e5ffa15e78c892349358
Author: Lukas F. Hartmann <lukas@mnt.mn>
Date: Mon, 3 Dec 2018 13:38:22 +0100
tiny fw: add lid sensor event mute/unmute, toggle sensing direction
Diffstat:
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/reform-tiny-fw/reform-tiny-fw.ino b/reform-tiny-fw/reform-tiny-fw.ino
@@ -56,15 +56,18 @@ float current = 0;
char cmd = 'a';
unsigned char echo = 1;
+char hallSenseDir = 0;
+char hallSenseEvents = 0;
+
// TODO if there is no battery power, ignore lid sensor (values >900)
void handleLidSensor() {
hallSense = analogRead(HALL_SENSOR_PIN);
- if (hallSense>(thresh+window) && hallState==LID_OPEN) {
+ if (hallState==LID_OPEN && (hallSenseDir == 0 && hallSense>(thresh+window) || hallSenseDir == 1 && hallSense<(thresh-window))) {
hallState = LID_CLOSED;
}
- if (hallSense<(thresh+window) && hallState==LID_CLOSED) {
- softSerial.println("event:wake");
+ if (hallState==LID_CLOSED && (hallSenseDir == 0 && hallSense<(thresh-window) || hallSenseDir == 1 && hallSense>(thresh+window))) {
hallState = LID_OPEN;
+ if (hallSenseEvents) softSerial.println("event:wake");
}
}
@@ -158,7 +161,7 @@ void handleCommands() {
softSerial.println(thresh);
}
else if (cmd == 'w') {
- // set open/closed threshold fuzz window
+ // set open/closed threshold hysteresis window
if (inputNumber>0) {
window = inputNumber;
}
@@ -176,6 +179,18 @@ void handleCommands() {
softSerial.print("echo:");
softSerial.println(echo);
}
+ else if (cmd == 'o') {
+ // toggle lid sensor magnet orientation
+ hallSenseDir = inputNumber?1:0;
+ softSerial.print("orientation:");
+ softSerial.println(hallSenseDir);
+ }
+ else if (cmd == 'v') {
+ // toggle lid sensor wake events
+ hallSenseEvents = inputNumber?1:0;
+ softSerial.print("events:");
+ softSerial.println(hallSenseEvents);
+ }
else {
softSerial.println("error:command");
}