Ejemplo n.º 1
0
    def clearDisplay(self):
        lcd.clear()

        lcd.orient(lcd.LANDSCAPE_FLIP)
        lcd.font(lcd.FONT_Ubuntu)

        return self
Ejemplo n.º 2
0
def printResult():
    lcd.clear()
    lcd.print('Date: ' + timestamp[0], 10, 10)
    lcd.print('Blue = Destination, Red = North', 10, 20)
    # lcd.print(
    #     'Location: ' + str(current_coord[0]) + ', ' + str(current_coord[1]), 10,
    #     30)
    # lcd.print("Azimuth Arg: {}".format(azimuth_arg), 10, 50)
    # lcd.print("Azimuth: {}".format(azimuth), 10, 70)

    rad = calcTargetRadian(current_coord, target_coords)
    # lcd.print("Rad: {}".format(rad), 10, 90)
    # lcd.print("Target Rad: {}".format(str((rad + azimuth) % 360)), 10, 110)
    lcd.lineByAngle(161, 119, 0, 120, round(azimuth), lcd.RED)
    lcd.lineByAngle(160, 120, 0, 120, round(azimuth), lcd.RED)
    lcd.lineByAngle(161, 121, 0, 120, round(azimuth), lcd.RED)

    lcd.lineByAngle(161, 119, 0, 120, round(rad + azimuth) % 360, lcd.BLUE)
    lcd.lineByAngle(160, 120, 0, 120, round(rad + azimuth) % 360, lcd.BLUE)
    lcd.lineByAngle(161, 121, 0, 120, round(rad + azimuth) % 360, lcd.BLUE)

    print('Date: ' + timestamp[0])
    print('Location: ' + str(current_coord[0]) + ', ' + str(current_coord[1]))
    print("Azimuth Arg: {}".format(azimuth_arg))
    print("Azimuth: {}".format(azimuth))
    print("Rad: {}".format(rad))
    print("Target Rad: {}".format(str((rad + azimuth) % 360)))
Ejemplo n.º 3
0
def GPSwatch():
    n = 0
    tm_last = 0
    satellites = dict()
    satellites_used = dict()
    while True:
        utime.sleep_ms(100)
        len = gps_s.any()
        if len>0:
            b = gps_s.read(len)
            for x in b:
                if 10 <= x <= 126:
                    stat = gps.update(chr(x))
                    if stat:
                        tm = gps.timestamp
                        tm_now = (tm[0] * 3600) + (tm[1] * 60) + int(tm[2])
                        if (tm_now - tm_last) >= 10:
                            n += 1
                            tm_last = tm_now
                            print("{} {}:{}:{}".format(gps.date_string(), tm[0], tm[1], int(tm[2])))
                            str = '%.10f %c, %.10f %c' % (gps.latitude[0], gps.latitude[1], gps.longitude[0], gps.longitude[1])
                            print(str)
                            lcd.clear()
                            lcd.print(str, 10, 0)
                            if gps.satellite_data_updated():
                                putSatellites(satellites, gps.satellite_data, tm_now)
                            putSatellitesUsed(satellites_used, gps.satellites_used, tm_now)
                            drawGrid()
                            drawSatellites(satellites, satellites_used)
                            if (n % 10) == 0:
                                print("Mem free:", gc.mem_free())
                                gc.collect()
Ejemplo n.º 4
0
def minmax():
  global offset
  global rate
  reg = register
  min_temp = 1000
  max_temp = -1000
  for i in range(0, 64):
    val = ustruct.unpack('<h', i2c.readfrom_mem(i2c_address, reg, 2))[0]
    tmp = getval(val)
    if tmp < min_temp:
      min_temp = tmp
    if max_temp < tmp:
      max_temp = tmp
    reg += 2

  diff = max_temp - min_temp
  # add some margin
  diff *= 1.4
  rate = len(colors) / diff
  offset = min_temp * 0.8

  lcd.clear()
  lcd.print('min:    ' + '{:.2f}'.format(min_temp), 0, 0)
  lcd.print('max:    ' + '{:.2f}'.format(max_temp), 0, 10)
  lcd.print('rate:   ' + '{:.2f}'.format(rate), 0, 20)
  lcd.print('offset: ' + '{:.2f}'.format(offset), 0, 30)
