Skip to content

Commit

Permalink
Transition Control
Browse files Browse the repository at this point in the history
- autotransition can be turn on and of in onscreen menu
- autotransition is turned off when only one app is loaded

closes #1
closes #2
  • Loading branch information
Blueforcer committed Mar 22, 2023
1 parent 1d18850 commit 667fff2
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 65 deletions.
16 changes: 8 additions & 8 deletions lib/MatrixUI/MatrixDisplayUi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ void MatrixDisplayUi::setTargetFPS(uint8_t fps)

// -/------ 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->lastTransitionDirection = 1;
}
void MatrixDisplayUi::setAutoTransitionBackwards()
void MatrixDisplayUi::setsetAutoTransitionBackwards()
{
this->state.frameTransitionDirection = -1;
this->lastTransitionDirection = -1;
Expand Down Expand Up @@ -173,7 +173,7 @@ int8_t MatrixDisplayUi::update()
if (timeBudget <= 0)
{
// 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.lastUpdate = frameStart;
Expand Down Expand Up @@ -205,7 +205,7 @@ void MatrixDisplayUi::tick()
}
if (this->state.ticksSinceLastStateSwitch >= this->ticksPerFrame)
{
if (this->autoTransition)
if (this->setAutoTransition)
{

this->state.frameState = IN_TRANSITION;
Expand Down
10 changes: 5 additions & 5 deletions lib/MatrixUI/MatrixDisplayUi.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class MatrixDisplayUi
uint16_t ticksPerFrame = 151; // ~ 5000ms at 30 FPS
uint16_t ticksPerTransition = 15; // ~ 500ms at 30 FPS

bool autoTransition = true;
bool setAutoTransition = true;

AppCallback *AppFunctions;

Expand Down Expand Up @@ -129,18 +129,18 @@ class MatrixDisplayUi
/**
* 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.
*/
void disableAutoTransition();
void disablesetAutoTransition();

/**
* Set the direction if the automatic transitioning
*/
void setAutoTransitionForwards();
void setAutoTransitionBackwards();
void setsetAutoTransitionForwards();
void setsetAutoTransitionBackwards();

/**
* Set the approx. time a frame is displayed
Expand Down
21 changes: 14 additions & 7 deletions src/DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}

Expand All @@ -406,6 +412,7 @@ void DisplayManager_::setup()
gif.setMatrix(&matrix);
ui.setAppAnimation(SLIDE_DOWN);
ui.setOverlays(overlays, 4);
setAutoTransition(AUTO_TRANSITION);
ui.init();
}

Expand Down
3 changes: 1 addition & 2 deletions src/DisplayManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class DisplayManager_
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);
};
Expand Down
6 changes: 3 additions & 3 deletions src/Frames.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions src/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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();
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
2 changes: 1 addition & 1 deletion src/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 667fff2

Please sign in to comment.