make indentation consistent

This commit is contained in:
interfisch 2021-07-01 21:50:35 +02:00
parent c219d7cf5f
commit 82652008d7
1 changed files with 71 additions and 72 deletions

View File

@ -10,87 +10,86 @@ __TOPIC_SCROLL_INTERVAL__ = "scroll_interval"
__TOPIC_TEXT__ = "text" __TOPIC_TEXT__ = "text"
class Controller: class Controller:
connected = False connected = False
display = None display = None
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.
self.i2c = busio.I2C(board.SCL, board.SDA) self.i2c = busio.I2C(board.SCL, board.SDA)
# Create the LED segment class. # Create the LED segment class.
# This creates a 14 segment 4 character display: # This creates a 14 segment 4 character display:
self.display = segments.Seg14x4(self.i2c) self.display = segments.Seg14x4(self.i2c)
# Clear the display. # Clear the display.
self.display.fill(0) self.display.fill(0)
# set brightness, range 0-1.0, 1.0 max brightness # set brightness, range 0-1.0, 1.0 max brightness
self.display.brightness = 1.0 self.display.brightness = 1.0
self.mqtt = mqtt.Client() self.mqtt = mqtt.Client()
self.mqtt.on_connect = self.on_connect self.mqtt.on_connect = self.on_connect
self.mqtt.on_message = self.on_message self.mqtt.on_message = self.on_message
self.mqtt.on_disconnect = self.on_disconnect self.mqtt.on_disconnect = self.on_disconnect
self.mqtt.connect(mqtt_host, mqtt_port) self.mqtt.connect(mqtt_host, mqtt_port)
self.topic = base_topic self.topic = base_topic
self.display.print("ABCD") self.display.print("BOOT")
def on_disconnect(self, client, userdata, rc): def on_disconnect(self, client, userdata, rc):
print("MQTT disconnected") print("MQTT disconnected")
self.connected = False self.connected = False
def on_message(self, client, userdata, message): def on_message(self, client, userdata, message):
msg = str(message.payload.decode("utf-8")) msg = str(message.payload.decode("utf-8"))
print("msg = " + msg) print("msg = " + msg)
if message.topic.endswith(__TOPIC_BRIGHTNESS__ + "/set"): if message.topic.endswith(__TOPIC_BRIGHTNESS__ + "/set"):
val = float(msg) val = float(msg)
if val >= 0.0 and val <=1.0: if val >= 0.0 and val <=1.0:
self.display.brightness = val self.display.brightness = val
print("changed brightness to ", self.display.brightness) print("changed brightness to ", self.display.brightness)
self.mqtt.publish(self.topic + "/" + __TOPIC_BRIGHTNESS__, self.display.brightness, 1 ) self.mqtt.publish(self.topic + "/" + __TOPIC_BRIGHTNESS__, self.display.brightness, 1 )
else: else:
print("invalid brightness ", val) print("invalid brightness ", val)
if message.topic.endswith(__TOPIC_SCROLL_INTERVAL__ + "/set"): if message.topic.endswith(__TOPIC_SCROLL_INTERVAL__ + "/set"):
val = float(msg) val = float(msg)
if val > 0.0: if val > 0.0:
self.scroll_interval = val self.scroll_interval = val
print("changed scroll_interval to ", self.scroll_interval) print("changed scroll_interval to ", self.scroll_interval)
self.mqtt.publish(self.topic + "/" + __TOPIC_SCROLL_INTERVAL__, self.scroll_interval, 1 ) self.mqtt.publish(self.topic + "/" + __TOPIC_SCROLL_INTERVAL__, self.scroll_interval, 1 )
else: else:
print("error not >0.0: ", val) print("error not >0.0: ", val)
if message.topic.endswith(__TOPIC_TEXT__ + "/set"):
self.text = msg
print("changed text to ", self.text)
self.mqtt.publish(self.topic + "/" + __TOPIC_TEXT__, self.text, 1 )
if message.topic.endswith(__TOPIC_TEXT__ + "/set"): def on_connect(self, client, userdata, flags, rc):
self.text = msg print("Connected to MQTT Broker")
print("changed text to ", self.text) self.mqtt.subscribe(self.topic + "/#")
self.mqtt.publish(self.topic + "/" + __TOPIC_TEXT__, self.text, 1 ) self.connected = True
def on_connect(self, client, userdata, flags, rc): def loop_forever(self):
print("Connected to MQTT Broker") run = True
self.mqtt.subscribe(self.topic + "/#")
self.connected = True
while run:
self.mqtt.loop()
def loop_forever(self): if self.display is not None:
run = True self.display.print(self.text[self.poscount])
self.poscount += 1
while run: self.poscount %= len(self.text)
self.mqtt.loop() time.sleep(self.scroll_interval)
if self.display is not None:
##display.print(self.text[self.poscount])
display.print(42)
self.poscount += 1
self.poscount %= len(self.text)
time.sleep(self.scroll_interval)