Skip to content

Commit

Permalink
Initalise default values, guard against missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
XK9274 committed Nov 12, 2023
1 parent 0e7b376 commit 73a854e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/common/system/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static settings_s __default_settings = (settings_s){
.enable_logging = false,
.blue_light_state = false,
.blue_light_level = 0,
.blue_light_rgb = 00000,
.blue_light_rgb = 8421504,
.blue_light_time = "20:00",
.blue_light_time_off = "08:00",
.mainui_button_x = "",
Expand Down
45 changes: 27 additions & 18 deletions src/tweaks/values.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,43 @@ int value_appShortcut(int button)
return 0;
}

int value_blueLightLevel(void)
{
int blueLightLevel = 0;
config_get("display/blueLightLevel", CONFIG_INT, &blueLightLevel);
return blueLightLevel;
}

int value_blueLightRGB(void)
{
int value_blueLightRGB(void) {
int blueLightRGB = 0;
config_get("display/blueLightRGB", CONFIG_INT, &blueLightRGB);
if (!config_get("display/blueLightRGB", CONFIG_INT, &blueLightRGB)) {
blueLightRGB = settings.blue_light_rgb;
config_setNumber("display/blueLightRGB", blueLightRGB);
}
return blueLightRGB;
}

int value_blueLightTimeOn(void)
{
char blueLightTime[12];
int value_blueLightLevel(void) {
int blueLightLevel = 0;
if (!config_get("display/blueLightLevel", CONFIG_INT, &blueLightLevel)) {
blueLightLevel = settings.blue_light_level;
config_setNumber("display/blueLightLevel", blueLightLevel);
}
value_blueLightRGB(); // also init a default rgb size
return blueLightLevel;
}

int value_blueLightTimeOn(void) {
char blueLightTime[12] = {0};
int blueLightID = 0;
config_get("display/blueLightTime", CONFIG_STR, blueLightTime);
if (!config_get("display/blueLightTime", CONFIG_STR, blueLightTime)) {
strcpy(blueLightTime, settings.blue_light_time);
config_setString("display/blueLightTime", blueLightTime);
}
blueLightID = formatter_timeStringToID(blueLightTime);
return blueLightID;
}

int value_blueLightTimeOff(void)
{
char blueLightTimeOff[12];
int value_blueLightTimeOff(void) {
char blueLightTimeOff[12] = {0};
int blueLightID = 0;
config_get("display/blueLightTimeOff", CONFIG_STR, blueLightTimeOff);
if (!config_get("display/blueLightTimeOff", CONFIG_STR, blueLightTimeOff)) {
strcpy(blueLightTimeOff, settings.blue_light_time_off);
config_setString("display/blueLightTimeOff", blueLightTimeOff);
}
blueLightID = formatter_timeStringToID(blueLightTimeOff);
return blueLightID;
}
Expand Down
13 changes: 11 additions & 2 deletions static/build/.tmp_update/script/blue_light.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,17 @@ disable_blue_light_filter() {

check_blf() {
sync
blueLightTimeOn=$(cat /mnt/SDCARD/.tmp_update/config/display/blueLightTime)
blueLightTimeOff=$(cat /mnt/SDCARD/.tmp_update/config/display/blueLightTimeOff)

blueLightTimeOnFile="/mnt/SDCARD/.tmp_update/config/display/blueLightTime"
blueLightTimeOffFile="/mnt/SDCARD/.tmp_update/config/display/blueLightTimeOff"

if [ ! -f "$blueLightTimeOnFile" ] || [ ! -f "$blueLightTimeOffFile" ]; then
rm -f "$lockfile"
return
fi

blueLightTimeOn=$(cat "$blueLightTimeOnFile")
blueLightTimeOff=$(cat "$blueLightTimeOffFile")

currentTime=$(date +"%H:%M")
currentTimeMinutes=$(to_minutes_since_midnight "$currentTime")
Expand Down

0 comments on commit 73a854e

Please sign in to comment.