-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvegimeter.py
118 lines (104 loc) · 4.26 KB
/
vegimeter.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
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python
#
# http://www.bionicbunny.org/
# Copyright (c) 2012-2011 Sladeware LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import re
import os
import bb
# Temporary flag in order to hide fritzing support from users.
USE_FRITZING = False
if USE_FRITZING:
from bb.tools.edas import fritzing
from bb.app.hardware.devices.processors.propeller_p8x32 import PropellerP8X32A_Q44
# First of all you need to setup Fritzing
# NOTE(team): developer can use fritzing.set_home_dir() to setup home
# directory directly.
fritzing.find_home_dir()
fritzing.add_search_path(os.path.join(os.getcwd(), "device", "parts"))
vegimeter_device = fritzing.parse(os.path.join("device", "device.fz"))
# Fix vegimeter device design loaded from Fritzing schematic. The reason is
# that the current version of QuickStart Board doesn't have a parts such as
# Propeller P8X32A-Q44 microchip. Thus we need to add them manually.
board = vegimeter_device.find_element('QSP1')
processor = board.add_element(PropellerP8X32A_Q44())
processor.set_designator('U1')
else:
from bb.app.hardware.devices.boards import P8X32A_QuickStartBoard
board = P8X32A_QuickStartBoard()
board.set_designator('QSP1')
vegimeter_device = board
vegimeter_board = None
if vegimeter_device.get_designator() == 'QSP1':
vegimeter_board = vegimeter_device
else:
vegimeter_board = vegimeter_device.find_element('QSP1')
if not vegimeter_board:
print "Board <QSP1> cannot be found!"
exit(0)
vegimeter = bb.app.Mapping("Vegimeter", processor=vegimeter_board.get_processor())
vegimeter.register_threads([
bb.app.Thread("UI", "ui_runner"),
bb.app.Thread("CONTROL_PANEL", "control_panel_runner")
])
# TODO(team): the following (and others) drivers has to be connected
# automatically.
from bb.app.meta_os.drivers.gpio.button_driver import ButtonDriver
from bb.app.meta_os.drivers.processors.propeller_p8x32 import ShMemDriver
vegimeter.register_threads([ButtonDriver(), ShMemDriver()])
def bill_of_materials():
bill_of_materials = dict()
for element in vegimeter_device.get_elements():
name = element.get_property_value('name')
if name not in bill_of_materials:
bill_of_materials[name] = 0
bill_of_materials[name] += 1
return bill_of_materials
if __name__ == '__main__':
print 'Vegimeter bill of materials:'
for name, amount in bill_of_materials().items():
print " %3d %s(s)" % (amount, name)
"""
from bb.hardware.primitives import Pin
## The next snippet shows all the pins
#pins = tempsensor1.find_elements(Pin)
#for pin in pins:
# print pin.get_property_value("name")
def get_quickstartboard_pin_designator(name):
mapping = {
33 : 34, 32 : 33, 21 : 18, 7 : 8, 26 : 28, 2 : 3, 17 : 38,
1 : 2, 18 : 39, 30 : 32, 16 : 37, 25 : 27, 27 : 29, 28 : 30,
40 : 26, 14 : 15, 20 : 17, 24 : 21, 10 : 11, 31 : 16, 11 : 12,
22 : 19, 0 : 1, 23 : 20, 13 : 14, 29 : 31, 6 : 7, 39 : 25,
3 : 4, 36 : 22, 9 : 10, 12 : 13, 15 : 36, 8 : 9, 38 : 24,
4 : 5, 34 : 35, 37 : 23, 19 : 40, 5 : 6
}
m = re.match(r"connector(\d+)", name)
return mapping[int(m.group(1))]
print "Connections of TS1 with QSB1"
for src_pin in tempsensor1.find_elements(Pin):
for dst_pin in quickstart.find_elements(Pin):
res = networkx.bidirectional_dijkstra(G, src_pin, dst_pin)
if res:
length, path = res
print "%s (%s) ==> %s (%s)" \
% (src_pin.get_property_value("name"),
get_quickstartboard_pin_designator(src_pin.designator),
dst_pin.get_property_value("name"),
get_quickstartboard_pin_designator(dst_pin.designator))
import networkx
from bb.hardware.primitives import G
quickstart = vegimeter_device.find_element("QSP1")
tempsensor1 = vegimeter_device.find_element("TS1")
"""