import display
import buttons
from machine import Pin
from neopixel import NeoPixel
import mch22 
import os
import sys

powerPin = Pin(19, Pin.OUT)
dataPin = Pin(5, Pin.OUT)
np = NeoPixel(dataPin, 5)
powerPin.on()

np[0] = (255,255,255)
np[1] = (255,255,255)
np[2] = (255,255,255)
np[3] = (255,255,255)
np[4] = (255,255,255)

np.write()

display.drawFill(0xFFFFFF)
display.flush()

try:
  with open("/sd/apps/python/flashlight/hardware.bin", "rb") as f:
    mch22.fpga_load(f.read())  
except Exception as e:
  sys.print_exception(e)

try:
  with open("/apps/python/flashlight/hardware.bin", "rb") as f:
    mch22.fpga_load(f.read())  
except Exception as e:
  sys.print_exception(e)

def reboot(pressed):
  if pressed:
    mch22.exit_python()

buttons.attach(buttons.BTN_A,reboot)
buttons.attach(buttons.BTN_B,reboot)
buttons.attach(buttons.BTN_HOME,reboot)
buttons.attach(buttons.BTN_MENU,reboot)
buttons.attach(buttons.BTN_SELECT,reboot)
buttons.attach(buttons.BTN_START,reboot)