Exemplo n.º 1
0
def wav_player(fname):
    i2s = I2S(mode=I2S.MODE_MASTER | I2S.MODE_TX | I2S.MODE_DAC_BUILT_IN,
              rate=16000,
              bits=16,
              channel_format=I2S.CHANNEL_ONLY_RIGHT,
              data_format=I2S.FORMAT_I2S_MSB)

    wav = wave.open(fname)
    i2s.set_dac_mode(I2S.DAC_RIGHT_EN)
    i2s.sample_rate(wav.getframerate())
    i2s.bits(wav.getsampwidth() * 8)
    i2s.nchannels(wav.getnchannels())
    i2s.volume(100)

    while True:
        data = wav.readframes(512)
        if len(data) > 0:
            i2s.write(data)
            print('.', end='')
        else:
            wav.close()
            break
        if buttonC.isPressed():
            wav.close()
            break

    i2s.deinit()
Exemplo n.º 2
0
def loop():
    global ison
    while True:
        if buttonA.isPressed():
            ison = True
        if buttonB.isPressed():
            minmax()
        if buttonC.isPressed():
            ison = False
        if ison:
            graph()
Exemplo n.º 3
0
def loop():
  global ison
  while True:
    if buttonA.isPressed():
      ison = True
    if buttonB.isPressed():
      minmax()
    if buttonC.isPressed():
      ison = False
    if ison:
      graph()
Exemplo n.º 4
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()
Exemplo n.º 5
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
Exemplo n.º 6
0
	def run(self):
		if self.fileCheck() < 0:
			return -1
		self.drawNaviButton()
		
		lcd.setCursor(0,0)
		lcd.println('Press START to start')
		while not buttonA.isPressed():
			if buttonC.isPressed():
				return 0
			time.sleep(.5)

		self.fname_save = self.fnameGen()
		lcd.println('Record into %s' % self.fname_save)

		self.scanner()
Exemplo n.º 7
0
def wav_player(fname):
    wav = wave.open(fname)
    i2s.set_dac_mode(I2S.DAC_RIGHT_EN)
    i2s.sample_rate(wav.getframerate())
    i2s.bits(wav.getsampwidth() * 8)
    i2s.nchannels(wav.getnchannels())
    i2s.volume(100)

    while True:
        data = wav.readframes(1024)
        if len(data) > 0:
            i2s.write(data)
            print('.', end='')
        else:
            wav.close()
            break
        if buttonC.isPressed():
            wav.close()
            break
Exemplo n.º 8
0
def main():
    ########## 初期化 ##########
    # 液晶画面を初期化する
    lcd.setColor(color, background_color)
    lcd.clear()

    # センサーを初期化する
    sensor = DHT12()

    # 温度計、湿度計の表示を初期化する
    temperature_view = ThermometerView(10, 10, min_value=-15, max_value=45)
    humidity_view = ThermometerView(80,
                                    10,
                                    min_value=0,
                                    max_value=100,
                                    color=lcd.BLUE,
                                    label='%')

    # SDカードのマウント
    uos.mountsd()

    # 背景の描画
    temperature_view.init()
    humidity_view.init()

    ########## 無限ループ ##########
    while not buttonC.isPressed():
        # センサーで温度と湿度を計測する
        sensor.measure()
        temperature = sensor.temperature()
        humidity = sensor.humidity()

        # デバッグ用
        print("Temperature: {} `C, Humidity: {} %".format(
            temperature, humidity))

        # 温度計、湿度計の表示を更新する
        temperature_view.update(temperature)
        humidity_view.update(humidity)

        # WBGT値を求める
        try:
            wbgt = calc_wbgt(temperature, humidity)
        except ValueError:
            wbgt = None

        # WBGT値を画面に表示する
        lcd.font(lcd.FONT_Default, color=color, transparent=False)
        lcd.textClear(160, 30, 'WBGT: Unknown')
        if wbgt is not None:
            lcd.text(160, 30, 'WBGT: {}'.format(wbgt))
        else:
            lcd.text(160, 30, 'WBGT: Unknown')

        image_path = None

        # WBGT値に応じて画像を描画する
        # 31度以上          : 危険
        # 28度以上31度未満  : 厳重警戒
        # 25度以上28度未満  : 警戒
        # 25度未満          : 注意
        if temperature >= 21 and wbgt is not None:
            if wbgt >= 31:
                # 危険
                image_path = image_path_kiken
            elif wbgt >= 28:
                # 厳重警戒
                image_path = image_path_genjukeikai
            elif wbgt >= 25:
                # 警戒
                image_path = image_path_keikai

        # 湿度に応じてインフルエンザ注意情報を表示する
        # 湿度40%未満 : インフルエンザ感染注意
        if humidity < 40:
            image_path = image_path_influenza

        if image_path is not None:
            # 画像を描画する
            lcd.image(image_x, image_y, image_path)
        else:
            # 画像を描画した領域を背景色で塗りつぶす
            lcd.rect(image_x, image_y, image_width, image_height,
                     background_color, background_color)

        # 表示の更新間隔
        utime.sleep(interval)
