This commit is contained in:
interfisch 2021-07-01 21:27:26 +02:00
parent 51d6fe3698
commit 29b04c7d00
1 changed files with 17 additions and 19 deletions

View File

@ -16,8 +16,8 @@ class Controller:
def __init__(self, base_topic, mqtt_host, mqtt_port = 1883):
self.scroll_interval = 0.25
self.text = ""
self.poscount = 0
self.text = ""
self.poscount = 0
# Create the I2C interface.
self.i2c = busio.I2C(board.SCL, board.SDA)
@ -49,29 +49,27 @@ class Controller:
print("msg = " + msg)
if message.topic.endswith(__TOPIC_BRIGHTNESS__ + "/set"):
val = float(msg)
if val >= 0.0 and val <=1.0:
self.display.brightness = val
print("changed brightness to ", self.display.brightness)
val = float(msg)
if val >= 0.0 and val <=1.0:
self.display.brightness = val
print("changed brightness to ", self.display.brightness)
self.mqtt.publish(self.topic + "/" + __TOPIC_BRIGHTNESS__, self.display.brightness, 1 )
else:
print("invalid brightness ", val)
else:
print("invalid brightness ", val)
if message.topic.endswith(__TOPIC_SCROLL_INTERVAL__ + "/set"):
val = float(msg)
if val > 0.0:
self.scroll_interval = val
print("changed scroll_interval to ", self.scroll_interval)
val = float(msg)
if val > 0.0:
self.scroll_interval = val
print("changed scroll_interval to ", self.scroll_interval)
self.mqtt.publish(self.topic + "/" + __TOPIC_SCROLL_INTERVAL__, self.scroll_interval, 1 )
else:
print("error not >0.0: ", val)
else:
print("error not >0.0: ", val)
if message.topic.endswith(__TOPIC_TEXT__ + "/set"):
if message.topic.endswith(__TOPIC_TEXT__ + "/set"):
self.text = msg
print("changed text to ", self.text)
print("changed text to ", self.text)
self.mqtt.publish(self.topic + "/" + __TOPIC_TEXT__, self.text, 1 )
@ -91,7 +89,7 @@ class Controller:
self.display.print(self.text[poscount])
poscount += 1
poscount %= len(self.text)
poscount %= len(self.text)
time.sleep(self.scroll_interval)