Split code between ulanzi environment and awtrix_upgrade
Added BME280 sensor support for awtrix_upgrade. Removed battery readings for awtrix_upgrade Added DFMiniMp3 lib for replacing the Ulanzi buzzer in the future
This commit is contained in:
@@ -214,6 +214,7 @@ void HumApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i
|
||||
matrix->print("%");
|
||||
}
|
||||
|
||||
#ifdef ULANZI
|
||||
void BatApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
|
||||
{
|
||||
if (notify.flag)
|
||||
@@ -225,6 +226,7 @@ void BatApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i
|
||||
matrix->print(BATTERY_PERCENT); // Ausgabe des Ladezustands
|
||||
matrix->print("%");
|
||||
}
|
||||
#endif
|
||||
|
||||
void MenuApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state)
|
||||
{
|
||||
|
||||
@@ -50,11 +50,13 @@ extern const char HAhumName[];
|
||||
extern const char HAhumClass[];
|
||||
extern const char HAhumUnit[];
|
||||
|
||||
#ifdef ULANZI
|
||||
extern const char HAbatID[];
|
||||
extern const char HAbatIcon[];
|
||||
extern const char HAbatName[];
|
||||
extern const char HAbatClass[];
|
||||
extern const char HAbatUnit[];
|
||||
#endif
|
||||
|
||||
extern const char HAluxID[];
|
||||
extern const char HAluxIcon[];
|
||||
|
||||
@@ -503,8 +503,10 @@ void DisplayManager_::loadNativeApps()
|
||||
// Update the "hum" app at position 3
|
||||
updateApp("hum", HumApp, SHOW_HUM, 3);
|
||||
|
||||
#ifdef ULANZI
|
||||
// Update the "bat" app at position 4
|
||||
updateApp("bat", BatApp, SHOW_BAT, 4);
|
||||
#endif
|
||||
|
||||
ui.setApps(Apps);
|
||||
|
||||
@@ -813,11 +815,13 @@ void DisplayManager_::updateAppVector(const char *json)
|
||||
callback = HumApp;
|
||||
SHOW_HUM = show;
|
||||
}
|
||||
#ifdef ULANZI
|
||||
else if (name == "bat")
|
||||
{
|
||||
callback = BatApp;
|
||||
SHOW_BAT = show;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
// If the app is not one of the built-in apps, check if it's already in the vector
|
||||
|
||||
@@ -11,8 +11,10 @@ private:
|
||||
|
||||
DisplayManager_() = default;
|
||||
|
||||
#ifdef ULANZI
|
||||
const int BatReadings = 10;
|
||||
uint16_t TotalBatReadings[10];
|
||||
#endif
|
||||
int readIndex = 0;
|
||||
uint16_t total = 0;
|
||||
uint16_t average = 0;
|
||||
|
||||
@@ -31,7 +31,9 @@ void loadSettings()
|
||||
SHOW_DATE = Settings.getBool("DAT", true);
|
||||
SHOW_TEMP = Settings.getBool("TEMP", true);
|
||||
SHOW_HUM = Settings.getBool("HUM", true);
|
||||
#ifdef ULANZI
|
||||
SHOW_BAT = Settings.getBool("BAT", true);
|
||||
#endif
|
||||
Settings.end();
|
||||
uniqueID = getID();
|
||||
MQTT_PREFIX = String(uniqueID);
|
||||
@@ -55,7 +57,9 @@ void saveSettings()
|
||||
Settings.putBool("DAT", SHOW_DATE);
|
||||
Settings.putBool("TEMP", SHOW_TEMP);
|
||||
Settings.putBool("HUM", SHOW_HUM);
|
||||
#ifdef ULANZI
|
||||
Settings.putBool("BAT", SHOW_BAT);
|
||||
#endif
|
||||
Settings.end();
|
||||
}
|
||||
|
||||
@@ -77,7 +81,9 @@ bool NET_STATIC = false;
|
||||
bool SHOW_TIME = true;
|
||||
bool SHOW_DATE = true;
|
||||
bool SHOW_WEATHER = true;
|
||||
#ifdef ULANZI
|
||||
bool SHOW_BAT = true;
|
||||
#endif
|
||||
bool SHOW_TEMP = true;
|
||||
bool SHOW_HUM = true;
|
||||
bool SHOW_SECONDS = true;
|
||||
@@ -102,8 +108,10 @@ float CURRENT_HUM;
|
||||
float CURRENT_LUX;
|
||||
uint8_t BRIGHTNESS = 120;
|
||||
uint8_t BRIGHTNESS_PERCENT;
|
||||
#ifdef ULANZI
|
||||
uint8_t BATTERY_PERCENT;
|
||||
uint16_t BATTERY_RAW;
|
||||
#endif
|
||||
uint16_t LDR_RAW;
|
||||
String TIME_FORMAT = "%H:%M:%S";
|
||||
String DATE_FORMAT = "%d.%m.%y";
|
||||
|
||||
@@ -20,7 +20,9 @@ extern bool NET_STATIC;
|
||||
extern bool SHOW_TIME;
|
||||
extern bool SHOW_DATE;
|
||||
extern bool SHOW_WEATHER;
|
||||
#ifdef ULANZI
|
||||
extern bool SHOW_BAT;
|
||||
#endif
|
||||
extern bool SHOW_TEMP;
|
||||
extern bool SHOW_HUM;
|
||||
extern bool SHOW_SECONDS;
|
||||
@@ -42,8 +44,10 @@ extern float CURRENT_HUM;
|
||||
extern float CURRENT_LUX;
|
||||
extern uint16_t LDR_RAW;
|
||||
extern String CURRENT_APP;
|
||||
#ifdef ULANZI
|
||||
extern uint8_t BATTERY_PERCENT;
|
||||
extern uint16_t BATTERY_RAW;
|
||||
#endif
|
||||
extern uint8_t BRIGHTNESS;
|
||||
extern uint8_t BRIGHTNESS_PERCENT;
|
||||
extern String TEXTCOLOR;
|
||||
|
||||
@@ -24,7 +24,9 @@ HAButton *nextApp = nullptr;
|
||||
HAButton *prevApp = nullptr;
|
||||
HASwitch *transition = nullptr;
|
||||
HASensor *curApp = nullptr;
|
||||
#ifdef ULANZI
|
||||
HASensor *battery = nullptr;
|
||||
#endif
|
||||
HASensor *temperature = nullptr;
|
||||
HASensor *humidity = nullptr;
|
||||
HASensor *illuminance = nullptr;
|
||||
@@ -238,7 +240,10 @@ void connect()
|
||||
}
|
||||
|
||||
char matID[40], briID[40];
|
||||
char btnAID[40], btnBID[40], btnCID[40], appID[40], tempID[40], humID[40], luxID[40], verID[40], batID[40], ramID[40], upID[40], sigID[40], btnLID[40], btnMID[40], btnRID[40], transID[40];
|
||||
char btnAID[40], btnBID[40], btnCID[40], appID[40], tempID[40], humID[40], luxID[40], verID[40], ramID[40], upID[40], sigID[40], btnLID[40], btnMID[40], btnRID[40], transID[40];
|
||||
#ifdef ULANZI
|
||||
char batID[40];
|
||||
#endif
|
||||
|
||||
void MQTTManager_::setup()
|
||||
{
|
||||
@@ -330,12 +335,14 @@ void MQTTManager_::setup()
|
||||
humidity->setDeviceClass(HAhumClass);
|
||||
humidity->setUnitOfMeasurement(HAhumUnit);
|
||||
|
||||
#ifdef ULANZI
|
||||
sprintf(batID, HAbatID, macStr);
|
||||
battery = new HASensor(batID);
|
||||
battery->setIcon(HAbatIcon);
|
||||
battery->setName(HAbatName);
|
||||
battery->setDeviceClass(HAbatClass);
|
||||
battery->setUnitOfMeasurement(HAbatUnit);
|
||||
#endif
|
||||
|
||||
sprintf(luxID, HAluxID, macStr);
|
||||
illuminance = new HASensor(luxID);
|
||||
@@ -432,8 +439,10 @@ void MQTTManager_::sendStats()
|
||||
if (HA_DISCOVERY)
|
||||
{
|
||||
char buffer[5];
|
||||
#ifdef ULANZI
|
||||
snprintf(buffer, 5, "%d", BATTERY_PERCENT);
|
||||
battery->setValue(buffer);
|
||||
#endif
|
||||
|
||||
snprintf(buffer, 5, "%.0f", CURRENT_TEMP);
|
||||
temperature->setValue(buffer);
|
||||
@@ -467,8 +476,10 @@ void MQTTManager_::sendStats()
|
||||
|
||||
StaticJsonDocument<200> doc;
|
||||
char buffer[5];
|
||||
#ifdef ULANZI
|
||||
doc[BatKey] = BATTERY_PERCENT;
|
||||
doc[BatRawKey] = BATTERY_RAW;
|
||||
#endif
|
||||
snprintf(buffer, 5, "%.0f", CURRENT_LUX);
|
||||
doc[LuxKey] = buffer;
|
||||
doc[LDRRawKey] = LDR_RAW;
|
||||
|
||||
@@ -75,8 +75,13 @@ const char *appsItems[][2] PROGMEM = {
|
||||
{"13", "time"},
|
||||
{"1158", "date"},
|
||||
{"234", "temp"},
|
||||
#ifdef ULANZI
|
||||
{"2075", "hum"},
|
||||
{"1486", "bat"}};
|
||||
#else
|
||||
{"2075", "hum"}};
|
||||
#endif
|
||||
|
||||
|
||||
int8_t appsIndex;
|
||||
uint8_t appsCount = 5;
|
||||
@@ -173,9 +178,11 @@ String MenuManager_::menutext()
|
||||
case 3:
|
||||
DisplayManager.drawBMP(0, 0, get_icon(2075), 8, 8);
|
||||
return SHOW_HUM ? "ON" : "OFF";
|
||||
#ifdef ULANZI
|
||||
case 4:
|
||||
DisplayManager.drawBMP(0, 0, get_icon(1486), 8, 8);
|
||||
return SHOW_BAT ? "ON" : "OFF";
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -374,9 +381,11 @@ void MenuManager_::selectButton()
|
||||
case 3:
|
||||
SHOW_HUM = !SHOW_HUM;
|
||||
break;
|
||||
#ifdef ULANZI
|
||||
case 4:
|
||||
SHOW_BAT = !SHOW_BAT;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#define BUTTON_SELECT_PIN 27
|
||||
#else
|
||||
// Pinouts für das WEMOS_D1_MINI32-Environment
|
||||
#define BATTERY_PIN -1
|
||||
#define BUZZER_PIN -1
|
||||
#define LDR_PIN A0
|
||||
#define BUTTON_UP_PIN D0
|
||||
@@ -29,7 +28,11 @@
|
||||
#define BUTTON_SELECT_PIN D8
|
||||
#endif
|
||||
|
||||
#ifdef ULANZI
|
||||
Adafruit_SHT31 sht31;
|
||||
#else
|
||||
Adafruit_BME280 bme280;
|
||||
#endif
|
||||
EasyButton button_left(BUTTON_UP_PIN);
|
||||
EasyButton button_right(BUTTON_DOWN_PIN);
|
||||
EasyButton button_select(BUTTON_SELECT_PIN);
|
||||
@@ -134,11 +137,16 @@ bool PeripheryManager_::isPlaying()
|
||||
|
||||
void fistStart()
|
||||
{
|
||||
|
||||
#ifdef ULANZI
|
||||
uint16_t ADCVALUE = analogRead(BATTERY_PIN);
|
||||
|
||||
BATTERY_PERCENT = min((int)map(ADCVALUE, 490, 690, 0, 100), 100);
|
||||
BATTERY_RAW = ADCVALUE;
|
||||
sht31.readBoth(&CURRENT_TEMP, &CURRENT_HUM);
|
||||
CURRENT_TEMP -= 9.0;
|
||||
#else
|
||||
CURRENT_TEMP = bme280.readTemperature();
|
||||
CURRENT_HUM = 0;
|
||||
#endif
|
||||
|
||||
uint16_t LDRVALUE = analogRead(LDR_PIN);
|
||||
brightnessPercent = LDRVALUE / 4095.0 * 100.0;
|
||||
@@ -160,7 +168,11 @@ void PeripheryManager_::setup()
|
||||
button_select.onPressedFor(1000, select_button_pressed_long);
|
||||
button_select.onSequence(2, 300, select_button_tripple);
|
||||
Wire.begin(21, 22);
|
||||
#ifdef ULANZI
|
||||
sht31.begin(0x44);
|
||||
#else
|
||||
bme280.begin();
|
||||
#endif
|
||||
photocell.setPhotocellPositionOnGround(false);
|
||||
fistStart();
|
||||
}
|
||||
@@ -176,11 +188,16 @@ void PeripheryManager_::tick()
|
||||
if (currentMillis_BatTempHum - previousMillis_BatTempHum >= interval_BatTempHum)
|
||||
{
|
||||
previousMillis_BatTempHum = currentMillis_BatTempHum;
|
||||
#ifdef ULANZI
|
||||
uint16_t ADCVALUE = analogRead(BATTERY_PIN);
|
||||
BATTERY_PERCENT = min((int)map(ADCVALUE, 475, 665, 0, 100), 100);
|
||||
BATTERY_RAW = ADCVALUE;
|
||||
sht31.readBoth(&CURRENT_TEMP, &CURRENT_HUM);
|
||||
CURRENT_TEMP -= 9.0;
|
||||
#else
|
||||
CURRENT_TEMP = bme280.readTemperature();
|
||||
CURRENT_HUM = bme280.readHumidity();
|
||||
#endif
|
||||
checkAlarms();
|
||||
MQTTManager.sendStats();
|
||||
}
|
||||
|
||||
@@ -3,15 +3,21 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <EasyButton.h>
|
||||
#ifdef ULANZI
|
||||
#include "Adafruit_SHT31.h"
|
||||
#else
|
||||
#include "Adafruit_BME280.h"
|
||||
#endif
|
||||
|
||||
class PeripheryManager_
|
||||
{
|
||||
private:
|
||||
PeripheryManager_() = default;
|
||||
void checkAlarms();
|
||||
#ifdef ULANZI
|
||||
const int BatReadings = 10;
|
||||
uint16_t TotalBatReadings[10];
|
||||
#endif
|
||||
int readIndex = 0;
|
||||
uint16_t total = 0;
|
||||
uint16_t average = 0;
|
||||
|
||||
Reference in New Issue
Block a user