import ugfx, badge
from machine import I2C, Pin

i2c=I2C(sda=Pin(26), scl=Pin(27), freq=100000)

ugfx.init()
ugfx.LUT_FULL
ugfx.input_init()
ugfx.clear(ugfx.BLACK)
ugfx.flush()
ugfx.clear(ugfx.WHITE)
ugfx.flush()

def go_home(pushed):
    if pushed:
        import machine
        machine.deepsleep(1)

def invert(pushed):
  	if pushed:
	  	ugfx.clear(ugfx.BLACK)
	  	badge.eink_png(16,16, '/lib/tilde/tilde_invert.png')
	  	ugfx.orientation(90)
      	ugfx.string_box(0,220,128,26, badge.nvs_get_str("owner", "name", 'Tilde'), "Roboto_Black22", ugfx.WHITE, ugfx.justifyCenter)
      	ugfx.flush()

ugfx.input_attach(ugfx.BTN_B, go_home)
ugfx.input_attach(ugfx.BTN_A, invert)

badge.eink_png(16,16, '/lib/tilde/tilde.png')

ugfx.orientation(90)
ugfx.string_box(0,220,128,26, badge.nvs_get_str("owner", "name", 'Tilde'), "Roboto_Black22", ugfx.BLACK, ugfx.justifyCenter)
ugfx.flush()

i2c.writeto(65, b'\x01\x00')