Transition Control

- autotransition can be turn on and of in onscreen menu
- autotransition is turned off when only one app is loaded

closes #1
closes #2
This commit is contained in:
Stephan Mühl
2023-03-22 18:34:51 +01:00
parent 1d18850c0b
commit 667fff226e
8 changed files with 95 additions and 65 deletions

View File

@@ -56,20 +56,20 @@ void MatrixDisplayUi::setTargetFPS(uint8_t fps)
// -/------ Automatic controll ------\- // -/------ Automatic controll ------\-
void MatrixDisplayUi::enableAutoTransition() void MatrixDisplayUi::enablesetAutoTransition()
{ {
this->autoTransition = true; this->setAutoTransition = true;
} }
void MatrixDisplayUi::disableAutoTransition() void MatrixDisplayUi::disablesetAutoTransition()
{ {
this->autoTransition = false; this->setAutoTransition = false;
} }
void MatrixDisplayUi::setAutoTransitionForwards() void MatrixDisplayUi::setsetAutoTransitionForwards()
{ {
this->state.frameTransitionDirection = 1; this->state.frameTransitionDirection = 1;
this->lastTransitionDirection = 1; this->lastTransitionDirection = 1;
} }
void MatrixDisplayUi::setAutoTransitionBackwards() void MatrixDisplayUi::setsetAutoTransitionBackwards()
{ {
this->state.frameTransitionDirection = -1; this->state.frameTransitionDirection = -1;
this->lastTransitionDirection = -1; this->lastTransitionDirection = -1;
@@ -173,7 +173,7 @@ int8_t MatrixDisplayUi::update()
if (timeBudget <= 0) if (timeBudget <= 0)
{ {
// Implement frame skipping to ensure time budget is keept // Implement frame skipping to ensure time budget is keept
if (this->autoTransition && this->state.lastUpdate != 0) if (this->setAutoTransition && this->state.lastUpdate != 0)
this->state.ticksSinceLastStateSwitch += ceil(-timeBudget / this->updateInterval); this->state.ticksSinceLastStateSwitch += ceil(-timeBudget / this->updateInterval);
this->state.lastUpdate = frameStart; this->state.lastUpdate = frameStart;
@@ -205,7 +205,7 @@ void MatrixDisplayUi::tick()
} }
if (this->state.ticksSinceLastStateSwitch >= this->ticksPerFrame) if (this->state.ticksSinceLastStateSwitch >= this->ticksPerFrame)
{ {
if (this->autoTransition) if (this->setAutoTransition)
{ {
this->state.frameState = IN_TRANSITION; this->state.frameState = IN_TRANSITION;

View File

@@ -86,7 +86,7 @@ private:
uint16_t ticksPerFrame = 151; // ~ 5000ms at 30 FPS uint16_t ticksPerFrame = 151; // ~ 5000ms at 30 FPS
uint16_t ticksPerTransition = 15; // ~ 500ms at 30 FPS uint16_t ticksPerTransition = 15; // ~ 500ms at 30 FPS
bool autoTransition = true; bool setAutoTransition = true;
AppCallback *AppFunctions; AppCallback *AppFunctions;
@@ -129,18 +129,18 @@ public:
/** /**
* Enable automatic transition to next frame after the some time can be configured with `setTimePerApp` and `setTimePerTransition`. * Enable automatic transition to next frame after the some time can be configured with `setTimePerApp` and `setTimePerTransition`.
*/ */
void enableAutoTransition(); void enablesetAutoTransition();
/** /**
* Disable automatic transition to next frame. * Disable automatic transition to next frame.
*/ */
void disableAutoTransition(); void disablesetAutoTransition();
/** /**
* Set the direction if the automatic transitioning * Set the direction if the automatic transitioning
*/ */
void setAutoTransitionForwards(); void setsetAutoTransitionForwards();
void setAutoTransitionBackwards(); void setsetAutoTransitionBackwards();
/** /**
* Set the approx. time a frame is displayed * Set the approx. time a frame is displayed

View File

@@ -67,14 +67,18 @@ void DisplayManager_::MatrixState(bool on)
setBrightness(BRIGHTNESS); setBrightness(BRIGHTNESS);
} }
void DisplayManager_::disableAutoTransition() bool DisplayManager_::setAutoTransition(bool active)
{ {
ui.disableAutoTransition(); if (active && AUTO_TRANSITION)
} {
ui.enablesetAutoTransition();
void DisplayManager_::enableAutoTransition() return true;
{ }
ui.enableAutoTransition(); else
{
ui.disablesetAutoTransition();
return false;
}
} }
void DisplayManager_::drawGIF(uint16_t x, uint16_t y, fs::File gifFile) void DisplayManager_::drawGIF(uint16_t x, uint16_t y, fs::File gifFile)
@@ -396,6 +400,8 @@ void DisplayManager_::loadApps()
// Apps.push_back(std::make_pair(5, WeatherFrame)); // Apps.push_back(std::make_pair(5, WeatherFrame));
nativeAppsCount = Apps.size(); nativeAppsCount = Apps.size();
ui.setApps(Apps); // Add frames ui.setApps(Apps); // Add frames
if (AUTO_TRANSITION && nativeAppsCount == 1)
setAutoTransition(false);
StartAppUpdater(); StartAppUpdater();
} }
@@ -406,6 +412,7 @@ void DisplayManager_::setup()
gif.setMatrix(&matrix); gif.setMatrix(&matrix);
ui.setAppAnimation(SLIDE_DOWN); ui.setAppAnimation(SLIDE_DOWN);
ui.setOverlays(overlays, 4); ui.setOverlays(overlays, 4);
setAutoTransition(AUTO_TRANSITION);
ui.init(); ui.init();
} }

View File

@@ -46,8 +46,7 @@ public:
void generateNotification(String); void generateNotification(String);
void generateCustomPage(uint16_t, String); void generateCustomPage(uint16_t, String);
void printText(int16_t x, int16_t y, const char *text, bool centered); void printText(int16_t x, int16_t y, const char *text, bool centered);
void disableAutoTransition(); bool setAutoTransition(bool active);
void enableAutoTransition();
void drawGIF(uint16_t x, uint16_t y, fs::File gifFile); void drawGIF(uint16_t x, uint16_t y, fs::File gifFile);
void drawJPG(uint16_t x, uint16_t y, fs::File jpgFile); void drawJPG(uint16_t x, uint16_t y, fs::File jpgFile);
}; };

View File

@@ -262,11 +262,11 @@ void ShowCustomFrame(uint8_t id, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
// Disable auto transition if text is repeating and too wide // Disable auto transition if text is repeating and too wide
if ((cf->repeat > 0) && (getTextWidth(cf->text.c_str()) > availableWidth) && (state->frameState == FIXED)) if ((cf->repeat > 0) && (getTextWidth(cf->text.c_str()) > availableWidth) && (state->frameState == FIXED))
{ {
DisplayManager.disableAutoTransition(); DisplayManager.setAutoTransition(false);
} }
else else
{ {
DisplayManager.enableAutoTransition(); DisplayManager.setAutoTransition(true);
} }
// Check if text is wider than available display width and frame is not in transition // Check if text is wider than available display width and frame is not in transition
@@ -286,7 +286,7 @@ void ShowCustomFrame(uint8_t id, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
// Transition to next app if frame is repeating and repeat limit has been reached // Transition to next app if frame is repeating and repeat limit has been reached
if ((cf->currentRepeat + 1 >= cf->repeat) && (cf->repeat > 0)) if ((cf->currentRepeat + 1 >= cf->repeat) && (cf->repeat > 0))
{ {
DisplayManager.enableAutoTransition(); DisplayManager.setAutoTransition(true);
cf->currentRepeat = 0; cf->currentRepeat = 0;
DisplayManager.nextApp(); DisplayManager.nextApp();
return; return;

View File

@@ -10,6 +10,7 @@ void loadSettings()
BRIGHTNESS = Settings.getUChar("BRI", 120); BRIGHTNESS = Settings.getUChar("BRI", 120);
AUTO_BRIGHTNESS = Settings.getBool("ABRI", true); AUTO_BRIGHTNESS = Settings.getBool("ABRI", true);
TEXTCOLOR_565 = Settings.getUInt("COL", 0xFFFF); TEXTCOLOR_565 = Settings.getUInt("COL", 0xFFFF);
AUTO_TRANSITION = Settings.getBool("TRANS", true);
Settings.end(); Settings.end();
} }
@@ -19,6 +20,7 @@ void saveSettings()
Settings.putUChar("FPS", MATRIX_FPS); Settings.putUChar("FPS", MATRIX_FPS);
Settings.putUChar("BRI", BRIGHTNESS); Settings.putUChar("BRI", BRIGHTNESS);
Settings.putBool("ABRI", AUTO_BRIGHTNESS); Settings.putBool("ABRI", AUTO_BRIGHTNESS);
Settings.putBool("TRANS", AUTO_TRANSITION);
Settings.putUInt("COL", TEXTCOLOR_565); Settings.putUInt("COL", TEXTCOLOR_565);
Settings.end(); Settings.end();
} }
@@ -28,7 +30,7 @@ IPAddress gateway;
IPAddress subnet; IPAddress subnet;
IPAddress primaryDNS; IPAddress primaryDNS;
IPAddress secondaryDNS; IPAddress secondaryDNS;
const char *VERSION = "0.30"; const char *VERSION = "0.31";
String MQTT_HOST = ""; String MQTT_HOST = "";
uint16_t MQTT_PORT = 1883; uint16_t MQTT_PORT = 1883;
String MQTT_USER; String MQTT_USER;
@@ -71,11 +73,11 @@ uint8_t SNOOZE_TIME;
String TIMER_SOUND; String TIMER_SOUND;
// Matrix States // Matrix States
bool AUTO_TRANSITION = false;
bool AUTO_BRIGHTNESS = true; bool AUTO_BRIGHTNESS = true;
bool UPPERCASE_LETTERS = true; bool UPPERCASE_LETTERS = true;
bool AP_MODE; bool AP_MODE;
bool MATRIX_OFF; bool MATRIX_OFF;
bool TIMER_ACTIVE; bool TIMER_ACTIVE;
bool ALARM_ACTIVE; bool ALARM_ACTIVE;
uint16_t TEXTCOLOR_565 = 0xFFFF; uint16_t TEXTCOLOR_565 = 0xFFFF;

View File

@@ -52,7 +52,7 @@ extern String ALARM_SOUND;
extern String TIMER_SOUND; extern String TIMER_SOUND;
extern uint16_t TEXTCOLOR_565; extern uint16_t TEXTCOLOR_565;
extern uint8_t SNOOZE_TIME; extern uint8_t SNOOZE_TIME;
extern bool AUTO_TRANSITION;
void loadSettings(); void loadSettings();
void saveSettings(); void saveSettings();

View File

@@ -19,36 +19,38 @@ enum MenuState
StationSelection, StationSelection,
PlayingStation, PlayingStation,
Reset, Reset,
Volume, VolumeMenu,
Brightness, BrightnessMenu,
FPS, FPSMenu,
Color ColorMenu,
SwitchMenu
}; };
const char *menuItems[] = { const char *menuItems[] = {
"BRIGHT", "BRIGHT",
"FPS", "FPS",
"COLOR", "COLOR",
"SWITCH",
"RESET"}; "RESET"};
byte menuItemCount = 4; byte menuItemCount = 5;
MenuState currentState = MainMenu; MenuState currentState = MainMenu;
uint16_t textColors[] = { uint16_t textColors[] = {
0xFFFF, // White 0xFFFF, // White
0xF800, // Red 0xF800, // Red
0xF812, // Dark orange 0xF812, // Dark orange
0xF81F, // Yellow 0xF81F, // Yellow
0x881F, // Dark green 0x881F, // Dark green
0x001F, // Blue 0x001F, // Blue
0x04FF, // Light blue 0x04FF, // Light blue
0x07FC, // Cyan 0x07FC, // Cyan
0x07E2, // Seafoam green 0x07E2, // Seafoam green
0xAFE0, // Light green 0xAFE0, // Light green
0xFFE0, // Light yellow 0xFFE0, // Light yellow
0xFD60, // Dark yellow 0xFD60, // Dark yellow
0xFBC0}; // Pink 0xFBC0}; // Pink
uint8_t currentColor; uint8_t currentColor;
@@ -67,7 +69,7 @@ String MenuManager_::menutext()
{ {
return (menuItems[menuIndex]); return (menuItems[menuIndex]);
} }
else if (currentState == Brightness) else if (currentState == BrightnessMenu)
{ {
if (AUTO_BRIGHTNESS) if (AUTO_BRIGHTNESS)
{ {
@@ -78,11 +80,11 @@ String MenuManager_::menutext()
return (String(BRIGHTNESS_PERCENT) + "%"); return (String(BRIGHTNESS_PERCENT) + "%");
} }
} }
else if (currentState == FPS) else if (currentState == FPSMenu)
{ {
return String(MATRIX_FPS) + " FPS"; return String(MATRIX_FPS) + " FPS";
} }
else if (currentState == Color) else if (currentState == ColorMenu)
{ {
DisplayManager.setTextColor(textColors[currentColor]); DisplayManager.setTextColor(textColors[currentColor]);
String colorStr = String(textColors[currentColor], HEX); String colorStr = String(textColors[currentColor], HEX);
@@ -92,6 +94,10 @@ String MenuManager_::menutext()
} }
return colorStr; return colorStr;
} }
else if (currentState == SwitchMenu)
{
return AUTO_TRANSITION ? "ON" : "OFF";
}
return ""; return "";
} }
@@ -111,7 +117,7 @@ void MenuManager_::rightButton()
{ {
AudioManager.nextStation(); AudioManager.nextStation();
} }
else if (currentState == Brightness) else if (currentState == BrightnessMenu)
{ {
if (!AUTO_BRIGHTNESS) if (!AUTO_BRIGHTNESS)
{ {
@@ -122,16 +128,20 @@ void MenuManager_::rightButton()
DisplayManager.setBrightness(BRIGHTNESS); DisplayManager.setBrightness(BRIGHTNESS);
} }
} }
else if (currentState == FPS) else if (currentState == FPSMenu)
{ {
if (MATRIX_FPS < 30) if (MATRIX_FPS < 30)
++MATRIX_FPS; ++MATRIX_FPS;
} }
else if (currentState == Color) else if (currentState == ColorMenu)
{ {
int arraySize = sizeof(textColors) / sizeof(textColors[0]); int arraySize = sizeof(textColors) / sizeof(textColors[0]);
currentColor = (currentColor + 1) % arraySize; currentColor = (currentColor + 1) % arraySize;
} }
else if (currentState == SwitchMenu)
{
AUTO_TRANSITION = !AUTO_TRANSITION;
}
} }
void MenuManager_::leftButton() void MenuManager_::leftButton()
@@ -150,7 +160,7 @@ void MenuManager_::leftButton()
{ {
AudioManager.prevStation(); AudioManager.prevStation();
} }
else if (currentState == Brightness) else if (currentState == BrightnessMenu)
{ {
if (!AUTO_BRIGHTNESS) if (!AUTO_BRIGHTNESS)
{ {
@@ -161,16 +171,20 @@ void MenuManager_::leftButton()
DisplayManager.setBrightness(BRIGHTNESS); DisplayManager.setBrightness(BRIGHTNESS);
} }
} }
else if (currentState == FPS) else if (currentState == FPSMenu)
{ {
if (MATRIX_FPS > 15) if (MATRIX_FPS > 15)
--MATRIX_FPS; --MATRIX_FPS;
} }
else if (currentState == Color) else if (currentState == ColorMenu)
{ {
int arraySize = sizeof(textColors) / sizeof(textColors[0]); int arraySize = sizeof(textColors) / sizeof(textColors[0]);
currentColor = (currentColor - 1 + arraySize) % arraySize; currentColor = (currentColor - 1 + arraySize) % arraySize;
} }
else if (currentState == SwitchMenu)
{
AUTO_TRANSITION = !AUTO_TRANSITION;
}
} }
void MenuManager_::selectButton() void MenuManager_::selectButton()
@@ -182,17 +196,21 @@ void MenuManager_::selectButton()
if (menuIndex == 0) // BRIGHT if (menuIndex == 0) // BRIGHT
{ {
BRIGHTNESS_PERCENT = map(BRIGHTNESS, 0, 255, 0, 100); BRIGHTNESS_PERCENT = map(BRIGHTNESS, 0, 255, 0, 100);
currentState = Brightness; currentState = BrightnessMenu;
} }
else if (menuIndex == 1) // RESET else if (menuIndex == 1) // RESET
{ {
currentState = FPS; currentState = FPSMenu;
} }
else if (menuIndex == 2) // COLOR else if (menuIndex == 2) // COLOR
{ {
currentState = Color; currentState = ColorMenu;
} }
else if (menuIndex == 3) // FPS else if (menuIndex == 3) // COLOR
{
currentState = SwitchMenu;
}
else if (menuIndex == 4) // FPS
{ {
ESP.restart(); ESP.restart();
} }
@@ -201,7 +219,7 @@ void MenuManager_::selectButton()
{ {
AudioManager.startRadioStation(AudioManager.getCurrentRadioStation()); AudioManager.startRadioStation(AudioManager.getCurrentRadioStation());
} }
else if (currentState == Brightness) else if (currentState == BrightnessMenu)
{ {
AUTO_BRIGHTNESS = !AUTO_BRIGHTNESS; AUTO_BRIGHTNESS = !AUTO_BRIGHTNESS;
} }
@@ -211,17 +229,17 @@ void MenuManager_::selectButtonLong()
{ {
if (inMenu) if (inMenu)
{ {
if (currentState == Brightness) if (currentState == BrightnessMenu)
{ {
BRIGHTNESS = map(BRIGHTNESS_PERCENT, 0, 100, 0, 255); BRIGHTNESS = map(BRIGHTNESS_PERCENT, 0, 100, 0, 255);
saveSettings(); saveSettings();
} }
else if (currentState == FPS) else if (currentState == FPSMenu)
{ {
DisplayManager.setFPS(MATRIX_FPS); DisplayManager.setFPS(MATRIX_FPS);
saveSettings(); saveSettings();
} }
else if (currentState == Color) else if (currentState == ColorMenu)
{ {
TEXTCOLOR_565 = textColors[currentColor]; TEXTCOLOR_565 = textColors[currentColor];
saveSettings(); saveSettings();
@@ -230,7 +248,11 @@ void MenuManager_::selectButtonLong()
{ {
inMenu = false; inMenu = false;
} }
else if (currentState == SwitchMenu)
{
DisplayManager.setAutoTransition(AUTO_TRANSITION);
saveSettings();
}
currentState = MainMenu; currentState = MainMenu;
} }
else else