Example #1
0
 def editCPS(self):
     self.encoder_state_machine.set(value=self.cps * 10,
                                    min_val=100,
                                    max_val=200,
                                    range_mode=Rotary.RANGE_WRAP)
     self.tft.clear()
     text = "Set CPS"
     self.__textWrapper(67, 110, text)
     time.sleep(1.0)
     while True:
         self.cps = self.encoder_value / 100
         text = "CPS:   {}\r".format(round(self.cps, 2))
         self.__textWrapper(67, 130, text, 0xec7d15)
         if not self.pin_menu.value():
             print(self.pin_menu.value())
             break
         time.sleep(0.1)
     machine.nvs_setint("cps", int(self.cps * 100))
     self.encoder_state_machine.set(value=0,
                                    min_val=0,
                                    max_val=2,
                                    range_mode=Rotary.RANGE_WRAP)
     self.tft.clear()
     self.edit_cps = False
     self.pin_menu.init(trigger=machine.Pin.IRQ_FALLING,
                        handler=self.switchState)
Example #2
0
def setbrightness(brightness=(MAX_BRIGHTNESS - 2)):
    brightness = 1 if brightness < 1 else (MAX_BRIGHTNESS if brightness > MAX_BRIGHTNESS else brightness)
    hub75.brightness(brightness)

    # Allow non-visible brightness, but don't make it persistent across reboot
    if brightness >= 3:
        machine.nvs_setint('system', 'brightness', brightness)
Example #3
0
def input_down(pressed):
    global current_index

    pm.feed()
    if pressed:
        current_index = (current_index + 1) % len(apps)
        machine.nvs_setint('launcher', 'index', current_index)
        render_current_app()
Example #4
0
def save_current_mode(mode, calls=0):
    """TODO: Docstring for save_current_mode.

    :mode: TODO
    :returns: TODO

    """
    print("Saving current mode: {}".format(mode))
    machine.nvs_setint('current_mode', mode)
Example #5
0
 def __setCoffeGrindTime(self, pin):
     """Interrupt routine for set timer"""
     self.update_display = True
     if self.state == 0:
         self.single_sec = self.seconds / 10
         self.print_s = self.single_sec
         machine.nvs_setint("single_sec", int(self.seconds))
     elif self.state == 1:
         self.double_sec = self.seconds / 10
         self.print_s = self.double_sec
         machine.nvs_setint("double_sec", int(self.seconds))
def next_check():
    if(len(checklist) == 0):
        rgb.clear()
        rgb.background((0, 50, 0))
        rgb.text("Done!", CYAN, (4, 1))
        machine.nvs_setint('system', 'factory_checked', 3)
        return

    background, textcolor, x_pos, text, gpio = checklist.pop(0)
    rgb.clear()
    rgb.background(background)
    rgb.text(text, textcolor, (x_pos, 1))

    buttons.register(gpio, lambda pressed, gpio=gpio: (buttons.unassign(gpio), next_check()) if not pressed else None)
def available(update=False):
    if update:
        if not wifi.status():
            wifi.connect()
            if not wifi.wait():
                return machine.nvs_getint('system', 'OTA.ready') or 0

        info = download_info()
        current_build = int(consts.INFO_FIRMWARE_BUILD)
        if info:
            if info["build"] > current_build:
                machine.nvs_setint('system', 'OTA.ready', 1)
                return True

        machine.nvs_setint('system', 'OTA.ready', 0)
    return machine.nvs_getint('system', 'OTA.ready') or 0
Example #8
0

system.start = hijacked_start

## Make badge sleep in undervoltage conditions
virtualtimers.activate(1000)  # low resolution needed


def _vcc_callback():
    try:
        vcc = system.get_vcc_bat()
        if vcc != None:
            if vcc < 3300:
                __import__('deepsleep')
                deepsleep.vcc_low()
    finally:
        # Return 10000 to start again in 10 seconds
        gc.collect()
        return 10000


virtualtimers.new(10000, _vcc_callback, hfpm=True)

## Dirty fix for upgrade path of existing CZ19 badges
if machine.nvs_getint("system", 'factory_checked') == 1:
    machine.nvs_setint("system", 'factory_checked', 2)

del folders, uos
gc.collect()
gc.mem_free()
Example #9
0
import machine, display, time, system, consts, easydraw, network, neopixel, mpr121, sndmixer, identification

PREV_TGT = 2
CURR_TGT = 3

# 1) Introduction
currentState = machine.nvs_getint('system', 'factory_checked') or 0

