コード例 #1
0
def splash_main():
    # Battery status
    cstate = badge.battery_charge_status()
    vbatt = badge.battery_volt_sense()
    percent = battery_percent(3800, 4300, vbatt)

    # Init graphics and show homescreen
    ugfx.init()

    # Depending on battery status...
    if (cstate) or (percent > 9):
        draw_home(percent, cstate, "Press START!")

        # Accept input
        ugfx.input_init()
        ugfx.input_attach(ugfx.BTN_START, start_launcher)

        # Start timer
        global splashTimer
        splashTimer.init(period=5000,
                         mode=Timer.PERIODIC,
                         callback=splashTimer_callback)

    else:
        draw_batterylow(percent)
        gotosleep()
コード例 #2
0
    def __init__(self):
        # initialize ugfx
        ugfx.init()
        ugfx.clear(ugfx.WHITE)

        # Buttons
        ugfx.input_init()
        self.init_buttons()

        # Container
        width = ugfx.width()
        height = ugfx.height()
        ind_height = 46
        container_height = height - ind_height

        self.indicator = ugfx.Container(0,
                                        0,
                                        width,
                                        ind_height,
                                        style=styles.ibm_st)
        self.container = ugfx.Container(0,
                                        ind_height,
                                        width,
                                        container_height,
                                        style=styles.ibm_st)

        self.graph_basepos = container_height - 5

        # Sensor
        SCL = Pin(26)  # SCL
        SDA = Pin(25)  # SDA
        self.sensor = MPU6050(I2C(scl=SCL, sda=SDA))

        # Buzzer
        self.buzzer = Buzzer()
コード例 #3
0
def drawui():
    ugfx.init()
    buttons.init()
    ugfx.clear(ugfx.html_color(0x87F717))

    ugfx.set_default_font(ugfx.FONT_MEDIUM)

    ugfx.fill_circle(50,50, 20, ugfx.WHITE)
    ugfx.fill_circle(50, 100, 20, ugfx.WHITE)

    ugfx.text(45, 45, "A", ugfx.RED)
    ugfx.text(45, 95, "B", ugfx.RED)

    ugfx.text(95, 45, "Flash the lights", ugfx.WHITE)
    ugfx.text(95, 95, "Disco Inferno", ugfx.WHITE)

    ugfx.fill_polygon(270,50, [ [0,0], [40,0], [40, 175], [0, 175] ], ugfx.RED)#  , [230, 100], [230, 60]
    ugfx.fill_polygon(270,50, [ [0,0], [-20,10], [-20, 50], [0, 40] ], ugfx.RED)#  , [230, 100], [230, 60]

    ugfx.area(283, 61, 14, 10, ugfx.WHITE)
    ugfx.area(283, 79, 14, 10, ugfx.WHITE)
    ugfx.area(283, 97, 14, 10, ugfx.WHITE)
    ugfx.area(283, 115, 14, 10, ugfx.WHITE)
    ugfx.area(283, 133, 14, 10, ugfx.WHITE)
    ugfx.area(283, 151, 14, 10, ugfx.WHITE)
    ugfx.area(283, 169, 14, 10, ugfx.WHITE)
    ugfx.area(283, 187, 14, 10, ugfx.WHITE)
コード例 #4
0
def init():
    print('trains/main: Init')
    ugfx.init()
    ntp.set_NTP_time()
    # ensure wifi connection
    if not wifi.is_connected():
        wifi.connect(show_wait_message=True)
