diff --git a/src/storyTeller/app_lock.h b/src/storyTeller/app_lock.h new file mode 100644 index 000000000..8710aee89 --- /dev/null +++ b/src/storyTeller/app_lock.h @@ -0,0 +1,97 @@ +#ifndef STORYTELLER_APP_LOCK__ +#define STORYTELLER_APP_LOCK__ + +#include "./time_helper.h" +#include "system/display.h" + +static bool applockIsLocked = false; + +bool applock_isLocked(void) +{ + return applockIsLocked; +} + +#include "./sdl_helper.h" + + +static long applockTimer = 0; +static long applockTimerScreenOn = 0; + +void applock_startScreenTimer(void) +{ + applockTimerScreenOn = get_time(); + display_setScreen(true); +} + +void applock_stopScreenTimer(void) +{ + applockTimerScreenOn = 0; +} + +void applock_endScreenTimer(void) +{ + applock_stopScreenTimer(); + display_setScreen(false); +} + +void applock_startTimer(void) +{ + applockTimer = get_time(); + if(applockIsLocked && !display_enabled) { + applock_startScreenTimer(); + } +} + +void applock_stopTimer(void) +{ + applockTimer = 0; +} + +void applock_lock(void) +{ + applock_stopTimer(); + applockIsLocked = true; + video_applyToVideo(); +} + +void applock_unlock(void) +{ + applock_stopTimer(); + applockIsLocked = false; + video_applyToVideo(); +} + +void applock_checkLock(void) +{ + long time = get_time(), laps; + + if(applockTimerScreenOn > 0) { + laps = time - applockTimerScreenOn; + if(laps > 3) { + applock_endScreenTimer(); + } + } + + if(applockTimer == 0) { + return; + } + + if(applockIsLocked && !display_enabled && applockTimerScreenOn == 0) { + applock_startScreenTimer(); + } + + laps = time - applockTimer; + + if(laps > 2) { + if(applockIsLocked) { + applock_unlock(); + } else { + applock_lock(); + if(!display_enabled) { + applock_startScreenTimer(); + } + } + } +} + +#endif // STORYTELLER_APP_LOCK__ \ No newline at end of file diff --git a/src/storyTeller/res/storytellerLock.png b/src/storyTeller/res/storytellerLock.png new file mode 100644 index 000000000..edfdf9a55 Binary files /dev/null and b/src/storyTeller/res/storytellerLock.png differ diff --git a/src/storyTeller/sdl_helper.h b/src/storyTeller/sdl_helper.h index ec0c9643c..32ecde211 100644 --- a/src/storyTeller/sdl_helper.h +++ b/src/storyTeller/sdl_helper.h @@ -11,7 +11,11 @@ #include "utils/str.h" #include "./file_helper.h" +#include "./app_lock.h" +#define SYSTEM_RESOURCES "/mnt/SDCARD/.tmp_update/res/" + +#define FALLBACK_FONT_REGULAR "/mnt/SDCARD/.tmp_update/res/Exo2-Regular.ttf" #define FALLBACK_FONT_REGULAR "/mnt/SDCARD/.tmp_update/res/Exo2-Regular.ttf" #define FALLBACK_FONT_BOLD "/mnt/SDCARD/.tmp_update/res/Exo2-Bold.ttf" @@ -71,21 +75,6 @@ void video_audio_quit(void) SDL_Quit(); } -void video_displayImage(const char *dir, char *name) -{ - char image_path[STR_MAX * 2]; - sprintf(image_path, "%s%s", dir, name); - SDL_Surface *image = IMG_Load(image_path); - - SDL_FillRect(screen, NULL, 0); - if(image != NULL) { - SDL_BlitSurface(image, NULL, screen, &(SDL_Rect){(screen->w - image->w) / 2, (screen->h - image->h) / 2}); - SDL_FreeSurface(image); - } - SDL_BlitSurface(screen, NULL, video, NULL); - SDL_Flip(video); -} - void video_screenBlack (void) { SDL_FillRect(screen, NULL, 0); } @@ -128,9 +117,30 @@ void video_screenWriteFont(const char *text, TTF_Font *font, SDL_Color color, in void video_applyToVideo(void) { SDL_BlitSurface(screen, NULL, video, NULL); + if(applock_isLocked()) { + char image_path[STR_MAX * 2]; + sprintf(image_path, "%s%s", SYSTEM_RESOURCES, "storytellerLock.png"); + SDL_Surface *image = IMG_Load(image_path); + SDL_BlitSurface(image, NULL, video, NULL); + } SDL_Flip(video); } +void video_displayImage(const char *dir, char *name) +{ + char image_path[STR_MAX * 2]; + sprintf(image_path, "%s%s", dir, name); + SDL_Surface *image = IMG_Load(image_path); + + SDL_FillRect(screen, NULL, 0); + if(image != NULL) { + SDL_BlitSurface(image, NULL, screen, &(SDL_Rect){(screen->w - image->w) / 2, (screen->h - image->h) / 2}); + SDL_FreeSurface(image); + } + + video_applyToVideo(); +} + void video_displayBlackScreen(void) { video_screenBlack(); diff --git a/src/storyTeller/storyTeller.c b/src/storyTeller/storyTeller.c index b9933a976..be2d104e8 100644 --- a/src/storyTeller/storyTeller.c +++ b/src/storyTeller/storyTeller.c @@ -8,9 +8,11 @@ #include "system/keymap_hw.h" #include "system/settings.h" #include "system/settings_sync.h" +#include "system/display.h" #include "utils/log.h" #include "./time_helper.h" +#include "./app_lock.h" #include "./app_autosleep.h" #include "./sdl_helper.h" #include "./app_selector.h" @@ -56,7 +58,7 @@ int main(int argc, char *argv[]) fds[0].events = POLLIN; bool isMenuPressed = false; - bool isVolumePressed = false; + bool menuPreventDefault = false; long startPowerPressed = 0; while (1) { @@ -65,6 +67,7 @@ int main(int argc, char *argv[]) goto exit_loop; } + applock_checkLock(); app_screenUpdate(); if (poll(fds, 1, 0) > 0) { @@ -78,6 +81,10 @@ int main(int argc, char *argv[]) { case HW_BTN_MENU : isMenuPressed = true; + applock_startTimer(); + if(applock_isLocked()) { + menuPreventDefault = true; + } break; case HW_BTN_POWER : startPowerPressed = get_time(); @@ -86,6 +93,12 @@ int main(int argc, char *argv[]) break; case RELEASED: + if(applock_isLocked()) { + if(ev.code == HW_BTN_MENU) { + applock_stopTimer(); + } + break; + } autosleep_keepAwake(); switch (ev.code) { @@ -95,11 +108,12 @@ int main(int argc, char *argv[]) } break; case HW_BTN_MENU : - if(!isVolumePressed) { + if(!menuPreventDefault) { app_menu(); } isMenuPressed = false; - isVolumePressed = false; + menuPreventDefault = false; + applock_stopTimer(); break; case HW_BTN_LEFT : app_previous(); @@ -129,7 +143,8 @@ int main(int argc, char *argv[]) if(isMenuPressed) { settings_setBrightness(settings.brightness - 1, true, false); osd_showBrightnessBar(settings.brightness); - isVolumePressed = true; + applock_stopTimer(); + menuPreventDefault = true; } else { settings_setVolume(settings.volume - 1, true); osd_showVolumeBar(settings.volume, false); @@ -139,7 +154,8 @@ int main(int argc, char *argv[]) if(isMenuPressed) { settings_setBrightness(parameters_getScreenBrightnessValidation(settings.brightness + 1), true, false); osd_showBrightnessBar(settings.brightness); - isVolumePressed = true; + applock_stopTimer(); + menuPreventDefault = true; } else { settings_setVolume(parameters_getAudioVolumeValidation(settings.volume + 1), true); osd_showVolumeBar(settings.volume, false); @@ -157,6 +173,7 @@ int main(int argc, char *argv[]) } exit_loop: + display_setScreen(true); video_audio_quit(); system_shutdown(); return EXIT_SUCCESS;