Skip to content

Commit

Permalink
new parameters implementation : disable night mode + disable repeat m…
Browse files Browse the repository at this point in the history
…odes
  • Loading branch information
DantSu committed Aug 27, 2024
1 parent 149ae12 commit 32b449b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 17 deletions.
16 changes: 16 additions & 0 deletions src/storyTeller/app_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ static int parametersScreenOnInactivityTime = 120;
static int parametersScreenOffInactivityTime = 300;
static int parametersMusicInactivityTime = 3600;
static bool parametersStoryDisplayTiles = false;
static bool parametersStoryDisableNightMode = false;
static bool parametersMusicDisableRepeatModes = false;

#define APP_PARAMETERS_PATH "/mnt/SDCARD/Saves/.parameters"

Expand Down Expand Up @@ -55,6 +57,14 @@ bool parameters_getStoryDisplayNine() {
return parametersStoryDisplayTiles;
}

bool parameters_getStoryDisableNightMode() {
return parametersStoryDisableNightMode;
}

bool parameters_getMusicDisableRepeatModes() {
return parametersMusicDisableRepeatModes;
}

void parameters_init(void)
{
cJSON *parameters = json_load(APP_PARAMETERS_PATH);
Expand All @@ -69,6 +79,12 @@ void parameters_init(void)
if(!cJSON_IsNull(cJSON_GetObjectItem(parameters, "storyDisplayTiles"))) {
json_getBool(parameters, "storyDisplayTiles", &parametersStoryDisplayTiles);
}
if(!cJSON_IsNull(cJSON_GetObjectItem(parameters, "storyDisableNightMode"))) {
json_getBool(parameters, "storyDisableNightMode", &parametersStoryDisableNightMode);
}
if(!cJSON_IsNull(cJSON_GetObjectItem(parameters, "musicDisableRepeatModes"))) {
json_getBool(parameters, "musicDisableRepeatModes", &parametersMusicDisableRepeatModes);
}
}
}

