GithubHelp home page GithubHelp logo

shawwwn / micropython-ainput Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 0.0 18 KB

Asynchronous user input libraries using the MicroPython uasyncio

License: MIT License

Python 100.00%
micropython uasyncio input telnet repl

micropython-ainput's Introduction

micropython-ainput

Asynchronous user input libraries using MicroPython uasyncio library

uaioinput <esp32(*), esp8266>

Library for for getting user input inside uasyncio event-loop

NOTE(*):
For this to work on esp32, you need to use my fork of micropython which incorperates a hack on the UART console.

Usage

import uasyncio
from uaioinput import ainput
s = await ainput(prompt="User Input: ", password=False)
print(s)

To prevent two ainput() being called at the same time, a global lock is implemented at the module level.
To check lock status,

import uaioinput
print(uaioinput.input_lock.locked)

Dependencies

uaiorepl <esp32(*), esp8266>

A simple(dumb) REPL console that runs inside uasyncio event-loop.
Features are severely limited comparing to the standard REPL, only basic operations are supported.

NOTE(*):
ctrl+b for manual linebreak
For this to work on esp32, you need to use my fork of micropython which incorperates a hack on the UART console.

Usage

import uasyncio
import uaiorepl
loop = uasyncio.get_event_loop()
loop.call_soon(uaiorepl.start())
loop.run_forever()

uaiotelnet <esp32(*), esp8266>

Modified telnet server that runs inside uasyncio event-loop.
Adapted from cpopp's MicroTelnetServer

NOTE(*):
Must run concurrently with a uaiorepl or uaioinput otherwise user input will still be blocked.

NOTE:
If you are using Putty in windows as your telnet client, then you must set the following parameters:\

  • Terminal - Local echo - force off
  • Terminal - Local line editing - force off
  • Connection - Telnet - [UNCHECK] Return key sends Telnet New Line instead of ^M

Usage

import uasyncio, uaiotelnet, uaiorepl
loop = uasyncio.get_event_loop()
loop.call_soon(uaiotelnet.start(ip="0.0.0.0", port=23))
loop.call_soon(uaiorepl.start()) # uasyncio repl will process telnet input
loop.run_forever()

uaiowebrepl <esp32(*), esp8266>

The offical implementation of WebREPL relies on socket interrupt and can be horribly slow. This modified WebREPL runs inside uasyncio event-loop and is way faster than the official one.
Adapted from the offical WebREPL for ESP8266

NOTE:
Must run concurrently with uaiorepl or uaioinput otherwise user input will still be blocked.

Usage

import uasyncio, uaiowebrepl, uaiorepl
loop = uasyncio.get_event_loop()
loop.call_soon(uaiowebrepl.start(ip="0.0.0.0", port=8266, password=123))
loop.call_soon(uaiorepl.start()) # uasyncio repl will process webrepl input
loop.run_forever()

micropython-ainput's People

Contributors

shawwwn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

micropython-ainput's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.