Initial commit
This commit is contained in:
commit
6dcd8c7a47
5 changed files with 207 additions and 0 deletions
21
README.md
Normal file
21
README.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Matrix Clock
|
||||
|
||||
>> sudo usermod -a -G spi,gpio pi
|
||||
>> sudo apt install build-essential python3-dev python3-pip libfreetype6-dev libjpeg-dev libopenjp2-7 libtiff5
|
||||
|
||||
|
||||
stomp.py (https://github.com/jasonrbriggs/stomp.py)
|
||||
luma.led_matrix (https://luma-led-matrix.readthedocs.io/en/latest/index.html)
|
||||
|
||||
py -m pip install XXX
|
||||
|
||||
PeopleCount
|
||||
LIN#-omxplayer
|
||||
Vielleicht auch überflüssigLIN#-mysqlclient (sudo apt-get install python-pip python-dev default-libmysqlclient-dev)
|
||||
-numpy
|
||||
WIN#-playsound
|
||||
LIN#-PyGame (pip)
|
||||
-mysql-connector
|
||||
-pip install --upgrade "watson-developer-cloud>=2.4.1"
|
||||
-pathlib2
|
||||
-stomp.py (https://github.com/jasonrbriggs/stomp.py)
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
gpiozero
|
||||
luma.led_matrix
|
139
src/matrixclock.py
Normal file
139
src/matrixclock.py
Normal file
|
@ -0,0 +1,139 @@
|
|||
import time
|
||||
from datetime import datetime, timedelta
|
||||
from luma.core.interface.serial import spi, noop
|
||||
from luma.core.render import canvas
|
||||
from luma.led_matrix.device import max7219
|
||||
from luma.core import legacy
|
||||
from luma.core.virtual import viewport
|
||||
from luma.core.legacy.font import proportional, CP437_FONT, LCD_FONT
|
||||
|
||||
|
||||
messageIncoming=False
|
||||
stdContrast=0
|
||||
directmessengerInitialized = False
|
||||
|
||||
|
||||
def setMsgInc (state):
|
||||
global messageIncoming
|
||||
messageIncoming = state
|
||||
|
||||
def getMsgInc ():
|
||||
global messageIncoming
|
||||
return messageIncoming
|
||||
|
||||
def setDirectmessengerState (state):
|
||||
global directmessengerInitialized
|
||||
directmessengerInitialized = state
|
||||
|
||||
def getDirectmessengerState ():
|
||||
global directmessengerInitialized
|
||||
return directmessengerInitialized
|
||||
|
||||
def printTextToMatrix (text):
|
||||
global device
|
||||
width=len(text) * 8 + 4 * 8
|
||||
virtual=viewport(device, width + 4 * 8, height=8)
|
||||
with canvas(virtual) as draw:
|
||||
legacy.text(draw, (4 * 8, 0), text, fill="white", font=proportional(CP437_FONT))
|
||||
|
||||
for offset in range(width):
|
||||
virtual.set_position((offset, 0))
|
||||
time.sleep(0.015)
|
||||
|
||||
def printFlash (count):
|
||||
global device
|
||||
device.contrast(255)
|
||||
while count > 0:
|
||||
with canvas(device) as draw:
|
||||
draw.rectangle((0, 0, 31, 7), outline="white", fill="white")
|
||||
time.sleep(0.1)
|
||||
|
||||
with canvas(device) as draw:
|
||||
draw.rectangle((0, 0, 31, 7), outline="black", fill="black")
|
||||
time.sleep(0.1)
|
||||
|
||||
count-=1
|
||||
global stdContrast
|
||||
device.contrast(stdContrast)
|
||||
|
||||
def printDark ():
|
||||
global device
|
||||
device.contrast(0)
|
||||
with canvas(device) as draw:
|
||||
draw.rectangle((0, 0, 31, 7), outline="black", fill="black")
|
||||
global stdContrast
|
||||
device.contrast(stdContrast)
|
||||
|
||||
|
||||
|
||||
def getEncodedMsg(message):
|
||||
message.encoding='utf-8'
|
||||
message=message.replace(chr(252), 'ue')
|
||||
message=message.replace(chr(228), 'ae')
|
||||
message=message.replace(chr(246), 'oe')
|
||||
message=message.replace(chr(220), 'Ue')
|
||||
message=message.replace(chr(196), 'Ae')
|
||||
message=message.replace(chr(214), 'Oe')
|
||||
return message
|
||||
|
||||
def initializeDirectmessenger ():
|
||||
global directmessengerInitialized
|
||||
try:
|
||||
connection=stomp.Connection([('wncld.goip.de',61613)], keepalive=True)
|
||||
connection.set_listener('', MyListener())
|
||||
connection.start()
|
||||
connection.connect('matrixclock', 'vj4.dV+vy2;ZBa4Y[Bg9=7<K{x9Z78', wait=True)
|
||||
connection.subscribe(destination='/topic/directmessenger', id=1, ack='auto')
|
||||
setDirectmessengerState(True)
|
||||
except:
|
||||
setDirectmessengerState(False)
|
||||
|
||||
def printClock ():
|
||||
hour=str(datetime.now().hour).rjust(2, '0')
|
||||
minute=str(datetime.now().minute).rjust(2, '0')
|
||||
with canvas(device) as draw:
|
||||
draw.rectangle((16, 0, 31, 7), outline="white", fill="white")
|
||||
legacy.text(draw, (0, 1), hour, fill="white", font=proportional(CP437_FONT))
|
||||
legacy.text(draw, (17, 1), minute, fill="black", font=proportional(CP437_FONT))
|
||||
|
||||
def timeInNightRange ():
|
||||
now = datetime.now()
|
||||
return now.hour < 6
|
||||
|
||||
def exitClock ():
|
||||
printTextToMatrix("DOWN")
|
||||
printDark()
|
||||
|
||||
|
||||
|
||||
|
||||
try:
|
||||
serial=spi(port=0, device=0, gpio=noop())
|
||||
device=max7219(serial, width=32, height=8, rotate=2, block_orientation=-90)
|
||||
|
||||
device.contrast(stdContrast)
|
||||
|
||||
while True:
|
||||
#while getMsgInc():
|
||||
# time.sleep(1)
|
||||
|
||||
if timeInNightRange():
|
||||
printDark()
|
||||
now = datetime.now()
|
||||
timeUntilMorning = 6 - now.hour - (3600 - 60*now.minute - now.second)
|
||||
time.sleep(timeUntilMorning)
|
||||
|
||||
printClock()
|
||||
|
||||
#if getDirectmessengerState() == False :
|
||||
# initializeDirectmessenger()
|
||||
|
||||
timeUntilNextMinute = 60 - datetime.now().second
|
||||
time.sleep(timeUntilNextMinute)
|
||||
except KeyboardInterrupt:
|
||||
print("Matrixclock shuts down, because of ^C")
|
||||
exitClock()
|
||||
exit()
|
||||
except BaseException:
|
||||
exitClock()
|
||||
exit()
|
36
src/mqtt_printer.py
Normal file
36
src/mqtt_printer.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
import time
|
||||
import sys
|
||||
|
||||
import stomp
|
||||
|
||||
from luma.core.interface.serial import spi, noop
|
||||
from luma.core.render import canvas
|
||||
from luma.led_matrix.device import max7219
|
||||
from luma.core import legacy
|
||||
from luma.core.legacy.font import proportional, CP437_FONT, LCD_FONT
|
||||
|
||||
class MyListener(stomp.ConnectionListener):
|
||||
def on_error(self, headers, message):
|
||||
print('received an error "%s"' % message)
|
||||
def on_message(self, headers, message):
|
||||
with canvas(device) as draw:
|
||||
legacy.text(draw, (0, 0), message, fill="white", font=proportional(CP437_FONT))
|
||||
print('received a message "%s"' % message)
|
||||
|
||||
conn = stomp.Connection([('192.168.178.36',61613)])
|
||||
conn.set_listener('', MyListener())
|
||||
conn.start()
|
||||
conn.connect('matrixclock', 'vj4.dV+vy2;ZBa4Y[Bg9=7<K{x9Z78', wait=True)
|
||||
|
||||
conn.subscribe(destination='/topic/test', id=1, ack='auto')
|
||||
|
||||
serial = spi(port=0, device=0, gpio=noop())
|
||||
device = max7219(serial, width=32, height=8, block_orientation=-90)
|
||||
|
||||
device.contrast(0)
|
||||
|
||||
while True:
|
||||
try:
|
||||
time.sleep(3)
|
||||
except KeyboardInterrupt:
|
||||
conn.disconnect()
|
9
src/start.sh
Normal file
9
src/start.sh
Normal file
|
@ -0,0 +1,9 @@
|
|||
#! /bin/sh
|
||||
# sleep 30
|
||||
|
||||
# echo "before screen" >> /home/pi/matrixclock/log.log
|
||||
|
||||
screen -dmS matrixclock python /home/pi/matrixclock/matrixclock.py
|
||||
|
||||
# echo $? >> /home/pi/matrixclock/log.log
|
||||
# echo "after screen" >> /home/pi/matrixclock/log.log
|
Loading…
Reference in a new issue