-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildOdriveConfig.py
More file actions
36 lines (29 loc) · 809 Bytes
/
buildOdriveConfig.py
File metadata and controls
36 lines (29 loc) · 809 Bytes
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
#!/usr/bin/env python3
import json
import sys
def flatten_json(nested_json):
out = {}
def flatten(x, name=''):
if type(x) is dict:
for a in x:
flatten(x[a], name + a + '.')
elif type(x) is list:
i = 0
for a in x:
flatten(a, name + str(i) + '.')
i += 1
else:
out[name[:-1]] = x
flatten(nested_json)
return out
data = json.load(open(sys.argv[1]))
print("#include <ODriveArduino.h>")
print("")
print("void configureOdrive( ODriveArduino& odrive ) {")
for key, value in flatten_json(data).items():
if value == True:
value = "true"
elif value == False:
value = "false"
print(" odrive.setProperty(\"{}\", {});".format(key, value))
print("}")