import ugfx, badge, random, time

badge.leds_enable()
ugfx.init()
ugfx.input_init()
ugfx.set_lut(ugfx.LUT_FULL)
ugfx.clear(ugfx.BLACK)
ugfx.flush()

def go_home(pushed):
    if pushed:
        badge.leds_send_data(bytes([0] * 24))
        badge.leds_disable()
        ugfx.set_lut(ugfx.LUT_FULL)
        ugfx.clear(ugfx.BLACK)
        ugfx.flush()
        ugfx.clear(ugfx.WHITE)
        ugfx.flush()
        import machine
        machine.deepsleep(1)

ugfx.input_attach(ugfx.BTN_START, go_home)
ugfx.orientation(90)
w, h, _, _ = badge.png_info('/lib/gotem/ok.png')
w_tot, h_tot = ugfx.width(), ugfx.height()
ugfx.set_lut(ugfx.GREYSCALE)
idx = 0
while True:
    badge.eink_busy_wait()
    badge.eink_png(h_tot - w, -5, '/lib/gotem/ok.png'.format(idx))
    ugfx.flush()
    time.sleep_ms(1000)
    badge.eink_png(h_tot - w, -5, '/lib/gotem/ko.png'.format(idx))
    ugfx.flush()
    idx += 1
    idx %= 24