def _try_update(): os.sdconfig(os.SDMODE_SPI, clk=Pin(18), mosi=Pin(23), miso=Pin(19), cs=Pin(4)) try: os.mountsd() print('SD card mounted') except OSError: print('SD card not found') return directories = os.listdir(SD_FOLDER) if 'update' not in directories: print('No update folder found') return print('Update folder found. Updating...') for filename in os.listdir(FLASH_FOLDER): if filename in [BACKUP_FILE, RUNTIME_CONFIG_FILE]: continue os.remove(filename) print('- removed {0}'.format(filename)) for filename in os.listdir(UPDATE_FOLDER): with open(UPDATE_FILE.format(filename), 'r') as source: content = '\n'.join(source.readlines()) with open(FLASH_FILE.format(filename), 'w') as destination: destination.write(content) print('- added {0}'.format(filename)) for filename in os.listdir(UPDATE_FOLDER): os.remove(UPDATE_FILE.format(filename)) os.rmdir(UPDATE_FOLDER) os.umountsd() print('Update completed')
def prepareForSleep(): try: os.umountsd() except: pass neopixel.send(bytes([0]*24)) # Turn off LEDs configureWakeupSource()
def prepareForSleep(): try: os.umountsd() except: pass sdcardPower.value(False) configureWakeupSource()
def sleep(duration=0, status=False): import time, os, badge #---BADGE specific--- try: os.umountsd() except: pass badge.setPower(False) machine.RTC().wake_on_ext0(pin=machine.Pin(39), level=0) #Navigation buttons machine.RTC().wake_on_ext1( [machine.Pin(34, machine.Pin.IN), machine.Pin(35, machine.Pin.IN)], 0) #Keyboard badge.eink_busy_wait() #--- if (duration >= 86400000): #One day duration = 0 if status: import term if duration < 1: term.header(True, "Sleeping until button is pressed...") else: term.header(True, "Sleeping for " + str(duration) + "ms...") time.sleep(0.05) machine.deepsleep(duration)
def prepareForSleep(): configureWakeupSource() try: os.umountsd() except: pass mpr121.set(10, False) eink.busy_wait()
def sleep(duration=0, status=False): import machine, time, os, badge #---SHA2017 specific--- try: os.umountsd() except: pass badge.setPower(False) #--- machine.RTC().wake_on_ext0(pin = machine.Pin(25), level = 0) machine.RTC().wake_on_ext1([machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_UP)], 0) if (duration >= 86400000): #One day duration = 0 if status: import term if duration < 1: term.header(True, "Sleeping until touchbutton is pressed...") else: term.header(True, "Sleeping for "+str(duration)+"ms...") time.sleep(0.05) machine.deepsleep(duration)
def sd_umount(): try: os.umountsd() except: pass