def streamsMenu(streamOffset=0):
    ofy = 0
    data = twitchAPI('streams', {
        'limit': 3,
        'offset': streamOffset,
        'game': gameFilter
    })
    channels = []
    lcd.clear()
    lcd.drawLine(0, 0, 80, 0, 0x6441a5)
    for item in data['streams']:
        lcd.fillRect(0, ofy, 80, 45, 0x333333)
        lcd.text(lcd.CENTER, ofy + 16, 'LOADING')
        loadAndDrawOnePreview(item['preview']['small'], 0, 1 + ofy)
        trippleText(2, ofy + 2, item['channel']['name'], 0xffffff)
        channels.append(item['channel']['name'])
        trippleText(lcd.RIGHT, ofy + 32, str(item['viewers']), 0xFF0000)
        ofy += 46
    del data
    lcd.text(4, 144, 'more', 0xFFFFFF)
    lcd.text(44, 144, 'back', 0xFFFFFF)

    def sc(n=0):
        return selectChannel(channels[n])

    def channelCallback(sel):
        return [(sc, sc, sc, streamsMenu, mainMenu)[sel],
                (streamOffset + sel if sel == 3 else sel)]

    return SelectionManager(3,
                            offsetY=1,
                            boxH=46,
                            callback=channelCallback,
                            menu=2).loop()
Ejemplo n.º 6
0
def webserver_start():
    global scanlist
    from microWebSrv import MicroWebSrv

    lcd.clear()
    lcd.setCursor(0, 0)
    ssid_name = "M5Stack-" + node_id[-4:]
    wlan_ap.active(True)
    wlan_ap.config(essid=ssid_name, authmode=network.AUTH_OPEN)
    addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
    print('WiFi AP WebServer Start!')
    print('Connect to Wifi SSID:' + ssid_name)
    print('And connect to esp via your web browser (like 192.168.4.1)')
    print('listening on', addr)
    lcd.image(0, 0, '/flash/img/1-1.jpg', type=lcd.JPG)
    lcd.font(lcd.FONT_DejaVu24)
    lcd.setTextColor(lcd.BLACK, lcd.WHITE)
    lcd.print('Wi-Fi SSID', 150, 145, lcd.BLACK)
    lcd.print(ssid_name, 125, 170, lcd.RED)
    webserver = MicroWebSrv(routeHandlers=routeHandlers)
    scanlist = wlan_sta.scan()
    if not wlan_sta.active():
        wlan_sta.active(True)
    while True:
        if len(wlan_ap.status('stations')) > 0:
            break
        time.sleep_ms(200)
    lcd.image(0, 0, '/flash/img/1-2.jpg', type=lcd.JPG)
    webserver.Start(threaded=False)
def gamesMenu(itemOffset=0):
    ofy = 0
    data = twitchAPI('games/top', {'limit': 3, 'offset': itemOffset})
    games = []
    lcd.clear()
    lcd.drawLine(0, 0, 80, 0, 0x6441a5)
    for item in data['top']:
        lcd.fillRect(0, ofy, 80, 45, 0x333333)
        lcd.text(lcd.CENTER, ofy + 16, 'LOADING')
        loadAndDrawOnePreview(
            item['game']['box']['template'].replace('{width}', '80').replace(
                '{height}', '45'), 0, 1 + ofy)
        trippleText(2, ofy + 2, item['game']['name'], 0xffffff)
        games.append(item['game']['name'])
        trippleText(lcd.RIGHT, ofy + 32, str(item['viewers']), 0xFF0000)
        ofy += 46
    lcd.text(4, 144, 'more', 0xFFFFFF)
    lcd.text(44, 144, 'back', 0xFFFFFF)

    def gameCallback(sel):
        global gameFilter
        if sel < 3:
            if sel >= len(games):
                return mainMenu
            gameFilter = games[sel].replace(' ', '+')
        return [(streamsMenu, streamsMenu, streamsMenu, gamesMenu,
                 mainMenu)[sel], (itemOffset + sel if sel == 3 else 0)]

    return SelectionManager(3,
                            offsetY=1,
                            boxH=46,
                            callback=gameCallback,
                            menu=2).loop()
