-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_file.py
56 lines (53 loc) · 2.86 KB
/
json_file.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
import json
def write_json(baf, filename = "backup.json"):
"""
function to save settings to a json file
"""
basic_dict = {
'info' : {
"manufacturer": baf.manufacturer,
"model": baf.model,
"hw_version": baf.hw_version,
"fw_version": baf.fw_version,
"voltagebytes": baf.voltagebytes,
"voltagestring": baf.voltagestring,
"max_current": baf.max_current
},
'basic': {
"low_battery_protect": baf.low_battery_protect,
"limited_current": baf.limited_current,
"limited_current_assist0": baf.limited_current_assist0,
"limited_current_assist1": baf.limited_current_assist1,
"limited_current_assist2": baf.limited_current_assist2,
"limited_current_assist3": baf.limited_current_assist3,
"limited_current_assist4": baf.limited_current_assist4,
"limited_current_assist5": baf.limited_current_assist5,
"limited_current_assist6": baf.limited_current_assist6,
"limited_current_assist7": baf.limited_current_assist7,
"limited_current_assist8": baf.limited_current_assist8,
"limited_current_assist9": baf.limited_current_assist9,
"limited_speed_assist0": baf.limited_speed_assist0,
"limited_speed_assist1": baf.limited_speed_assist1,
"limited_speed_assist2": baf.limited_speed_assist2,
"limited_speed_assist3": baf.limited_speed_assist3,
"limited_speed_assist4": baf.limited_speed_assist4,
"limited_speed_assist5": baf.limited_speed_assist5,
"limited_speed_assist6": baf.limited_speed_assist6,
"limited_speed_assist7": baf.limited_speed_assist7,
"limited_speed_assist8": baf.limited_speed_assist8,
"limited_speed_assist9": baf.limited_speed_assist9,
"wheel_diameter": baf.wheel_diameter,
"speedmeter_signals": baf.speedmeter_signals,
"speedmeter_model": baf.speedmeter_model
}
}
with open(filename, 'w') as outfile:
json.dump(basic_dict, outfile, indent=4)
outfile.close()
def read_json(backup_file = 'backup.json'):
"""function to read bafang settings from json file"""
with open(backup_file) as json_file:
data = json.load(json_file)
info = data['info']
basic = data['basic']
return info, basic