-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsettings.py
89 lines (71 loc) · 2.49 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#=============================================================
#=============================================================
#=============================================================
# Settings and global variables, shared by all python modules
#=============================================================
#=============================================================
#=============================================================
import json
# GPIO Pin Numbers for LCD
RST_PIN = 12
CLK_PIN = 10
DIN_PIN = 11
DC_PIN = 8
CS1_PIN = 2
CS2_PIN = 3
CS3_PIN = 4
BL_PIN = 13
# GPIO pins for push buttons
MODE_PIN = 17
LEFT_PIN = 16
RIGHT_PIN = 15
# Other GPIO Pins
BUZZER_PIN = 14
NEOPIXEL_PIN = 22
RTC_1HZ_PIN = 18
# Global Variables
settings = {
"alarm_hour": 7,
"alarm_min": 30,
"alarm_on": 0,
"font": 1,
"brightness" : 5,
"rgb_mode": 1,
"24_hour" : 1,
"show_secs" : 1,
"adjust_timing" : 128
}
tick = True
#==============================================================================
#==============================================================================
#==============================================================================
# Functions to Read and write the Settings File "settings.json" on eeprom
#==============================================================================
#==============================================================================
#==============================================================================
# Save all settings to "disk".
def save_settings():
with open("settings.json", "w") as f:
json.dump(settings, f)
# Load all settings from "disk"
def load_settings():
global settings
try:
with open("settings.json", "r") as f:
settings = json.load(f)
except:
print("Unable to load settings.json . Creating new file")
save_settings()
# Retrieve a single setting value from memory
def get_setting(key):
if key in settings:
return int(settings[key])
else:
raise Exception("Key '" + key + "' not found in settings. Delete file settings.json and try again")
# Update a single setting value in memory and "disk"
def save_setting(key,value):
if key in settings:
settings[key] = value
save_settings()
else:
raise Exception("Key '" + key + "' not found in settings. Delete file settings.json and try again")