if currentState >= PREV_TGT:
    machine.nvs_setint('system', 'factory_checked', CURR_TGT)
    system.home()

easydraw.messageCentered(
    "FACTORY\n" + consts.INFO_FIRMWARE_NAME + "\nBuild " +
    str(consts.INFO_FIRMWARE_BUILD), True)
display.flush()
time.sleep(1.5)

# 2) Determine badge type
easydraw.messageCentered(identification.getName(), True)
display.flush()
time.sleep(3)

# 3) Calibrate the MPR121
import _mpr121calib

# 4) Make sure that WiFi works
easydraw.messageCentered("WiFi\nScanning...", True)
display.flush()
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
Example #10
0
	def onTelnetChange(self, value):
		machine.nvs_setint("telnetEnabled", value and 1 or 0)
    buttons.register(defines.BTN_UP, input_up)
    buttons.register(defines.BTN_DOWN, input_down)
    buttons.register(defines.BTN_LEFT, input_left)
    buttons.register(defines.BTN_RIGHT, input_right)

    populate_apps()
    render_current_app()


start()
init_power_management()

# Install CZ countdown app to replace activities app
if not machine.nvs_getint('system', 'czcount_inst'):
    import uinterface
    if uinterface.connect_wifi():
        import woezel
        uinterface.loading_text('Installing CZ20 countdown')
        if woezel.is_installed('campzone_2020_countdown') or woezel.install(
                'campzone_2020_countdown'):
            machine.nvs_setint('system', 'czcount_inst', 1)
            system.reboot()
        else:
            rgb.clear()
            uinterface.skippabletext('Installation failed')

    render_current_app()

menu = term_menu.UartMenu(deepsleep.start_sleeping, pm)
menu.main()
    rgb.framerate(3)
    rgb.gif(data, (12, 0), size, frames)

    del data, size, frames, animation_connecting_wifi
    gc.collect()
    wifi.wait()
    wifi.connect()
    wifi.wait()

    if not wifi.status():
        data, frames = icon_no_wifi
        rgb.gif(data, (12, 0), (8, 8), frames)
        time.sleep(3)
        system.reboot()
    ###

    rgb.clear()
    rgb.framerate(20)
    uinterface.loading_text('Installing %s' % to_install)
    del icon_no_wifi
    gc.collect()
    if woezel.install(to_install):
        # Reset launcher's selected index to newly installed app
        machine.nvs_setint('launcher', 'index', 0)
        rgb.clear()
        uinterface.skippabletext('Install succeeded')
    else:
        rgb.clear()
        uinterface.skippabletext('Failed to install "%s"' % to_install)

    system.reboot()
Example #13
0
        try:
            #Use the START button if available
            recovery_button = buttons.BTN_START
        except:
            #Else use the B button
            recovery_button = buttons.BTN_B
        __chk_recovery = machine.wake_reason() == (
            7, 0) and buttons.value(recovery_button)
    except:
        pass

#Application starting
if __chk_recovery:
    app = "dashboard.recovery"
elif machine.nvs_getint('system', 'force_sponsors'):
    machine.nvs_setint('system', 'force_sponsors', 0)
    system.start("sponsors_disobey_2020")
else:
    app = rtc.read_string()
    if not app:
        if not machine.nvs_getint("system", 'factory_checked') == 2:
            app = "factory_checks"
        else:
            app = machine.nvs_getstr("system", 'default_app')
            if not app:
                app = 'dashboard.home'

if app and not app == "shell":
    try:
        print("Starting app '%s'..." % app)
        system.__current_app__ = app
import tasks.otacheck as otacheck, term, system, time, version, wifi, machine, consts

current_build = int(consts.INFO_FIRMWARE_BUILD)
current_name = consts.INFO_FIRMWARE_NAME

term.header(True, "Update check")
print("Checking for updates...")
print("")
print("Currently installed:", current_name,
      "(Build " + str(current_build) + ")")

print("Current version:", "Update check", True)
print(str(current_build) + ") " + current_name)
available = 0

machine.nvs_setint('badge', 'OTA.ready', 0)


def start(pressed):
    if pressed:
        system.ota()


if not wifi.status():
    wifi.connect()
    if not wifi.wait():
        print("Error: could not connect to WiFi!")

title = "Update check"
message = "?? Unknown state ??"
import machine, display, time, system, consts, easydraw, network

PREV_TGT = 2
CURR_TGT = 3

# 1) Introduction
currentState = machine.nvs_getint('system', 'factory_checked') or 0

