This repository was archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.py
More file actions
97 lines (80 loc) · 3.59 KB
/
Copy pathgenerator.py
File metadata and controls
97 lines (80 loc) · 3.59 KB
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
import unicodedata
import xml.etree.ElementTree as ET
tree = ET.parse('./iot.xml')
root = tree.getroot()
methods = []
libMethods = []
file = open('gen.cpp', 'w') # clear file
with open('gen.cpp', 'a') as file:
def p(*args, **kwargs):
print(''.join(map(str, args)), **kwargs)
file.write(''.join(map(str, args)), **kwargs)
file.write('\n')
file.truncate()
# p(root.tag)
libs = []
for i, component in enumerate(root):
# p(component.tag)#, component.attrib)
if component.tag == 'Arduino':
arduinoModel = component.get('model')
totalDigitalPorts = int(component.get('digitalPorts'))
totalAnalogPorts = component.get('analogPorts')
p(component.get('connector'))
# p(component.text)
# p("found arduino!")
digitalPorts = 0
analogPorts = 0
else:
method = component.get('method')
# p(method)
methods.append(method)
libName = component.get('library')
libPath = 'arduino-libraries/'+libName+'/src/'+libName+'.h'
libFile = open('arduino-libraries/'+libName +
'/src/'+libName+'.h', 'r')
if libName not in libs:
libs.append(libName)
p('#include <'+libPath+'>')
# p('#include <',libName,'>')
longComment = False
with open(libPath) as file_iterator:
for line in file_iterator:
if longComment:
if "*/" in line:
longComment = False
else:
if "/*" in line: # long comment
longComment = True
if "()" in line or "(int" in line:
# if any(elem in ["void","int","bool"] for elem in line):
libMethod = line.split(
"//")[0].replace(" ", "")
libMethods.append(libMethod)
# print(file_iterator)
print(next(file_iterator))
else:
print("denied" + line)
# with open(libFile) as f:
# while 'setSpeed(' not in f.readline():
# continue
# print(f.readlines())
# iterator = iter(libFile.splitlines())
# for line in iterator:
# if "setSpeed(" in line:
# # print next(iterator)
# print (line)
for port in range(0, int(component.get('digitalPorts'))):
digitalPorts += 1
p(component.get('type'), ' ', component.get('name'),
' = ', component.get('type'), '(', digitalPorts, ')')
for port in range(0, int(component.get('digitalPorts'))):
digitalPorts += 1
p(component.get('type'), ' ', component.get('name'),
' = ', component.get('type'), '(', digitalPorts, ')')
p('// Code generated for Arduino ', arduinoModel)
p('// with ', totalDigitalPorts, ' digital ports in total with ',
digitalPorts, ' in use and ', totalDigitalPorts-digitalPorts, ' free')
p('// and ', totalAnalogPorts, ' analog ports in total')
p('void setup(){\n\n}')
p('void loop(){\n\n}')
print(libMethods)