Exemplo n.º 9
0
def main():
    import time
    import uos

    from m5stack import lcd, buttonA, buttonB, buttonC
    import network
    import binascii

    DNAME_ROOT = 'wifi_analyzer'

    def drawNaviButton(strA='START', strB='STOP', strC='EXIT'):
        lcd.text(40, 215, strA, lcd.WHITE)
        lcd.text(135, 215, strB, lcd.WHITE)
        lcd.text(240, 215, strC, lcd.WHITE)

    def fnameGen():
        currentFileList = list(
            filter(lambda x: 'WA_' in x, uos.listdir('/sd/' + DNAME_ROOT)))
        currentFileList = list(map(lambda x: x.lower(), currentFileList))
        if 'wa_0001.csv' not in currentFileList:
            return 'WA_0001.csv'
        else:
            currentFileList.sort()
            newestFileName = currentFileList[-1]
            no = int(newestFileName[3:7])
            return 'WA_%s.csv' % (('%4d' % (no + 1)).replace(' ', '0'))

    def resdisplay(apresults, n, time):
        lcd.rect(0, 0, 320, 24, lcd.BLUE, lcd.BLUE)
        lcd.font(lcd.FONT_Ubuntu, transparent=True)
        lcd.text(0, 2, 'N_AP:%d N_SCAN:%d TIME:%d' % (len(apresults), n, time),
                 lcd.WHITE)
        lcd.rect(0, 24, 320, 186, lcd.BLACK, lcd.BLACK)
        lcd.setCursor(0, 24)
        lcd.font(lcd.FONT_DefaultSmall)

        if len(apresults) < 15:
            i = 0
            for apresult in apresults:
                resstr = '%02d, ch: %02d, rs: %d, %s\n' % (
                    i + 1, apresult[2], apresult[3], apresult[0].decode())
                lcd.print(resstr, color=lcd.WHITE)
                i = i + 1
        else:
            for i in range(0, 15):
                apresult = apresults[i]
                resstr = '%02d, ch: %02d, rs: %d, %s\n' % (
                    i + 1, apresult[2], apresult[3], apresult[0].decode())
                lcd.print(resstr, color=lcd.WHITE)

    try:
        uos.stat('/sd')
    except:
        try:
            uos.mountsd()
        except:
            lcd.println('No SD card is found.')
            return -1

    try:
        sdFiles = uos.listdir('/sd')
        if DNAME_ROOT not in sdFiles:
            uos.mkdir('/sd/' + DNAME_ROOT)
    except:
        lcd.println('The SD card is not writable.')
        return -2

    try:
        drawNaviButton()
        lcd.setCursor(0, 0)

        lcd.println('Press START to start')
        while not buttonA.isPressed():
            time.sleep(.5)
            if buttonC.isPressed():
                return 0

        wlan = network.WLAN(network.STA_IF)
        wlan.active(True)

        fname = fnameGen()
        lcd.println('Recording into %s...' % fname)

        ts = time.time()
        n = 0
        while not buttonB.isPressed():
            buf = ''
            aps = wlan.scan()
            n += 1
            te = time.time() - ts
            for ap in aps:
                # (ssid, bssid, primary_chan, rssi, auth_mode, auth_mode_string, hidden)
                mac = (binascii.hexlify(ap[1])).decode()
                mac = ':'.join([
                    mac[:2], mac[2:4], mac[4:6], mac[6:8], mac[8:10],
                    mac[10:12]
                ])
                buf += '%.3f,%s,%s,%d,%s\n' % (te, mac, ap[0].decode(), ap[3],
                                               ap[2])
            print(buf + '---------------------')
            resdisplay(aps, n, int(te))

            with open('/sd/' + DNAME_ROOT + '/' + fname, 'a') as o:
                o.write(buf)
        lcd.println('Exit.')

    except:
        print('Exit since error.')
        pass