-
Notifications
You must be signed in to change notification settings - Fork 2
/
GPIO_Consts.jl
81 lines (60 loc) · 2.34 KB
/
GPIO_Consts.jl
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
import LightXML
export initialize, is_digital_pin_configured, is_analog_pin_configured,
is_pwm_pin_configured, is_i2c_pin_configured
abstract type AbstractGPIO end
abstract type MachineGPIO <: AbstractGPIO end
function initialize(gpio::MachineGPIO, filename::String)
#using LightXML
xdoc = LightXML.parse_file(filename)
# get the root element
xroot = LightXML.root(xdoc) # an instance of XMLElement
# print its name
#println(LightXML.name(xroot)) # this should print: machine_information
machine = LightXML.get_elements_by_tagname(xroot, "machine")
mid = LightXML.attribute(machine[1], "id")
gpio.id = mid
mname = LightXML.attribute(machine[1], "name")
gpio.name = mname
node = LightXML.attribute(machine[1], "node")
gpio.node = node
bindir = LightXML.attribute(machine[1], "julia-bin")
gpio.path = bindir
for n in machine
for o in LightXML.child_elements(n)
if (LightXML.name(o) == "pins")
if (LightXML.has_attribute(o, "category") && LightXML.attribute(o, "category") == "digital")
for p in collect(LightXML.child_elements(o))
gpio.digital_pin[LightXML.name(p)] = parse(Int32, LightXML.content(p))
end
end
if (LightXML.has_attribute(o, "category") && LightXML.attribute(o, "category") == "analog")
for p in collect(LightXML.child_elements(o))
gpio.analog_pin[LightXML.name(p)] = parse(Int32, LightXML.content(p))
end
end
if (LightXML.has_attribute(o, "category") && LightXML.attribute(o, "category") == "pwm")
for p in collect(LightXML.child_elements(o))
gpio.pwm_pin[LightXML.name(p)] = parse(Int32, LightXML.content(p))
end
end
if (LightXML.has_attribute(o, "category") && LightXML.attribute(o, "category") == "i2c")
for p in collect(LightXML.child_elements(o))
gpio.i2c_pin[LightXML.name(p)] = parse(Int32, LightXML.content(p))
end
end
end
if (LightXML.name(o) == "device")
if (LightXML.has_attribute(o, "category") && LightXML.attribute(o, "category") == "i2c")
for p in collect(LightXML.child_elements(o))
push!(gpio.i2c_devices, LightXML.content(p))
end
end
if (LightXML.has_attribute(o, "category") && LightXML.attribute(o, "category") == "spi")
for p in collect(LightXML.child_elements(o))
push!(gpio.spi_devices, LightXML.content(p))
end
end
end
end
end
end