コード例 #5
0
ファイル: main.py プロジェクト: trandi/Mk4-Apps
    def setup_screen(self):
        """ Set up the screen and the labels that display
            values on it. 
        """
        ugfx.init()
        width=ugfx.width()
        height=ugfx.height()
        ugfx.clear(ugfx.html_color(0x800080))
        style = ugfx.Style()
        style.set_enabled([ugfx.WHITE, ugfx.html_color(0x800080), ugfx.html_color(0x800080), ugfx.html_color(0x800080)])
        style.set_background(ugfx.html_color(0x800080))
        ugfx.set_default_style(style)
        ugfx.orientation(90)
        ugfx.set_default_font(ugfx.FONT_TITLE)
        ugfx.Label(0, 0, width, 60,"Air Quality", justification=ugfx.Label.CENTER)
        label_height=45
        self.ppm10_label = ugfx.Label(0, label_height, width, label_height,"PPM 10: starting", justification=ugfx.Label.CENTER)
        self.ppm25_label = ugfx.Label(0, label_height*2, width, label_height,"PPM 2.5: starting", justification=ugfx.Label.CENTER)

        self.temp_label = ugfx.Label(0, label_height*3, width, label_height,"Temp: starting", justification=ugfx.Label.CENTER)
        self.humid_label = ugfx.Label(0, label_height*4, width, label_height,"Humid: starting", justification=ugfx.Label.CENTER)
        self.error_label = ugfx.Label(0, label_height*5, width, label_height,"", justification=ugfx.Label.CENTER)
        self.message_label = ugfx.Label(0, label_height*6, width, label_height,"", justification=ugfx.Label.CENTER)
        self.error_count = 0
        self.error_message = ""
        self.neopix = Neopix()
        self.p10_decode = ((100,0x00ff00),(250,0xffff00),(350,0xff8000),(430,0xff0000),(-1,0xcc6600))
        self.p25_decode = ((60, 0x00ff00),(91, 0xffff00), (121,0xff8000),(251,0xff0000),(-1,0xcc6600))
コード例 #6
0
def main():
    from home import launcher

    global app

    ugfx.init()
    app = launcher.Display()
    app.main()
コード例 #7
0
def program_main():
    print("--- SPONSORS APP ---")
    ugfx.init()
    ugfx.set_lut(ugfx.LUT_FULL)
    ugfx.clear(ugfx.BLACK)
    ugfx.flush()
    show_sponsors()
    appglue.start_app("")  # Return home
コード例 #8
0
def main():
    from netconfig import manager

    global app

    ugfx.init()
    app = manager.Status()
    app.main()
コード例 #9
0
def main():
    from appmanager import manager
    dir(manager)

    global app

    ugfx.init()
    app = manager.AppList()
    app.main()
コード例 #10
0
def program_main():
    ugfx.init()
    ugfx.clear(ugfx.WHITE)

    badge.leds_init()

    try:
        badge.eink_png(0, 0, logo_path)
    except:
        log('+ Failed to load graphics')

    # Name tag
    ugfx.string(ugfx.width() - ugfx.get_string_width(name, fonts[1]),
                ugfx.height() - 36, name, fonts[1], ugfx.BLACK)

    # Button info
    ugfx.string(0,
                ugfx.height() - 13, '[FLASH to update] [B to exit]', fonts[2],
                ugfx.BLACK)
    ugfx.flush()

    ugfx.input_init()
    ugfx.input_attach(ugfx.BTN_B, lambda pressed: exit_app())
    ugfx.input_attach(ugfx.BTN_FLASH, lambda pressed: start_self_update())

    HOST = "chat.freenode.net"
    PORT = 6667
    NICK = name + "[luv]"
    REALNAME = name + ' @ SHA2017'

    log('+ waiting for network...')
    wifi.init()
    while not wifi.sta_if.isconnected():
        time.sleep(0.1)

    s = socket.socket()
    s.connect((HOST, PORT))

    s.send(bytes("NICK %s\r\n" % NICK, "UTF-8"))
    s.send(bytes("USER %s 0 * :%s\r\n" % (NICK, REALNAME), "UTF-8"))
    s.send(bytes("JOIN #sha2017\r\n", "UTF-8"))

    # IRC Client
    while True:
        line = s.readline().rstrip()
        parts = line.split()

        if parts:
            if (parts[0] == b"PING"):
                s.send(bytes("PONG %s\r\n" % line[1], "UTF-8"))
                blink_led(green)
            if (parts[1] == b"PRIVMSG"):
                blink_led(red)
                msg = b' '.join(parts[3:])
                rnick = line.split(b'!')[0]
                log(b'%s: %s' % (rnick, msg))
コード例 #11
0
ファイル: tilda.py プロジェクト: pbrook/pychuckie
 def __init__(self):
     ugfx.init()
     if ugfx.backlight() == 0:
         ugfx.power_mode(ugfx.POWER_ON)
     ugfx.backlight(70)
     self.rm = chuckie.render.RenderManager()
     self.raster = raster.RasterTile()
     self._tick = time.ticks_ms()
     self._delta = 0
     buttons.init()
