Esempio n. 1
0
# Hijack the system start function to fix some CZ19 screen issues
orig_start = system.start


def hijacked_start(app, status=True):
    import rgb, time
    rgb.clear()
    time.sleep(0.1)
    orig_start(app, status)


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

Esempio n. 2
0
            animation_step += 1
        else:
            display.drawFill()
            drawEyeClosed(0, 0xFFFFFF)
            drawEyeClosed(7, 0xFFFFFF)
            display.flush()
            animation_step = 0
    elif animation_type == 3:
        for x in range(14):
            for y in range(5):
                color = x + (y * 14)
                display.drawPixel(x, y, color | (color << 8) | (color << 16))
    return 100


virtualtimers.activate(100)
virtualtimers.new(1, animation_task)


def btnA(pressed):
    global animation_type
    if pressed:
        animation_type = 1
    elif animation_type == 1:
        animation_type = 0


def btnB(pressed):
    global animation_type
    if pressed:
        animation_type = 2

start()


def goToSleep(unused_variable=None):
    system.home()


# Read configuration from NVS or apply default values
cfg_term_menu = machine.nvs_get_u8(
    'splash',
    'term_menu')  # Show a menu on the serial port instead of a prompt
if cfg_term_menu == None:
    cfg_term_menu = True  # If not set the menu is shown

# Scheduler
virtualtimers.activate(100)  # Start scheduler with 100ms ticks
virtualtimers.new(100, updateEink)

# Terminal menu
if cfg_term_menu:
    init_power_management()
    umenu = term_menu.UartMenu(system.home, pm, False, "< Back")
    umenu.main()

#(Note: power management is disabled when the menu is disabled, to keep the python prompt clean and usefull)

term.header(True, "Python shell")
print("Type \"import menu\" to access the menu.")
Esempio n. 4
0
except:
	pass
try: # First try to attach the start button to the launcher
	buttons.attach(buttons.BTN_START,  cbStartLauncher      )
except:
	try: # If the start button is not available use the A/OK button
		buttons.attach(buttons.BTN_A, cbStartLauncher)
	except:
		pass
try:
	buttons.attach(buttons.BTN_SELECT, cbFeedPowerManagement)
except:
	pass

# Scheduler
virtualtimers.activate(25)

# Power management
def cbSleep(idleTime=None):
	global stopThreads#scrollerTask#, ledTask
	if neopixel:
		neopixel.send(bytes([0x00]*3*12))
	if idleTime == None:
		idleTime = virtualtimers.idle_time()
	gui_redraw = True
	#virtualtimers.delete(scrollerTask)
	#virtualtimers.delete(ledTask)
	stopThreads = True
	display.windowHide("scroller")
	drawTask(True)
	display.flush()
Esempio n. 5
0
def init_power_management():
    virtualtimers.activate(1000) # Start scheduler with 1 second ticks
    pm.set_timeout(5*60*1000) # Set timeout to 5 minutes
    pm.callback(pm_cb) # Go to splash instead of sleep
    pm.feed() # Feed the power management task, starts the countdown...
def init_power_management():
    virtualtimers.activate(1000)  # Start scheduler with 1 second ticks
    pm.set_timeout(5 * 60 * 1000)  # Set timeout to 5 minutes
    pm.callback(cbSleep)  # Show sleep message
    pm.feed()  # Feed the power management task, starts the countdown...
		if (gyros[0] < 0):
			gu = (-gyros[0])>>8
		else:
			gd = (gyros[0])>>8
		if (gyros[1] < 0):
			gl = (-gyros[1])>>8
		else:
			gr = (gyros[1])>>8
		if (gyros[2] < 0):
			gz1 = (-gyros[2])>>8
		else:
			gz2 = (gyros[2])>>8
	
	if mode > 0:
		setLed(l,r,u,d,z1,z2,gl,gr,gu,gd,gz1,gz2)
	else:
		r = 0
		g = 0
		if (accel[1] < 0):
			g = (-accel[1])>>8
		else:
			r = (accel[1])>>8
		setSmiley(r,g)
	
	return 20

virtualtimers.activate(20)
virtualtimers.new(20, task)

import menu