Example #1
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
Example #2
0
 def loop(self):
     self.callback(self)
     while True:
         if btnA.isPressed():
             while btnA.isPressed():
                 pass
             return self.sel
         if btnB.isPressed():
             self.sel = self.sel + 1 if self.sel < self.total - 1 else 0
             while btnB.isPressed():
                 pass
             self.callback(self)
 def loop(self):
     self._render()
     while btnA.isPressed():
         pass
     while True:
         if btnB.isPressed():
             self.selection = (self.selection +
                               1) if self.selection < self.total else 1
             while True:
                 if not btnB.isPressed():
                     break
             self._render()
         if btnA.isPressed():
             return self.callback(self.selection - 1)
def pressLoop():
    while True:
        if btnA.isPressed():
            lcd.clear()
            statusText("taking\nphoto")
            uart.uart.write(b'takePhoto')
            while not btnA.isReleased():
                pass
Example #5
0
 def dirChange():
     if btnB.isPressed():
         Snake.dr += 1
     if btnA.isPressed():
         Snake.dr -= 1
     if Snake.dr > 3:
         Snake.dr = 0
     if Snake.dr < 0:
         Snake.dr = 3
Example #6
0
    def loop(self):
        from libs.imu import IMU  #from hardware import mpu6050
        mpu = IMU()  #mpu = mpu6050.MPU6050()

        maxX = 80.0
        maxY = 160.0
        accel = [0.0, 0.0]
        accelSense = self.sensitivity
        curSize = self.cursorSize
        curPos = [40.0, 40.0]
        self._drawInputForm()
        self._drawLayoutBG()
        while True:
            self._showLayout()
            self._drawSelectedLetter(curPos)
            if curPos[1] <= 21:
                self._drawInputForm()
                self._drawInputText()
            accelX = mpu.acceleration[0] * accelSense * -1
            accelY = mpu.acceleration[1] * accelSense
            lcd.fillRect(round(curPos[0]), round(curPos[1]), curSize, curSize,
                         self.topBG if curPos[1] < 104 else self.keyboardBG)
            if curPos[0] + accelX < 80 - curSize and curPos[0] + accelX > 0:
                curPos[0] += accelX
            if curPos[1] + accelY < 160 - curSize and curPos[1] + accelY > 0:
                curPos[1] += accelY
            lcd.fillRect(round(curPos[0]), round(curPos[1]), curSize, curSize,
                         self.cursorColor)
            if btnA.isPressed():
                key = self._getLetter(curPos)
                if key == '>':
                    self._hide()
                    return self.input
                else:
                    self.input += key
                    self._drawInputText()
                while btnA.isPressed():
                    pass
            if btnB.isPressed():
                if len(self.input) > 0:
                    self.input = self.input[:-1]
                    self._drawInputText()
                while btnB.isPressed():
                    pass
Example #7
0
def search():
    from accelKeyboard import Keyboard
    from geolocate import findPlace
    inputText = Keyboard().loop()
    coords = findPlace(inputText)
    del Keyboard
    del inputText
    del findPlace
    if coords:
        gc.collect()
        return mapView(coords[0], coords[1], 14 if coords[2] != 'city' else 8)
    else:
        lcd.clear()
        lcd.text(0, 20, 'Place not Found')
        lcd.text(lcd.CENTER, 100, 'ok')
        while not btnA.isPressed() or btnB.isPressed():
            while btnA.isPressed() or btnB.isPressed():
                pass
        return search
Example #8
0
def BSIApp():
    from m5stack import lcd, btnA, btnB, rtc
    from machine import Timer
    import _thread

    lcd.font(lcd.FONT_Small)
    info = False
    xCenter = (0, 9, 5, 0, -4, -4)
    order = False
    mode = 1

    def updateBusDataThreaded(tmr=False):
        _thread.start_new_thread(updateBusData, tuple())

    def updateBusData():
        nonlocal info
        info = False
        print('updating')
        info = getBusStopInfo(BUS_STOP)
        drawBusData()
        gc.collect()

    def drawBusData():
        if not info:
            return

        lcd.clear(0xffffff)
        offsetY = 2
        offsetX = 35
        info['data']['transports'].sort(reverse=order, key= \
            lambda x: int(getBusTimeData(x['times'][0])['value']) if len(x['times']) > 0 else float('inf'))

        for i, t in enumerate(info['data']['transports']):
            lcd.fillRoundRect(2, offsetY, 30, 12, 2,
                              getVehicleColor(t['type']))
            lcd.text(6 + xCenter[len(t['name'])], offsetY, t['name'], 0xffffff)
            if len(t['times']) > 0:
                if mode == 0:
                    target = getBusTimeData(t['times'][0])
                    lcd.text(38, offsetY, target['text'], 0)
                else:
                    currentTime = info['data']['currentTime'] // 1000 + info[
                        'data']['tzOffset']
                    for k, v in enumerate(t['times']):
                        target = getBusTimeData(v)
                        arrivalTime = int(target['value']) + int(
                            target['tzOffset'])
                        waitTime = str(
                            getMinuteWaitTime(currentTime, arrivalTime))
                        lcd.fillRoundRect(1 + offsetX, offsetY, 20, 12, 2,
                                          getWaitTimeColor(int(waitTime)))
                        if len(waitTime) > 2:
                            waitTime = str(int(waitTime) // 60 + 1) + 'H'
                        lcd.text(offsetX + xCenter[len(waitTime)], offsetY,
                                 waitTime, 0xffffff)
                        offsetX += 22
                        if k == 1:
                            break
                    offsetX = 35
            offsetY += 13
            if i == 10:
                break
        displayTime()

    def getBusTimeData(src):
        return src['Estimated' if 'Estimated' in src else 'Scheduled']

    def getMinuteWaitTime(currentTime, busTime):
        return round((busTime - currentTime) / 60)

    def getWaitTimeColor(wt: int) -> int:
        return 0x3cb300 * int(wt <= 10) + 0xfce513 * int(
            wt > 10 and wt <= 16) + 0xfe7613 * (
                wt > 16 and wt <= 25) + 0xff2812 * int(wt > 25)

    def getVehicleColor(vtype):
        return int(vtype == 'bus' or vtype == 'trolleybus') * 0x3377e4 + int(vtype == 'minibus') * 0xb43dcc \
            + int(vtype == 'tramway') * 0xf43000 + int(vtype == 'suburban') * 0x777000

    def displayTimeThreaded(tmr=False):
        _thread.start_new_thread(displayTime, tuple())

    @micropython.native
    def displayTime():
        time = rtc.now()
        txt = '{:02d}:{:02d}:{:02d}'.format(*time[-3:])
        lcd.textClear(9, 148, txt, 0xFFFFFF)
        lcd.text(9, 148, txt, 0)

    syncTime()
    updateBusData()
    timeTimer = Timer(8005)
    updateTimer = Timer(8006)
    timeTimer.init(period=1000,
                   mode=Timer.PERIODIC,
                   callback=displayTimeThreaded)
    updateTimer.init(period=30000,
                     mode=Timer.PERIODIC,
                     callback=updateBusDataThreaded)

    while True:
        if btnA.isPressed():
            order = not order
            drawBusData()
            while btnA.isPressed():
                pass
        if btnB.isPressed():
            mode = not mode
            drawBusData()
            while btnB.isPressed():
                pass