v0.42
- 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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ enum AnimationDirection
|
||||
SLIDE_RIGHT
|
||||
};
|
||||
|
||||
enum FrameState
|
||||
enum AppState
|
||||
{
|
||||
IN_TRANSITION,
|
||||
FIXED
|
||||
@@ -58,11 +58,11 @@ struct MatrixDisplayUiState
|
||||
u_int64_t lastUpdate = 0;
|
||||
uint16_t ticksSinceLastStateSwitch = 0;
|
||||
|
||||
FrameState frameState = FIXED;
|
||||
uint8_t currentFrame = 0;
|
||||
AppState appState = FIXED;
|
||||
uint8_t currentApp = 0;
|
||||
|
||||
// Normal = 1, Inverse = -1;
|
||||
int8_t frameTransitionDirection = 1;
|
||||
int8_t appTransitionDirection = 1;
|
||||
|
||||
bool manuelControll = false;
|
||||
|
||||
@@ -70,7 +70,7 @@ struct MatrixDisplayUiState
|
||||
void *userData = NULL;
|
||||
};
|
||||
|
||||
typedef void (*AppCallback)(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame);
|
||||
typedef void (*AppCallback)(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp);
|
||||
typedef void (*OverlayCallback)(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state);
|
||||
|
||||
class MatrixDisplayUi
|
||||
@@ -78,21 +78,19 @@ class MatrixDisplayUi
|
||||
private:
|
||||
FastLED_NeoMatrix *matrix;
|
||||
|
||||
// Values for the Frames
|
||||
AnimationDirection frameAnimationDirection = SLIDE_RIGHT;
|
||||
// Values for the Apps
|
||||
AnimationDirection appAnimationDirection = SLIDE_RIGHT;
|
||||
|
||||
int8_t lastTransitionDirection = 1;
|
||||
|
||||
uint16_t ticksPerFrame = 151; // ~ 5000ms at 30 FPS
|
||||
uint16_t ticksPerApp = 151; // ~ 5000ms at 30 FPS
|
||||
uint16_t ticksPerTransition = 15; // ~ 500ms at 30 FPS
|
||||
|
||||
bool setAutoTransition = true;
|
||||
|
||||
AppCallback *AppFunctions;
|
||||
|
||||
uint8_t AppCount = 0;
|
||||
|
||||
// Internally used to transition to a specific frame
|
||||
// Internally used to transition to a specific app
|
||||
int8_t nextAppNumber = -1;
|
||||
|
||||
// Values for Overlays
|
||||
@@ -115,6 +113,7 @@ private:
|
||||
public:
|
||||
MatrixDisplayUi(FastLED_NeoMatrix *matrix);
|
||||
|
||||
uint8_t AppCount = 0;
|
||||
/**
|
||||
* Initialise the display
|
||||
*/
|
||||
@@ -127,12 +126,12 @@ public:
|
||||
|
||||
// Automatic Controll
|
||||
/**
|
||||
* Enable automatic transition to next frame after the some time can be configured with `setTimePerApp` and `setTimePerTransition`.
|
||||
* Enable automatic transition to next app after the some time can be configured with `setTimePerApp` and `setTimePerTransition`.
|
||||
*/
|
||||
void enablesetAutoTransition();
|
||||
|
||||
/**
|
||||
* Disable automatic transition to next frame.
|
||||
* Disable automatic transition to next app.
|
||||
*/
|
||||
void disablesetAutoTransition();
|
||||
|
||||
@@ -143,7 +142,7 @@ public:
|
||||
void setsetAutoTransitionBackwards();
|
||||
|
||||
/**
|
||||
* Set the approx. time a frame is displayed
|
||||
* Set the approx. time a app is displayed
|
||||
*/
|
||||
void setTimePerApp(uint16_t time);
|
||||
|
||||
@@ -154,22 +153,22 @@ public:
|
||||
|
||||
// Customize indicator position and style
|
||||
|
||||
// Frame settings
|
||||
// App settings
|
||||
|
||||
/**
|
||||
* Configure what animation is used to transition from one frame to another
|
||||
* Configure what animation is used to transition from one app to another
|
||||
*/
|
||||
void setAppAnimation(AnimationDirection dir);
|
||||
|
||||
/**
|
||||
* Add frame drawing functions
|
||||
* Add app drawing functions
|
||||
*/
|
||||
void setApps(const std::vector<std::pair<String, AppCallback>> &appPairs);
|
||||
|
||||
// Overlay
|
||||
|
||||
/**
|
||||
* Add overlays drawing functions that are draw independent of the Frames
|
||||
* Add overlays drawing functions that are draw independent of the Apps
|
||||
*/
|
||||
void setOverlays(OverlayCallback *overlayFunctions, uint8_t overlayCount);
|
||||
|
||||
@@ -178,15 +177,15 @@ public:
|
||||
void previousApp();
|
||||
|
||||
/**
|
||||
* Switch without transition to frame `frame`.
|
||||
* Switch without transition to app `app`.
|
||||
*/
|
||||
void switchToApp(uint8_t frame);
|
||||
void switchToApp(uint8_t app);
|
||||
|
||||
/**
|
||||
* Transition to frame `frame`, when the `frame` number is bigger than the current
|
||||
* frame the forward animation will be used, otherwise the backwards animation is used.
|
||||
* Transition to app `app`, when the `app` number is bigger than the current
|
||||
* app the forward animation will be used, otherwise the backwards animation is used.
|
||||
*/
|
||||
void transitionToApp(uint8_t frame);
|
||||
void transitionToApp(uint8_t app);
|
||||
|
||||
// State Info
|
||||
MatrixDisplayUiState *getUiState();
|
||||
|
||||
Reference in New Issue
Block a user