Browse Source

reform-tiny-fw: simplify/split up power reporting, remove strings for value reporting

Lukas F. Hartmann 4 months ago
parent
commit
d951896b07
1 changed files with 21 additions and 28 deletions
  1. 21
    28
      reform-tiny-fw/reform-tiny-fw.ino

+ 21
- 28
reform-tiny-fw/reform-tiny-fw.ino View File

@@ -42,7 +42,7 @@ SoftwareSerial softSerial(8, 3);
42 42
 
43 43
 float ampSecs = 5*3600.0;
44 44
 unsigned char hallState = LID_OPEN;
45
-int thresh = 500;
45
+int thresh = 100;
46 46
 int window = 10;
47 47
 int hallSense = 0;
48 48
 
@@ -56,7 +56,7 @@ float current = 0;
56 56
 char cmd = 'a';
57 57
 unsigned char echo = 1;
58 58
 
59
-char hallSenseDir = 0;
59
+char hallSenseDir = 1;
60 60
 char hallSenseEvents = 0;
61 61
 
62 62
 // TODO if there is no battery power, ignore lid sensor (values >900)
@@ -125,31 +125,27 @@ void handleCommands() {
125 125
     }
126 126
     else if (chr == '\r') {
127 127
       // execute
128
-      if (cmd == 'p') {
129
-        // print power stats
130
-        softSerial.print("power(Ah,V,A):");
131
-        softSerial.print(ampSecs/3600.0);
132
-        softSerial.print("\t");
133
-        softSerial.print(volts);
134
-        softSerial.print("\t");
135
-        softSerial.println(current);
128
+      if (cmd == 'a') {
129
+        // get current (mA)
130
+        softSerial.println((int)(current*1000.0));
131
+      }
132
+      else if (cmd == 'v') {
133
+        // get voltage
134
+        softSerial.println((int)(volts*1000.0));
136 135
       }
137 136
       else if (cmd == 'c') {
138
-        // set battery capacity
137
+        // set/get battery capacity (mAh)
139 138
         if (inputNumber>0) {
140
-          ampSecs = inputNumber*60.0;
139
+          ampSecs = ((float)inputNumber)*3.6;
141 140
         }
142
-        softSerial.print("capacity(Ah):");
143
-        softSerial.println(ampSecs/3600.0);
141
+        softSerial.println((int)(ampSecs/3.6));
144 142
       }
145
-      else if (cmd == 'h') {
146
-        // print hall sensor analog reading
147
-        softSerial.print("sensor:");
143
+      else if (cmd == 's') {
144
+        // print sensor analog reading 0-1023
148 145
         softSerial.println(hallSense);
149 146
       }
150 147
       else if (cmd == 'l') {
151 148
         // print lid open/close state
152
-        softSerial.print("lid:");
153 149
         softSerial.println(hallState);
154 150
       }
155 151
       else if (cmd == 't') {
@@ -157,7 +153,6 @@ void handleCommands() {
157 153
         if (inputNumber>0) {
158 154
           thresh = inputNumber;
159 155
         }
160
-        softSerial.print("threshold:");
161 156
         softSerial.println(thresh);
162 157
       }
163 158
       else if (cmd == 'w') {
@@ -165,31 +160,29 @@ void handleCommands() {
165 160
         if (inputNumber>0) {
166 161
           window = inputNumber;
167 162
         }
168
-        softSerial.print("window:");
169 163
         softSerial.println(window);
170 164
       }
171 165
       else if (cmd == 'u') {
172 166
         // uptime of attiny in seconds
173
-        softSerial.print("uptime(s):");
174 167
         softSerial.println(millis()/1000);
175 168
       }
176 169
       else if (cmd == 'e') {
177 170
         // toggle serial echo
178 171
         echo = inputNumber?1:0;
179
-        softSerial.print("echo:");
180
-        softSerial.println(echo);
172
+        //softSerial.print("echo:");
173
+        //softSerial.println(echo);
181 174
       }
182 175
       else if (cmd == 'o') {
183 176
         // toggle lid sensor magnet orientation
184 177
         hallSenseDir = inputNumber?1:0;
185
-        softSerial.print("orientation:");
178
+        //softSerial.print("orientation:");
186 179
         softSerial.println(hallSenseDir);
187 180
       }
188
-      else if (cmd == 'v') {
189
-        // toggle lid sensor wake events
181
+      else if (cmd == 'k') {
182
+        // toggle lid sensor waKe events
190 183
         hallSenseEvents = inputNumber?1:0;
191
-        softSerial.print("events:");
192
-        softSerial.println(hallSenseEvents);
184
+        //softSerial.print("events:");
185
+        //softSerial.println(hallSenseEvents);
193 186
       }
194 187
       else {
195 188
         softSerial.println("error:command");

Loading…
Cancel
Save