comparison service/piNode/devices.py @ 636:7c04b4f675ec

piNode to py3 Ignore-this: c04a6b87bb776997781404c7e76898d4
author drewp@bigasterisk.com
date Mon, 12 Aug 2019 10:07:49 -0700
parents 42dab8c6200a
children 6e906d390ed7
comparison
equal deleted inserted replaced
635:ae6aefbd7a10 636:7c04b4f675ec
1 """ 1 """
2 https://github.com/juniorug/libsensorPy is a similar project 2 https://github.com/juniorug/libsensorPy is a similar project
3 """ 3 """
4 from __future__ import division
5
6 import time, logging, os 4 import time, logging, os
7 from rdflib import Namespace, URIRef, Literal 5 from rdflib import Namespace, URIRef, Literal
8 from twisted.internet import reactor, threads 6 from twisted.internet import reactor, threads
9 from twisted.internet.defer import inlineCallbacks, returnValue 7 from twisted.internet.defer import inlineCallbacks, returnValue
10 from greplin import scales 8 from greplin import scales
261 rrggbb = h.lstrip('#') 259 rrggbb = h.lstrip('#')
262 return [int(x, 16) for x in [rrggbb[0:2], rrggbb[2:4], rrggbb[4:6]]] 260 return [int(x, 16) for x in [rrggbb[0:2], rrggbb[2:4], rrggbb[4:6]]]
263 261
264 def sendOutput(self, statements): 262 def sendOutput(self, statements):
265 assert len(statements) == 1 263 assert len(statements) == 1
266 assert statements[0][:2] == (self.uri, ROOM['color']) 264 stmt = list(statements)[0]
267 265 assert stmt[:2] == (self.uri, ROOM['color'])
268 rgb = self._rgbFromHex(statements[0][2]) 266
269 self.value = statements[0][2] 267 rgb = self._rgbFromHex(stmt[2])
268 self.value = stmt[2]
270 269
271 for (i, v) in zip(self.rgb, rgb): 270 for (i, v) in zip(self.rgb, rgb):
272 self.pi.set_PWM_dutycycle(i, v) 271 self.pi.set_PWM_dutycycle(i, v)
273 272
274 def outputWidgets(self): 273 def outputWidgets(self):
483 def outputPatterns(self): 482 def outputPatterns(self):
484 return [(self.uri, ROOM['brightness'], None)] 483 return [(self.uri, ROOM['brightness'], None)]
485 484
486 def sendOutput(self, statements): 485 def sendOutput(self, statements):
487 assert len(statements) == 1 486 assert len(statements) == 1
488 assert statements[0][:2] == (self.uri, ROOM['brightness']) 487 stmt = list(statements)[0]
489 self.value = float(statements[0][2]) 488 assert stmt[:2] == (self.uri, ROOM['brightness'])
489 self.value = float(stmt[2])
490 self.fv.set(self.value) 490 self.fv.set(self.value)
491 491
492 def _setPwm(self, x): 492 def _setPwm(self, x):
493 v = max(0, min(255, int((x ** self.gamma)* 255))) 493 v = max(0, min(255, int((x ** self.gamma)* 255)))
494 self.pi.set_PWM_dutycycle(self.pinNumber, v) 494 self.pi.set_PWM_dutycycle(self.pinNumber, v)
569 colors = self.anim.currentColors() 569 colors = self.anim.currentColors()
570 570
571 for idx, (r, g, b) in colors: 571 for idx, (r, g, b) in colors:
572 if idx < 4: 572 if idx < 4:
573 log.debug('out color %s (%s,%s,%s)', idx, r, g, b) 573 log.debug('out color %s (%s,%s,%s)', idx, r, g, b)
574 self.neo.setPixelColorRGB(idx, r, g, b) 574 self.neo.setPixelColorRGB(idx, int(r), int(g), int(b))
575 self.neo.show() 575 self.neo.show()
576 576
577 @pixelStats.poll.time() 577 @pixelStats.poll.time()
578 def poll(self): 578 def poll(self):
579 self.anim.step() 579 self.anim.step()
695 def outputPatterns(self): 695 def outputPatterns(self):
696 return [(area, ROOM['brightness'], None) for area in self.outs] 696 return [(area, ROOM['brightness'], None) for area in self.outs]
697 697
698 def sendOutput(self, statements): 698 def sendOutput(self, statements):
699 assert len(statements) == 1 699 assert len(statements) == 1
700 assert statements[0][1] == ROOM['brightness']; 700 stmt = list(statements)[0]
701 chan = self.outs[statements[0][0]] 701 assert stmt[1] == ROOM['brightness'];
702 value = float(statements[0][2]) 702 chan = self.outs[stmt[0]]
703 self.values[statements[0][0]] = value 703 value = float(stmt[2])
704 self.values[stmt[0]] = value
704 self.pwm.set_duty_cycle(chan, value * 100) 705 self.pwm.set_duty_cycle(chan, value * 100)
705 706
706 def outputWidgets(self): 707 def outputWidgets(self):
707 return [{ 708 return [{
708 'element': 'output-slider', 709 'element': 'output-slider',