v0.41
- adds new timeformats for a blinking second colon - awtrix now send stats to [PREFIX]/stats - fixes a bug where turning on an native app causes a crash.
This commit is contained in:
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "AWTRIX Light",
|
||||
"version": "0.40",
|
||||
"version": "0.41",
|
||||
"home_assistant_domain": "AwtrixLight",
|
||||
"funding_url": "https://blueforcer.de",
|
||||
"new_install_prompt_erase": true,
|
||||
|
||||
@@ -361,7 +361,14 @@ void DisplayManager_::loadNativeApps()
|
||||
{
|
||||
if (show)
|
||||
{
|
||||
Apps.insert(Apps.begin() + position, std::make_pair(name, callback));
|
||||
if (position >= Apps.size())
|
||||
{
|
||||
Apps.push_back(std::make_pair(name, callback));
|
||||
}
|
||||
else
|
||||
{
|
||||
Apps.insert(Apps.begin() + position, std::make_pair(name, callback));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -568,7 +575,7 @@ void DisplayManager_::drawProgressBar(int cur, int total)
|
||||
matrix.show();
|
||||
}
|
||||
|
||||
void DisplayManager_::drawMenuIndicator(int cur, int total)
|
||||
void DisplayManager_::drawMenuIndicator(int cur, int total, uint16_t color)
|
||||
{
|
||||
int menuItemWidth = 1;
|
||||
int totalWidth = total * menuItemWidth + (total - 1);
|
||||
@@ -579,7 +586,7 @@ void DisplayManager_::drawMenuIndicator(int cur, int total)
|
||||
int x = leftMargin + i * (menuItemWidth + pixelSpacing);
|
||||
if (i == cur)
|
||||
{
|
||||
matrix.drawLine(x, 7, x + menuItemWidth - 1, 7, matrix.Color(255, 0, 0));
|
||||
matrix.drawLine(x, 7, x + menuItemWidth - 1, 7, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
void drawGIF(uint16_t x, uint16_t y, fs::File gifFile);
|
||||
void drawJPG(uint16_t x, uint16_t y, fs::File jpgFile);
|
||||
void drawProgressBar(int cur, int total);
|
||||
void drawMenuIndicator(int cur, int total);
|
||||
void drawMenuIndicator(int cur, int total, uint16_t color);
|
||||
void drawBMP(int16_t x, int16_t y, const uint16_t bitmap[], int16_t w, int16_t h);
|
||||
};
|
||||
|
||||
|
||||
23
src/Frames.h
23
src/Frames.h
@@ -109,8 +109,27 @@ void TimeFrame(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x
|
||||
time_t now = time(nullptr);
|
||||
struct tm *timeInfo;
|
||||
timeInfo = localtime(&now);
|
||||
const char *timeformat = TIME_FORMAT.c_str();
|
||||
char t[20];
|
||||
strftime(t, sizeof(t), TIME_FORMAT.c_str(), localtime(&now));
|
||||
char t2[20];
|
||||
if (timeformat[2] == ' ')
|
||||
{
|
||||
strcpy(t2, timeformat);
|
||||
if (now % 2)
|
||||
{
|
||||
t2[2] = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
t2[2] = ':';
|
||||
}
|
||||
strftime(t, sizeof(t), t2, localtime(&now));
|
||||
}
|
||||
else
|
||||
{
|
||||
strftime(t, sizeof(t), timeformat, localtime(&now));
|
||||
}
|
||||
|
||||
DisplayManager.printText(0 + x, 6 + y, t, true, false);
|
||||
|
||||
if (!SHOW_WEEKDAY)
|
||||
@@ -184,7 +203,7 @@ void HumFrame(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x,
|
||||
return;
|
||||
CURRENT_APP = "Humidity";
|
||||
DisplayManager.getInstance().resetTextColor();
|
||||
matrix->drawRGBBitmap(x, y + 1, get_icon(2075), 8,8);
|
||||
matrix->drawRGBBitmap(x, y + 1, get_icon(2075), 8, 8);
|
||||
matrix->setCursor(14 + x, 6 + y);
|
||||
int humidity = CURRENT_HUM; // Temperatur ohne Nachkommastellen
|
||||
matrix->print(humidity); // Ausgabe der Temperatur
|
||||
|
||||
@@ -91,7 +91,8 @@ float CURRENT_LUX;
|
||||
uint8_t BRIGHTNESS = 120;
|
||||
uint8_t BRIGHTNESS_PERCENT;
|
||||
uint8_t BATTERY_PERCENT;
|
||||
|
||||
uint16_t BATTERY_RAW;
|
||||
uint16_t LDR_RAW;
|
||||
String TIME_FORMAT = "%H:%M:%S";
|
||||
String DATE_FORMAT = "%d.%m.%y";
|
||||
bool START_ON_MONDAY;
|
||||
|
||||
@@ -39,8 +39,10 @@ extern bool UPPERCASE_LETTERS;
|
||||
extern float CURRENT_TEMP;
|
||||
extern float CURRENT_HUM;
|
||||
extern float CURRENT_LUX;
|
||||
extern uint16_t LDR_RAW;
|
||||
extern String CURRENT_APP;
|
||||
extern uint8_t BATTERY_PERCENT;
|
||||
extern uint16_t BATTERY_RAW;
|
||||
extern uint8_t BRIGHTNESS;
|
||||
extern uint8_t BRIGHTNESS_PERCENT;
|
||||
extern String TEXTCOLOR;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "ServerManager.h"
|
||||
#include <ArduinoHA.h>
|
||||
#include <WiFi.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
WiFiClient espClient;
|
||||
uint8_t lastBrightness;
|
||||
@@ -306,20 +307,39 @@ void MQTTManager_::sendStats()
|
||||
if (HA_DISCOVERY)
|
||||
{
|
||||
char buffer[5];
|
||||
snprintf(buffer, 5, "%d", BATTERY_PERCENT); // Formatieren von BATTERY_PERCENT als Integer
|
||||
battery.setValue(buffer); // Senden von BATTERY_PERCENT als const char*
|
||||
snprintf(buffer, 5, "%d", BATTERY_PERCENT);
|
||||
battery.setValue(buffer);
|
||||
|
||||
snprintf(buffer, 5, "%.0f", CURRENT_TEMP); // Formatieren von CURRENT_TEMP als Float ohne Nachkommastellen
|
||||
temperature.setValue(buffer); // Senden von CURRENT_TEMP als const char*
|
||||
snprintf(buffer, 5, "%.0f", CURRENT_TEMP);
|
||||
temperature.setValue(buffer);
|
||||
|
||||
snprintf(buffer, 5, "%.0f", CURRENT_HUM); // Formatieren von CURRENT_HUM als Float ohne Nachkommastellen
|
||||
humidity.setValue(buffer); // Senden von CURRENT_HUM als const char*
|
||||
snprintf(buffer, 5, "%.0f", CURRENT_HUM);
|
||||
humidity.setValue(buffer);
|
||||
|
||||
snprintf(buffer, 5, "%.0f", CURRENT_LUX); // Formatieren von CURRENT_LUX als Double ohne Nachkommastellen
|
||||
illuminance.setValue(buffer); // Senden von CURRENT_LUX als const char*
|
||||
snprintf(buffer, 5, "%.0f", CURRENT_LUX);
|
||||
illuminance.setValue(buffer);
|
||||
|
||||
BriMode.setState(AUTO_BRIGHTNESS, true);
|
||||
Matrix.setBRIGHTNESS(BRIGHTNESS);
|
||||
Matrix.setState(!MATRIX_OFF, false);
|
||||
}
|
||||
|
||||
StaticJsonDocument<200> doc;
|
||||
char buffer[5];
|
||||
doc["bat"] = BATTERY_PERCENT;
|
||||
doc["batraw"] = BATTERY_RAW;
|
||||
snprintf(buffer, 5, "%.0f", CURRENT_LUX);
|
||||
doc["lux"] = buffer;
|
||||
doc["ldrraw"] = LDR_RAW;
|
||||
doc["bri"] = BRIGHTNESS;
|
||||
snprintf(buffer, 5, "%.0f", CURRENT_TEMP);
|
||||
doc["temp"] = buffer;
|
||||
snprintf(buffer, 5, "%.0f", CURRENT_HUM);
|
||||
doc["hum"] = buffer;
|
||||
String jsonString;
|
||||
serializeJson(doc, jsonString);
|
||||
char topic[50];
|
||||
strcpy(topic, MQTT_PREFIX.c_str());
|
||||
strcat(topic, "/stats");
|
||||
mqtt.publish(topic, jsonString.c_str());
|
||||
}
|
||||
@@ -49,10 +49,13 @@ const char *timeFormat[] PROGMEM = {
|
||||
"%H:%M:%S",
|
||||
"%l:%M:%S",
|
||||
"%H:%M",
|
||||
"%H %M",
|
||||
"%l:%M",
|
||||
"%l:%M %p"};
|
||||
"%l %M",
|
||||
"%l:%M %p",
|
||||
"%l %M %p"};
|
||||
int8_t timeFormatIndex;
|
||||
uint8_t timeFormatCount = 5;
|
||||
uint8_t timeFormatCount = 8;
|
||||
|
||||
const char *dateFormat[] PROGMEM = {
|
||||
"%d.%m.%y", // 01.04.22
|
||||
@@ -110,16 +113,18 @@ String MenuManager_::menutext()
|
||||
{
|
||||
time_t now = time(nullptr);
|
||||
char t[20];
|
||||
char display[20];
|
||||
switch (currentState)
|
||||
{
|
||||
case MainMenu:
|
||||
DisplayManager.drawMenuIndicator(menuIndex, menuItemCount);
|
||||
DisplayManager.drawMenuIndicator(menuIndex, menuItemCount, 0xF800);
|
||||
return menuItems[menuIndex];
|
||||
case BrightnessMenu:
|
||||
return AUTO_BRIGHTNESS ? "AUTO" : String(BRIGHTNESS_PERCENT) + "%";
|
||||
case FPSMenu:
|
||||
return String(MATRIX_FPS) + " FPS";
|
||||
case ColorMenu:
|
||||
DisplayManager.drawMenuIndicator(currentColor, sizeof(textColors) / sizeof(textColors[0]), 0xFBC0);
|
||||
DisplayManager.setTextColor(textColors[currentColor]);
|
||||
return "0x" + String(textColors[currentColor], HEX);
|
||||
case SwitchMenu:
|
||||
@@ -129,9 +134,29 @@ String MenuManager_::menutext()
|
||||
case AppTimeMenu:
|
||||
return String(TIME_PER_APP / 1000.0, 0) + "s";
|
||||
case TimeFormatMenu:
|
||||
strftime(t, sizeof(t), timeFormat[timeFormatIndex], localtime(&now));
|
||||
return t;
|
||||
DisplayManager.drawMenuIndicator(timeFormatIndex, timeFormatCount, 0xFBC0);
|
||||
if (timeFormat[timeFormatIndex][2] == ' ')
|
||||
{
|
||||
strcpy(display, timeFormat[timeFormatIndex]);
|
||||
if (now % 2)
|
||||
{
|
||||
display[2] = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
display[2] = ':';
|
||||
}
|
||||
strftime(t, sizeof(t), display, localtime(&now));
|
||||
return t;
|
||||
}
|
||||
else
|
||||
{
|
||||
strftime(t, sizeof(t), timeFormat[timeFormatIndex], localtime(&now));
|
||||
return t;
|
||||
}
|
||||
|
||||
case DateFormatMenu:
|
||||
DisplayManager.drawMenuIndicator(dateFormatIndex, dateFormatCount, 0xFBC0);
|
||||
strftime(t, sizeof(t), dateFormat[dateFormatIndex], localtime(&now));
|
||||
return t;
|
||||
case WeekdayMenu:
|
||||
@@ -139,6 +164,7 @@ String MenuManager_::menutext()
|
||||
case TempMenu:
|
||||
return IS_CELSIUS ? "°C" : "°F";
|
||||
case Appmenu:
|
||||
DisplayManager.drawMenuIndicator(appsIndex, appsCount, 0xFBC0);
|
||||
switch (appsIndex)
|
||||
{
|
||||
case 0:
|
||||
|
||||
@@ -162,30 +162,25 @@ void PeripheryManager_::tick()
|
||||
button_right.read();
|
||||
button_select.read();
|
||||
|
||||
|
||||
unsigned long currentMillis_BatTempHum = millis();
|
||||
if (currentMillis_BatTempHum - previousMillis_BatTempHum >= interval_BatTempHum)
|
||||
{
|
||||
previousMillis_BatTempHum = currentMillis_BatTempHum;
|
||||
uint16_t ADCVALUE = analogRead(BATTERY_PIN);
|
||||
BATTERY_PERCENT = min((int)map(ADCVALUE, 510, 665, 0, 100), 100);
|
||||
CURRENT_LUX = (roundf(photocell.getSmoothedLux() * 1000) / 1000);
|
||||
BATTERY_RAW = ADCVALUE;
|
||||
sht31.readBoth(&CURRENT_TEMP, &CURRENT_HUM);
|
||||
CURRENT_TEMP -= 9.0;
|
||||
checkAlarms();
|
||||
MQTTManager.sendStats();
|
||||
uint32_t freeHeap = esp_get_free_heap_size();
|
||||
float freeHeapKB = freeHeap / 1024.0;
|
||||
Serial.print(ESP.getFreeHeap() / 1024);
|
||||
Serial.println(" KB");
|
||||
}
|
||||
|
||||
|
||||
unsigned long currentMillis_LDR = millis();
|
||||
if (currentMillis_LDR - previousMillis_LDR >= interval_LDR && AUTO_BRIGHTNESS)
|
||||
if (currentMillis_LDR - previousMillis_LDR >= interval_LDR)
|
||||
{
|
||||
previousMillis_LDR = currentMillis_LDR;
|
||||
TotalLDRReadings[sampleIndex] = analogRead(LDR_PIN);
|
||||
|
||||
sampleIndex = (sampleIndex + 1) % LDRReadings;
|
||||
sampleSum = 0.0;
|
||||
for (int i = 0; i < LDRReadings; i++)
|
||||
@@ -193,11 +188,15 @@ void PeripheryManager_::tick()
|
||||
sampleSum += TotalLDRReadings[i];
|
||||
}
|
||||
sampleAverage = sampleSum / (float)LDRReadings;
|
||||
|
||||
brightnessPercent = sampleAverage / 4095.0 * 100.0;
|
||||
int brightness = map(brightnessPercent, 0, 100, 10, 120);
|
||||
BRIGHTNESS = map(brightnessPercent, 0, 100, 0, 255);
|
||||
DisplayManager.setBrightness(brightness);
|
||||
LDR_RAW = sampleAverage;
|
||||
CURRENT_LUX = (roundf(photocell.getSmoothedLux() * 1000) / 1000);
|
||||
if (AUTO_BRIGHTNESS)
|
||||
{
|
||||
brightnessPercent = sampleAverage / 4095.0 * 100.0;
|
||||
BRIGHTNESS = map(brightnessPercent, 0, 100, 0, 255);
|
||||
int brightness = map(brightnessPercent, 0, 100, 10, 120);
|
||||
DisplayManager.setBrightness(brightness);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user