- App transistion is now inacitve if there is only 1 app
- Adds bargraph to notify and customapps
- Every awtrix now gets a unique id for AP, MQTT and HA
- Adds firmware as HA sensor
- Adds wifi strength as HA sensor
- Adds ram usage as HA sensor
- Adds version as HA sensor
- Adds uptime as ISO 8601 as HA sensot
- HA discorvery now gets correct device classes
- fixes bug where date formats are not saved

closes #24
closes #23
closes #21
This commit is contained in:
Stephan Mühl
2023-03-29 00:24:38 +02:00
parent 3de324605e
commit c51c769cb5
16 changed files with 1217 additions and 967 deletions

View File

@@ -48,9 +48,9 @@ void MatrixDisplayUi::setTargetFPS(uint8_t fps)
float oldInterval = this->updateInterval;
this->updateInterval = ((float)1.0 / (float)fps) * 1000;
// Calculate new ticksPerFrame
// Calculate new ticksPerApp
float changeRatio = oldInterval / (float)this->updateInterval;
this->ticksPerFrame *= changeRatio;
this->ticksPerApp *= changeRatio;
this->ticksPerTransition *= changeRatio;
}
@@ -66,33 +66,34 @@ void MatrixDisplayUi::disablesetAutoTransition()
}
void MatrixDisplayUi::setsetAutoTransitionForwards()
{
this->state.frameTransitionDirection = 1;
this->state.appTransitionDirection = 1;
this->lastTransitionDirection = 1;
}
void MatrixDisplayUi::setsetAutoTransitionBackwards()
{
this->state.frameTransitionDirection = -1;
this->state.appTransitionDirection = -1;
this->lastTransitionDirection = -1;
}
void MatrixDisplayUi::setTimePerApp(uint16_t time)
{
this->ticksPerFrame = (int)((float)time / (float)updateInterval);
this->ticksPerApp = (int)((float)time / (float)updateInterval);
}
void MatrixDisplayUi::setTimePerTransition(uint16_t time)
{
this->ticksPerTransition = (int)((float)time / (float)updateInterval);
}
// -/----- Frame settings -----\-
// -/----- App settings -----\-
void MatrixDisplayUi::setAppAnimation(AnimationDirection dir)
{
this->frameAnimationDirection = dir;
this->appAnimationDirection = dir;
}
void MatrixDisplayUi::setApps(const std::vector<std::pair<String, AppCallback>> &appPairs)
{
delete[] AppFunctions;
AppCount = appPairs.size();
Serial.println(AppCount);
AppFunctions = new AppCallback[AppCount];
for (size_t i = 0; i < AppCount; ++i)
@@ -113,51 +114,51 @@ void MatrixDisplayUi::setOverlays(OverlayCallback *overlayFunctions, uint8_t ove
// -/----- Manuel control -----\-
void MatrixDisplayUi::nextApp()
{
if (this->state.frameState != IN_TRANSITION)
if (this->state.appState != IN_TRANSITION)
{
this->state.manuelControll = true;
this->state.frameState = IN_TRANSITION;
this->state.appState = IN_TRANSITION;
this->state.ticksSinceLastStateSwitch = 0;
this->lastTransitionDirection = this->state.frameTransitionDirection;
this->state.frameTransitionDirection = 1;
this->lastTransitionDirection = this->state.appTransitionDirection;
this->state.appTransitionDirection = 1;
}
}
void MatrixDisplayUi::previousApp()
{
if (this->state.frameState != IN_TRANSITION)
if (this->state.appState != IN_TRANSITION)
{
this->state.manuelControll = true;
this->state.frameState = IN_TRANSITION;
this->state.appState = IN_TRANSITION;
this->state.ticksSinceLastStateSwitch = 0;
this->lastTransitionDirection = this->state.frameTransitionDirection;
this->state.frameTransitionDirection = -1;
this->lastTransitionDirection = this->state.appTransitionDirection;
this->state.appTransitionDirection = -1;
}
}
void MatrixDisplayUi::switchToApp(uint8_t frame)
void MatrixDisplayUi::switchToApp(uint8_t app)
{
if (frame >= this->AppCount)
if (app >= this->AppCount)
return;
this->state.ticksSinceLastStateSwitch = 0;
if (frame == this->state.currentFrame)
if (app == this->state.currentApp)
return;
this->state.frameState = FIXED;
this->state.currentFrame = frame;
this->state.appState = FIXED;
this->state.currentApp = app;
}
void MatrixDisplayUi::transitionToApp(uint8_t frame)
void MatrixDisplayUi::transitionToApp(uint8_t app)
{
if (frame >= this->AppCount)
if (app >= this->AppCount)
return;
this->state.ticksSinceLastStateSwitch = 0;
if (frame == this->state.currentFrame)
if (app == this->state.currentApp)
return;
this->nextAppNumber = frame;
this->lastTransitionDirection = this->state.frameTransitionDirection;
this->nextAppNumber = app;
this->lastTransitionDirection = this->state.appTransitionDirection;
this->state.manuelControll = true;
this->state.frameState = IN_TRANSITION;
this->state.appState = IN_TRANSITION;
this->state.frameTransitionDirection = frame < this->state.currentFrame ? -1 : 1;
this->state.appTransitionDirection = app < this->state.currentApp ? -1 : 1;
}
// -/----- State information -----\-
@@ -168,18 +169,18 @@ MatrixDisplayUiState *MatrixDisplayUi::getUiState()
int8_t MatrixDisplayUi::update()
{
long frameStart = millis();
int8_t timeBudget = this->updateInterval - (frameStart - this->state.lastUpdate);
long appStart = millis();
int8_t timeBudget = this->updateInterval - (appStart - this->state.lastUpdate);
if (timeBudget <= 0)
{
// Implement frame skipping to ensure time budget is keept
// Implement app skipping to ensure time budget is keept
if (this->setAutoTransition && this->state.lastUpdate != 0)
this->state.ticksSinceLastStateSwitch += ceil(-timeBudget / this->updateInterval);
this->state.lastUpdate = frameStart;
this->state.lastUpdate = appStart;
this->tick();
}
return this->updateInterval - (millis() - frameStart);
return this->updateInterval - (millis() - appStart);
}
void MatrixDisplayUi::tick()
@@ -188,13 +189,13 @@ void MatrixDisplayUi::tick()
if (this->AppCount > 0)
{
switch (this->state.frameState)
switch (this->state.appState)
{
case IN_TRANSITION:
if (this->state.ticksSinceLastStateSwitch >= this->ticksPerTransition)
{
this->state.frameState = FIXED;
this->state.currentFrame = getnextAppNumber();
this->state.appState = FIXED;
this->state.currentApp = getnextAppNumber();
this->state.ticksSinceLastStateSwitch = 0;
this->nextAppNumber = -1;
}
@@ -203,14 +204,14 @@ void MatrixDisplayUi::tick()
// Revert manuelControll
if (this->state.manuelControll)
{
this->state.frameTransitionDirection = this->lastTransitionDirection;
this->state.appTransitionDirection = this->lastTransitionDirection;
this->state.manuelControll = false;
}
if (this->state.ticksSinceLastStateSwitch >= this->ticksPerFrame)
if (this->state.ticksSinceLastStateSwitch >= this->ticksPerApp)
{
if (this->setAutoTransition)
{
this->state.frameState = IN_TRANSITION;
this->state.appState = IN_TRANSITION;
}
this->state.ticksSinceLastStateSwitch = 0;
}
@@ -227,13 +228,13 @@ void MatrixDisplayUi::tick()
void MatrixDisplayUi::drawApp()
{
switch (this->state.frameState)
switch (this->state.appState)
{
case IN_TRANSITION:
{
float progress = (float)this->state.ticksSinceLastStateSwitch / (float)this->ticksPerTransition;
int16_t x, y, x1, y1;
switch (this->frameAnimationDirection)
switch (this->appAnimationDirection)
{
case SLIDE_LEFT:
x = -32 * progress;
@@ -261,20 +262,20 @@ void MatrixDisplayUi::drawApp()
break;
}
// Invert animation if direction is reversed.
int8_t dir = this->state.frameTransitionDirection >= 0 ? 1 : -1;
int8_t dir = this->state.appTransitionDirection >= 0 ? 1 : -1;
x *= dir;
y *= dir;
x1 *= dir;
y1 *= dir;
bool FirstFrame = progress < 0.2;
bool LastFrame = progress > 0.8;
bool FirstApp = progress < 0.2;
bool LastApp = progress > 0.8;
this->matrix->drawRect(x, y, x1, y1, matrix->Color(0, 0, 0));
(this->AppFunctions[this->state.currentFrame])(this->matrix, &this->state, x, y, FirstFrame, LastFrame);
(this->AppFunctions[this->getnextAppNumber()])(this->matrix, &this->state, x1, y1, FirstFrame, LastFrame);
(this->AppFunctions[this->state.currentApp])(this->matrix, &this->state, x, y, FirstApp, LastApp);
(this->AppFunctions[this->getnextAppNumber()])(this->matrix, &this->state, x1, y1, FirstApp, LastApp);
break;
}
case FIXED:
(this->AppFunctions[this->state.currentFrame])(this->matrix, &this->state, 0, 0, false, false);
(this->AppFunctions[this->state.currentApp])(this->matrix, &this->state, 0, 0, false, false);
break;
}
}
@@ -283,8 +284,8 @@ void MatrixDisplayUi::resetState()
{
this->state.lastUpdate = 0;
this->state.ticksSinceLastStateSwitch = 0;
this->state.frameState = FIXED;
this->state.currentFrame = 0;
this->state.appState = FIXED;
this->state.currentApp = 0;
}
void MatrixDisplayUi::drawOverlays()
@@ -299,5 +300,5 @@ uint8_t MatrixDisplayUi::getnextAppNumber()
{
if (this->nextAppNumber != -1)
return this->nextAppNumber;
return (this->state.currentFrame + this->AppCount + this->state.frameTransitionDirection) % this->AppCount;
return (this->state.currentApp + this->AppCount + this->state.appTransitionDirection) % this->AppCount;
}