if currentState >= PREV_TGT:
    machine.nvs_setint('system', 'factory_checked', CURR_TGT)
    system.home()

easydraw.messageCentered("FACTORY\n"+consts.INFO_FIRMWARE_NAME+"\nBuild "+str(consts.INFO_FIRMWARE_BUILD), True)
display.flush()
time.sleep(2)

# 2) Make sure that WiFi works
easydraw.messageCentered("WiFi\nScanning...", True)
display.flush()
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
data = sta_if.scan()
if len(data) > 0:
	easydraw.messageCentered("WiFi\nFound {}".format(len(data)), True)
	display.flush()
	for item in data:
		print("SSID: {}, BSSID: {}. CHANNEL: {}, RSSI: {}, AUTHMODE: {} / {}, HIDDEN: {}".format(item[0], item[1], item[2], item[3], item[4], item[5], item[6]))
else:
	easydraw.messageCentered("WiFi\nNo network!", True)
	while True:
		time.sleep(1) #Sleep forever
Example #16
0
def _set_last_updated():
    try:
        return machine.nvs_setint('system', 'lastUpdate', int(time.time()))
    except:
        pass
Example #17
0
	def onFTPChange(self, value):
		machine.nvs_setint("ftpEnabled", value and 1 or 0)
Example #18
0
def _show_progress(text, error=False):
    if error:
        machine.nvs_setint('system', 'lastUpdate', 0)

    if callable(_progress_callback):
        _progress_callback(text, error)
Example #19
0
import machine

tz = machine.RTC().timezone()
print("Default timezone:", tz)

machine.nvs_setint('system', 'factory_checked',
                   1)  # We have completed the factory script
Example #20
0
ulp_pulse_count = ULP_MEM_BASE + 0
ulp_debounce = ULP_MEM_BASE + 4

machine.Pin(4, machine.Pin.IN, machine.Pin.PULL_UP)
pin21 = machine.Pin(21, machine.Pin.OUT)

print("\nLoading ULP...\n")

binary = src_to_binary(source)

ulp = machine.ULP()
ulp.set_wakeup_period(0, 100)  # use timer0, wakeup after ~100us
ulp.load_binary(load_addr, binary)

if machine.nvs_getint('pulse_count_nv') == None:
    machine.nvs_setint('pulse_count_nv', 0)

init_count = machine.nvs_getint('pulse_count_nv')

pulse_count = init_count  # init pulse counts
pulse_gen_count = init_count
mem32[ulp_pulse_count] = init_count

mem32[ulp_debounce] = 3  # 3 sample debounce

ulp.run(entry_addr)

print("\n\nPulse Count Test: \n----------------- \n")

while True:
    pulse_countL = mem32[ulp_pulse_count] & ULP_DATA_MASK
            legacy_mpr5 = machine.nvs_get_u16("badge", "mpr121.base.5")
            legacy_mpr6 = machine.nvs_get_u16("badge", "mpr121.base.6")
            legacy_mpr7 = machine.nvs_get_u16("badge", "mpr121.base.7")
            machine.nvs_set_u16("system", "mpr121.base.0", legacy_mpr0)
            machine.nvs_set_u16("system", "mpr121.base.1", legacy_mpr1)
            machine.nvs_set_u16("system", "mpr121.base.2", legacy_mpr2)
            machine.nvs_set_u16("system", "mpr121.base.3", legacy_mpr3)
            machine.nvs_set_u16("system", "mpr121.base.4", legacy_mpr4)
            machine.nvs_set_u16("system", "mpr121.base.5", legacy_mpr5)
            machine.nvs_set_u16("system", "mpr121.base.6", legacy_mpr6)
            machine.nvs_set_u16("system", "mpr121.base.7", legacy_mpr7)
        except:
            print("Unable to move MPR121 calibration!")
            import _mpr121calib
    else:
        print("Badge has been freshly installed!")
        import _mpr121calib
    try:
        # Remove old settings from NVS
        machine.nvs_erase_all("badge")
    except:
        pass

if currentState < 3:
    import dashboard.resources.png_icons as icons
    icons.install()

# We have completed the factory script
machine.nvs_setint('system', 'factory_checked', 3)
system.home()
Example #22
0
import machine

machine.nvs_setint('system', 'splash_played', 1)