コード例 #12
0
def app_main():
    ugfx.init()

    clear()
    ugfx.set_lut(ugfx.LUT_FASTEST)

    badge.vibrator_init()

    ugfx.input_attach(ugfx.BTN_A, lambda pressed: badge.vibrator_activate(0xd))
    ugfx.input_attach(ugfx.BTN_START, lambda pressed: appglue.home())

    loop()
コード例 #13
0
ファイル: game.py プロジェクト: mscroggs/sha-mathsteroids
    def __init__(self):
        self.x = 30
        self.y = 30
        self.r = 0
        self.size = 1
        self.wrapper = Wrapper()

        ugfx.init()
        ugfx.input_init()

        self.select_surface()

        self.main_loop()
コード例 #14
0
def main():
    ugfx.init()

    h = htu21d.HTU21D(25, 26)

    ugfx.set_default_font('IBMPlexMono_Bold48')
    l = ugfx.Label(40, 60, 240, 120, text='')

    while True:
        try:
            l.text('{:.1f} C\n{:.1f} %'.format(h.temperature, h.humidity))
        except OSError:
            l.text('OSError')
        time.sleep(0.5)
コード例 #15
0
ファイル: main.py プロジェクト: wamonite/emfbadge_2016_life
def do_circle_of_life():
    ugfx.init()
    buttons.init()
    buttons.disable_menu_reset()

    colour = get_colour()
    grid = Grid(ugfx.width(), ugfx.height(), colour_fore = colour, colour_back = COLOUR_BACK)
    grid.randomise()

    ugfx.clear(COLOUR_BACK)

    hash_count = 0
    hash_last = None
    hash_last_last = None
    while True:
        # display
        hash_val = grid.display_badge()

        # randomise, if needed
        if hash_val == hash_last_last:
            hash_count += 1

            if hash_count == HASH_COUNT_LIMIT:
                colour = get_colour(colour)
                grid.set_colour(colour)
                grid.randomise()
                hash_count = 0

        else:
            hash_count = 0

        hash_last_last = hash_last
        hash_last = hash_val

        # process next generation
        grid.next_generation()
        grid.swap_cell_buffers()

        # buttons
        pyb.wfi()
        if buttons.is_triggered("BTN_A") or buttons.is_triggered("BTN_B"):
            colour = get_colour(colour)
            grid.set_colour(colour)
            grid.randomise()

        if buttons.is_triggered("BTN_MENU"):
            break
コード例 #16
0
ファイル: __init__.py プロジェクト: sourcx/sha2017-matrix
def setup():
    global background
    badge.init()
    ugfx.init()
    ugfx.input_init()
    ugfx.input_attach(ugfx.BTN_SELECT, reboot)
    ugfx.input_attach(ugfx.BTN_START, reboot)
    ugfx.input_attach(ugfx.JOY_DOWN, invert)
    ugfx.input_attach(ugfx.JOY_UP, invert)
    ugfx.input_attach(ugfx.JOY_RIGHT, invert)
    ugfx.input_attach(ugfx.JOY_LEFT, invert)
    ugfx.input_attach(ugfx.BTN_A, invert)
    ugfx.input_attach(ugfx.BTN_B, invert)
    ugfx.set_lut(ugfx.LUT_NORMAL)
    ugfx.clear(background)
    ugfx.flush()
    flip()
コード例 #17
0
    def __init__(self):
        # initialize ugfx
        ugfx.init()

        # Container
        width = ugfx.width()
        height = ugfx.height()
        self.container = ugfx.Container(0,
                                        0,
                                        width,
                                        height,
                                        style=styles.ibm_st)

        # Status box
        self.create_status_box()

        # Nametag Image
        self.filename = '/nametag.gif'
