Skip to content

Commit

Permalink
Merge pull request #412 from luebbe/main
Browse files Browse the repository at this point in the history
Fixes #354
  • Loading branch information
Blueforcer authored Nov 28, 2023
2 parents a2c9d27 + 5863865 commit 22edc7b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ uint16_t MAX_BATTERY = 665;
float TEMP_OFFSET;
#else
float TEMP_OFFSET = -9;
uint8_t BATTERY_PERCENT;
uint16_t BATTERY_RAW;
uint8_t BATTERY_PERCENT = 0;
uint16_t BATTERY_RAW = 0;
#endif
float HUM_OFFSET;
uint16_t LDR_RAW;
Expand Down Expand Up @@ -392,6 +392,7 @@ bool BLOCK_NAVIGATION = false;
bool UPDATE_CHECK = false;
float GAMMA = 0;
bool SENSOR_READING = true;
bool SENSORS_STABLE = false;
bool DFPLAYER_ACTIVE = false;
bool ROTATE_SCREEN = false;
uint8_t TIME_MODE = 1;
Expand Down
1 change: 1 addition & 0 deletions src/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ void saveSettings();
extern bool BLOCK_NAVIGATION;
extern bool UPDATE_CHECK;
extern bool SENSOR_READING;
extern bool SENSORS_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 @@ -699,7 +699,7 @@ void MQTTManager_::tick()
{
mqtt.loop();
unsigned long currentMillis_Stats = millis();
if (currentMillis_Stats - previousMillis_Stats >= STATS_INTERVAL)
if ((currentMillis_Stats - previousMillis_Stats >= STATS_INTERVAL) && (SENSORS_STABLE))
{
previousMillis_Stats = currentMillis_Stats;
sendStats();
Expand Down
11 changes: 9 additions & 2 deletions src/PeripheryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,15 @@ void PeripheryManager_::tick()
previousMillis_BatTempHum = currentMillis_BatTempHum;
#ifndef awtrix2_upgrade
uint16_t ADCVALUE = analogRead(BATTERY_PIN);
BATTERY_PERCENT = max(min((int)map(ADCVALUE, MIN_BATTERY, MAX_BATTERY, 0, 100), 100), 0);
BATTERY_RAW = ADCVALUE;
// Discard values that are totally out of range, especially the first value read after a reboot.
// Meaningful values for a Ulanzi are in the range 400..700
if ((ADCVALUE > 100) && (ADCVALUE < 1000)) {
BATTERY_PERCENT = max(min((int)map(ADCVALUE, MIN_BATTERY, MAX_BATTERY, 0, 100), 100), 0);
BATTERY_RAW = ADCVALUE;
SENSORS_STABLE = true;
}
#else
SENSORS_STABLE = true;
#endif
if (SENSOR_READING)
{
Expand Down

0 comments on commit 22edc7b

Please sign in to comment.