Browse Source

tiny fw: add lid sensor event mute/unmute, toggle sensing direction

Lukas F. Hartmann 1 month ago
parent
commit
644742a885
1 changed files with 19 additions and 4 deletions
  1. 19
    4
      reform-tiny-fw/reform-tiny-fw.ino

+ 19
- 4
reform-tiny-fw/reform-tiny-fw.ino View File

@@ -56,15 +56,18 @@ float current = 0;
56 56
 char cmd = 'a';
57 57
 unsigned char echo = 1;
58 58
 
59
+char hallSenseDir = 0;
60
+char hallSenseEvents = 0;
61
+
59 62
 // TODO if there is no battery power, ignore lid sensor (values >900)
60 63
 void handleLidSensor() {
61 64
   hallSense = analogRead(HALL_SENSOR_PIN);
62
-  if (hallSense>(thresh+window) && hallState==LID_OPEN) {
65
+  if (hallState==LID_OPEN && (hallSenseDir == 0 && hallSense>(thresh+window) || hallSenseDir == 1 && hallSense<(thresh-window))) {
63 66
     hallState = LID_CLOSED;
64 67
   }
65
-  if (hallSense<(thresh+window) && hallState==LID_CLOSED) {
66
-    softSerial.println("event:wake");
68
+  if (hallState==LID_CLOSED && (hallSenseDir == 0 && hallSense<(thresh-window) || hallSenseDir == 1 && hallSense>(thresh+window))) {
67 69
     hallState = LID_OPEN;
70
+    if (hallSenseEvents) softSerial.println("event:wake");
68 71
   }
69 72
 }
70 73
 
@@ -158,7 +161,7 @@ void handleCommands() {
158 161
         softSerial.println(thresh);
159 162
       }
160 163
       else if (cmd == 'w') {
161
-        // set open/closed threshold fuzz window
164
+        // set open/closed threshold hysteresis window
162 165
         if (inputNumber>0) {
163 166
           window = inputNumber;
164 167
         }
@@ -176,6 +179,18 @@ void handleCommands() {
176 179
         softSerial.print("echo:");
177 180
         softSerial.println(echo);
178 181
       }
182
+      else if (cmd == 'o') {
183
+        // toggle lid sensor magnet orientation
184
+        hallSenseDir = inputNumber?1:0;
185
+        softSerial.print("orientation:");
186
+        softSerial.println(hallSenseDir);
187
+      }
188
+      else if (cmd == 'v') {
189
+        // toggle lid sensor wake events
190
+        hallSenseEvents = inputNumber?1:0;
191
+        softSerial.print("events:");
192
+        softSerial.println(hallSenseEvents);
193
+      }
179 194
       else {
180 195
         softSerial.println("error:command");
181 196
       }

Loading…
Cancel
Save