コード例 #18
0
 def badge_init(self):
     badge.init()
     ugfx.init()
     ugfx.input_init()
     ugfx.input_attach(ugfx.BTN_B, lambda pushed: home()
                       if pushed else False)
     ugfx.input_attach(ugfx.BTN_START, lambda pushed: self.shoot()
                       if pushed else False)
     ugfx.input_attach(ugfx.JOY_UP, lambda pushed: print("JOY_UP")
                       if pushed else False)
     ugfx.input_attach(
         ugfx.JOY_DOWN, lambda pushed: print("JOY_DOWN")
         if pushed else False)
     ugfx.input_attach(
         ugfx.JOY_RIGHT, lambda pushed: self.move(DIRECTION_RIGHT)
         if pushed else False)
     ugfx.input_attach(
         ugfx.JOY_LEFT, lambda pushed: self.move(DIRECTION_LEFT)
         if pushed else False)
コード例 #19
0
ファイル: main.py プロジェクト: EMF-Hams/emf_hub_mon_v3
def main():
    print("emf_hub_mon: Starting emf_hub_mon")

    # Init GFX and Buttons
    ugfx.init()
    buttons.init()

    # Config
    config = database.Database(filename='apps/emf_hub_mon/emf_hub_mon.json')

    # Status bar service
    status_service = status_bar(config)

    # LED service
    led_service = led(config)

    # Display service
    mon_service = mon_display(config, status_service, led_service)

    # Display welcome screen on first boot
    if config.get('first_boot'):
        mon_service.welcome()

    # MQTT service
    mqtt_service = mqtt_handler(config, mon_service)

    # Initialise the monitor display
    mon_service.init()

    while True:
        # Handle MQTT operations
        mqtt_service.handle()

        # Handle Display operations
        mon_service.update()

        # Give the CPU a break
        pyb.delay(200)

    # clean up some stuff, not sure if this is required but w/e
    ugfx.clear()
    led_service.off()
コード例 #20
0
def run_game():

    badge.eink_init()
    ugfx.init()
    ugfx.clear(ugfx.WHITE)
    ugfx.flush()

    badge.init()

    ugfx.clear(ugfx.WHITE)

    ugfx.input_init()

    ugfx.input_attach(ugfx.JOY_UP, lambda pressed: up(pressed, this_game))
    ugfx.input_attach(ugfx.JOY_DOWN, lambda pressed: down(pressed, this_game))
    ugfx.input_attach(ugfx.JOY_LEFT, lambda pressed: left(pressed, this_game))
    ugfx.input_attach(ugfx.JOY_RIGHT,
                      lambda pressed: right(pressed, this_game))
    ugfx.input_attach(ugfx.BTN_SELECT,
                      lambda pressed: exit_game(pressed, this_game))

    ugfx.string(50, 50, "Snake Game", "PermanentMarker22", ugfx.BLACK)
    ugfx.string(50, 72, "press SELECT to exit", "Roboto_Regular18", ugfx.BLACK)
    ugfx.flush()
    time.sleep(5)
    ugfx.clear(ugfx.WHITE)
    ugfx.flush()

    snake = Snake(True, Renderer())
    this_game = Game(snake, Border(), [Food.create_random_food(snake)])

    ugfx.flush()

    print("Start Log")

    while True:
        if (this_game.game_state == "FAIL"):
            FailGame(this_game)
        Step(this_game, 5)
コード例 #21
0
    def __init__(self):
        # initialize ugfx
        ugfx.init()
        ugfx.clear(ugfx.WHITE)

        # Buttons
        ugfx.input_init()
        self.init_buttons()

        # Container
        width = ugfx.width()
        height = ugfx.height()
        ind_height = 46
        container_height = height - ind_height

        self.indicator = ugfx.Container(0,
                                        0,
                                        width,
                                        ind_height,
                                        style=styles.ibm_st)
        self.container = ugfx.Container(0,
                                        ind_height,
                                        width,
                                        container_height,
                                        style=styles.ibm_st)

        self.graph_basepos = container_height - 5

        # Sensor
        self.gas_sensor = ADC(Pin(34))
        self.gas_sensor.atten(ADC.ATTN_11DB)
        self.gas_sensor.width(ADC.WIDTH_12BIT)

        # Smooth
        self.Vos = 0

        # Buzzer
        self.buzzer = Buzzer()
