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 usb_attached(): try: import badge return badge.usb_volt_sense() > 4500 except: return False
def usb_attached(): return badge.usb_volt_sense() > 4500
ugfx.input_attach(ugfx.JOY_UP, splash_input_other) ugfx.input_attach(ugfx.JOY_DOWN, splash_input_other) ugfx.input_attach(ugfx.JOY_LEFT, splash_input_other) ugfx.input_attach(ugfx.JOY_RIGHT, splash_input_other) # Power management def onSleep(idleTime): draw(False, True) services.force_draw(True) draw(True, True) ### PROGRAM # Calibrate battery voltage drop if badge.battery_charge_status() == False and badge.usb_volt_sense() > 4500 and badge.battery_volt_sense() > 2500: badge.nvs_set_u16('splash', 'bat.volt.drop', 5200 - badge.battery_volt_sense()) # mV print('Set vDrop to: ' + str(4200 - badge.battery_volt_sense())) vDrop = badge.nvs_get_u16('splash', 'bat.volt.drop', 1000) - 1000 # mV splash_input_init() splash_about_countdown_reset() # post ota script import post_ota setupState = badge.nvs_get_u8('badge', 'setup.state', 0) if setupState == 0: #First boot print("[SPLASH] First boot (start setup)...") appglue.start_app("setup") elif setupState == 1: # Second boot: Show sponsors
neopixel.send(bytes([0xFF, 0xFF, 0xFF]*12)) else: neopixel.send(bytes([0, 0, 0]*12)) buttons.attach(buttons.BTN_A, toggleLeds) def draw(vbatt, vusb): display.drawFill(0x000000) display.drawText(0,0,"Battery") display.drawText(0,15,"USB") display.drawText(50,0,str(vbatt)+"v") display.drawText(50,15,str(vusb)+"v") dataPoints.pop(0) dataPoints.append(round(vbatt*8)) for i in range(64): display.drawPixel(i,display.height()-1-dataPoints[i],0xFFFFFF) dataPoints2.pop(0) dataPoints2.append(round(vusb*8)) for i in range(64): display.drawPixel(64+i,display.height()-1-dataPoints2[i],0xFFFFFF) display.flush() while True: vbatt = badge.battery_volt_sense()/1000.0 vusb = badge.usb_volt_sense()/1000.0 draw(vbatt, vusb) time.sleep(0.1)