Browse Source

Minimum voltage check moved into a separate function. Minimum voltage constant added.

klaute 2 years ago
parent
commit
a8c40a7e23
2 changed files with 11 additions and 11 deletions
  1. 1
    0
      firmware/config.h
  2. 10
    11
      firmware/firmware.ino

+ 1
- 0
firmware/config.h View File

@@ -14,6 +14,7 @@
14 14
 #define UPDATE_WEBSERVER_INTVERVAL_S   1
15 15
 #define DELAY_LOOP_MS                 50
16 16
 #define POWERSAVING_SLEEP_S          600
17
+#define BAT_LOW_VOLTAGE              3.4
17 18
 
18 19
 #define STATUS_LED_PIN        BUILTIN_LED
19 20
 #define ANEMOMETER_PIN        D7

+ 10
- 11
firmware/firmware.ino View File

@@ -106,13 +106,7 @@ void setup() {
106 106
 
107 107
   digitalWrite(STATUS_LED_PIN, LOW);
108 108
 
109
-  if (currentSensorData[SENSOR_BAT_VOLTAGE] <= 3.4)
110
-  {
111
-#ifdef DEBUG
112
-    Serial.println("Low battery, going into deep sleep.");
113
-#endif
114
-    ESP.deepSleep(4294967295); // battery low, shutting down
115
-  }
109
+  lowBatCheck();
116 110
 
117 111
   WiFi.mode(WIFI_OFF);
118 112
   WiFi.forceSleepBegin();
@@ -126,15 +120,20 @@ void setup() {
126 120
 
127 121
 //*************************************************************************//
128 122
 
129
-void loop() {
130
-
131
-  if (currentSensorData[SENSOR_BAT_VOLTAGE] <= 3.4)
123
+void lowBatCheck()
124
+{
125
+  if (currentSensorData[SENSOR_BAT_VOLTAGE] <= BAT_LOW_VOLTAGE)
132 126
   {
133 127
 #ifdef DEBUG
134 128
     Serial.println("Low battery, going into deep sleep.");
135 129
 #endif
136 130
     ESP.deepSleep(4294967295); // battery low, shutting down
137 131
   }
132
+}
133
+
134
+void loop() {
135
+
136
+  lowBatCheck();
138 137
 
139 138
 #ifdef POWERSAVING
140 139
   delay(50);
@@ -191,4 +190,4 @@ void _loop() {
191 190
 }
192 191
 
193 192
 //*************************************************************************//
194
-
193
+

Loading…
Cancel
Save