コード例 #1
0
                if flip:
                    recfile = ICON_REC1
                else:
                    recfile = ICON_REC2
                flip = not flip
                tft.image(0, 0, recfile)
    else:
        break

    sleep(INTERVAL)

print("Shutdown")

if SD_present:
    # uos.sync()
    uos.umountsd()

if GNSS_present:
    gps.stopservice()

if TFT_present:
    bl_timer.deinit()
    if Battery_Low:
        offname = ICON_LOWBAT
    else:
        offname = ICON_OFF
    tft.image(0, 0, offname)
    width, height = tft.screensize()
    tft.rect(1, 1, width - 1, height - 1, tft.WHITE)
    if not Backlight:
        backlight(True)
コード例 #2
0
ファイル: micropyos.py プロジェクト: SaimShuja/micropyos
def main():
    print(
        ' __   __  ___   _______  ______    _______  _______  __   __  _______  _______ '
    )
    print(
        '|  |_|  ||   | |       ||    _ |  |       ||       ||  | |  ||       ||       |'
    )
    print(
        '|       ||   | |       ||   | ||  |   _   ||    _  ||  |_|  ||   _   ||  _____|'
    )
    print(
        '|       ||   | |       ||   |_||_ |  | |  ||   |_| ||       ||  | |  || |_____ '
    )
    print(
        '|       ||   | |      _||    __  ||  |_|  ||    ___||_     _||  |_|  ||_____  |'
    )
    print(
        '| ||_|| ||   | |     |_ |   |  | ||       ||   |      |   |  |       | _____| |'
    )
    print(
        '|_|   |_||___| |_______||___|  |_||_______||___|      |___|  |_______||_______|'
    )
    print('small OS for micropython ver ' + version + ' by theCodeman')
    print('https://github.com/TheCodeman/myos')
    print('MicroPython Version : {} Platform : {}'.format(
        sys.version, sys.platform))

    timer.init(period=1000, mode=machine.Timer.PERIODIC, callback=intCallback)

    while True:
        str = input(uos.getcwd() + '>')
        cmd = str.split()
        #        print(cmd)
        if len(str) != 0:
            if cmd[0] == 'cd':
                try:
                    uos.chdir(cmd[1])
                except:
                    print('bad dir')

            elif cmd[0] == 'ls':
                print('Current Directory ', uos.getcwd())
                total = 0
                #F       1366    lora.py
                print('Type    Size    Filename')
                print('----------------------------------')
                if len(cmd) == 2:
                    path = cmd[1]
                else:
                    path = uos.getcwd()
                try:
                    for l in uos.ilistdir(path):
                        if l[1] & 0x4000:
                            print('D{0:>31}'.format(l[0]))
                        else:
                            # F       3360    myos.py
                            total += int(uos.stat(l[0])[6])
                            print('F       {0:<8}{1:>16}'.format(
                                uos.stat(l[0])[6], l[0]))
                    print('----------------------------------')
                    print('File Size Total: {0}'.format(total))
                except Exception as e:
                    print(e)

            elif cmd[0] == 'cp':
                if len(cmd) == 3:
                    try:
                        with open(cmd[1], 'rb') as source:
                            print('Source {0}'.format(cmd[1]))
                            data = source.read()
                            source.close()
                    except Exception as e:
                        print(e)
                    try:
                        with open(cmd[2], 'wb') as dest:
                            print('Dest {0}'.format(cmd[2]))
                            dest.write(data)
                            dest.close()
                    except Exception as e:
                        print(e)
                else:
                    print(
                        'cp requires source filename and destination filename '
                    )

            elif cmd[0] == 'run':
                if len(cmd) == 2:
                    __import__(cmd[1])
                    del sys.modules[cmd[1]]
                else:
                    print('Need File Name')

            elif cmd[0] == 'lr':
                if networkUp:
                    if len(cmd) == 1:
                        res = ssh.list(settings.remoteIP + settings.remotePath,
                                       settings.uname, settings.upass)
                    else:
                        res = ssh.list(
                            settings.remoteIP + settings.remotePath + cmd[1],
                            settings.uname, settings.upass)
                    print(res[0])
                    if res[0] == 0:
                        print(res[1])
                        print(res[2])
                else:
                    print('No Network Connection')
            elif cmd[0] == 'put':
                if networkUp:
                    res = ssh.put(settings.remoteIP + settings.remotePath +
                                  cmd[1],
                                  settings.uname,
                                  settings.upass,
                                  file=cmd[1])
                    if res[0] == 0:
                        print('File %s copied to %s' %
                              (cmd[1], settings.remotePath))
                else:
                    print('No Network Connection')
            elif cmd[0] == 'get':
                if networkUp:
                    res = ssh.get(settings.remoteIP + settings.remotePath +
                                  cmd[1],
                                  settings.uname,
                                  settings.upass,
                                  file='$$$.tmp')
                    if res[0] == 0:
                        try:
                            uos.remove(cmd[1])
                        except:
                            pass
                        uos.rename('$$$.tmp', cmd[1])
                        print('File %s copied from %s' %
                              (cmd[1], settings.remotePath))
                    else:
                        uos.remove('$$$.tmp')
                        print('File Not Found')
                else:
                    print('No Network Connection')
            elif cmd[0] == 'edit':
                pye(cmd[1])

            elif cmd[0] == 'rm':
                try:
                    uos.remove(cmd[1])
                except:
                    print('no file')

            elif cmd[0] == 'md':
                try:
                    uos.mkdir(cmd[1])
                except:
                    print("Need Directory Name")

            elif cmd[0] == 'rmdir':
                try:
                    uos.rmdir(cmd[1])
                except:
                    print("Need Directory Name")

            elif cmd[0] == 'reset':
                machine.reset()

            elif cmd[0] == 'cat':
                line = 0
                try:
                    f = open(cmd[1], 'r')
                    while True:
                        str = f.readline()
                        if str == "":
                            break
                        print(str, end="")
                        line += 1
                        if line > 25:
                            print(
                                '----- press space to continue or q to quit -----',
                                end="")
                            ret = getch()
                            print(
                                '\r                                                \r',
                                end="")
                            if ret == 'q':
                                break
                            else:
                                line = 0
                    f.close()
                except:
                    print('no file')

            elif cmd[0] == 'time':
                print('Time set to: {}'.format(
                    utime.strftime('%c', utime.localtime())))

            elif cmd[0] == 'df':
                if len(cmd) == 1:
                    fs_stat = uos.statvfs(uos.getcwd())
                else:
                    fs_stat = uos.statvfs(cmd[1])
                fs_size = fs_stat[0] * fs_stat[2]
                fs_free = fs_stat[0] * fs_stat[3]
                print('File System Size {:,} - Free Space {:,}'.format(
                    fs_size, fs_free))

            elif cmd[0] == 'wget':
                if networkUp:
                    try:
                        response = urequests.get(cmd[1])

                        if response.status_code == 200:
                            print(type(response))
                            print(response.text)
                            print(type(response.text))
                            fileName = cmd[1].split('/')
                            print(fileName)
                            print(fileName[-1])
                            f = open(fileName[-1], 'w')
                            f.write(response.text)
                            f.close()
                        else:
                            print('Error: {0} {1}'.format(
                                response.status_code,
                                response.reason.decode('utf-8')))
                    except Exception as e:
                        print(e)
                else:
                    print('No Network Connection')
            elif cmd[0] == 'wifi':
                try:
                    if cmd[1] == 'active':
                        nic.active(True)
                    if cmd[1] == 'deactive':
                        nic.active(False)
                    if cmd[1] == 'config':
                        status = nic.ifconfig()
                        print(
                            'IP: {0}\n\rSubnet: {1}\r\nGateway: {2}\r\nDNS: {3}'
                            .format(status[0], status[1], status[2],
                                    status[3]))
                    if cmd[1] == 'isconnected':
                        print(nic.isconnected())
                    if cmd[1] == 'connect':
                        try:
                            nic.connect(cmd[2], cmd[3])
                        except Exception as e:
                            print(e)
                    if cmd[1] == 'scan':
                        stations = nic.scan()
                        for s in stations:
                            if s[4] == 0:
                                authmode = 'Open'
                            if s[4] == 1:
                                authmode = 'Wep'
                            if s[4] == 2:
                                authmode = 'WPA-PSK'
                            if s[4] == 3:
                                authmode = 'WPA2-PSK'
                            if s[4] == 4:
                                authmode = 'WPA/WPA2-PSK'
                            print(
                                'SSID: {0:<32} Channel: {1} RSSSI: {2} Auth Type: {3}'
                                .format(s[0].decode('utf-8'), s[2], s[3],
                                        authmode))
                except Exception as e:
                    print(e)
                    print(' no action')

            elif cmd[0] == 'umountsd':
                try:
                    uos.umountsd()
                except Exception as e:
                    print(e)

            elif cmd[0] == 'mountsd':
                try:
                    uos.mountsd()
                except Exception as e:
                    print(e)

            elif cmd[0] == 'help':
                print('Command List')
                print('----------------------------------')
                print('ls      - list files current directory')
                print(
                    'lr      - list files on remote server optional directory')
                print('cat     - display file')
                print('rm      - remove file')
                print('df      - display drive space')
                print('time    - display time and date')
                print('get     - scp from server')
                print('put     - scp to server')
                print('md      - make directory')
                print('rmdir   - remove directory')
                print('run     - run python script')
                print('edit    - edit file using pye')
                print('modules - list installed modules')
                print('reset   - reset board')
                print('wget    - get file over http and save to file')
                print('----------------------------------')

            elif cmd[0] == 'exit':
                timer.deinit()
                return 1

            elif cmd[0] == 'update':
                if networkUp:
                    res = ssh.get(settings.remoteIP + settings.remotePath +
                                  'micropyos.py',
                                  settings.uname,
                                  settings.upass,
                                  file='$$$.tmp')
                    if res[0] == 0:
                        try:
                            uos.remove('micropyos.py')
                        except:
                            pass
                        uos.rename('$$$.tmp', 'micropyos.py')
                        print('File %s copied from %s' %
                              ('micropyos.py', settings.remotePath))
                    else:
                        uos.remove('$$$.tmp')
                        print('File Not Found')
                    timer.deinit()
                    return 2
                else:
                    print('No Network Connection')

            elif cmd[0] == 'modules':
                for m in sys.modules:
                    print(m)

            elif cmd[0] == 'settings':
                pye('settings.py')

            else:
                print('unknown command')