Ejemplo n.º 8
0
def minmax():
    global offset
    global rate
    reg = register
    min_temp = 1000
    max_temp = -1000
    for i in range(0, 64):
        val = ustruct.unpack('<h', i2c.readfrom_mem(i2c_address, reg, 2))[0]
        tmp = getval(val)
        if tmp < min_temp:
            min_temp = tmp
        if max_temp < tmp:
            max_temp = tmp
        reg += 2

    diff = max_temp - min_temp
    # add some margin
    diff *= 1.4
    rate = len(colors) / diff
    offset = min_temp * 0.8

    lcd.clear()
    lcd.print('min:    ' + '{:.2f}'.format(min_temp), 0, 0)
    lcd.print('max:    ' + '{:.2f}'.format(max_temp), 0, 10)
    lcd.print('rate:   ' + '{:.2f}'.format(rate), 0, 20)
    lcd.print('offset: ' + '{:.2f}'.format(offset), 0, 30)
Ejemplo n.º 9
0
def header(tx, setclip):

    # adjust screen dimensions (depends on used display and orientation)

    global maxx, maxy, miny

    maxx, maxy = lcd.screensize()

    lcd.clear()

    if maxx < 240:

        lcd.font(lcd.FONT_Small, rotate=0)

    else:

        lcd.font(lcd.FONT_Default, rotate=0)

    _, miny = lcd.fontSize()

    miny += 5

    lcd.rect(0, 0, maxx - 1, miny - 1, lcd.OLIVE, lcd.DARKGREY)

    lcd.text(lcd.CENTER, 2, tx, lcd.CYAN, transparent=True)

    if setclip:

        lcd.setwin(0, miny, maxx, maxy)
Ejemplo n.º 10
0
def main_loop():
    while True:
        try:
            # Ensure network is connected.
            # https://github.com/espressif/arduino-esp32/issues/653
            connect_wifi()

            now = time.time()
            dateStart = now - GRAPH_DURATION
            resp = requests.get(DATA_SOURCE + "?count=" +
                                str(GRAPH_MAX_POINTS) + "&find[date][$gte]=" +
                                str(dateStart)).json()

            current = resp[0]
            bg_color = get_bg_color(current["sgv"], current["date"])
            lcd.clear(bg_color)

            lcd.font("UbuntuMono-B40.fon")
            lcd.setTextColor(color=BLACK, bcolor=bg_color)
            lcd.print(
                text_transform_bg(current["sgv"]) + " " +
                text_transform_direction(current["direction"]), lcd.CENTER, 20)

            draw_graph(resp, dateStart, now)
            print("Response is", resp[0]["sgv"])

        except RuntimeError as e:
            print("Some error occured, retrying! -", e)
        time.sleep(180)
Ejemplo n.º 11
0
def render(arr):
    w = int(arr[0])
    h = int(arr[1])
    lcd.clear()
    for y in range(0, h):
        for x in range(0, w):
            lcd.drawPixel(x, y, arr[3 + x + y * w])
Ejemplo n.º 12
0
    def __init__(self,
                 client_id,
                 server,
                 port,
                 user=None,
                 password=None,
                 keepalive=300):
        if m5base.get_start() != 1:
            autoConnect(lcdShow=True)
            lcd.clear()
        else:
            raise ImportError('mqtt need download...')

        if user == '':
            user = None

        if password == '':
            password = None

        self.mqtt = MQTTClient(client_id, server, port, user, password,
                               keepalive)
        self.mqtt.set_callback(self._on_data)
        try:
            self.mqtt.connect()
        except:
            lcd.clear()
            lcd.font(lcd.FONT_DejaVu24)
            lcd.setTextColor(lcd.RED)
            lcd.print('connect fail', lcd.CENTER, 100)
        self.topic_callback = {}
        self.mqttState = True
        self.ping_out_time = time.ticks_ms() + 60000
