Skip to content

Commit

Permalink
Merge pull request #167 from waveform80/fix-sense-hat
Browse files Browse the repository at this point in the history
Fix Sense HAT monitor
  • Loading branch information
waveform80 committed Jun 27, 2019
2 parents 7e96a9d + c1b0c71 commit 951eda2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions piwheels-master.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ NoNewPrivileges=true
TimeoutStartSec=3m
TimeoutStopSec=5m
ExecStart=/usr/local/bin/piw-master -v
ExecStartPost=-chmod g+w /tmp/piw-status /tmp/piw-control

[Install]
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion piwheels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
'logger': ['lars'],
'test': ['pytest', 'coverage'],
'doc': ['sphinx'],
'sense': ['pisense'],
'sense': ['pisense', 'python-dateutil'],
}

__classifiers__ = [
Expand Down
14 changes: 12 additions & 2 deletions piwheels/sense/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@

from pisense import SenseHAT, StickEvent, array
from colorzero import Color
from dateutil import tz

from .. import terminal, const, protocols, transport, tasks
from .renderers import MainRenderer, StatusRenderer, QuitRenderer


LOCAL = tz.tzlocal()


class PiWheelsSense:
"""
This is the main class for the :program:`piw-sense` script. It
Expand Down Expand Up @@ -118,7 +122,13 @@ def run(self):
while not self._quit:
event = self.stick.read(0.1)
if event is not None and event.pressed:
self.stick_queue.send_msg('EVENT', event)
self.stick_queue.send_msg('EVENT', (
event.timestamp.replace(tzinfo=LOCAL),
event.direction,
event.pressed,
event.held,
))

finally:
self.stick_queue.close()

Expand All @@ -127,7 +137,7 @@ class ScreenTask(tasks.Task):
name = "screen"

def __init__(self, config, hat):
super().__init__()
super().__init__(config)
self.screen = hat.screen
self.renderers = {}
self.renderers['main'] = MainRenderer()
Expand Down
8 changes: 2 additions & 6 deletions piwheels/sense/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(self):
self.status = {}
self.position = (0, 3)
self.limits = (0, 3, 7, 7)
self.last_message = datetime(1970, 1, 1)
self.last_message = datetime(1970, 1, 1, tzinfo=UTC)
self.blue_grad = list(Color('blue').gradient(Color('white'), 32))

def message(self, msg, data):
Expand Down Expand Up @@ -240,10 +240,6 @@ def __init__(self, main):
self.update_text()

def move(self, event, task):
if event.direction == 'enter' and self.position[0] == 4:
task.ctrl_queue.send_pyobj(['QUIT'])
if event.direction == 'enter' and self.position[0] >= 4:
signal.pthread_kill(main_thread().ident, signal.SIGINT)
delta = super().move(event, task)
if event.direction == 'down':
task.renderer = self.main
Expand Down Expand Up @@ -362,7 +358,7 @@ def __init__(self, main):

def move(self, event, task):
if event.direction == 'enter' and self.position[0] == 1:
task.ctrl_queue.send_pyobj(['QUIT'])
task.ctrl_queue.send_msg('QUIT')
if event.direction == 'enter':
signal.pthread_kill(main_thread().ident, signal.SIGINT)
delta = super().move(event, task)
Expand Down

0 comments on commit 951eda2

Please sign in to comment.