def lineSplit(message, width=None, font=version.font_default): words = message.split(" ") lines = [] line = "" if width == None: width = ugfx.width() for word in words: wordLength = ugfx.get_string_width(word, font) lineLength = ugfx.get_string_width(line, font) if wordLength > width: lines.append(line) lines.append(word) line = "" elif lineLength + wordLength < width: if (line == ""): line = word else: line += " " + word else: lines.append(line) line = word if len(line) > 0: lines.append(line) return lines
def draw(mode, goingToSleep=False): if mode: # We flush the buffer and wait ugfx.flush(ugfx.LUT_FULL) badge.eink_busy_wait() else: # We prepare the screen refresh ugfx.clear(ugfx.WHITE) if goingToSleep: info1 = 'Sleeping...' info2 = 'Press any key to wake up' else: info1 = 'Press start to open the launcher' if otac.available(False): info2 = 'Press select to start OTA update' else: info2 = '' l = ugfx.get_string_width(info1,"Roboto_Regular12") ugfx.string(296-l, 0, info1, "Roboto_Regular12",ugfx.BLACK) l = ugfx.get_string_width(info2,"Roboto_Regular12") ugfx.string(296-l, 12, info2, "Roboto_Regular12",ugfx.BLACK) easydraw.nickname() vUsb = badge.usb_volt_sense() vBatt = badge.battery_volt_sense() vBatt += vDrop charging = badge.battery_charge_status() easydraw.battery(vUsb, vBatt, charging) if vBatt>500: ugfx.string(52, 0, str(round(vBatt/1000, 1)) + 'v','Roboto_Regular12',ugfx.BLACK)
def cuss(): ## t = easyrtc.string() ugfx.clear(ugfx.WHITE) one = str(random.choice(first)) two = str(random.choice(second)) three = str(random.choice(third)) len1 = ugfx.get_string_width(one, "Roboto_BlackItalic24") len2 = ugfx.get_string_width(two, "PermanentMarker36") len3 = ugfx.get_string_width(three, "Roboto_BlackItalic24") ugfx.string_box(90, 0, len1, 24, one, "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) ugfx.string_box(40, 25, len2, 36, two, "PermanentMarker36", ugfx.BLACK, ugfx.justifyCenter) ugfx.string_box(90, 63, len3, 34, three, "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) ###ugfx.string(x, y, string, font, colour) #ugfx.string(20, 5, str(random.choice(first)), "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) #ugfx.string(30, 20, str(random.choice(second)), "PermanentMarker36", ugfx.BLACK) #len = ugfx.get_string_width(str(random.choice(second)),"PermanentMarker36") #ugfx.line(25, 57, 64 + len, 57, ugfx.BLACK) #ugfx.line(140 + len, 52, 140 + len, 70, ugfx.BLACK) #ugfx.string(120, 60, str(random.choice(third)), "Roboto_BlackItalic24", ugfx.BLACK) #ugfx.string(30, 95, " it's ", "PermanentMarker22", ugfx.BLACK) ## ugfx.string(140, 95, t, "PermanentMarker36", ugfx.BLACK) ugfx.flush() time.sleep(3)
def draw_logo(x, y, h): ugfx.string(x + 20, y, "STILL", "Roboto_BlackItalic24", ugfx.BLACK) ugfx.string(x, y + 25, h, "PermanentMarker22", ugfx.BLACK) len = ugfx.get_string_width(h, "PermanentMarker22") ugfx.line(x, y + 47, x + 14 + len, y + 47, ugfx.BLACK) ugfx.line(x + 10 + len, y + 27, x + 10 + len, y + 45, ugfx.BLACK) ugfx.string(x + 10, y + 50, "Anyway", "Roboto_BlackItalic24", ugfx.BLACK)
def show_names(): global names c = False for n in range(0, len(names)): color = ugfx.BLACK if (c): c = False else: c = True color = ugfx.WHITE fill_screen_with_crap(color) x = int.from_bytes(uos.urandom(1), 1) y = round(int.from_bytes(uos.urandom(1), 1) / 2) w = ugfx.get_string_width(names[n], "PermanentMarker22") if (x + w > ugfx.width()): x = x + w if (y > ugfx.height() - 22): y = ugfx.height() - 22 if (x == 0): x = 1 if (y == 0): y = 1 print("NAME AT " + str(x) + ", " + str(y)) draw_name(x, y, names[n]) time.sleep(1)
def show_shift_detail(): global shifts global shift_list shift_list.visible(False) ugfx.clear(ugfx.WHITE) ugfx.flush() i = shift_list.selected_index() title = shifts[i]["name"] title_height = 20 if ugfx.get_string_width( title, "PermanentMarker22") <= ugfx.width() else 60 title = ugfx.string_box(0, 0, ugfx.width(), title_height, title, "PermanentMarker22", ugfx.BLACK, ugfx.justifyCenter) location = ugfx.string(0, title_height + 5, "Location: " + shifts[i]["Name"], "Roboto_Regular18", ugfx.BLACK) description = ugfx.string_box(0, title_height + 25, ugfx.width(), 40, "Description: " + shifts[i]["title"], "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) time = ugfx.string( 0, ugfx.height() - 20, "Time: " + generate_timedelta_text( int(shifts[i]["start"]), int(shifts[i]["end"])), "Roboto_Regular18", ugfx.BLACK) ugfx.flush() ugfx.input_attach(ugfx.BTN_B, lambda pressed: show_shift_list() if pressed else None)
def wait_sauna(): clear(ugfx.BLACK) ugfx.string(50, 25, "STILL", "Roboto_BlackItalic24", ugfx.WHITE) ugfx.string(30, 50, "Connecting to sauna", "PermanentMarker22", ugfx.WHITE) len = ugfx.get_string_width("Connecting to sauna", "PermanentMarker22") ugfx.line(30, 72, 30 + 14 + len, 72, ugfx.WHITE) ugfx.string(140, 75, "Anyway", "Roboto_BlackItalic24", ugfx.WHITE) ugfx.flush()
def start(): ugfx.input_init() ugfx.set_lut(ugfx.LUT_FASTER) ugfx.clear(ugfx.BLACK) ugfx.flush() ugfx.clear(ugfx.WHITE) ugfx.flush() ugfx.string_box(148, 0, 148, 26, "STILL", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) ugfx.string_box(148, 23, 148, 23, "Hacking", "PermanentMarker22", ugfx.BLACK, ugfx.justifyCenter) ugfx.string_box(148, 48, 148, 26, "Anyway", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) #the line under the text str_len = ugfx.get_string_width("Hacking", "PermanentMarker22") line_begin = 148 + int((148 - str_len) / 2) line_end = str_len + line_begin ugfx.line(line_begin, 46, line_end, 46, ugfx.BLACK) #the cursor past the text cursor_pos = line_end + 5 ugfx.line(cursor_pos, 22, cursor_pos, 44, ugfx.BLACK) # Instructions ugfx.line(148, 78, 296, 78, ugfx.BLACK) ugfx.string_box(148, 78, 148, 18, " A: Run", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.string_box(148, 78, 148, 18, " B: Return to home", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyRight) ugfx.string_box(148, 92, 148, 18, " SELECT: Uninstall", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.line(148, 110, 296, 110, ugfx.BLACK) ugfx.string_box(148, 110, 148, 18, " " + version.name, "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) global options global install_path options = None install_path = None ugfx.input_attach(ugfx.BTN_A, input_a) ugfx.input_attach(ugfx.BTN_B, input_b) ugfx.input_attach(ugfx.BTN_SELECT, input_select) ugfx.input_attach(ugfx.JOY_UP, input_other) ugfx.input_attach(ugfx.JOY_DOWN, input_other) ugfx.input_attach(ugfx.JOY_LEFT, input_other) ugfx.input_attach(ugfx.JOY_RIGHT, input_other) ugfx.input_attach(ugfx.BTN_START, input_other) populate_apps() populate_category() populate_options() ugfx.flush(ugfx.LUT_FULL)
def program_main(): ugfx.init() ugfx.clear(ugfx.WHITE) badge.leds_init() try: badge.eink_png(0, 0, logo_path) except: log('+ Failed to load graphics') # Name tag ugfx.string(ugfx.width() - ugfx.get_string_width(name, fonts[1]), ugfx.height() - 36, name, fonts[1], ugfx.BLACK) # Button info ugfx.string(0, ugfx.height() - 13, '[FLASH to update] [B to exit]', fonts[2], ugfx.BLACK) ugfx.flush() ugfx.input_init() ugfx.input_attach(ugfx.BTN_B, lambda pressed: exit_app()) ugfx.input_attach(ugfx.BTN_FLASH, lambda pressed: start_self_update()) HOST = "chat.freenode.net" PORT = 6667 NICK = name + "[luv]" REALNAME = name + ' @ SHA2017' log('+ waiting for network...') wifi.init() while not wifi.sta_if.isconnected(): time.sleep(0.1) s = socket.socket() s.connect((HOST, PORT)) s.send(bytes("NICK %s\r\n" % NICK, "UTF-8")) s.send(bytes("USER %s 0 * :%s\r\n" % (NICK, REALNAME), "UTF-8")) s.send(bytes("JOIN #sha2017\r\n", "UTF-8")) # IRC Client while True: line = s.readline().rstrip() parts = line.split() if parts: if (parts[0] == b"PING"): s.send(bytes("PONG %s\r\n" % line[1], "UTF-8")) blink_led(green) if (parts[1] == b"PRIVMSG"): blink_led(red) msg = b' '.join(parts[3:]) rnick = line.split(b'!')[0] log(b'%s: %s' % (rnick, msg))
def wait_wifi(): clear(ugfx.BLACK) ugfx.string(50, 25, "STILL", "Roboto_BlackItalic24", ugfx.WHITE) ugfx.string(30, 50, "Connecting to wifi", "PermanentMarker22", ugfx.WHITE) len = ugfx.get_string_width("Connecting to wifi", "PermanentMarker22") ugfx.line(30, 72, 30 + 14 + len, 72, ugfx.WHITE) ugfx.string(140, 75, "Anyway", "Roboto_BlackItalic24", ugfx.WHITE) ugfx.flush() while not wifi.sta_if.isconnected(): time.sleep(0.1)
def nickname(y=0, font=version.font_nickname_large, color=ugfx.BLACK, lineHeight=15): nick = badge.nvs_get_str("owner", "name", 'WELCOME TO HACKERHOTEL') lines = lineSplit(nick, ugfx.width(), font) for i in range(len(lines)): line = lines[len(lines) - i - 1] pos_x = int((ugfx.width() - ugfx.get_string_width(line, font)) / 2) ugfx.string(pos_x, y + lineHeight * (len(lines) - i - 1), line, font, color) return len(lines) * lineHeight
def cuss(): ## t = easyrtc.string() ugfx.clear(ugfx.WHITE) herp = str(random.choice(first)) ###ugfx.string(x, y, string, font, colour) ugfx.string(10, 5, str(random.choice(first)), "Roboto_BlackItalic24", ugfx.BLACK) ugfx.string(30, 25, str(random.choice(second)), "PermanentMarker36", ugfx.BLACK) len = ugfx.get_string_width(str(random.choice(second)),"PermanentMarker36") ugfx.line(25, 59, 72 + len, 59, ugfx.BLACK) ugfx.string(135, 68, str(random.choice(third)), "Roboto_BlackItalic24", ugfx.BLACK) # ugfx.string(110, 85, str(herp), "PermanentMarker22", ugfx.BLACK) ugfx.string(30, 95, " it's ", "PermanentMarker22", ugfx.BLACK) ## ugfx.string(140, 85, t, "PermanentMarker36", ugfx.BLACK) ugfx.flush() time.sleep(3)
def get_days(): url = 'http://192.168.178.16:5000/' r = requests.get(url) data = r.json() xpos = 0 weekday = utime.localtime()[6] for index, day_data in enumerate(data): if index == 4: break ypos = 0 text = WEEKDAYS[weekday] twidth = ugfx.get_string_width(text, FONT) ugfx.string(xpos, ypos, text, FONT, ugfx.BLACK) ypos += 22 iconcode = day_data['iconcode'] icon = BUIENRADAR_ICONS.get(iconcode) # Add xpos a bit since icons are weird ugfx.string(xpos + 10, ypos, icon, "weather42", ugfx.BLACK) # Min / Max / Rain ypos += 44 text = str(int(day_data['maxtemp'])) + 'C' ugfx.string(xpos, ypos, text, FONT, ugfx.BLACK) ypos += 20 text = str(int(day_data['mintemp'])) + 'C' ugfx.string(xpos, ypos, text, FONT, ugfx.BLACK) ypos += 20 text = str(int(day_data['precipitation'])) + 'mm' ugfx.string(xpos, ypos, text, FONT, ugfx.BLACK) xpos += twidth + 24 if weekday == 7: weekday = 1 else: weekday += 1
def draw(r): # Rows: 32 infoLine = None try: title = r.get("dates").get("summary") time = r.get("dates").get("start").get("dateTime")[11:16] infoLine = time + " - " + title except: print("no cal") try: if infoLine is None: infoLine = r.get("news") except: print("no news") try: if infoLine is None: infoLine = r.get("other") except: print("no other") if infoLine is not None: font = "DejaVuSans20" if (ugfx.get_string_width(infoLine, "DejaVuSans20") > 592): font = "Roboto_Regular12" firstLine = infoLine while (ugfx.get_string_width(firstLine, font) > 296): firstLine = firstLine[:-1] secondLine = None # Check for second line if len(firstLine) != len(infoLine): secondLine = infoLine[len(firstLine):] while (ugfx.get_string_width(secondLine, font) > 296): secondLine = secondLine[:-1] if font == "Roboto_Regular12": ugfx.string(2, 82, secondLine, font, ugfx.BLACK) else: ugfx.string(2, 90, secondLine, font, ugfx.BLACK) # Third line if font == "Roboto_Regular12": if (len(firstLine) + len(secondLine)) != len(infoLine): ugfx.string(2, 94, infoLine[len(firstLine) + len(secondLine):], font, ugfx.BLACK) singleLineOffset = 0 if secondLine is None: singleLineOffset += 10 ugfx.string(2, 70 + singleLineOffset, firstLine, font, ugfx.BLACK) try: ugfx.string(2, 110, "£" + str(r.get("bank")), "DejaVuSans20", ugfx.BLACK) except: print("no balance") ugfx.thickline(0, 68, 296, 68, ugfx.BLACK, 3, 0) boxes = drawweather(r) ugfx.flush() try: boxes[0].destroy() boxes[1].destroy() except: print("no weather")
if nick: badge.nvs_set_str("owner", "name", nick) #Nice clean screen ugfx.clear(ugfx.BLACK) ugfx.flush() ugfx.clear(ugfx.WHITE) ugfx.flush() ugfx.string_box(0, 10, 296, 26, "STILL", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) ugfx.string_box(0, 45, 296, 38, nick, "PermanentMarker36", ugfx.BLACK, ugfx.justifyCenter) ugfx.string_box(0, 94, 296, 26, "Anyway", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) #the line under the text str_len = ugfx.get_string_width(nick, "PermanentMarker36") line_begin = int((296 - str_len) / 2) line_end = str_len + line_begin ugfx.line(line_begin, 83, line_end, 83, ugfx.BLACK) #the cursor past the text cursor_pos = line_end + 5 ugfx.line(cursor_pos, 46, cursor_pos, 81, ugfx.BLACK) ugfx.flush(ugfx.LUT_FULL) import deepsleep, badge badge.eink_busy_wait() deepsleep.start_sleeping(60000)
def lineCentered(pos_y, line, font, color): pos_x = int((ugfx.width() - ugfx.get_string_width(line, font)) / 2) ugfx.string(pos_x, pos_y, line, font, color)
def disp_string_right_bottom(y, s): l = ugfx.get_string_width(s, version.font_default) ugfx.string(ugfx.width() - l, ugfx.height() - (y + 1) * 14, s, version.font_default, ugfx.BLACK)
ugfx.init() ugfx.clear(ugfx.BLACK) ugfx.fill_circle(60, 60, 50, ugfx.WHITE) ugfx.fill_circle(60, 60, 40, ugfx.BLACK) ugfx.fill_circle(60, 60, 30, ugfx.WHITE) ugfx.fill_circle(60, 60, 20, ugfx.BLACK) ugfx.fill_circle(60, 60, 10, ugfx.WHITE) ugfx.thickline(1, 1, 100, 100, ugfx.WHITE, 10, 5) ugfx.box(30, 30, 50, 50, ugfx.WHITE) ugfx.string(150, 25, "STILL", "Roboto_BlackItalic24", ugfx.WHITE) ugfx.string(130, 50, "Hacking", "PermanentMarker22", ugfx.WHITE) len = ugfx.get_string_width("Hacking", "PermanentMarker22") ugfx.line(130, 72, 144 + len, 72, ugfx.WHITE) ugfx.line(140 + len, 52, 140 + len, 70, ugfx.WHITE) ugfx.string(140, 75, "Anyway", "Roboto_BlackItalic24", ugfx.WHITE) ugfx.flush() def render(text, pushed): if (pushed): ugfx.string(100, 10, text, "PermanentMarker22", ugfx.WHITE) else: ugfx.string(100, 10, text, "PermanentMarker22", ugfx.BLACK) ugfx.flush()
def disp_string_right(y, s): l = ugfx.get_string_width(s, "Roboto_Regular12") ugfx.string(296 - l, y, s, "Roboto_Regular12", ugfx.BLACK)
def get_string_width(string, font_id): return ugfx.get_string_width(string, font_types[font_id][0])
ugfx.input_attach(ugfx.JOY_DOWN, dec_brightness) ugfx.input_attach(ugfx.JOY_LEFT, dec_decay) # same here ugfx.input_attach(ugfx.JOY_RIGHT, inc_decay) ugfx.input_attach(ugfx.BTN_A, larson_mode_next) ugfx.input_attach(ugfx.BTN_B, larson_mode_prev) ugfx.input_attach(ugfx.BTN_START, home) ugfx.input_attach(ugfx.BTN_SELECT, home) ugfx.clear(ugfx.BLACK) ugfx.flush() ugfx.clear(ugfx.WHITE) ugfx.flush() ugfx.string(190, 7, "STILL", "Roboto_BlackItalic24", ugfx.BLACK) ugfx.string(170, 32, name, "PermanentMarker22", ugfx.BLACK) length = ugfx.get_string_width(name, "PermanentMarker22") ugfx.line(170, 54, 184 + length, 54, ugfx.BLACK) ugfx.line(180 + length, 34, 180 + length, 54, ugfx.BLACK) ugfx.string(180, 57, "Anyway", "Roboto_BlackItalic24", ugfx.BLACK) ugfx.string(177, 88, "Mode: A/B, Tail: L/R", "Roboto_Regular12", ugfx.BLACK) ugfx.string(177, 101, "Brightness: UP/DOWN", "Roboto_Regular12", ugfx.BLACK) ugfx.string(215, 116, "Larson Pride", "Roboto_Regular10", ugfx.BLACK) ugfx.string(279, 116, LARSON_VERSION, "Roboto_Regular10", ugfx.BLACK) ugfx.flush() current_color_map = settings_get_color_map() show_scanner() while True: scanner.draw()