Ejemplo n.º 13
0
def render():
    lcd.font(lcd.FONT_Default, transparent=True, fixedwidth=False)
    lcd.text(lcd.RIGHT, 220, "Loading...", lcd.DARKGREY)

    response = urequests.get(url)
    data = ujson.loads(response.text)

    temps = data["temps"]
    rains = data["rains"]
    icon_basename = data["icon_basename"]

    lcd.clear(color=lcd.WHITE)

    lcd.font(lcd.FONT_DejaVu24, transparent=True, fixedwidth=True)
    lcd.text(lcd.CENTER, 20, "%2s [%3s]" % (temps["max"], temps["max_diff"]),
             lcd.RED)
    lcd.text(lcd.CENTER, 50, "%2s [%3s]" % (temps["min"], temps["min_diff"]),
             lcd.BLUE)

    lcd.image(110, 85, "/flash/images/%s.jpg" % (icon_basename), 0, lcd.JPG)

    lcd.font(lcd.FONT_DefaultSmall, transparent=True, fixedwidth=True)
    lcd.text(lcd.CENTER, 160, "~06 | ~12 | ~18 | ~24 ", lcd.BLACK)
    lcd.text(
        lcd.CENTER, 180, "%3s | %3s | %3s | %3s " %
        (rains["t00_06"], rains["t06_12"], rains["t12_18"], rains["t18_24"]),
        lcd.BLACK)

    lcd.font(lcd.FONT_Default, transparent=True, fixedwidth=False)
    lcd.text(lcd.CENTER, 220,
             time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
             lcd.DARKGREY)
Ejemplo n.º 14
0
def pressLoop():
    while True:
        if btnA.isPressed():
            lcd.clear()
            statusText("taking\nphoto")
            uart.uart.write(b'takePhoto')
            while not btnA.isReleased():
                pass
Ejemplo n.º 15
0
def set_colors(invert=False, clear=True):
    if invert:
        lcd.set_bg(FG_COLOR)
        lcd.set_fg(BG_COLOR)
    else:
        lcd.set_bg(BG_COLOR)
        lcd.set_fg(FG_COLOR)
    if clear:
        lcd.clear()
Ejemplo n.º 16
0
def _tryingmine(httpClient, httpResponse,routeArgs):
    lcd.clear(0x000000)
    lcd.font('hp.fon')
    lcd.setCursor(0,0)
    lcd.print(routeArgs['message'])
    httpResponse.WriteResponseOk( headers         = None,
                                 contentType     = "text/html",
                                 contentCharset = "UTF-8",
                                 content          = "OK" )
Ejemplo n.º 17
0
def show_image(file):
    lcd.clear()
    (screen_width, screen_height) = lcd.screensize()
    image_width = 300 / 2
    image_height = 300 / 2
    lcd.image(int((screen_width - image_width) / 2),
              int((screen_height - image_height) / 2),
              file,
              scale=1,
              type=lcd.JPG)
Ejemplo n.º 18
0
def get_partBtn():
    load_screen()
    parts = api.getParts()
    lcd.clear()
    for part in parts:
        if part['name'] == partName:
            partCount = part["quantity"]
            message = "{}-off {}".format(part['quantity'], part['name'])
            lcd.text(lcd.CENTER, lcd.CENTER, message)
    lcd.text(lcd.CENTER, lcd.BOTTOM, "Hold to refresh")
Ejemplo n.º 19
0
    def show(self):
        ScreenManager.isShown(self)
        self._isShown = True

        lcd.clear(lcd.WHITE)
        lcd.setColor(lcd.BLACK)
        lcd.font(lcd.FONT_Tooney, transparent=True)
        lcd.print('speckbosch', lcd.CENTER, 10)
        lcd.font(lcd.FONT_DejaVu24, transparent=True)
        lcd.print('Chicken Shed Mgr {}'.format(self._getVersion()), lcd.CENTER,
                  45)
