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 FailGame(this_game): ugfx.clear(ugfx.WHITE) ugfx.string(20, 50, "Game Over - Score: {}".format(this_game.snake.score), "PermanentMarker22", ugfx.BLACK) ugfx.flush() time.sleep(5) sys.exit(0)
def cuss(): ugfx.clear(ugfx.WHITE) #ugfx.string(0,0,"Hey, look at my c*ock!","PermanentMarker24",ugfx.BLACK) ## t = easyrtc.string() # n1 = random.getrandbits(2) # n2 = random.getrandbits(2) # n3 = random.getrandbits(2) #herp = len(first) herp = str(random.choice(first)) # ugfx.string(50, 10, str(first[n1]), "PermanentMarker24", ugfx.BLACK) # ugfx.string(70, 35, str(second[n1]), "PermanentMarker24", ugfx.BLACK) # ugfx.string(90, 60, str(third[n1]), "PermanentMarker24", ugfx.BLACK) ugfx.string(30, 5, str(random.choice(first)), "PermanentMarker36", ugfx.BLACK) ugfx.string(50, 30, str(random.choice(second)), "PermanentMarker36", ugfx.BLACK) ugfx.string(100, 55, str(random.choice(third)), "PermanentMarker36", ugfx.BLACK) # ugfx.string(110, 85, str(herp), "PermanentMarker24", ugfx.BLACK) ugfx.string(110, 85, " it's ", "PermanentMarker24", ugfx.BLACK) ugfx.string(130, 50, t, "PermanentMarker36", ugfx.BLACK) ugfx.flush() time.sleep(3) cuss()
def connectClick(pushed): if pushed: selected = options.selected_text().encode() print('selected') options.destroy() ssidType = scanResults[ssidList.index(selected)][4] print(ssidType) print(ssidList.index(selected)) ugfx.clear(ugfx.WHITE) ugfx.string(100, 50, selected, 'Roboto_Regular18', ugfx.BLACK) ugfx.flush() if ssidType == 5: clearGhosting() ugfx.clear(ugfx.WHITE) ugfx.string(20, 50, 'WPA Enterprise unsupported...', 'Roboto_Regular18', ugfx.BLACK) ugfx.set_lut(ugfx.LUT_FULL) ugfx.flush() badge.eink_busy_wait() system.reboot() badge.nvs_set_str("system", "wifi.ssid", selected) if ssidType == 0: badge.nvs_set_str("system", "wifi.password", '') system.reboot() else: clearGhosting() dialogs.prompt_text("WiFi password", cb=passInputDone)
def display_app(position): try: gui_apps[gui_app_current].draw(position) except BaseException as e: sys.print_exception(e) ugfx.string(5, position, "(" + gui_app_names[gui_app_current] + ")", "Roboto_Regular18", ugfx.BLACK)
def passInputDone(passIn): badge.nvs_set_str("system", "wifi.password", passIn) ugfx.clear(ugfx.WHITE) ugfx.string(100, 50, 'Restarting!', 'Roboto_Regular18', ugfx.BLACK) ugfx.flush() badge.eink_busy_wait() system.reboot()
def get_tweets(pushed): if (pushed): print("Downloading JSON...") gc.collect() try: data = requests.get("https://example/twitter.php") except: print("Could not download JSON!") sleep(1) return try: global tweets tweets = data.json() except: data.close() print("Could not decode JSON!") sleep(1) return data.close() print("Rendering list...") ugfx.clear(ugfx.WHITE) ugfx.flush() #get 1 tweet only, but possible to convert to scroll/something x = 1 tweet_text = str(tweets['statuses'][x]['text']) ugfx.string(45, 85, tweet_text, "Roboto_Black22", ugfx.BLACK) ugfx.flush()
def display_next(tweets,pressed): if (pressed): ugfx.clear(ugfx.WHITE) tweet_text = str(tweets[x]) ugfx.string(45,85,tweet_text,"Roboto_Black22",ugfx.BLACK) ugfx.flush() x=x+1
def display_logo(): ugfx.clear(ugfx.BLACK) ugfx.string(280, 228, 'v{}'.format(get_version()), 'IBMPlexSans_Regular12', ugfx.WHITE) ugfx.display_image(40, 70, bytearray(open('ibm_logo.gif', 'rb').read()), 2, 300) ugfx.string_box(0, 140, ugfx.width(), 50, 'Developer Day 2018', 'IBMPlexSans_Regular22', ugfx.HTML2COLOR(0x01d7dd), ugfx.justifyCenter) gc.collect()
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 draw_batterylow(percent): ugfx.clear(ugfx.WHITE) ugfx.string(0, 0, str(percent) + "% - BATTERY LOW, PLEASE CHARGE!", "Roboto_Regular12", ugfx.BLACK) #ugfx.string(0, 15, "BATTERY LOW! PLEASE CHARGE THE BATTERY!","Roboto_Regular12",ugfx.BLACK) nick = badge.nvs_get_str("owner", "name", "Hacker1337") ugfx.string(0, 40, nick, "PermanentMarker36", ugfx.BLACK) ugfx.set_lut(ugfx.LUT_FASTER) ugfx.flush()
def draw(entries): debug("Will now draw") y = 10 ugfx.clear(ugfx.WHITE) for entry in entries: extension = entry[0] name = entry[1] ugfx.string(10, y, extension + " -> " + name, "Roboto_Regular12", 0) y += 20 ugfx.flush() badge.eink_busy_wait()
def show_sponsors(): for x in range(1, 6): ugfx.clear(ugfx.WHITE) ugfx.flush() try: badge.eink_png(0, 0, '/lib/sponsors/sponsor%s.png' % x) except: ugfx.string(0, 0, "SPONSOR LOAD ERROR #" + str(x), "Roboto_Regular12", ugfx.BLACK) ugfx.flush() utime.sleep(4)
def start_app(pushed): if (pushed): ugfx.clear(ugfx.BLACK) ugfx.string(40, 25, "Running:", "Roboto_BlackItalic24", ugfx.WHITE) ugfx.string(100, 75, packages[options.selected_index()]["name"], "PermanentMarker22", ugfx.WHITE) ugfx.flush() selected = packages[options.selected_index()]["slug"] esp.rtcmem_write_string(selected) badge.eink_busy_wait() esp.start_sleeping(1)
def run_it(pushed): if (pushed): selected = options.selected_text() options.destroy() ugfx.clear(ugfx.BLACK) ugfx.string(40, 25, "Running:", "Roboto_BlackItalic24", ugfx.WHITE) ugfx.string(100, 75, selected, "PermanentMarker22", ugfx.WHITE) ugfx.flush() badge.eink_busy_wait() esp.rtcmem_write_string(selected) esp.start_sleeping(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 fill_screen_with_crap(c): print("Filling screen...") for i in range(0, 3): nr = int.from_bytes(uos.urandom(1), 1) sha = hashlib.sha1(str(nr)) s = ubinascii.hexlify(sha.digest()) for j in range(0, 8): x = 0 #int.from_bytes(uos.urandom(1), 1) y = int.from_bytes(uos.urandom(1), 1) if (x < ugfx.width()) and (y < ugfx.height()): ugfx.string(x, y, s + s + s, "Roboto_Regular12", c) ugfx.flush() print("done.")
def drawweather(r): dayweather = r.get("weatherday") xline = 106 xday = 115 xevening = 5 if (utime.localtime()[3] > 12): dayweather = dayweather[1] else: dayweather = dayweather[0] xline = 190 xevening = 199 xday = 5 ugfx.thickline(xline, 0, xline, 68, ugfx.BLACK, 3, 0) try: ugfx.string(xevening + 37, 6, "17:00", "DejaVuSans20", ugfx.BLACK) ugfx.string( xevening + 37, 38, str(int(r.get("weatherevening").get("precipProbability") * 100)) + "%", "DejaVuSans20", ugfx.BLACK) ugfx.string(xday + 37, 22, "WS:" + str(int(dayweather.get("windSpeed"))) + "mph", "DejaVuSans20", ugfx.BLACK) sunup = utime.localtime(int(dayweather.get("sunriseTime"))) sundown = utime.localtime(int(dayweather.get("sunsetTime"))) ugfx.string( xday + 37, 44, "S:" + str(sunup[3]) + ":" + str(sunup[4]) + "-" + str(sundown[3]) + ":" + str(sundown[4]), "DejaVuSans20", ugfx.BLACK) ugfx.string( xday + 37, 0, "Temp:" + str(int(dayweather.get("apparentTemperatureLow"))) + "-" + str(int(dayweather.get("apparentTemperatureHigh"))) + u"\u00b0" + "C", "DejaVuSans20", ugfx.BLACK) except: print("missing precip chance") first = "" second = "" try: first = weathericon(r.get("weatherevening"), xevening, 16) second = weathericon(dayweather, xday, 16) except: print("no weather") return (first, second)
def write_lock(): global ransom_id badge.nvs_set_str('boot', 'splash', 'ascii_porn') #Now you are the homescreen :P ugfx.clear(ugfx.WHITE) ugfx.string(15, 10, "SHA2017 - Ransomware", "Roboto_BlackItalic24", ugfx.BLACK) write(40, "Oh noes, your badge is being held hostage!") write(52, "Deliver a club mate to the Snowden field.") write(64, "We're in the first big tent to the left.") write(76, "Be sure to show us this ID: " + ransom_id) ugfx.input_attach(ugfx.BTN_START, attempt_unlock) ugfx.string(20, 100, "[PRESS START TO UNLOCK]", "Roboto_Regular18", ugfx.BLACK) ugfx.flush()
def scan(): global scroll, max_scroll, scanResults print("Scanning") ugfx.clear(ugfx.WHITE) ugfx.string(100,50,'Scanning...','Roboto_Regular18',ugfx.BLACK) ugfx.flush() sta_if = network.WLAN(network.STA_IF); sta_if.active(True) scanResults = sta_if.scan() sorted(scanResults, key=lambda net: net[3], reverse=True) max_scroll = len(scanResults) scroll = 0 re_draw()
def draw(y, sleep=False): print("> angelshifts draw") name = badge.nvs_get_str("engel", "shift_name", "") loc = badge.nvs_get_str("engel", "shift_loc", "") start = int(badge.nvs_get_str("engel", "shift_start", 0)) end = int(badge.nvs_get_str("engel", "shift_end", 0)) if name: time_text = generate_timedelta_text(start, end) ugfx.string(0, y - 14, "{}: {} @ {}".format(time_text, name, loc), "Roboto_Regular12", ugfx.BLACK) # ugfx.flush() return 60000, 14 else: return 120000, 0
def cuss(): t = easyrtc.string() ugfx.clear(ugfx.WHITE) #ugfx.string(x, y, string, font, colour) ugfx.string(10, 5, str(random.choice(first)), "PermanentMarker36", ugfx.BLACK) ugfx.string(30, 30, str(random.choice(second)), "PermanentMarker36", ugfx.BLACK) ugfx.string(100, 55, str(random.choice(third)), "PermanentMarker36", ugfx.BLACK) # ugfx.string(110, 85, str(herp), "PermanentMarker22", ugfx.BLACK) ugfx.string(30, 85, " it's ", "PermanentMarker22", ugfx.BLACK) ugfx.string(140, 85, t, "PermanentMarker36", ugfx.BLACK) ugfx.flush() time.sleep(3) cuss()
def attempt_unlock_secret_entered(secret): ugfx.clear(ugfx.WHITE) ugfx.string(15, 10, "SHA2017 - Ransomware", "Roboto_BlackItalic24", ugfx.BLACK) if secret == ransom_secret: badge.nvs_set_str('boot', 'splash', 'splash') write(40, "Dobby is free!") ugfx.flush() time.sleep(4) appglue.home() else: write(40, "INVALID RANSOM SECRET!") ugfx.flush() time.sleep(4) write_lock()
def show_temp(temperature): clear(ugfx.BLACK) ugfx.string(50, 25, "Sauna Finland PRKL", "Roboto_BlackItalic24", ugfx.WHITE) ugfx.string(100, 50, str(temperature) + " C", "Roboto_BlackItalic24", ugfx.WHITE) if temperature < 50: ugfx.string(70, 75, "Good for Swedes", "Roboto_BlackItalic24", ugfx.WHITE) elif temperature > 50 and temperature < 70: ugfx.string(70, 75, "Heat is up!", "Roboto_BlackItalic24", ugfx.WHITE) else: ugfx.string(70, 75, "Good for Finns!", "Roboto_BlackItalic24", ugfx.WHITE) ugfx.flush()
def draw_msg(msg): global line_number try: line_number except: line_number = 0 ugfx.clear(ugfx.WHITE) ugfx.string(0, 0, 'Still Loading Anyway...', "PermanentMarker22", ugfx.BLACK) ugfx.set_lut(ugfx.LUT_FASTER) draw_msg(msg) else: ugfx.string(0, 30 + (line_number * 15), msg, "Roboto_Regular12", ugfx.BLACK) ugfx.flush() line_number += 1
def loop(): print("> angelshifts loop") last_update = int(badge.nvs_get_str("engel", "update", "0")) print("last update: ", last_update) if api_key: # Perform update if update_interval has passed if last_update + update_interval < easyrtc.time.time(): print("angelshifts: updating...") wifi.init() tries = 0 while not wifi.sta_if.isconnected(): time.sleep(0.1) tries += 1 if tries >= wifi_tries: return wakeup_interval next_shift = get_next_shift(api_key) if next_shift: badge.nvs_set_str("engel", "shift_name", next_shift["name"]) badge.nvs_set_str("engel", "shift_loc", next_shift["Name"]) badge.nvs_set_str("engel", "shift_start", next_shift["start"]) badge.nvs_set_str("engel", "shift_end", next_shift["end"]) badge.nvs_set_u8("engel", "notified", 0) else: badge.nvs_set_str("engel", "shift_name", "") badge.nvs_set_str("engel", "update", str(easyrtc.time.time())) else: print("angelshifts: no update needed") # Notify about upcoming shift if it starts in less than notify_time if badge.nvs_get_str("engel", "shift_name", "") and not bool( badge.nvs_get_u8("engel", "notified")): start = int(badge.nvs_get_str("engel", "shift_start", "")) now = easyrtc.time.time() if start > now and start < now + notify_time: global notified badge.vibrator_init() badge.vibrator_activate(200) ugfx.string( 0, 0, "NEXT SHIFT IN {} MINUTES!".format(notify_time // 60), "PermanentMarker22", ugfx.BLACK) ugfx.flush() return wakeup_interval else: print("no api key set up") return 0
def draw(mode, goingToSleep=False): ugfx.orientation(0) 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 = '' def disp_string_right(y, s): l = ugfx.get_string_width(s, "Roboto_Regular12") ugfx.string(296 - l, y, s, "Roboto_Regular12", ugfx.BLACK) disp_string_right(0, info1) disp_string_right(12, info2) if badge.safe_mode(): disp_string_right(92, "Safe Mode - services disabled") disp_string_right(104, "Sleep disabled - will drain battery quickly") disp_string_right(116, "Press Reset button to exit") nickname() on_usb = pm.usb_attached() vBatt = badge.battery_volt_sense() vBatt += vDrop charging = badge.battery_charge_status() battery(on_usb, vBatt, charging) if vBatt > 500: ugfx.string(52, 0, str(round(vBatt / 1000, 1)) + 'v', 'Roboto_Regular12', ugfx.BLACK)
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 fire_gun(round, bullet): print(str('round ') + str(round) + str(' vs ') + str(bullet)) if bullet == round: ugfx.clear(ugfx.WHITE) badge.png(0, 0, '/lib/russian_roulette_9000/shot.png') ugfx.flush() time.sleep(4.0) ugfx.clear(ugfx.WHITE) ugfx.string(0, 30, lost_text, big_font, ugfx.BLACK) ugfx.flush() time.sleep(4.0) reset_game() else: ugfx.clear(ugfx.WHITE) ugfx.string(10, 20, click_text, big_font, ugfx.BLACK) ugfx.flush() time.sleep(1.0) print_start()
def draw_ship(self): ugfx.clear(ugfx.WHITE) ugfx.string(10, SCREEN_Y-15, "You are playing on a "+self.wrapper.name(), "RobotoRegular12", ugfx.BLACK) #ugfx.string(10, SCREEN_Y-28, "r: "+str(self.r), # "RobotoRegular12", ugfx.BLACK) #ugfx.string(10, SCREEN_Y-41, "y: "+str(self.y), # "RobotoRegular12", ugfx.BLACK) #ugfx.string(10, SCREEN_Y-54, "x: "+str(self.x), # "RobotoRegular12", ugfx.BLACK) self.draw_line(self.x+4*self.size, self.y, self.x-6*self.size, self.y-5*self.size) self.draw_line(self.x+4*self.size, self.y, self.x-6*self.size, self.y+5*self.size) self.draw_line(self.x-3*self.size, self.y, self.x-6*self.size, self.y-5*self.size) self.draw_line(self.x-3*self.size, self.y, self.x-6*self.size, self.y+5*self.size) ugfx.flush()