Expand Down
23 changes: 16 additions & 7 deletions src/storyTeller/app_selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ static char appImages[3][32] = {"selectStories.png", "selectMusic.png", "selectN
static int appIndex = 0;
static bool appOpened = false;

void app_refreshScreen(void) {
if (appIndex >= APP_COUNT) {
appIndex = 0;
} else if (appIndex < 0) {
appIndex = APP_COUNT - 1;
int app_validAppIndex(int currentAppIndex, int direction) {
int newAppIndex = currentAppIndex + direction;
if (newAppIndex >= APP_COUNT) {
return app_validAppIndex(-1 * direction, direction);
}
if (newAppIndex < 0) {
return app_validAppIndex(APP_COUNT - 1 - direction, direction);
}
if(newAppIndex == APP_NIGHTMODE && parameters_getStoryDisableNightMode()) {
return app_validAppIndex(newAppIndex, direction);
}
return newAppIndex;
}

void app_refreshScreen(void) {
video_displayImage(SYSTEM_RESOURCES, appImages[appIndex]);
display_setScreen(true);
autosleep_unlock(parameters_getScreenOnInactivityTime(), parameters_getScreenOffInactivityTime());
Expand Down Expand Up @@ -92,7 +101,7 @@ void app_previous(void) {
break;
}
} else {
appIndex -= 1;
appIndex = app_validAppIndex(appIndex, -1);
app_refreshScreen();
}
}
Expand All @@ -111,7 +120,7 @@ void app_next(void) {
break;
}
} else {
appIndex += 1;
appIndex = app_validAppIndex(appIndex, 1);
app_refreshScreen();
}
}
Expand Down
28 changes: 18 additions & 10 deletions src/storyTeller/music_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void musicplayer_interfaceplayer_drawSideMusic(int index, int top) {

void musicplayer_interfaceplayer_drawInterface(int displayMusicPosition) {
char fileImageName[STR_MAX], writeTitle[STR_MAX], writeArtist[STR_MAX], writeDuration[STR_MAX], writeTime[STR_MAX],
imageName[STR_MAX - 4], imageNameCopy[STR_MAX - 4], imageNameDelimiter[] = "_", imageRepeatMode[STR_MAX];
imageName[STR_MAX - 4], imageNameCopy[STR_MAX - 4], imageNameDelimiter[] = "_";

int length = strlen(musicPlayerTracksList[musicPlayerTrackIndex]) - 4;
strncpy(imageName, musicPlayerTracksList[musicPlayerTrackIndex], length);
Expand All @@ -132,7 +132,6 @@ void musicplayer_interfaceplayer_drawInterface(int displayMusicPosition) {
sprintf(writeDuration, "%i:%02i", musicDuration / 60, musicDuration % 60);
sprintf(writeTime, "%i:%02i", displayMusicPosition / 60, displayMusicPosition % 60);
sprintf(fileImageName, "%s.png", imageName);
sprintf(imageRepeatMode, "musicPlayerRepeatMode%i.png", musicPlayerRepeatMode);

video_screenBlack();
video_drawRectangle(185, 258, (int) ((double) displayMusicPosition * 422.0 / (double) musicDuration), 12, 255, 186,
Expand All @@ -143,7 +142,11 @@ void musicplayer_interfaceplayer_drawInterface(int displayMusicPosition) {
video_screenWriteFont(writeArtist, fontRegular20, colorWhite, 185, 222, SDL_ALIGN_LEFT);
video_screenWriteFont(writeTime, fontRegular18, colorWhite, 185, 275, SDL_ALIGN_LEFT);
video_screenWriteFont(writeDuration, fontRegular18, colorWhite, 605, 275, SDL_ALIGN_RIGHT);
video_screenAddImage(SYSTEM_RESOURCES, imageRepeatMode, 332, 274, 128);
if(!parameters_getMusicDisableRepeatModes()) {
char imageRepeatMode[STR_MAX];
sprintf(imageRepeatMode, "musicPlayerRepeatMode%i.png", musicPlayerRepeatMode);
video_screenAddImage(SYSTEM_RESOURCES, imageRepeatMode, 332, 274, 128);
}
musicplayer_interfaceplayer_drawSideMusic(-2, 0);
musicplayer_interfaceplayer_drawSideMusic(-1, 83);
musicplayer_interfaceplayer_drawSideMusic(1, 314);
Expand Down Expand Up @@ -394,15 +397,20 @@ void musicplayer_ok(void) {
if (musicPlayerTracksCount == 0) {
return;
}
musicplayer_screenActivate();
if(!display_enabled) {
musicplayer_screenActivate();
return;
}
if (musicPlayerMode == MUSICPLAYER_MODE_PLAYER) {
musicPlayerRepeatMode++;
if (musicPlayerRepeatMode > MUSICPLAYER_REPEAT_TITLE) {
musicPlayerRepeatMode = MUSICPLAYER_REPEAT_ALL;
} else if (musicPlayerRepeatMode < MUSICPLAYER_REPEAT_ALL) {
musicPlayerRepeatMode = MUSICPLAYER_REPEAT_TITLE;
if(!parameters_getMusicDisableRepeatModes()) {
musicPlayerRepeatMode++;
if (musicPlayerRepeatMode > MUSICPLAYER_REPEAT_TITLE) {
musicPlayerRepeatMode = MUSICPLAYER_REPEAT_ALL;
} else if (musicPlayerRepeatMode < MUSICPLAYER_REPEAT_ALL) {
musicPlayerRepeatMode = MUSICPLAYER_REPEAT_TITLE;
}
musicplayer_interfaceplayer_drawInterface(musicplayer_getTrackPosition());
}
musicplayer_interfaceplayer_drawInterface(musicplayer_getTrackPosition());
} else {
musicPlayerMode = MUSICPLAYER_MODE_PLAYER;
musicPlayerTrackPosition = 0;
Expand Down

0 comments on commit 32b449b

Please sign in to comment.