Ejemplo n.º 20
0
def get_partBtn():
    load_screen()
    id = get_id()
    part = api.getPart(id)
    part = part['data']['getPart']
    lcd.clear()
    partCount = part['quantity']
    message = "{}x {}".format(part['quantity'], part['name'])
    lcd.text(lcd.CENTER, lcd.CENTER, message)
    lcd.text(lcd.CENTER, lcd.BOTTOM, "Hold to refresh")
    return part['id']
Ejemplo n.º 21
0
def renderChatMsg(usr, msg):
    global msgQueue
    if len(msgQueue) > 8:
        msgQueue.pop(0)
    lcd.clear()
    msgQueue.append(usr + ':' + msg)
    if tcfg['tickers']:
        for i in range(len(msgQueue)):
            ticker.text[i] = msgQueue[i]
    else:
        lcd.clear()
        lcd.text(0, 2, '\n'.join(msgQueue[-4:]))
Ejemplo n.º 22
0
 def over():
     Snake.timer.deinit()
     lcd.clear()
     lcd.text(lcd.CENTER, lcd.CENTER, "GAME OVER")
     lcd.text(lcd.CENTER, 10, "score: " + repr(len(Snake.tail)))
     while btnA.isPressed():
         pass
     while True:
         if btnA.isPressed():
             Snake.reset()
             Game.prepareField()
             return 0
Ejemplo n.º 23
0
def dispData(buff):
    lcd.clear()
    str = "%.1f'C, %dppm" % (buff[-1][0], buff[-1][1])
    if dispNum:
        lcd.font(lcd.FONT_DejaVu24)  # フォントを指定
        lcd.print("%4.1f'C" % buff[-1][0], 120, 80)
        lcd.print("%dppm" % buff[-1][1], 120, 120)
    else:
        lcd.font(lcd.FONT_DejaVu18)  # フォントを指定
        lcd.print(str, X0, Y0)  # 温度、CO2を表示
        drawChart(buff)
    print(str)
Ejemplo n.º 24
0
def watchGPS():
    lcd.print('GPS:Start loop\n')

    n = 0
    tm_last = 0
    satellites = dict()
    satellites_used = dict()

    fp = open('/sd/gpslog.txt', 'a')
    lcd.print('fp %s\n' % fp)

    while True:
        utime.sleep_ms(100)
        length = gps_s.any()
        if length > 0:
            buf = gps_s.read(length)
            fp.write(buf)

            if buttonC.isPressed():
                lcd.clear()
                lcd.print('Button C Pressed.\n', 0, 0)
                fp.close()
                lcd.print('File closed.\n')
                lcd.print('System exit.\n')
                sys.exit()

            for val in buf:

                if 10 <= val <= 126:
                    stat = gps.update(chr(val))
                    if stat:
                        tm = gps.timestamp
                        tm_now = (tm[0] * 3600) + (tm[1] * 60) + int(tm[2])
                        print('compare time tm_now={}, tm_last={}'.format(tm_now, tm_last))
                        if (tm_now - tm_last) >= 10:
                            print('compare True')
                            n += 1
                            tm_last = tm_now
                            print('{} {}:{}:{}'.format(gps.date_string(), tm[0], tm[1], int(tm[2])))
                            str_ = '%.10f %c, %.10f %c' % (
                            gps.latitude[0], gps.latitude[1], gps.longitude[0], gps.longitude[1],
                            )
                            print(str_)
                            lcd.clear()
                            lcd.print(str_, 10, 0)
                            if gps.satellite_data_updated():
                                putSatellites(satellites, gps.satellite_data, tm_now)
                            putSatellitesUsed(satellites_used, gps.satellites_used, tm_now)
                            drawGrid()
                            drawSatellites(satellites, satellites_used)
                            if (n % 10) == 0:
                                print('Mem free:', gc.mem_free())
                                gc.collect()
Ejemplo n.º 25
0
def temp():
    adc = machine.ADC(PIN)  # ADコンバータのインスタンスを生成
    lcd.font(font)  # フォントを指定
    lcd.clear()  # 画面をクリア

    while True:
        t = 0
        for i in range(MULTISAMPLES):
            t = t + adc.read() / 10  # ADコンバータを読み、温度に変換
        t = t / MULTISAMPLES
        lcd.print('\r', X0, Y0)  # 表示位置以降をクリア
        lcd.print("%4.1f" % t, X0, Y0)  # 温度を表示
        time.sleep(5)
Ejemplo n.º 26
0
def main():
    tm.init(mode=Timer.CHRONO)
    tm.start()

    while True:
        lcd.clear()
        buff = []
        sample(buff)
        buff.sort()
        global minz, maxz
        d = max(buff[-1] - buff[0], drange) / 2
        minz = buff[0] - d
        maxz = buff[-1] + d
        print((buff[0], buff[-1], minz, maxz))
Ejemplo n.º 27
0
def mainMenu(idk=0):
    global gameFilter
    gameFilter = ''
    lcd.font(lcd.FONT_Small)
    lcd.clear()
    drawHeader()
    lcd.text(lcd.CENTER, 20, 'Streams')
    lcd.text(lcd.CENTER, 40, 'Games')
    lcd.text(lcd.CENTER, 60, 'Users')
    lcd.text(lcd.CENTER, 80, 'Exit')

    def mainCallback(sel):
        return (streamsMenu, gamesMenu, searchMenu, leave)[sel]

    return SelectionManager(4, offsetY=18, callback=mainCallback).loop()
Ejemplo n.º 28
0
def game_start():
	lcd.font(lcd.FONT_DejaVu18)
	GAME_RUNNING = True
	HEALTH = 10
	bird = [80,20,0,0,15] # y,x,vy,vx,r
	blns = [[80,-10,0,-1,15,lcd.BLUE],[40,-10,0.2,-0.5,10,lcd.GREEN]] # y,x,vy,vx,r,color
	GRAV = -1
	lastbtn = False
	while GAME_RUNNING:
		if HEALTH < 1: break
		if buttonA.isPressed() and not lastbtn: bird[2] += 15
		lastbtn = buttonA.isPressed()
		bird[2] += GRAV
		bird[2] *= 0.9
		bird[0] += bird[2]
		bird[0] = min(max(bird[4], bird[0]), 160-bird[4])
		lcd.clear()
		lcd.fillCircle(int(bird[0]), bird[1], bird[4], lcd.RED)
		lcd.fillCircle(int(bird[0])+6, bird[1]+2, 3, lcd.WHITE)
		lcd.fillCircle(int(bird[0])+6, bird[1]+10, 3, lcd.WHITE)
		lcd.fillCircle(int(bird[0])+6, bird[1]+2, 1, lcd.BLACK)
		lcd.fillCircle(int(bird[0])+6, bird[1]+10, 1, lcd.BLACK)
		lcd.fillTriangle(int(bird[0])-5, bird[1]+13, int(bird[0])-10, bird[1]+3, int(bird[0]), bird[1]+3, lcd.YELLOW)
		for b in blns:
			if b[1] < -b[4]:
				b[1] = 80+b[4]
				b[0] = randint(20,140)
				b[2] = (randint(0,10)-5)/5.0
				b[3] = -randint(5,10)/5.0
				b[4] = randint(5,15)
				b[5] = getrandbits(24)
			b[0] += b[2]
			b[1] += b[3]
			if((b[0]-bird[0])**2 + (b[1]-bird[1])**2 < (bird[4]+b[4])**2):
				HEALTH -= 1
				b[1] = -100
				tone([(440, 100)])
			lcd.line(int(b[0]),int(b[1]),int(b[0])-(4*b[4]),int(b[1]),lcd.WHITE)
			lcd.fillCircle(int(b[0]),int(b[1]),b[4],b[5])
		lcd.print(str(HEALTH)+" <3",140,0,lcd.WHITE,rotate=90)
		sleep_ms(30)
	
	lcd.setTextColor(lcd.WHITE)
	lcd.text(40,0,"GAME")
	lcd.text(20,0,"OVER")
	sleep_ms(700)
	tone(TONE_DENY)
	reset()
