new words and inuse timer for manual flipdot usage, blocks time/power update for a while

This commit is contained in:
interfisch 2017-02-23 22:10:50 +01:00
parent b3132e31cb
commit a2d997099d
2 changed files with 26 additions and 12 deletions

View File

@ -842,3 +842,5 @@ Borg
Adrino Adrino
Arduino Arduino
Nodalpunktadapter Nodalpunktadapter
Informationslebenszyklusmanagement
desoxyribonukleinsaeure

View File

@ -8,8 +8,8 @@ from threading import Thread
global mode global mode
mode="standby" mode="standby"
global gametimeout global timeout
gametimeout=0 timeout=0
global flipthread global flipthread
flipthread=None flipthread=None
@ -24,13 +24,14 @@ def on_connect(client, userdata, flags, rc):
def on_message(client, userdata, msg): def on_message(client, userdata, msg):
print(msg.topic + " " + str(msg.payload.decode("utf-8"))) print(msg.topic + " " + str(msg.payload.decode("utf-8")))
global mode global mode
global gametimeout global timeout
global flipthread global flipthread
if mode=="standby": if mode=="standby" or mode=="inuse":
gametimeout=0
if msg.topic == "raum2/flipdot/scroll/set": if msg.topic == "raum2/flipdot/scroll/set":
mode="inuse"
updateTimeout()
payload = msg.payload.decode("utf-8") payload = msg.payload.decode("utf-8")
if len(payload)>0 and (payload[0]).isdigit(): if len(payload)>0 and (payload[0]).isdigit():
@ -51,7 +52,7 @@ def on_message(client, userdata, msg):
flipthread=Thread(target=flipdot.send_marquee, args=(text,speed)) flipthread=Thread(target=flipdot.send_marquee, args=(text,speed))
flipthread.start() flipthread.start()
if msg.topic == "raum2/flipdot/text/set": if mode!="inuse" and msg.topic == "raum2/flipdot/text/set": #used to display information regulary (time etc). only available if flipdot not in use
payload = msg.payload.decode("utf-8") payload = msg.payload.decode("utf-8")
if flipthread is not None and flipthread.isAlive(): if flipthread is not None and flipthread.isAlive():
@ -71,7 +72,9 @@ def on_message(client, userdata, msg):
flipthread.start() flipthread.start()
if msg.topic == "raum2/flipdot/textFull/set": if msg.topic == "raum2/flipdot/textFull/set": #scale/break text automatically
mode="inuse"
updateTimeout()
payload = msg.payload.decode("utf-8") payload = msg.payload.decode("utf-8")
if len(payload)>0 and payload[0]=='~': if len(payload)>0 and payload[0]=='~':
payload=payload[1:] payload=payload[1:]
@ -79,6 +82,8 @@ def on_message(client, userdata, msg):
flipdot.send_textFull(payload) flipdot.send_textFull(payload)
if msg.topic == "raum2/flipdot/image/set": if msg.topic == "raum2/flipdot/image/set":
mode="inuse"
updateTimeout()
payload = msg.payload.decode("utf-8") payload = msg.payload.decode("utf-8")
print(payload) print(payload)
flipdot.send_bytes(payload) flipdot.send_bytes(payload)
@ -90,12 +95,12 @@ def on_message(client, userdata, msg):
if payload=="#start": if payload=="#start":
hangman.setup() hangman.setup()
gametimeout=int(round(time.time() * 1000)) updateTimeout()
client.publish("raum2/flipdot/hangman","started") client.publish("raum2/flipdot/hangman","started")
mode="hangman" mode="hangman"
elif (mode=="hangman") and (len(payload)>0): #try entered character elif (mode=="hangman") and (len(payload)>0): #try entered character
gametimeout=int(round(time.time() * 1000)) updateTimeout()
trychar=payload[-1] trychar=payload[-1]
gamestatus=hangman.step(trychar) gamestatus=hangman.step(trychar)
client.publish("raum2/flipdot/hangman","char="+trychar.upper()) client.publish("raum2/flipdot/hangman","char="+trychar.upper())
@ -113,6 +118,9 @@ def on_message(client, userdata, msg):
mode="standby" mode="standby"
client.publish("raum2/flipdot/hangman","ended") client.publish("raum2/flipdot/hangman","ended")
def updateTimeout():
global timeout
timeout=int(round(time.time() * 1000))
#flipdot = FlipdotSender("2001:67c:275c:a9::c", 2323) #flipdot = FlipdotSender("2001:67c:275c:a9::c", 2323)
@ -131,11 +139,15 @@ client.loop_start()
while True: while True:
millis = int(round(time.time() * 1000)) millis = int(round(time.time() * 1000))
if gametimeout!=0: if (timeout!=0) and (mode=="hangman"):
if millis-120000 > gametimeout: #timeout if millis-120000 > timeout: #timeout
print("Game Timeout") print("Game Timeout")
mode="standby" mode="standby"
gametimeout=0 timeout=0
if (timeout!=0) and (mode=="inuse"): #inuse: flipdot was manually controlled, do not update time,pwr etc for a while
if millis-10000 > timeout: #timeout
mode="standby"
timeout=0
time.sleep(2) time.sleep(2)