try:
    import display, audio, keypad, time, system

    audio.play('/cache/boot/splash.mp3')
    sleeptime = 0.25

    for _ in range(2):
        for i in range(7, 3, -1):
            display.drawFill(0x00)
            x, y = keypad.index_to_coords(i)
            display.drawPixel(x, y, 0x707070)
            x, y = keypad.index_to_coords(15 - i)
            display.drawPixel(x, y, 0x707070)
            display.flush()
            time.sleep(sleeptime)

        for i in range(0, 4):
            display.drawFill(0x00)
            x, y = keypad.index_to_coords(i)
            display.drawPixel(x, y, 0x707070)
            x, y = keypad.index_to_coords(15 - i)
            display.drawPixel(x, y, 0x707070)
            display.flush()
            time.sleep(sleeptime)

    for i in range(4):
        display.drawFill(0x00)
Example #23
0
	def onWiFiChange(self, value):
		machine.nvs_setint("wifiEnabled", value and 1 or 0)
		self.wlan.active(value)
Example #24
0
def set_last_updated():
    try:
        return machine.nvs_setint('activities', 'lastUpdate',
                                  int(utime.time()))
    except:
        pass
    def tpcalib(self, save=False):
        if self.tft.getTouchType() == self.tft.TOUCH_XPT:
            self.tft.orient(display.TFT.LANDSCAPE)
        elif self.tft.getTouchType() == self.tft.TOUCH_STMPE:
            self.tft.orient(display.TFT.PORTRAIT)
        else:
            print("Touch not configured")
            return

        dispx, dispy = self.tft.screensize()
        
        self.tft.font(self.tft.FONT_Default, rotate=0, fixedwidth=False)
        self.tft.text(self.tft.CENTER,40,"Touch yellow point and release", self.tft.GREEN)
        self.tft.text(self.tft.CENTER,60,"Repeat for all calibration points", self.tft.GREEN)
        
        self.tft.font(self.tft.FONT_Default, rotate=0, fixedwidth=True)
        self.drawCrossHair(dispx-11, 10, self.tft.WHITE)
        self.drawCrossHair(dispx//2, 10, self.tft.WHITE)
        self.drawCrossHair(10, 10, self.tft.WHITE)
        self.drawCrossHair(dispx-11, dispy//2, self.tft.WHITE)
        self.drawCrossHair(10, dispy//2, self.tft.WHITE)
        self.drawCrossHair(dispx-11, dispy-11, self.tft.WHITE)
        self.drawCrossHair(dispx//2, dispy-11, self.tft.WHITE)
        self.drawCrossHair(10, dispy-11, self.tft.WHITE)

        if not self.calibrate(10, 10, 0):
            self.calibError()
            return False
        if not self.calibrate(10, dispy//2, 1):
            self.calibError()
            return False
        if not self.calibrate(10, dispy-11, 2):
            self.calibError()
            return False
        if not self.calibrate(dispx//2, 10, 3):
            self.calibError()
            return False
        if not self.calibrate(dispx//2, dispy-11, 4):
            self.calibError()
            return False
        if not self.calibrate(dispx-11, 10, 5):
            self.calibError()
            return False
        if not self.calibrate(dispx-11, dispy//2, 6):
            self.calibError()
            return False
        if not self.calibrate(dispx-11, dispy-11, 7):
            self.calibError()
            return False

        px = abs((((self.rx[3]+self.rx[4]+self.rx[7]) / 3) - ((self.rx[0]+self.rx[0]+self.rx[2]) / 3)) / (dispy-20))
        clx = (((self.rx[0]+self.rx[1]+self.rx[2])/3))
        crx = (((self.rx[5]+self.rx[6]+self.rx[7])/3))

        if (clx < crx):
            clx = clx - (px*10)
            crx = crx + (px*10)
        else:
            clx = clx + (px*10)
            crx = crx - (px*10)

        py = abs((((self.ry[0]+self.ry[3]+self.ry[5])/3) - ((self.ry[2]+self.ry[4]+self.ry[7])/3))/(dispx-20))
        cty = (((self.ry[0]+self.ry[3]+self.ry[5])/3))
        cby = (((self.ry[2]+self.ry[4]+self.ry[7])/3))

        if (cty < cby):
            cty = cty - (py*10)
            cby = cby + (py*10)
        else:
            cty = cty + (py*10)
            cby = cby - (py*10)

        calx = (math.ceil(clx) << 16) + math.ceil(crx)
        caly = (math.ceil(cty) << 16) + math.ceil(cby)

        self.tft.clear()
        self.tft.font(self.tft.FONT_Default, rotate=0, fixedwidth=False)
        self.tft.text(self.tft.CENTER, self.tft.CENTER, "Calibration completed\n")
        if save:
            self.tft.setCalib(calx, caly)
            machine.nvs_setint("tpcalibX", calx)
            machine.nvs_setint("tpcalibY", caly)
            self.tft.text(self.tft.CENTER, self.tft.LAST_Y, "Saved to NVS", self.tft.ORANGE)
            print("Calibration completed and saved to NVS memory.")
        else:
            print("Calibration completed.")
        print("X = ({},{})  Y = ({},{})".format(math.ceil(clx), math.ceil(crx), math.ceil(cty), math.ceil(cby)))
        return calx, caly
    def tpcalib(self, tptype, save=False):
        if tptype == self.tft.TOUCH_XPT:
            self.tft.orient(display.TFT.LANDSCAPE)
        if tptype == self.tft.TOUCH_STMPE:
            self.tft.orient(display.TFT.PORTRAIT)
        else:
            print("Wrong touch type, use tft.TOUCH_XPT or TOUCH_STMPE")
            return

        dispx, dispy = self.tft.screensize()
        
        self.tft.font(self.tft.FONT_Default, rotate=0, fixedwidth=False)
        self.tft.text(self.tft.CENTER,40,"Touch yellow point and release", self.tft.GREEN)
        self.tft.text(self.tft.CENTER,60,"Repeat for all calibration points", self.tft.GREEN)
        
        self.tft.font(self.tft.FONT_Default, rotate=0, fixedwidth=True)
        self.drawCrossHair(dispx-11, 10, self.tft.WHITE)
        self.drawCrossHair(dispx//2, 10, self.tft.WHITE)
        self.drawCrossHair(10, 10, self.tft.WHITE)
        self.drawCrossHair(dispx-11, dispy//2, self.tft.WHITE)
        self.drawCrossHair(10, dispy//2, self.tft.WHITE)
        self.drawCrossHair(dispx-11, dispy-11, self.tft.WHITE)
        self.drawCrossHair(dispx//2, dispy-11, self.tft.WHITE)
        self.drawCrossHair(10, dispy-11, self.tft.WHITE)

        self.calibrate(10, 10, 0)
        self.calibrate(10, dispy//2, 1)
        self.calibrate(10, dispy-11, 2)
        self.calibrate(dispx//2, 10, 3)
        self.calibrate(dispx//2, dispy-11, 4)
        self.calibrate(dispx-11, 10, 5)
        self.calibrate(dispx-11, dispy//2, 6)
        self.calibrate(dispx-11, dispy-11, 7)

        px = abs((((self.rx[3]+self.rx[4]+self.rx[7]) / 3) - ((self.rx[0]+self.rx[0]+self.rx[2]) / 3)) / (dispy-20))  # LANDSCAPE
        clx = (((self.rx[0]+self.rx[1]+self.rx[2])/3))  # LANDSCAPE
        crx = (((self.rx[5]+self.rx[6]+self.rx[7])/3))  # LANDSCAPE

        if (clx < crx):
            clx = clx - (px*10)
            crx = crx + (px*10)
        else:
            clx = clx + (px*10)
            crx = crx - (px*10)

        py = abs((((self.ry[0]+self.ry[3]+self.ry[5])/3) - ((self.ry[2]+self.ry[4]+self.ry[7])/3))/(dispx-20))  # LANDSCAPE
        cty = (((self.ry[0]+self.ry[3]+self.ry[5])/3))  # LANDSCAPE
        cby = (((self.ry[2]+self.ry[4]+self.ry[7])/3))  # LANDSCAPE

        if (cty < cby):
            cty = cty - (py*10)
            cby = cby + (py*10)
        else:
            cty = cty + (py*10)
            cby = cby - (py*10)

        calx = (math.ceil(clx) << 16) + math.ceil(crx)
        caly = (math.ceil(cty) << 16) + math.ceil(cby)

        self.tft.clear()
        self.tft.font(self.tft.FONT_Default, rotate=0, fixedwidth=False)
        self.tft.text(self.tft.CENTER, self.tft.CENTER, "Calibration completed")
        if save:
            self.tft.setCalib(calx, caly)
            machine.nvs_setint("tpcalibX", calx)
            machine.nvs_setint("tpcalibY", caly)
            print("Calibration completed and saved to NVS memory.")
        else:
            print("Calibration completed.")
        print("X:", math.ceil(clx), math.ceil(crx), "Y:", math.ceil(cty), math.ceil(cby))
        return calx, caly