annotate service/arduinoNode/devices.py @ 1140:f349fe25789c

rgb strip animation support in arduinoNode Ignore-this: 5f50c7b54ce1588243735c43d2cbea0f darcs-hash:0e2e1e2156b181c83d6e4f2f85afc849dc07fec0
author drewp <drewp@bigasterisk.com>
date Sat, 03 Mar 2018 17:55:37 -0800
parents db955e7943af
children 686079900c20
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
1 from __future__ import division
1136
1e43ec4a5f23 build and import updates for rdfdb, etc
drewp <drewp@bigasterisk.com>
parents: 1110
diff changeset
2
1e43ec4a5f23 build and import updates for rdfdb, etc
drewp <drewp@bigasterisk.com>
parents: 1110
diff changeset
3 import itertools, logging, struct, os, sys
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
4 from rdflib import Namespace, RDF, URIRef, Literal
981
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 977
diff changeset
5 import time
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
6
1136
1e43ec4a5f23 build and import updates for rdfdb, etc
drewp <drewp@bigasterisk.com>
parents: 1110
diff changeset
7 sys.path.append('../../lib')
1e43ec4a5f23 build and import updates for rdfdb, etc
drewp <drewp@bigasterisk.com>
parents: 1110
diff changeset
8 from devices_shared import RgbPixelsAnimation
1e43ec4a5f23 build and import updates for rdfdb, etc
drewp <drewp@bigasterisk.com>
parents: 1110
diff changeset
9
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
10 ROOM = Namespace('http://projects.bigasterisk.com/room/')
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
11 XSD = Namespace('http://www.w3.org/2001/XMLSchema#')
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
12 log = logging.getLogger()
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
13
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
14 def readLine(read):
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
15 buf = ''
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
16 for c in iter(lambda: read(1), '\n'):
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
17 buf += c
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
18 return buf
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
19
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
20 class DeviceType(object):
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
21 deviceType = None
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
22 @classmethod
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
23 def findInstances(cls, graph, board):
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
24 """
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
25 return any number of instances of this class for all the separately
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
26 controlled devices on the board. Two LEDS makes two instances,
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
27 but two sensors on the same onewire bus makes only one device
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
28 (which yields more statements).
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
29 """
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
30 for row in graph.query("""SELECT ?dev ?pinNumber WHERE {
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
31 ?board :hasPin ?pin .
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
32 ?pin :pinNumber ?pinNumber;
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
33 :connectedTo ?dev .
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
34 ?dev a ?thisType .
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
35 } ORDER BY ?dev""",
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
36 initBindings=dict(board=board,
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
37 thisType=cls.deviceType),
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
38 initNs={'': ROOM}):
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
39 log.info('found %s, a %s', row.dev, cls.deviceType)
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
40 yield cls(graph, row.dev, int(row.pinNumber))
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
41
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
42 # subclasses may add args to this
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
43 def __init__(self, graph, uri, pinNumber):
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
44 self.graph, self.uri = graph, uri
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
45 self.pinNumber = pinNumber
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
46 self.hostStateInit()
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
47
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
48 def hostStateInit(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
49 """
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
50 If you don't want to use __init__, you can use this to set up
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
51 whatever storage you might need for hostStatements
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
52 """
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
53
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
54 def description(self):
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
55 return {
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
56 'uri': self.uri,
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
57 'className': self.__class__.__name__,
1038
ffe6a00c6cef server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp <drewp@bigasterisk.com>
parents: 1035
diff changeset
58 'pinNumber': getattr(self, 'pinNumber', None),
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
59 'outputPatterns': self.outputPatterns(),
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
60 'watchPrefixes': self.watchPrefixes(),
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
61 'outputWidgets': self.outputWidgets(),
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
62 }
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
63
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
64 def readFromPoll(self, read):
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
65 """
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
66 read an update message returned as part of a poll bundle. This may
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
67 consume a varying number of bytes depending on the type of
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
68 input (e.g. IR receiver).
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
69 Returns rdf statements.
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
70 """
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
71 raise NotImplementedError('readFromPoll in %s' % self.__class__)
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
72
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
73 def wantIdleOutput(self):
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
74 return False
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
75
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
76 def outputIdle(self, write):
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
77 return
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
78
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
79 def hostStatements(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
80 """
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
81 Like readFromPoll but these statements come from the host-side
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
82 python code, not the connected device. Include output state
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
83 (e.g. light brightness) if its master version is in this
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
84 object. This method is called on /graph requests so it should
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
85 be fast.
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
86 """
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
87 return []
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
88
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
89 def watchPrefixes(self):
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
90 """
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
91 subj,pred pairs of the statements that might be returned from
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
92 readFromPoll, so the dashboard knows what it should
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
93 watch. This should be eliminated, as the dashboard should just
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
94 always watch the whole tree of statements starting self.uri
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
95 """
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
96 return []
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
97
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
98 def generateIncludes(self):
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
99 """filenames of .h files to #include"""
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
100 return []
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
101
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
102 def generateArduinoLibs(self):
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
103 """names of libraries for the ARDUINO_LIBS line in the makefile"""
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
104 return []
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
105
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
106 def generateGlobalCode(self):
990
11fff6301027 support for device code in the idle loop
drewp <drewp@bigasterisk.com>
parents: 981
diff changeset
107 """C code to emit in the global section.
11fff6301027 support for device code in the idle loop
drewp <drewp@bigasterisk.com>
parents: 981
diff changeset
108
11fff6301027 support for device code in the idle loop
drewp <drewp@bigasterisk.com>
parents: 981
diff changeset
109 Note that 'frame' (uint8) is available and increments each frame.
11fff6301027 support for device code in the idle loop
drewp <drewp@bigasterisk.com>
parents: 981
diff changeset
110 """
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
111 return ''
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
112
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
113 def generateSetupCode(self):
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
114 """C code to emit in setup()"""
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
115 return ''
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
116
990
11fff6301027 support for device code in the idle loop
drewp <drewp@bigasterisk.com>
parents: 981
diff changeset
117 def generateIdleCode(self):
11fff6301027 support for device code in the idle loop
drewp <drewp@bigasterisk.com>
parents: 981
diff changeset
118 """C code to emit in the serial-read loop"""
11fff6301027 support for device code in the idle loop
drewp <drewp@bigasterisk.com>
parents: 981
diff changeset
119 return ''
11fff6301027 support for device code in the idle loop
drewp <drewp@bigasterisk.com>
parents: 981
diff changeset
120
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
121 def generatePollCode(self):
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
122 """
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
123 C code to run a poll update. This should Serial.write its output
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
124 for readFromPoll to consume. If this returns nothing, we don't
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
125 try to poll this device.
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
126 """
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
127 return ''
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
128
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
129 def generateActionCode(self):
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
130 """
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
131 If the host side runs sendOutput, this C code will be run on the
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
132 board to receive whatever sendOutput writes. Each sendOutput
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
133 write(buf) call should be matched with len(buf) Serial.read()
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
134 calls in here.
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
135 """
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
136 return ''
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
137
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
138 def outputPatterns(self):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
139 """
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
140 Triple patterns, using None as a wildcard, that should be routed
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
141 to sendOutput
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
142 """
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
143 return []
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
144
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
145 def outputWidgets(self):
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
146 """
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
147 structs to make output widgets on the dashboard. ~1 of these per
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
148 handler you have in sendOutput
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
149 """
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
150 return []
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
151
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
152 def sendOutput(self, statements, write, read):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
153 """
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
154 If we got statements that match this class's outputPatterns, this
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
155 will be called with the statements that matched, and a serial
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
156 write method. What you write here will be available as
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
157 Serial.read in the generateActionCode C code.
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
158
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
159 Todo: it would be fine to read back confirmations or
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
160 whatever. Just need a way to collect them into graph statements.
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
161 """
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
162 raise NotImplementedError
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
163
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
164 _knownTypes = set()
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
165 def register(deviceType):
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
166 _knownTypes.add(deviceType)
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
167 return deviceType
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
168
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
169 @register
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
170 class PingInput(DeviceType):
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
171 @classmethod
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
172 def findInstances(cls, graph, board):
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
173 return [cls(graph, board, None)]
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
174
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
175 def generatePollCode(self):
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
176 return "Serial.write('k');"
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
177
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
178 def readFromPoll(self, read):
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
179 byte = read(1)
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
180 if byte != 'k':
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
181 raise ValueError('invalid ping response: chr(%s)' % ord(byte))
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
182 return [(self.uri, ROOM['ping'], ROOM['ok'])]
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
183
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
184 def watchPrefixes(self):
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
185 return [(self.uri, ROOM['ping'])]
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
186
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
187 @register
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
188 class MotionSensorInput(DeviceType):
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
189 deviceType = ROOM['MotionSensor']
1056
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1038
diff changeset
190 def __init__(self, graph, uri, pinNumber):
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1038
diff changeset
191 DeviceType.__init__(self, graph, uri, pinNumber)
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1038
diff changeset
192 self.lastRead = None
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1038
diff changeset
193
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
194 def generateSetupCode(self):
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
195 return 'pinMode(%(pin)d, INPUT); digitalWrite(%(pin)d, LOW);' % {
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
196 'pin': self.pinNumber,
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
197 }
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
198
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
199 def generatePollCode(self):
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
200 return "Serial.write(digitalRead(%(pin)d) ? 'y' : 'n');" % {
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
201 'pin': self.pinNumber
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
202 }
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
203
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
204 def readFromPoll(self, read):
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
205 b = read(1)
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
206 if b not in 'yn':
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
207 raise ValueError('unexpected response %r' % b)
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
208 motion = b == 'y'
1056
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1038
diff changeset
209
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1038
diff changeset
210 oneshot = []
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1038
diff changeset
211 if self.lastRead is not None and motion != self.lastRead:
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1038
diff changeset
212 oneshot = [(self.uri, ROOM['sees'], ROOM['motionStart'])]
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1038
diff changeset
213 self.lastRead = motion
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1038
diff changeset
214
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1038
diff changeset
215 return {'latest': [
981
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 977
diff changeset
216 (self.uri, ROOM['sees'],
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 977
diff changeset
217 ROOM['motion'] if motion else ROOM['noMotion']),
1073
054fccde9a49 'seesRecently30' in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1062
diff changeset
218 ] + self.recentMotionStatements(motion),
054fccde9a49 'seesRecently30' in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1062
diff changeset
219 'oneshot': oneshot}
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
220
1073
054fccde9a49 'seesRecently30' in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1062
diff changeset
221 def recentMotionStatements(self, motion):
981
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 977
diff changeset
222 if not hasattr(self, 'lastMotionTime'):
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 977
diff changeset
223 self.lastMotionTime = 0
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 977
diff changeset
224 now = time.time()
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 977
diff changeset
225 if motion:
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 977
diff changeset
226 self.lastMotionTime = now
1073
054fccde9a49 'seesRecently30' in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1062
diff changeset
227 dt = now - self.lastMotionTime
054fccde9a49 'seesRecently30' in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1062
diff changeset
228 return [(self.uri, ROOM['seesRecently'],
054fccde9a49 'seesRecently30' in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1062
diff changeset
229 ROOM['motion'] if (dt < 60 * 10) else ROOM['noMotion']),
054fccde9a49 'seesRecently30' in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1062
diff changeset
230 (self.uri, ROOM['seesRecently30'],
054fccde9a49 'seesRecently30' in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1062
diff changeset
231 ROOM['motion'] if (dt < 30) else ROOM['noMotion'])]
981
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 977
diff changeset
232
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
233 def watchPrefixes(self):
981
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 977
diff changeset
234 return [
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 977
diff changeset
235 (self.uri, ROOM['sees']),
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 977
diff changeset
236 (self.uri, ROOM['seesRecently']),
1073
054fccde9a49 'seesRecently30' in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1062
diff changeset
237 (self.uri, ROOM['seesRecently30']),
981
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 977
diff changeset
238 ]
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
239
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
240 @register
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
241 class PushbuttonInput(DeviceType):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
242 """add a switch to ground; we'll turn on pullup"""
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
243 deviceType = ROOM['Pushbutton']
1062
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
244 def __init__(self, graph, uri, pinNumber):
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
245 DeviceType.__init__(self, graph, uri, pinNumber)
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
246 self.lastClosed = None
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
247
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
248 def generateSetupCode(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
249 return 'pinMode(%(pin)d, INPUT); digitalWrite(%(pin)d, HIGH);' % {
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
250 'pin': self.pinNumber,
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
251 }
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
252
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
253 def generatePollCode(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
254 # note: pulldown means unpressed reads as a 1
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
255 return "Serial.write(digitalRead(%(pin)d) ? '0' : '1');" % {
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
256 'pin': self.pinNumber
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
257 }
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
258
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
259 def readFromPoll(self, read):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
260 b = read(1)
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
261 if b not in '01':
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
262 raise ValueError('unexpected response %r' % b)
1062
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
263 closed = b == '0'
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
264
1062
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
265 if self.lastClosed is not None and closed != self.lastClosed:
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
266 oneshot = [
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
267 (self.uri, ROOM['buttonState'],
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
268 ROOM['press'] if closed else ROOM['release']),
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
269 ]
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
270 else:
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
271 oneshot = []
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
272 self.lastClosed = closed
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
273
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
274 return {'latest': [
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
275 (self.uri, ROOM['buttonState'],
1062
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
276 ROOM['pressed'] if closed else ROOM['notPressed']),
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
277 ],
6ab7a933c2a8 button :press oneshot
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
278 'oneshot': oneshot}
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
279
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
280 def watchPrefixes(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
281 return [
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
282 (self.uri, ROOM['buttonState']),
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
283 ]
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
284
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
285 @register
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
286 class OneWire(DeviceType):
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
287 """
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
288 A OW bus with temperature sensors (and maybe other devices, which
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
289 are also to be handled under this object). We return graph
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
290 statements for all devices we find, even if we don't scan them, so
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
291 you can more easily add them to your config. Onewire search
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
292 happens only at device startup (not even program startup, yet).
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
293
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
294 self.uri is a resource representing the bus.
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
295
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
296 DS18S20 pin 1: ground, pin 2: data and pull-up with 4.7k.
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
297 """
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
298 deviceType = ROOM['OneWire']
1110
6ee834a6f970 influx output for arduino, update web lib path
drewp <drewp@bigasterisk.com>
parents: 1073
diff changeset
299 pollPeriod = 2
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
300 def hostStateInit(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
301 # eliminate this as part of removing watchPrefixes
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
302 self._knownTempSubjects = set()
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
303 def generateIncludes(self):
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
304 return ['OneWire.h', 'DallasTemperature.h']
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
305
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
306 def generateArduinoLibs(self):
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
307 return ['OneWire', 'DallasTemperature']
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
308
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
309 def generateGlobalCode(self):
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
310 # not yet isolated to support multiple OW buses
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
311 return '''
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
312 OneWire oneWire(%(pinNumber)s);
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
313 DallasTemperature sensors(&oneWire);
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
314 #define MAX_DEVICES 8
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
315 DeviceAddress tempSensorAddress[MAX_DEVICES];
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
316
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
317 void initSensors() {
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
318 sensors.begin();
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
319 sensors.setResolution(12);
991
c6989dcf1f4f temp sensor try to work with idle loop (but there are still stutters)
drewp <drewp@bigasterisk.com>
parents: 990
diff changeset
320 sensors.setWaitForConversion(false);
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
321 for (uint8_t i=0; i < sensors.getDeviceCount(); ++i) {
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
322 sensors.getAddress(tempSensorAddress[i], i);
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
323 }
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
324 }
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
325 ''' % dict(pinNumber=self.pinNumber)
991
c6989dcf1f4f temp sensor try to work with idle loop (but there are still stutters)
drewp <drewp@bigasterisk.com>
parents: 990
diff changeset
326
c6989dcf1f4f temp sensor try to work with idle loop (but there are still stutters)
drewp <drewp@bigasterisk.com>
parents: 990
diff changeset
327 def generateSetupCode(self):
c6989dcf1f4f temp sensor try to work with idle loop (but there are still stutters)
drewp <drewp@bigasterisk.com>
parents: 990
diff changeset
328 return 'initSensors();'
c6989dcf1f4f temp sensor try to work with idle loop (but there are still stutters)
drewp <drewp@bigasterisk.com>
parents: 990
diff changeset
329
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
330 def generatePollCode(self):
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
331 return r'''
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
332 sensors.requestTemperatures();
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
333
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
334 // If we need frequent idle calls or fast polling again, this needs
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
335 // to be changed, but it makes temp sensing work. I had a note that I
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
336 // could just wait until the next cycle to get my reading, but that's
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
337 // not working today, maybe because of a changed poll rate.
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
338 sensors.setWaitForConversion(true); // ~100ms
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
339
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
340 Serial.write((uint8_t)sensors.getDeviceCount());
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
341 for (uint8_t i=0; i < sensors.getDeviceCount(); ++i) {
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
342 float newTemp = sensors.getTempF(tempSensorAddress[i]);
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
343
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
344 Serial.write(tempSensorAddress[i], 8);
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
345 Serial.write((uint8_t*)(&newTemp), 4);
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
346 }
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
347 '''
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
348
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
349 def readFromPoll(self, read):
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
350 t1 = time.time()
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
351 count = ord(read(1))
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
352 stmts = []
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
353 for i in range(count):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
354 addr = struct.unpack('>Q', read(8))[0]
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
355 tempF = struct.unpack('<f', read(4))[0]
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
356 sensorUri = URIRef(os.path.join(self.uri, 'dev-%s' % hex(addr)[2:]))
1110
6ee834a6f970 influx output for arduino, update web lib path
drewp <drewp@bigasterisk.com>
parents: 1073
diff changeset
357 if tempF > 180:
6ee834a6f970 influx output for arduino, update web lib path
drewp <drewp@bigasterisk.com>
parents: 1073
diff changeset
358 stmts.extend([
6ee834a6f970 influx output for arduino, update web lib path
drewp <drewp@bigasterisk.com>
parents: 1073
diff changeset
359 (self.uri, ROOM['connectedTo'], sensorUri),
6ee834a6f970 influx output for arduino, update web lib path
drewp <drewp@bigasterisk.com>
parents: 1073
diff changeset
360 (sensorUri, RDF.type, ROOM['FailingTemperatureReading']),
6ee834a6f970 influx output for arduino, update web lib path
drewp <drewp@bigasterisk.com>
parents: 1073
diff changeset
361 ])
6ee834a6f970 influx output for arduino, update web lib path
drewp <drewp@bigasterisk.com>
parents: 1073
diff changeset
362 continue
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
363 stmts.extend([
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
364 (self.uri, ROOM['connectedTo'], sensorUri),
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1023
diff changeset
365 # rounding may be working around a bug where the
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1023
diff changeset
366 # Literal gets two representations (at different
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1023
diff changeset
367 # roundings), and this makes an extra value linger on
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1023
diff changeset
368 # the client.
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1023
diff changeset
369 (sensorUri, ROOM['temperatureF'], Literal(round(tempF, 2)))])
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
370 self._knownTempSubjects.add(sensorUri)
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
371
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
372 log.debug("read temp in %.1fms" % ((time.time() - t1) * 1000))
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
373 return stmts
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
374
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
375 def watchPrefixes(self):
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
376 # these uris will become dynamic! see note on watchPrefixes
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
377 # about eliminating it.
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
378 return [(uri, ROOM['temperatureF']) for uri in self._knownTempSubjects]
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
379
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
380 def byteFromFloat(f):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
381 return chr(int(min(255, max(0, f * 255))))
997
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
382
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
383 @register
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
384 class LedOutput(DeviceType):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
385 deviceType = ROOM['LedOutput']
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
386 def hostStateInit(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
387 self.value = 0
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
388
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
389 def generateSetupCode(self):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
390 return 'pinMode(%(pin)d, OUTPUT); digitalWrite(%(pin)d, LOW);' % {
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
391 'pin': self.pinNumber,
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
392 }
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
393
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
394 def outputPatterns(self):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
395 return [(self.uri, ROOM['brightness'], None)]
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
396
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
397 def sendOutput(self, statements, write, read):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
398 assert len(statements) == 1
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
399 assert statements[0][:2] == (self.uri, ROOM['brightness'])
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
400 self.value = float(statements[0][2])
977
03cfee8f9154 obey ActiveLowOutput correctly
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
401 if (self.uri, RDF.type, ROOM['ActiveLowOutput']) in self.graph:
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
402 self.value = 1 - self.value
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
403 write(byteFromFloat(self.value))
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
404
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
405 def hostStatements(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
406 return [(self.uri, ROOM['brightness'], Literal(self.value))]
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
407
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
408 def generateActionCode(self):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
409 return r'''
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
410 while(Serial.available() < 1) NULL;
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
411 analogWrite(%(pin)d, Serial.read());
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
412 ''' % dict(pin=self.pinNumber)
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
413
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
414 def outputWidgets(self):
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
415 return [{
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
416 'element': 'output-slider',
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
417 'min': 0,
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
418 'max': 1,
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
419 'step': 1 / 255,
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
420 'subj': self.uri,
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
421 'pred': ROOM['brightness'],
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
422 }]
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
423
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
424 @register
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
425 class DigitalOutput(DeviceType):
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
426 deviceType = ROOM['DigitalOutput']
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
427 def hostStateInit(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
428 self.value = 0
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
429
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
430 def generateSetupCode(self):
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
431 return 'pinMode(%(pin)d, OUTPUT); digitalWrite(%(pin)d, LOW);' % {
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
432 'pin': self.pinNumber,
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
433 }
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
434
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
435 def outputPatterns(self):
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
436 return [(self.uri, ROOM['level'], None)]
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
437
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
438 def sendOutput(self, statements, write, read):
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
439 assert len(statements) == 1
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
440 assert statements[0][:2] == (self.uri, ROOM['level'])
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
441 self.value = {"high": 1, "low": 0}[str(statements[0][2])]
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
442 write(chr(self.value))
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
443
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
444 def hostStatements(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
445 return [(self.uri, ROOM['level'],
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
446 Literal('high' if self.value else 'low'))]
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
447
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
448 def generateActionCode(self):
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
449 return r'''
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
450 while(Serial.available() < 1) NULL;
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
451 digitalWrite(%(pin)d, Serial.read());
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
452 ''' % dict(pin=self.pinNumber)
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
453
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
454 def outputWidgets(self):
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
455 return [{
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
456 'element': 'output-switch',
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
457 'subj': self.uri,
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
458 'pred': ROOM['level'],
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
459 }]
997
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
460
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
461
997
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
462 @register
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
463 class PwmBoard(DeviceType):
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
464 deviceType = ROOM['PwmBoard']
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
465 @classmethod
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
466 def findInstances(cls, graph, board):
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
467 for row in graph.query("""SELECT DISTINCT ?dev ?sda ?scl WHERE {
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
468 ?board :hasPin ?sdaPin .
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
469 ?board :hasPin ?sclPin .
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
470 ?sdaPin :pinNumber ?sda; :connectedTo ?sdaConn .
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
471 ?sclPin :pinNumber ?scl; :connectedTo ?sclConn .
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
472 ?dev a :PwmBoard;
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
473 :scl ?sclConn;
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
474 :sda ?sdaConn .
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
475 }""", initBindings=dict(board=board), initNs={'': ROOM}):
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
476 if (row.sda, row.scl) != (Literal('a4'), Literal('a5')):
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
477 raise NotImplementedError(row)
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
478 outs = {}
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
479 for out in graph.query("""SELECT DISTINCT ?area ?chan WHERE {
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
480 ?dev :output [:area ?area; :channel ?chan] .
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
481 }""", initBindings=dict(dev=row.dev), initNs={'': ROOM}):
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
482 outs[out.area] = out.chan.toPython()
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
483 yield cls(graph, row.dev, outs=outs)
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
484
997
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
485 def __init__(self, graph, dev, outs):
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
486 self.codeVals = {'pwm': 'pwm%s' % (hash(str(dev)) % 99999)}
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
487 self.outs = outs
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
488 super(PwmBoard, self).__init__(graph, dev, pinNumber=None)
997
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
489
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
490 def hostStateInit(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
491 self.values = {uri: 0 for uri in self.outs.keys()} # uri: brightness
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
492
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
493 def hostStatements(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
494 return [(uri, ROOM['brightness'], Literal(b))
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
495 for uri, b in self.values.items()]
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
496
997
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
497 def generateIncludes(self):
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
498 return ['Wire.h', 'Adafruit_PWMServoDriver.h']
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
499
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
500 def generateArduinoLibs(self):
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
501 return ['Wire', 'Adafruit-PWM-Servo-Driver-Library']
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
502
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
503 def generateGlobalCode(self):
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
504 return r'''
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
505 Adafruit_PWMServoDriver %(pwm)s = Adafruit_PWMServoDriver(0x40);
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
506 ''' % self.codeVals
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
507
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
508 def generateSetupCode(self):
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
509 return '''
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
510 %(pwm)s.begin();
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
511 %(pwm)s.setPWMFreq(1200);
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
512 ''' % self.codeVals
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
513
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
514 def generateActionCode(self):
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
515 return r'''
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
516 while(Serial.available() < 3) NULL;
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
517 byte chan = Serial.read();
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
518 uint16_t level = uint16_t(Serial.read()) << 8;
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
519 level |= Serial.read();
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
520 %(pwm)s.setPWM(chan, 0, level);
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
521 ''' % self.codeVals
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
522
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
523 def outputPatterns(self):
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
524 return [(area, ROOM['brightness'], None) for area in self.outs]
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
525
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
526 def sendOutput(self, statements, write, read):
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
527 assert len(statements) == 1
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
528 assert statements[0][1] == ROOM['brightness'];
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
529 chan = self.outs[statements[0][0]]
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
530 value = float(statements[0][2])
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
531 self.values[statements[0][0]] = value
997
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
532 v12 = int(min(4095, max(0, value * 4095)))
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
533 write(chr(chan) + chr(v12 >> 8) + chr(v12 & 0xff))
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
534
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
535 def outputWidgets(self):
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
536 return [{
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
537 'element': 'output-slider',
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
538 'min': 0,
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
539 'max': 1,
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
540 'step': 1 / 255,
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
541 'subj': area,
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
542 'pred': ROOM['brightness'],
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
543 } for area in self.outs]
b24885725f59 support for pwm board
drewp <drewp@bigasterisk.com>
parents: 991
diff changeset
544
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
545 @register
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
546 class ST7576Lcd(DeviceType):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
547 deviceType = ROOM['ST7565Lcd']
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
548 @classmethod
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
549 def findInstances(cls, graph, board):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
550 grouped = itertools.groupby(
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
551 graph.query("""SELECT DISTINCT ?dev ?pred ?pinNumber WHERE {
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
552 ?board :hasPin ?pin .
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
553 ?pin :pinNumber ?pinNumber;
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
554 :connectedTo ?devPin .
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
555 ?dev a :ST7565Lcd .
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
556 ?dev ?pred ?devPin .
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
557 } ORDER BY ?dev""",
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
558 initBindings=dict(board=board,
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
559 thisType=cls.deviceType),
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
560 initNs={'': ROOM}),
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
561 lambda row: row.dev)
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
562 for dev, connections in grouped:
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
563 connections = dict((role, int(num)) for unused_dev, role, num
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
564 in connections)
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
565 yield cls(graph, dev, connections=connections)
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
566
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
567 def __init__(self, graph, dev, connections):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
568 super(ST7576Lcd, self).__init__(graph, dev, pinNumber=None)
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
569 self.connections = connections
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
570 self.text = ''
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
571
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
572 def generateIncludes(self):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
573 return ['ST7565.h']
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
574
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
575 def generateArduinoLibs(self):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
576 return ['ST7565']
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
577
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
578 def generateGlobalCode(self):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
579 return '''
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
580 ST7565 glcd(%(SID)d, %(SCLK)d, %(A0)d, %(RST)d, %(CS)d);
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
581 char newtxt[21*8+1];
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
582 unsigned int written;
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
583 ''' % dict(SID=self.connections[ROOM['lcdSID']],
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
584 SCLK=self.connections[ROOM['lcdSCLK']],
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
585 A0=self.connections[ROOM['lcdA0']],
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
586 RST=self.connections[ROOM['lcdRST']],
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
587 CS=self.connections[ROOM['lcdCS']])
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
588
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
589 def generateSetupCode(self):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
590 return '''
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
591 glcd.st7565_init();
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
592 glcd.st7565_command(CMD_DISPLAY_ON);
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
593 glcd.st7565_command(CMD_SET_ALLPTS_NORMAL);
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
594 glcd.st7565_set_brightness(0x18);
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
595
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
596 glcd.display(); // show splashscreen
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
597 '''
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
598
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
599 def outputPatterns(self):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
600 return [(self.uri, ROOM['text'], None)]
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
601
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
602 def sendOutput(self, statements, write, read):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
603 assert len(statements) == 1
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
604 assert statements[0][:2] == (self.uri, ROOM['text'])
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
605 self.text = str(statements[0][2])
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
606 assert len(self.text) < 254, repr(self.text)
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
607 write(chr(len(self.text)) + self.text)
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
608
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
609 def hostStatements(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
610 return [(self.uri, ROOM['text'], Literal(self.text))]
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
611
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
612 def outputWidgets(self):
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
613 return [{
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
614 'element': 'output-fixed-text',
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
615 'cols': 21,
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
616 'rows': 8,
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
617 'subj': self.uri,
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
618 'pred': ROOM['text'],
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
619 }]
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
620
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
621 def generateActionCode(self):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
622 return '''
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
623 while(Serial.available() < 1) NULL;
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
624 byte bufSize = Serial.read();
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
625 for (byte i = 0; i < bufSize; ++i) {
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
626 while(Serial.available() < 1) NULL;
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
627 newtxt[i] = Serial.read();
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
628 }
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
629 for (byte i = bufSize; i < sizeof(newtxt); ++i) {
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
630 newtxt[i] = 0;
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
631 }
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
632 glcd.clear();
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
633 glcd.drawstring(0,0, newtxt);
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
634 glcd.display();
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
635 '''
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
636
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
637 @register
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
638 class RgbPixels(DeviceType):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
639 """chain of FastLED-controllable rgb pixels"""
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
640 deviceType = ROOM['RgbPixels']
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
641
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
642 def __init__(self, graph, uri, pinNumber):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
643 super(RgbPixels, self).__init__(graph, uri, pinNumber)
1140
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
644 self.anim = RgbPixelsAnimation(graph, uri, self.updateOutput)
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
645
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
646 self.replace = {'ledArray': 'leds_%s' % self.pinNumber,
1140
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
647 'ledCount': self.anim.maxIndex() - 1,
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
648 'pin': self.pinNumber,
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
649 'ledType': 'WS2812',
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
650 }
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
651
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
652 def generateIncludes(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
653 """filenames of .h files to #include"""
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
654 return ['FastLED.h']
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
655
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
656 def generateArduinoLibs(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
657 """names of libraries for the ARDUINO_LIBS line in the makefile"""
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
658 return ['FastLED-3.1.0']
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
659
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
660 def myId(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
661 return 'rgb_%s' % self.pinNumber
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
662
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
663 def generateGlobalCode(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
664 return 'CRGB {ledArray}[{ledCount}];'.format(**self.replace)
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
665
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
666 def generateSetupCode(self):
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
667 return 'FastLED.addLeds<{ledType}, {pin}>({ledArray}, {ledCount});'.format(**self.replace)
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
668
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
669 def sendOutput(self, statements, write, read):
1140
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
670 log.info('sendOutput start')
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
671 self.write = write
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
672 self.anim.onStatements(statements)
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
673 self.anim.updateOutput()
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
674 log.info('sendOutput end')
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
675
1140
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
676 def updateOutput(self):
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
677 write = self.write
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
678 write(chr(self.anim.maxIndex() + 1))
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
679 for idx, (r, g, b) in self.anim.currentColors():
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
680 # my WS2812 need these flipped
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
681 write(chr(idx) + chr(g) + chr(r) + chr(b))
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
682
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
683 def wantIdleOutput(self):
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
684 return True
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
685
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
686 def outputIdle(self, write):
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
687 self.write = write
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
688 self.updateOutput()
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
689
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
690 def hostStatements(self):
1140
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
691 return self.anim.hostStatements()
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
692
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
693 def outputPatterns(self):
1140
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
694 return self.anim.outputPatterns()
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
695
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
696 def outputWidgets(self):
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
697 return self.anim.outputWidgets()
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
698
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
699 def generateActionCode(self):
1140
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
700 # not yet combining updates- may be slow
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
701 return '''
1140
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
702 while(Serial.available() < 1) NULL;
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
703 byte count = Serial.read();
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
704 for (byte elt=0; elt<count; ++elt) {{
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
705 while(Serial.available() < 1) NULL;
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
706 byte id = Serial.read();
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
707
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
708 while(Serial.available() < 1) NULL;
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
709 byte r = Serial.read();
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
710
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
711 while(Serial.available() < 1) NULL;
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
712 byte g = Serial.read();
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
713
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
714 while(Serial.available() < 1) NULL;
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
715 byte b = Serial.read();
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
716
1140
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
717 {ledArray}[id] = CRGB(r, g, b);
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
718 }}
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
719 FastLED.show();
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
720
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
721 '''.format(**self.replace)
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
722
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
723 def makeDevices(graph, board):
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
724 out = []
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
725 for dt in sorted(_knownTypes, key=lambda cls: cls.__name__):
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
726 out.extend(dt.findInstances(graph, board))
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
727 return out
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
728