working code with python 3
This commit is contained in:
parent
82652008d7
commit
e09b57aab5
|
@ -12,6 +12,7 @@ __TOPIC_TEXT__ = "text"
|
|||
class Controller:
|
||||
connected = False
|
||||
display = None
|
||||
last_scrollupdate = 0
|
||||
|
||||
def __init__(self, base_topic, mqtt_host, mqtt_port = 1883):
|
||||
|
||||
|
@ -70,7 +71,10 @@ class Controller:
|
|||
|
||||
|
||||
if message.topic.endswith(__TOPIC_TEXT__ + "/set"):
|
||||
self.poscount = 0 #start at beginning of new text
|
||||
self.text = msg
|
||||
if len(self.text)==0:
|
||||
self.text=" "
|
||||
print("changed text to ", self.text)
|
||||
self.mqtt.publish(self.topic + "/" + __TOPIC_TEXT__, self.text, 1 )
|
||||
|
||||
|
@ -85,11 +89,12 @@ class Controller:
|
|||
run = True
|
||||
|
||||
while run:
|
||||
self.mqtt.loop()
|
||||
self.mqtt.loop(0.1) #with block timeout
|
||||
|
||||
if self.display is not None:
|
||||
if self.display is not None and time.time() > self.last_scrollupdate+self.scroll_interval:
|
||||
self.display.print(self.text[self.poscount])
|
||||
self.poscount += 1
|
||||
self.poscount %= len(self.text)
|
||||
time.sleep(self.scroll_interval)
|
||||
self.last_scrollupdate = time.time()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue