mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Overhaul Lua API
Lua API moved into a tio library table and names adjusted to Lua stdlib style. Regex in expect() replaced with Lua patterns so binary data can be handled. New tio.alwaysecho variable allows enabling and disabling echo to console. Read and write functions now manage complex retry and timeout logic internally, giving the user a simple "nil if fail" API like the rest of Lua. exit() was removed, os.exit() already exists in the Lua standard library.
This commit is contained in:
parent
8f33cff6ea
commit
114b69b68a
9 changed files with 318 additions and 465 deletions
|
|
@ -69,7 +69,7 @@ color = 13
|
|||
[esp32]
|
||||
device = /dev/ttyUSB0
|
||||
color = 14
|
||||
script = set{DTR=high,RTS=low}; msleep(100); set{DTR=low,RTS=high}; msleep(100); set{RTS=low}
|
||||
script = tio.set{DTR=high,RTS=low}; tio.msleep(100); tio.set{DTR=low,RTS=high}; tio.msleep(100); tio.set{RTS=low}
|
||||
script-run = always
|
||||
|
||||
[buspirate]
|
||||
|
|
|
|||
|
|
@ -13,14 +13,13 @@ local logins = {
|
|||
},
|
||||
}
|
||||
|
||||
local found, match_str = expect("\\w+- login:", 10)
|
||||
if (1 == found) then
|
||||
local hostname = string.match(match_str, "^%w+")
|
||||
local hostname = tio.expect("^(%g+) login:", 10)
|
||||
if hostname then
|
||||
local login = logins[hostname]
|
||||
if (nil ~= login) then
|
||||
write(login.username .. "\n")
|
||||
expect("Password:")
|
||||
write(login.password .. "\n")
|
||||
tio.write(login.username .. "\n")
|
||||
tio.expect("Password:")
|
||||
tio.write(login.password .. "\n")
|
||||
else
|
||||
io.write("\r\nDon't know login info for " .. hostname .. "\r\n")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
set{DTR=high, RTS=low}
|
||||
msleep(100)
|
||||
set{DTR=low, RTS=high}
|
||||
msleep(100)
|
||||
set{RTS=toggle}
|
||||
tio.set{DTR=high, RTS=low}
|
||||
tio.msleep(100)
|
||||
tio.set{DTR=low, RTS=high}
|
||||
tio.msleep(100)
|
||||
tio.set{RTS=toggle}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
read(1000, 6000) -- initial config
|
||||
write("\n")
|
||||
msleep(100)
|
||||
read(650, 60) -- main menu
|
||||
write("S") -- S menu
|
||||
msleep(30)
|
||||
read(650, 60)
|
||||
write("t") -- Parallel Value Table
|
||||
read(650, 60)
|
||||
tio.read(1000, 6000) -- initial config
|
||||
tio.write("\n")
|
||||
tio.msleep(100)
|
||||
tio.read(650, 60) -- main menu
|
||||
tio.write("S") -- S menu
|
||||
tio.msleep(30)
|
||||
tio.read(650, 60)
|
||||
tio.write("t") -- Parallel Value Table
|
||||
tio.read(650, 60)
|
||||
while true do
|
||||
msleep(1000)
|
||||
write("t")
|
||||
read(650, 50) -- repeat PVT forever
|
||||
tio.msleep(1000)
|
||||
tio.write("t")
|
||||
tio.read(650, 50) -- repeat PVT forever
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,17 +1,15 @@
|
|||
read(1000, 8000) -- read initial config
|
||||
write("\n")
|
||||
read(650, 100) -- main menu
|
||||
write("S") -- S menu
|
||||
n = 1
|
||||
while n > 0 do -- while not empty, read more
|
||||
n, str = read_line(25)
|
||||
end
|
||||
tio.read(1000, 8000) -- read initial config
|
||||
tio.write("\n")
|
||||
tio.read(650, 100) -- main menu
|
||||
tio.write("S") -- S menu
|
||||
repeat
|
||||
str = tio.readline(25)
|
||||
until str == nil
|
||||
while true do
|
||||
write("t") -- query PV table
|
||||
msleep(880)
|
||||
n = 1
|
||||
while n > 0 do -- while not empty, read more
|
||||
n, str = read_line(60)
|
||||
msleep(60)
|
||||
end
|
||||
tio.write("t") -- query PV table
|
||||
tio.msleep(880)
|
||||
repeat
|
||||
str = tio.readline(60)
|
||||
tio.msleep(60)
|
||||
until str == nil
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
io.write("Searching... ")
|
||||
|
||||
local device = tty_search()
|
||||
local device = tio.ttysearch()
|
||||
|
||||
io.write("done\r\n")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue