Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ bool BLOCK_NAVIGATION = false;
bool UPDATE_CHECK = false;
float GAMMA = 0;
bool SENSOR_READING = true;
bool SENSORS_STABLE = false;
bool BATTERY_READING_STABLE = false;
bool DFPLAYER_ACTIVE = false;
bool ROTATE_SCREEN = false;
uint8_t TIME_MODE = 1;
Expand Down
4 changes: 3 additions & 1 deletion src/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ void saveSettings();
extern bool BLOCK_NAVIGATION;
extern bool UPDATE_CHECK;
extern bool SENSOR_READING;
extern bool SENSORS_STABLE;
// This boolean is used to indicate that the battery sensor readings via the ADC are stable.
// If your device dosn't have a battery, make sure that BATTERY_PIN in PeripheryManager.cpp is undefined
extern bool BATTERY_READING_STABLE;
extern bool ROTATE_SCREEN;
extern long STATS_INTERVAL;
extern uint8_t TIME_MODE;
Expand Down
2 changes: 1 addition & 1 deletion src/MQTTManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ void MQTTManager_::tick()
mqtt.loop();
}
unsigned long currentMillis_Stats = millis();
if ((currentMillis_Stats - previousMillis_Stats >= STATS_INTERVAL) && (SENSORS_STABLE))
if ((currentMillis_Stats - previousMillis_Stats >= STATS_INTERVAL) && (BATTERY_READING_STABLE))
{
previousMillis_Stats = currentMillis_Stats;
sendStats();
Expand Down
11 changes: 4 additions & 7 deletions src/PeripheryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ void PeripheryManager_::tick()
if (currentMillis_BatTempHum - previousMillis_BatTempHum >= interval_BatTempHum)
{
previousMillis_BatTempHum = currentMillis_BatTempHum;
#ifndef awtrix2_upgrade
// Only try to read the battery when BATTERY_PIN is defined
#ifdef BATTERY_PIN
uint16_t ADCVALUE = analogRead(BATTERY_PIN);
// Discard values that are totally out of range, especially the first value read after a reboot.
// Meaningful values for an Ulanzi clock are in the range 400..700
Expand All @@ -493,10 +494,10 @@ void PeripheryManager_::tick()
// Send ADC values through median filter to get rid of the remaining spikes and then calculate the average
BATTERY_RAW = meanFilterBatt.AddValue(medianFilterBatt.AddValue(ADCVALUE));
BATTERY_PERCENT = max(min((int)map(BATTERY_RAW, MIN_BATTERY, MAX_BATTERY, 0, 100), 100), 0);
SENSORS_STABLE = true;
BATTERY_READING_STABLE = true;
}
#else
SENSORS_STABLE = true;
BATTERY_READING_STABLE = true; // Always set this to true, when there is no battery
#endif
if (SENSOR_READING)
{
Expand Down Expand Up @@ -526,10 +527,6 @@ void PeripheryManager_::tick()
CURRENT_TEMP += TEMP_OFFSET;
CURRENT_HUM += HUM_OFFSET;
}
else
{
SENSORS_STABLE = true;
}
}

unsigned long currentMillis_LDR = millis();
Expand Down