21 |
22 | Module pymata4.pin_data
23 |
24 |
25 | Copyright (c) 2015-2017 Alan Yorinks All rights reserved.
26 | This program is free software; you can redistribute it and/or
27 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
28 | Version 3 as published by the Free Software Foundation; either
29 | or (at your option) any later version.
30 | This library is distributed in the hope that it will be useful,
31 | but WITHOUT ANY WARRANTY; without even the implied warranty of
32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
33 | See the GNU
34 | General Public License for more details.
35 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
36 | along with this library; if not, write to the Free Software
37 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
38 | 02110-1301
39 | USA
40 |
41 |
42 | Expand source code
43 |
44 | """
45 | Copyright (c) 2015-2017 Alan Yorinks All rights reserved.
46 |
47 | This program is free software; you can redistribute it and/or
48 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
49 | Version 3 as published by the Free Software Foundation; either
50 | or (at your option) any later version.
51 | This library is distributed in the hope that it will be useful,
52 | but WITHOUT ANY WARRANTY; without even the implied warranty of
53 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
54 | General Public License for more details.
55 |
56 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
57 | along with this library; if not, write to the Free Software
58 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
59 | """
60 |
61 |
62 | class PinData:
63 | """
64 | Each analog and digital input pin is described by an instance of
65 | this class. It contains both the last data value received and a potential
66 | callback reference. It may also contain a callback differential that if met
67 | will cause a callback to occur. The differential pertains to non-digital
68 | inputs.
69 | """
70 |
71 | def __init__(self, data_lock):
72 | self.data_lock = data_lock
73 | # current data value
74 | self._current_value = 0
75 | # time stamp of last change event
76 | self._event_time = 0
77 | # callback reference
78 | self._cb = None
79 | # analog differential
80 | self._differential = 1
81 | # digital pin was set as a pullup pin
82 | self._pull_up = False
83 |
84 | @property
85 | def current_value(self):
86 | with self.data_lock:
87 | return self._current_value
88 |
89 | @current_value.setter
90 | def current_value(self, value):
91 | with self.data_lock:
92 | self._current_value = value
93 |
94 | @property
95 | def event_time(self):
96 | with self.data_lock:
97 | return self._event_time
98 |
99 | @event_time.setter
100 | def event_time(self, value):
101 | with self.data_lock:
102 | self._event_time = value
103 |
104 | @property
105 | def cb(self):
106 | with self.data_lock:
107 | return self._cb
108 |
109 | @cb.setter
110 | def cb(self, value):
111 | with self.data_lock:
112 | self._cb = value
113 |
114 | @property
115 | def differential(self):
116 | with self.data_lock:
117 | return self._differential
118 |
119 | @differential.setter
120 | def differential(self, value):
121 | with self.data_lock:
122 | self._differential = value
123 |
124 | @property
125 | def pull_up(self):
126 | with self.data_lock:
127 | return self._pull_up
128 |
129 | @pull_up.setter
130 | def pull_up(self, value):
131 | with self.data_lock:
132 | self._pull_up = value
133 |
134 |
135 |
137 |
139 |
141 |
142 |
143 |
144 |
145 | class PinData
146 | (data_lock)
147 |
148 | -
149 |
Each analog and digital input pin is described by an instance of
150 | this class. It contains both the last data value received and a potential
151 | callback reference. It may also contain a callback differential that if met
152 | will cause a callback to occur. The differential pertains to non-digital
153 | inputs.
154 |
155 |
156 | Expand source code
157 |
158 | class PinData:
159 | """
160 | Each analog and digital input pin is described by an instance of
161 | this class. It contains both the last data value received and a potential
162 | callback reference. It may also contain a callback differential that if met
163 | will cause a callback to occur. The differential pertains to non-digital
164 | inputs.
165 | """
166 |
167 | def __init__(self, data_lock):
168 | self.data_lock = data_lock
169 | # current data value
170 | self._current_value = 0
171 | # time stamp of last change event
172 | self._event_time = 0
173 | # callback reference
174 | self._cb = None
175 | # analog differential
176 | self._differential = 1
177 | # digital pin was set as a pullup pin
178 | self._pull_up = False
179 |
180 | @property
181 | def current_value(self):
182 | with self.data_lock:
183 | return self._current_value
184 |
185 | @current_value.setter
186 | def current_value(self, value):
187 | with self.data_lock:
188 | self._current_value = value
189 |
190 | @property
191 | def event_time(self):
192 | with self.data_lock:
193 | return self._event_time
194 |
195 | @event_time.setter
196 | def event_time(self, value):
197 | with self.data_lock:
198 | self._event_time = value
199 |
200 | @property
201 | def cb(self):
202 | with self.data_lock:
203 | return self._cb
204 |
205 | @cb.setter
206 | def cb(self, value):
207 | with self.data_lock:
208 | self._cb = value
209 |
210 | @property
211 | def differential(self):
212 | with self.data_lock:
213 | return self._differential
214 |
215 | @differential.setter
216 | def differential(self, value):
217 | with self.data_lock:
218 | self._differential = value
219 |
220 | @property
221 | def pull_up(self):
222 | with self.data_lock:
223 | return self._pull_up
224 |
225 | @pull_up.setter
226 | def pull_up(self, value):
227 | with self.data_lock:
228 | self._pull_up = value
229 |
230 | Instance variables
231 |
232 | var cb
233 | -
234 |
235 |
236 |
237 | Expand source code
238 |
239 | @property
240 | def cb(self):
241 | with self.data_lock:
242 | return self._cb
243 |
244 |
245 | var current_value
246 | -
247 |
248 |
249 |
250 | Expand source code
251 |
252 | @property
253 | def current_value(self):
254 | with self.data_lock:
255 | return self._current_value
256 |
257 |
258 | var differential
259 | -
260 |
261 |
262 |
263 | Expand source code
264 |
265 | @property
266 | def differential(self):
267 | with self.data_lock:
268 | return self._differential
269 |
270 |
271 | var event_time
272 | -
273 |
274 |
275 |
276 | Expand source code
277 |
278 | @property
279 | def event_time(self):
280 | with self.data_lock:
281 | return self._event_time
282 |
283 |
284 | var pull_up
285 | -
286 |
287 |
288 |
289 | Expand source code
290 |
291 | @property
292 | def pull_up(self):
293 | with self.data_lock:
294 | return self._pull_up
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
329 |