def on_oled_message(topic, payload_in): if payload_in == "(oled:clear)": oleds_clear(bg) 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()] for oled in oleds: oled.pixel(tokens[0], height - tokens[1] - 1, fg) oleds_show() return True if payload_in.startswith("(oled:text "): tokens = payload_in[11:-1].split() text = " ".join(tokens[2:]) oleds_text(text, int(tokens[0]), height - font_size - int(tokens[1]), fg) oleds_show() return True return False
def on_oled_message(topic, payload_in): if payload_in == "(oled:clear)": oleds_clear() return True if payload_in.startswith("(oled:log "): oleds_log(payload_in[10:-1]) return True if payload_in.startswith("(oled:pixel "): tokens = [int(token) for token in payload_in[12:-1].split()] for oled in oleds: oled.pixel(tokens[0], height - tokens[1] - 1, FG) oleds_show() return True # (oled:text x y message) if payload_in.startswith("(oled:text "): tokens = payload_in[11:-1].split() try: x = int(tokens[0]) y = height - font_size - int(tokens[1]) text = " ".join(tokens[2:]) oleds_text(text, x, y, FG) oleds_show() except Exception: print( "Error: Expected (oled.text x y message) where x and y are integers" ) return True return False