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