Esempio n. 1
0
def initialise(settings=configuration.oled.settings):
  global oled, width, height, font_size, bottom_row, lock_title
  parameter = configuration.boot.parameter

  Pin(int(settings["enable_pin"]), Pin.OUT).value(1)
  scl_pin = int(settings["scl_pin"])
  sda_pin = int(settings["sda_pin"])
  width = int(settings["width"])
  height = int(settings["height"])
  font_size = int(settings["font_size"])
  bottom_row = height - font_size

  i2c = machine.I2C(scl=Pin(scl_pin), sda=Pin(sda_pin))
# i2c.scan()
  oled = ssd1306.SSD1306_I2C(width, height, i2c)

  oled.fill(bg)
  write_title()
  lock_title = parameter("lock_title", settings)

  mqtt.add_message_handler(on_oled_message, "$me/in")
  if parameter("logger_enabled"):
    mqtt.add_message_handler(on_oled_log_message, "$all/log")
Esempio n. 2
0
def on_oled_message(topic, payload_in):
  if payload_in == "(oled:clear)":
    oled.fill(bg)
    oled.show()
    return True

  if payload_in.startswith("(oled:log "):
    log(payload_in[10:-1])
    return True

  if payload_in.startswith("(oled:pixel "):
    tokens = [int(token) for token in payload_in[12:-1].split()]
    oled.pixel(tokens[0], height - tokens[1] - 1, fg)
    oled.show()
    return True

  if payload_in.startswith("(oled:text "):
    tokens = payload_in[11:-1].split()
    text = " ".join(tokens[2:])
    oled.text(text, int(tokens[0]), height - font_size - int(tokens[1]), fg)
    oled.show()
    return True

  return False
Esempio n. 3
0
def test(text="Line "):
    for oled in oleds:
        oled.fill(bg)
    for y in range(0, height, font_size):
        oleds_text(text + str(y), 0, y, fg)
    oleds_show()
Esempio n. 4
0
def oleds_clear(color):
    for oled in oleds:
        oled.fill(color)
    oleds_show()
    if lock_title: write_title()
Esempio n. 5
0
def oleds_clear(color=BG, write=True):
    for oled in oleds:
        oled.fill(color)
    if write: oleds_show()
Esempio n. 6
0
def oleds_clear(bg):
  for oled in oleds:
    oled.fill(bg)
    oled.show()
  if lock_title: write_title()
Esempio n. 7
0
def oleds_clear(bg):
  for oled in oleds:
    oled.fill(bg)
    oled.show()