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

@@ -67,14 +67,18 @@ void DisplayManager_::MatrixState(bool on)
setBrightness(BRIGHTNESS);
}
void DisplayManager_::disableAutoTransition()
bool DisplayManager_::setAutoTransition(bool active)
{
ui.disableAutoTransition();
}
void DisplayManager_::enableAutoTransition()
{
ui.enableAutoTransition();
if (active && AUTO_TRANSITION)
{
ui.enablesetAutoTransition();
return true;
}
else
{
ui.disablesetAutoTransition();
return false;
}
}
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));
nativeAppsCount = Apps.size();
ui.setApps(Apps); // Add frames
if (AUTO_TRANSITION && nativeAppsCount == 1)
setAutoTransition(false);
StartAppUpdater();
}
@@ -406,6 +412,7 @@ void DisplayManager_::setup()
gif.setMatrix(&matrix);
ui.setAppAnimation(SLIDE_DOWN);
ui.setOverlays(overlays, 4);
setAutoTransition(AUTO_TRANSITION);
ui.init();
}

View File

@@ -46,8 +46,7 @@ public:
void generateNotification(String);
void generateCustomPage(uint16_t, String);
void printText(int16_t x, int16_t y, const char *text, bool centered);
void disableAutoTransition();
void enableAutoTransition();
bool setAutoTransition(bool active);
void drawGIF(uint16_t x, uint16_t y, fs::File gifFile);
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
if ((cf->repeat > 0) && (getTextWidth(cf->text.c_str()) > availableWidth) && (state->frameState == FIXED))
{
DisplayManager.disableAutoTransition();
DisplayManager.setAutoTransition(false);
}
else
{
DisplayManager.enableAutoTransition();
DisplayManager.setAutoTransition(true);
}
// 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
if ((cf->currentRepeat + 1 >= cf->repeat) && (cf->repeat > 0))
{
DisplayManager.enableAutoTransition();
DisplayManager.setAutoTransition(true);
cf->currentRepeat = 0;
DisplayManager.nextApp();
return;

View File

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

View File

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