Skip to content

Commit

Permalink
Merge pull request #123 from AEFeinstein/screensaver
Browse files Browse the repository at this point in the history
Screensaver
  • Loading branch information
AEFeinstein authored Nov 18, 2023
2 parents 0083343 + ea4e6ff commit 048129f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 8 deletions.
10 changes: 9 additions & 1 deletion components/hdw-led/hdw-led.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,12 @@ uint8_t getLedState(led_t* leds, uint8_t numLeds)
}

return 0;
}
}

/**
* @brief Wait until any pending LED transactions are finished, then return
*/
void flushLeds(void)
{
rmt_tx_wait_all_done(led_chan, -1);
}
6 changes: 6 additions & 0 deletions components/hdw-led/include/hdw-led.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
* Brightness is adjusted per-color-channel, so dimming may produce different colors.
* setLedBrightnessSetting() should be called instead if the brightness change should be persistent through reboots.
*
* flushLeds() may be called to wait until all pending LED transactions are completed. This does not need to be called
* under normal operation. The RMT peripheral handles updating LEDs in the background automatically, but transactions
* must be flushed before entering light sleep. If they are not, garbage data may be sent after light sleep begins,
* resulting in indeterminate LED behavior.
*
* Even though \c CONFIG_NUM_LEDS declares eight LEDs, there is a ninth LED which is controllable. By default, setting
* \c CONFIG_NUM_LEDS LEDs will automatically set the ninth to the average of the sixth, seventh, and eighth, which
* surround it on the PCB. To set the ninth LED, set `CONFIG_NUM_LEDS + 1` LEDs.
Expand Down Expand Up @@ -70,5 +75,6 @@ esp_err_t deinitLeds(void);
esp_err_t setLeds(led_t* leds, uint8_t numLeds);
void setLedBrightness(uint8_t brightness);
uint8_t getLedState(led_t* leds, uint8_t numLeds);
void flushLeds(void);

#endif
9 changes: 9 additions & 0 deletions emulator/src/components/hdw-led/hdw-led.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,12 @@ led_t* getLedMemory(uint8_t* numLeds)
*numLeds = CONFIG_NUM_LEDS;
return rdLeds;
}

/**
* @brief Wait until any pending LED transactions are finished, then return
* Immediately returns on the emulator
*/
void flushLeds(void)
{
return;
}
13 changes: 8 additions & 5 deletions main/modes/dance/dance.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,14 @@ void danceMainLoop(int64_t elapsedUs)
// Only sleep with a blank screen, otherwise the screen flickers
if (danceState->blankScreen)
{
// Light sleep for 4ms. The longer the sleep, the choppier the LED animations
// 4ms looks pretty good, though some LED timers do run faster (like 'rise')
// TODO this isn't working, but it used to?
// esp_sleep_enable_timer_wakeup(4000);
// esp_light_sleep_start();
// Wait for any LED transactions to finish, otherwise RMT will do weird things during CPU sleep
flushLeds();
/* Light sleep for 40ms (see DEFAULT_FRAME_RATE_US).
* The longer the sleep, the choppier the LED animations.
* Sleeping longer than the current framerate will look worse
*/
esp_sleep_enable_timer_wakeup(DEFAULT_FRAME_RATE_US);
esp_light_sleep_start();
}
}

Expand Down
14 changes: 14 additions & 0 deletions main/modes/mainMenu/mainMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef struct
int32_t cheatCodeIdx;
bool debugMode;
bool fanfarePlaying;
int32_t autoLightDanceTimer;
} mainMenu_t;

//==============================================================================
Expand Down Expand Up @@ -208,10 +209,23 @@ static void mainMenuExitMode(void)
*/
static void mainMenuMainLoop(int64_t elapsedUs)
{
// Increment this timer
mainMenu->autoLightDanceTimer += elapsedUs;
// If 10s have elapsed with no user input
if (getScreensaverTimeSetting() != 0 && mainMenu->autoLightDanceTimer >= (getScreensaverTimeSetting() * 1000000))
{
// Switch to the LED dance mode
switchToSwadgeMode(&danceMode);
return;
}

// Pass all button events to the menu
buttonEvt_t evt = {0};
while (checkButtonQueueWrapper(&evt))
{
// Any button event resets this timer
mainMenu->autoLightDanceTimer = 0;

if ((!mainMenu->debugMode) && (evt.down))
{
if (evt.button == cheatCode[mainMenu->cheatCodeIdx])
Expand Down
3 changes: 1 addition & 2 deletions main/swadge2024.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@
#define RTC_DATA_ATTR
#endif

#define EXIT_TIME_US 1000000
#define DEFAULT_FRAME_RATE_US 40000
#define EXIT_TIME_US 1000000

//==============================================================================
// Variables
Expand Down
3 changes: 3 additions & 0 deletions main/swadge2024.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@
#include "settingsManager.h"
#include "touchUtils.h"

/// @brief the default time between drawn frames, in microseconds
#define DEFAULT_FRAME_RATE_US 40000

/**
* @struct swadgeMode_t
* @brief A struct of all the function pointers necessary for a swadge mode. If a mode does not need a particular
Expand Down

0 comments on commit 048129f

Please sign in to comment.