コード例 #22
0
    def __init__(self):
        # initialize ugfx
        ugfx.init()
        ugfx.clear(ugfx.WHITE)
        ugfx.input_init()

        # Buttons
        self.init_buttons()

        # Container
        width = ugfx.width()
        height = ugfx.height()
        ind_height = 40
        ind_pos = height - ind_height

        self.indicator = ugfx.Container(0,
                                        ind_pos,
                                        width,
                                        ind_height,
                                        style=styles.ibm_st)
        self.container = ugfx.Container(0,
                                        0,
                                        width,
                                        ind_pos,
                                        style=styles.ibm_st)

        self.y_offset = ind_pos - 10

        # Sensor
        #self.dust_sensor = gp2y1014au.GP2Y1014AU(iled=32, vo=36, K=0.5, Voc=0.6)
        self.dust_sensor = gp2y1014au.GP2Y1014AU(iled=32,
                                                 vo=36,
                                                 K=0.5,
                                                 Voc=0.0)

        # Smooth
        self.Vos = 0.1  # 0.8
コード例 #23
0
    def __init__(self):
        # initialize ugfx
        ugfx.init()
        ugfx.clear(ugfx.WHITE)

        # Buttons
        ugfx.input_init()
        self.init_buttons()

        # Container
        width = ugfx.width()
        height = ugfx.height()
        ind_height = 66
        container_height = height - ind_height

        self.indicator = ugfx.Container(0,
                                        0,
                                        width,
                                        ind_height,
                                        style=styles.ibm_st)
        self.container = ugfx.Container(0,
                                        ind_height,
                                        width,
                                        container_height,
                                        style=styles.ibm_st)

        self.graph_basepos = container_height - 5

        # Sensor
        self.dust_sensor = gp2y1014au.GP2Y1014AU(iled=32,
                                                 vo=36,
                                                 K=0.5,
                                                 Voc=0.6)

        # Smooth
        self.Vos = 0
コード例 #24
0
ファイル: __init__.py プロジェクト: leftshift/angelshifts
def main():
    print("> Main")
    global api_key

    ugfx.init()
    ugfx.input_init()

    ugfx.clear(ugfx.BLACK)
    ugfx.flush()
    ugfx.clear(ugfx.WHITE)
    ugfx.flush()

    ugfx.input_attach(ugfx.BTN_B, appglue.home)
    ugfx.input_attach(ugfx.BTN_SELECT, prompt_api_key)
    wifi.init()
    while not wifi.sta_if.isconnected():
        time.sleep(0.1)
        pass

    api_key = badge.nvs_get_str("engel", "key", "")
    if not api_key:
        prompt_api_key()

    show_shift_list()
コード例 #25
0
def run_app(path):
	import buttons
	import ugfx
	import sys

	buttons.init()
	ugfx.init()
	ugfx.clear()

	if not buttons.has_interrupt("BTN_MENU"):
		buttons.enable_menu_reset()

	try:
		# Make libraries shipped by the app importable
		app_path = '/flash/' + '/'.join(path.split('/')[:-1])
		sys.path.append(app_path)

		mod = __import__(path)
		if "main" in dir(mod):
			mod.main()
	except Exception as e:
		import sys
		import uio
		import ugfx
		s = uio.StringIO()
		sys.print_exception(e, s)
		ugfx.clear()
		ugfx.set_default_font(ugfx.FONT_SMALL)
		w=ugfx.Container(0,0,ugfx.width(),ugfx.height())
		ugfx.Label(0,0,ugfx.width(),ugfx.height(),s.getvalue(),parent=w)
		w.show()
		raise(e)
	import stm
	stm.mem8[0x40002850] = 0x9C
	import pyb
	pyb.hard_reset()
コード例 #26
0
def init():
    ugfx.init()
    Pin(Pin.PWM_LCD_BLIGHT).on()
コード例 #27
0
    def __init__(self):
        # initialize ugfx
        ugfx.init()

        # Create RPS View manager
        self.view_manager = RPSViewManager(self)
コード例 #28
0
 def setUp(self):
     ugfx.init()
     ugfx.clear()
コード例 #29
0
ファイル: main.py プロジェクト: farragar/Mk3-Firmware
		ugfx.backlight(100)
	elif (l > 20):
		ugfx.backlight(70)
	else:
		ugfx.backlight(30)

# Finds all locally installed apps that have an external.py
def get_external_hook_paths():
	return ["%s/external" % app.folder_path for app in get_local_apps() if is_file("%s/external.py" % app.folder_path)]

