-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
picomotodash_env.py
109 lines (90 loc) · 2.38 KB
/
picomotodash_env.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
"""Pico Motorcycle Dashboard ENV
"""
__author__ = "Salvatore La Bua"
# Config utility functions
import ujson
def initialise_state(STATE_FILE):
LAYOUT_PEN_ID = 0
RPM_LAYOUT_ID = 2
SPLIT_BARS = True
LARGE_BATTERY = True
BATTERY_ICON_DISCRETE = False
BV = 2
state = {
"LAYOUT_PEN_ID": LAYOUT_PEN_ID,
"RPM_LAYOUT_ID": RPM_LAYOUT_ID,
"SPLIT_BARS": SPLIT_BARS,
"LARGE_BATTERY": LARGE_BATTERY,
"BATTERY_ICON_DISCRETE": BATTERY_ICON_DISCRETE,
"BV": BV,
}
print("state initialised")
with open(STATE_FILE, "w") as state_file:
ujson.dump(state, state_file)
return [
LAYOUT_PEN_ID,
RPM_LAYOUT_ID,
SPLIT_BARS,
LARGE_BATTERY,
BATTERY_ICON_DISCRETE,
BV,
]
def read_state(STATE_FILE):
with open(STATE_FILE, "r") as state_file:
state = ujson.load(state_file)
LAYOUT_PEN_ID = state["LAYOUT_PEN_ID"]
RPM_LAYOUT_ID = state["RPM_LAYOUT_ID"]
SPLIT_BARS = state["SPLIT_BARS"]
LARGE_BATTERY = state["LARGE_BATTERY"]
BATTERY_ICON_DISCRETE = state["BATTERY_ICON_DISCRETE"]
BV = state["BV"]
return [
LAYOUT_PEN_ID,
RPM_LAYOUT_ID,
SPLIT_BARS,
LARGE_BATTERY,
BATTERY_ICON_DISCRETE,
BV,
]
def write_state(
STATE_FILE,
LAYOUT_PEN_ID,
RPM_LAYOUT_ID,
SPLIT_BARS,
LARGE_BATTERY,
BATTERY_ICON_DISCRETE,
BV,
):
state = {
"LAYOUT_PEN_ID": LAYOUT_PEN_ID,
"RPM_LAYOUT_ID": RPM_LAYOUT_ID,
"SPLIT_BARS": SPLIT_BARS,
"LARGE_BATTERY": LARGE_BATTERY,
"BATTERY_ICON_DISCRETE": BATTERY_ICON_DISCRETE,
"BV": BV,
}
print("state updated")
with open(STATE_FILE, "w") as state_file:
ujson.dump(state, state_file)
def read_config(CONFIG_FILE):
with open(CONFIG_FILE, "r") as config_file:
config = ujson.load(config_file)
USE_BG_IMAGE = config["USE_BG_IMAGE"]
FUEL_RESERVE = config["FUEL_RESERVE"]
RPM_MAX = config["RPM_MAX"]
RPM_REDLINE = config["RPM_REDLINE"]
BATTERY_TH = config["BATTERY_TH"]
TEMP_TH = config["TEMP_TH"]
INFO_TEXT = config["INFO_TEXT"]
QR_URL = config["QR_URL"]
return [
USE_BG_IMAGE,
FUEL_RESERVE,
RPM_MAX,
RPM_REDLINE,
BATTERY_TH,
TEMP_TH,
INFO_TEXT,
QR_URL,
]