Ejemplo n.º 29
0
def main():
    from m5stack import lcd, buttonA
    from mpu9250 import MPU9250
    from time import sleep_ms
    from machine import I2C
    import network
    
	# lcd.font(lcd.FONT_Small, transparent=True, fixedwidth=False)

    try:
        sta_if = network.WLAN(network.STA_IF)
        if sta_if.active() == True:
            m_acc = network.mqtt('acc', 'mqtt://srdmobilex.ddns.net', port=65530, clientid='a')
            m_gyro = network.mqtt('gyro', 'mqtt://srdmobilex.ddns.net', port=65530, clientid='g')
            m_acc.start()
            m_gyro.start()
            m_acc.subscribe('acc', 2)
            m_gyro.subscribe('gyro', 0)

        i2c = I2C(sda = 21, scl = 22)
        
        imu = MPU9250(i2c)

        lcd.clear()
        lcd.setColor(lcd.WHITE)
        lcd.font(lcd.FONT_Small, transparent=False)

        counter = 0

        while not buttonA.isPressed():
            accel = imu.acceleration
            gyro = imu.gyro
            mag = imu.magnetic
            lcd.print("ACCEL: {:+7.2f}  {:+7.2f}  {:+7.2f}".format(accel[0], accel[1], accel[2]), lcd.CENTER, 20)
            lcd.print("GYRO:  {:+7.2f}  {:+7.2f}  {:+7.2f}".format(gyro[0], gyro[1], gyro[2]), lcd.CENTER, 40)
            lcd.print("MAG:   {:+7.2f}  {:+7.2f}  {:+7.2f}".format(mag[0], mag[1], mag[2]), lcd.CENTER, 60)
            if sta_if.active() == True:
                m_acc.publish('acc', '{:+7.2f},{:+7.2f},{:+7.2f}'.format(accel[0], accel[1], accel[2]) + '(%d)'%counter)
                m_gyro.publish('gyro', '{:+7.2f}  {:+7.2f}  {:+7.2f}'.format(gyro[0], gyro[1], gyro[2]) + '(%d)'%counter)
                counter += 1
            sleep_ms(20)

        m_acc.free()
        m_gyro.free()
        i2c.deinit()
        lcd.print('Exit.', 0, 100)
    except:
        return -1
Ejemplo n.º 30
0
    def app_txtReader(self, fname):
        lcd.clear()
        f = Framework('txtReader')
        f.drawNaviButton(strC='EXIT')
        lcd.font(lcd.FONT_DefaultSmall, transparent=False, fixedwidth=True)
        idx = 0
        idx_s = [0]
        page = 0
        while True:
            letter_current_page = 0
            lcd.setCursor(0, 0)
            lcd.rect(0, 0, 320, 240 - f.h_bottom, lcd.BLACK, lcd.BLACK)
            with open(fname, 'r') as o:
                o.seek(idx)
                flag_end = False

                for row in range(20):
                    for col in range(29):
                        c = o.read(1)
                        if not c:
                            lcd.println('--- END ---')
                            flag_end = True
                            break
                        if c != '\n':
                            lcd.print(c)
                            letter_current_page += 1
                        else:
                            letter_current_page += 1
                            break
                    lcd.print('\n')
                    if flag_end:
                        break
            while True:
                time.sleep(0.1)
                if buttonA.isPressed():
                    if page != 0:
                        page -= 1
                        del (idx_s[-1])
                        idx = idx_s[-1]
                        break
                elif buttonB.isPressed():
                    if c:
                        idx += letter_current_page
                        idx_s.append(idx)
                        page += 1
                        break
                elif buttonC.isPressed():
                    return 0
Ejemplo n.º 31
0
def mainMenu():
    def worldMap():
        return mapView

    def leave():
        import sys
        sys.exit()

    lcd.clear(0x2b4860)
    lcd.fillRect(0, 0, 80, 12, 0xc6585a)
    lcd.font(lcd.FONT_Arial12)
    lcd.text(lcd.CENTER, 0, 'MAPS', 0xFFFFFF)
    lcd.font(lcd.FONT_Small)
    callbacks = (worldMap, search, findMe)
    s = SelectionManagerV2(0, 4, selectionRenderer).loop()
    return callbacks[s]