def low_power():
	ugfx.backlight(0)
	ugfx.power_mode(ugfx.POWER_OFF)


ugfx.init()
imu=IMU()
neo = pyb.Neopix(pyb.Pin("PB13"))
neo.display(0x04040404)
ledg = pyb.LED(2)
ival = imu.get_acceleration()
if ival['y'] < 0:
	ugfx.orientation(0)
else:
	ugfx.orientation(180)


buttons.init()
if not onboard.is_splash_hidden():
	splashes = ["splash1.bmp"]
	for s in splashes:
コード例 #30
0
def init():
    badge.init()
    ugfx.init()
    easywifi.enable()
    easyrtc.configure()
    clear_screen()
コード例 #31
0
ファイル: main.py プロジェクト: catalin-ursachi/Mk4-Apps
def main():
    ugfx.init()

    read_progress()
    run()
コード例 #32
0
ファイル: main.py プロジェクト: SimonWoolf/Mk3-Firmware
### Author: EMF Badge team
### Description: Test app for the hook into the home screen
### Category: Example
### License: MIT
### Appname : Home Callback Test

import ugfx, buttons, pyb

ugfx.init()
buttons.init()
ugfx.clear()

ugfx.Label(5, 5, ugfx.width(), ugfx.height(), "Nothing to see here")

while True:
    pyb.wfi()
コード例 #33
0
def game_of_life():
    badge.eink_init()
    ugfx.init()
    ugfx.input_init()
    ugfx.input_attach(ugfx.JOY_RIGHT, reboot)
    ugfx.input_attach(ugfx.JOY_LEFT, reboot)
    ugfx.input_attach(ugfx.JOY_UP, reboot)
    ugfx.input_attach(ugfx.JOY_DOWN, reboot)
    ugfx.input_attach(ugfx.JOY_RIGHT, reboot)
    ugfx.input_attach(ugfx.BTN_A, reboot)
    ugfx.input_attach(ugfx.BTN_B, reboot)
    ugfx.input_attach(ugfx.BTN_START, reboot)
    ugfx.input_attach(ugfx.BTN_SELECT, reboot)
    ugfx.clear(ugfx.WHITE)
    ugfx.flush()
    width = 37
    height = 16
    cell_width = 8
    cell_height = 8
    grid = [[False] * height for _ in range(width)]

    def seed():
        for x in range(0, width - 1):
            for y in range(0, height - 1):
                if urandom.getrandbits(30) % 2 == 1:
                    grid[x][y] = True
                else:
                    grid[x][y] = False

    def display():
        for x in range(0, width):
            for y in range(0, height):
                if grid[x][y]:
                    ugfx.area(x * cell_width, y * cell_height, cell_width - 1,
                              cell_height - 1, ugfx.BLACK)
                else:
                    ugfx.area(x * cell_width, y * cell_height, cell_width - 1,
                              cell_height - 1, ugfx.WHITE)
        badge.eink_busy_wait()
        ugfx.flush()

    def alive_neighbours(x, y, wrap):
        if wrap:
            range_func = lambda dim, size: range(dim - 1, dim + 2)
        else:
            range_func = lambda dim, size: range(max(0, dim - 1),
                                                 min(size, dim + 2))
        n = 0
        for nx in range_func(x, width):
            for ny in range_func(y, height):
                if grid[nx % width][ny % height]:
                    if nx != x or ny != y:
                        n += 1
        return n

    def step():
        changed = False
        new_grid = [[False] * height for _ in range(width)]
        for x in range(width):
            for y in range(height):
                neighbours = alive_neighbours(x, y, True)
                if neighbours < 2:  # Starvation
                    new_grid[x][y] = False
                    changed = True
                elif neighbours > 3:  # Overpopulation
                    new_grid[x][y] = False
                    changed = True
                elif not grid[x][y] and neighbours == 3:  # Birth
                    new_grid[x][y] = True
                    changed = True
                else:  # Survival
                    new_grid[x][y] = grid[x][y]
                    pass
        grid = new_grid
        return changed

    seed()
    generation = 0
    while True:
        generation += 1
        display()
        if not step() or generation > 50:
            seed()
            generation = 0