mirror of
https://github.com/20kdc/OC-KittenOS.git
synced 2024-11-23 19:08:05 +11:00
Update the tape interface application to do everything it should need to be able to do
This commit is contained in:
parent
99cb58d9fc
commit
71a0aa0b08
@ -202,7 +202,7 @@ return {
|
|||||||
},
|
},
|
||||||
["app-tapedeck"] = {
|
["app-tapedeck"] = {
|
||||||
desc = "Computronics Tape Drive interface",
|
desc = "Computronics Tape Drive interface",
|
||||||
v = 0,
|
v = 1,
|
||||||
deps = {
|
deps = {
|
||||||
"neo",
|
"neo",
|
||||||
"zzz-license-pd"
|
"zzz-license-pd"
|
||||||
|
@ -10,6 +10,8 @@ for v in neo.requireAccess("c.tape_drive", "tapedrives").list() do
|
|||||||
table.insert(tapes, v)
|
table.insert(tapes, v)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local tapeRate = 4096
|
||||||
|
|
||||||
local event = require("event")(neo)
|
local event = require("event")(neo)
|
||||||
local neoux = require("neoux")(event, neo)
|
local neoux = require("neoux")(event, neo)
|
||||||
|
|
||||||
@ -31,7 +33,92 @@ local focused = true
|
|||||||
|
|
||||||
local updateTick
|
local updateTick
|
||||||
|
|
||||||
local function genPlayer(inst)
|
local downloadCancelled = false
|
||||||
|
|
||||||
|
local genPlayer -- used to return to player
|
||||||
|
|
||||||
|
local function genDownloading(inst)
|
||||||
|
local lclLabelText = {"downloading..."}
|
||||||
|
local lclLabel = neoux.tcrawview(1, 1, lclLabelText)
|
||||||
|
local thr = {
|
||||||
|
"/",
|
||||||
|
"-",
|
||||||
|
"\\",
|
||||||
|
"|"
|
||||||
|
}
|
||||||
|
local thri = 0
|
||||||
|
updateTick = function ()
|
||||||
|
lclLabelText[1] = "downloading... " .. (inst.getPosition() / (1024 * 1024)) .. "MB " .. thr[(thri % #thr) + 1]
|
||||||
|
thri = thri + 1
|
||||||
|
lclLabel.update(window)
|
||||||
|
end
|
||||||
|
return 40, 1, nil, neoux.tcwindow(40, 1, {
|
||||||
|
lclLabel
|
||||||
|
}, function (w)
|
||||||
|
downloadCancelled = true
|
||||||
|
end, 0xFFFFFF, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function doINetThing(inet, url, inst)
|
||||||
|
inet = inet.list()()
|
||||||
|
assert(inet, "No available card")
|
||||||
|
inst.stop()
|
||||||
|
inst.seek(-inst.getSize())
|
||||||
|
downloadCancelled = false
|
||||||
|
downloadPercent = 0
|
||||||
|
window.reset(genDownloading(inst))
|
||||||
|
local req = assert(inet.request(url))
|
||||||
|
req.finishConnect()
|
||||||
|
local tapePos = 0
|
||||||
|
local tapeSize = inst.getSize()
|
||||||
|
while (not downloadCancelled) and tapePos < tapeSize do
|
||||||
|
local n, n2 = req.read(neo.readBufSize)
|
||||||
|
if not n then
|
||||||
|
if n2 then
|
||||||
|
req.close()
|
||||||
|
error(n2)
|
||||||
|
end
|
||||||
|
break
|
||||||
|
elseif n == "" then
|
||||||
|
event.sleepTo(os.uptime() + 0.05)
|
||||||
|
else
|
||||||
|
inst.write(n)
|
||||||
|
tapePos = tapePos + #n
|
||||||
|
end
|
||||||
|
end
|
||||||
|
req.close()
|
||||||
|
inst.seek(-inst.getSize())
|
||||||
|
end
|
||||||
|
|
||||||
|
local function genWeb(inst)
|
||||||
|
updateTick = nil
|
||||||
|
local url = ""
|
||||||
|
local lockout = false
|
||||||
|
return 40, 3, nil, neoux.tcwindow(40, 3, {
|
||||||
|
neoux.tcrawview(1, 1, {"URL to write to tape?"}),
|
||||||
|
neoux.tcfield(1, 2, 40, function (t)
|
||||||
|
url = t or url
|
||||||
|
return url
|
||||||
|
end),
|
||||||
|
neoux.tcbutton(1, 3, "Download & Write", function (w)
|
||||||
|
lockout = true
|
||||||
|
local inet = neo.requestAccess("c.internet")
|
||||||
|
lockout = false
|
||||||
|
if inet then
|
||||||
|
local ok, err = pcall(doINetThing, inet, url, inst)
|
||||||
|
if not ok then
|
||||||
|
neoux.startDialog("Couldn't download: " .. tostring(err), "error")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
w.reset(genPlayer(inst))
|
||||||
|
end)
|
||||||
|
}, function (w)
|
||||||
|
w.reset(genPlayer(inst))
|
||||||
|
end, 0xFFFFFF, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- The actual main UI --
|
||||||
|
genPlayer = function (inst)
|
||||||
local cachedLabel = inst.getLabel() or ""
|
local cachedLabel = inst.getLabel() or ""
|
||||||
local cachedState = inst.getState()
|
local cachedState = inst.getState()
|
||||||
local function pausePlay()
|
local function pausePlay()
|
||||||
@ -51,20 +138,19 @@ local function genPlayer(inst)
|
|||||||
local sp = inst.getPosition()
|
local sp = inst.getPosition()
|
||||||
local tapeSize = inst.getSize()
|
local tapeSize = inst.getSize()
|
||||||
inst.seek(-tapeSize)
|
inst.seek(-tapeSize)
|
||||||
local tapeReadBuf = 8192
|
|
||||||
local tapePos = 0
|
local tapePos = 0
|
||||||
while tapePos < tapeSize do
|
while tapePos < tapeSize do
|
||||||
if mode then
|
if mode then
|
||||||
local data = inst.read(tapeReadBuf)
|
local data = inst.read(neo.readBufSize)
|
||||||
if not data then break end
|
if not data then break end
|
||||||
tapePos = tapePos + tapeReadBuf
|
tapePos = tapePos + #data
|
||||||
local res, ifo = fh.write(data)
|
local res, ifo = fh.write(data)
|
||||||
if not res then
|
if not res then
|
||||||
neoux.startDialog(tostring(ifo), "issue")
|
neoux.startDialog(tostring(ifo), "issue")
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local data = fh.read(tapeReadBuf)
|
local data = fh.read(neo.readBufSize)
|
||||||
if not data then break end
|
if not data then break end
|
||||||
tapePos = tapePos + #data
|
tapePos = tapePos + #data
|
||||||
inst.write(data)
|
inst.write(data)
|
||||||
@ -75,19 +161,31 @@ local function genPlayer(inst)
|
|||||||
fh.close()
|
fh.close()
|
||||||
end
|
end
|
||||||
local elems = {
|
local elems = {
|
||||||
|
neoux.tcrawview(1, 1, {
|
||||||
|
"Label:",
|
||||||
|
"Contents:"
|
||||||
|
}),
|
||||||
|
neoux.tcfield(7, 1, 34, function (tx)
|
||||||
|
if tx then
|
||||||
|
inst.setLabel(tx)
|
||||||
|
cachedLabel = tx
|
||||||
|
end
|
||||||
|
return cachedLabel
|
||||||
|
end),
|
||||||
{
|
{
|
||||||
x = 1,
|
x = 1,
|
||||||
y = 5,
|
y = 5,
|
||||||
w = 20,
|
w = 40,
|
||||||
h = 1,
|
h = 1,
|
||||||
selectable = true,
|
selectable = true,
|
||||||
line = function (w, x, y, lined, bg, fg, selected)
|
line = function (w, x, y, lined, bg, fg, selected)
|
||||||
local lx = ""
|
local lx = ""
|
||||||
local pos = inst.getPosition()
|
local pos = inst.getPosition()
|
||||||
|
local sz = inst.getSize()
|
||||||
if inst.isReady() then
|
if inst.isReady() then
|
||||||
-- Show a bar
|
-- Show a bar
|
||||||
local tick = inst.getSize() / 13
|
local tick = sz / 23
|
||||||
for i = 1, 13 do
|
for i = 1, 23 do
|
||||||
local alpos = (tick * i) - (tick / 2)
|
local alpos = (tick * i) - (tick / 2)
|
||||||
if pos > alpos then
|
if pos > alpos then
|
||||||
lx = lx .. "="
|
lx = lx .. "="
|
||||||
@ -98,13 +196,16 @@ local function genPlayer(inst)
|
|||||||
else
|
else
|
||||||
lx = "NO TAPE HERE."
|
lx = "NO TAPE HERE."
|
||||||
end
|
end
|
||||||
local sec = pos / 4096
|
local sec = pos / tapeRate
|
||||||
lx = lx .. string.format(" %03i:%02i", math.floor(sec / 60), math.floor(sec) % 60)
|
local secz = sz / tapeRate
|
||||||
|
lx = lx .. string.format(" %03i:%02i / %03i:%02i ",
|
||||||
|
math.floor(sec / 60), math.floor(sec) % 60,
|
||||||
|
math.floor(secz / 60), math.floor(secz) % 60)
|
||||||
if selected then bg, fg = fg, bg end
|
if selected then bg, fg = fg, bg end
|
||||||
window.span(x, y, lx, bg, fg)
|
window.span(x, y, lx, bg, fg)
|
||||||
end,
|
end,
|
||||||
key = function (w, update, a, b, c, kf)
|
key = function (w, update, a, b, c, kf)
|
||||||
local amount = 40960
|
local amount = tapeRate * 10
|
||||||
if kf.shift or kf.rshift then
|
if kf.shift or kf.rshift then
|
||||||
amount = amount * 24
|
amount = amount * 24
|
||||||
end
|
end
|
||||||
@ -123,52 +224,53 @@ local function genPlayer(inst)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
neoux.tcrawview(14, 3, {
|
neoux.tcrawview(33, 3, {
|
||||||
"% Vol. ",
|
"% Volume"
|
||||||
|
}),
|
||||||
|
neoux.tcrawview(20, 3, {
|
||||||
"% Speed"
|
"% Speed"
|
||||||
}),
|
}),
|
||||||
pcbox(9, 3, 0, 100, "vol", inst.setVolume),
|
pcbox(15, 3, 25, 200, "spd", inst.setSpeed),
|
||||||
pcbox(9, 4, 25, 200, "spd", inst.setSpeed),
|
pcbox(28, 3, 0, 100, "vol", inst.setVolume),
|
||||||
neoux.tcbutton(1, 3, "{", function (w)
|
neoux.tcrawview(1, 4, {
|
||||||
|
"Seeker: use ◃/▹ (shift goes faster)"
|
||||||
|
}),
|
||||||
|
neoux.tcbutton(1, 3, "«", function (w)
|
||||||
inst.seek(-inst.getSize())
|
inst.seek(-inst.getSize())
|
||||||
end),
|
end),
|
||||||
neoux.tcbutton(5, 3, "}", function (w)
|
neoux.tcbutton(11, 3, "»", function (w)
|
||||||
inst.seek(inst.getSize())
|
inst.seek(inst.getSize())
|
||||||
end),
|
end),
|
||||||
neoux.tcbutton(1, 4, ((inst.getState() == "PLAYING") and "Pause") or "Play", function (w)
|
neoux.tcbutton(4, 3, ((inst.getState() == "PLAYING") and "Pause") or "Play", function (w)
|
||||||
pausePlay()
|
pausePlay()
|
||||||
end),
|
end),
|
||||||
-- R/W buttons
|
-- R/W buttons
|
||||||
neoux.tcbutton(1, 2, "Read", function (w)
|
neoux.tcbutton(11, 2, "Read", function (w)
|
||||||
rwButton(true)
|
rwButton(true)
|
||||||
end),
|
end),
|
||||||
neoux.tcbutton(8, 2, "Write", function (w)
|
neoux.tcbutton(17, 2, "Write", function (w)
|
||||||
rwButton(false)
|
rwButton(false)
|
||||||
end),
|
end),
|
||||||
neoux.tcfield(1, 1, 20, function (tx)
|
neoux.tcbutton(24, 2, "Write From Web", function (w)
|
||||||
if tx then
|
w.reset(genWeb(inst))
|
||||||
inst.setLabel(tx)
|
|
||||||
cachedLabel = tx
|
|
||||||
end
|
|
||||||
return cachedLabel
|
|
||||||
end)
|
end)
|
||||||
}
|
}
|
||||||
updateTick = function ()
|
updateTick = function ()
|
||||||
local lcl = cachedLabel
|
local lcl = cachedLabel
|
||||||
cachedLabel = inst.getLabel() or ""
|
cachedLabel = inst.getLabel() or ""
|
||||||
elems[1].update(window)
|
elems[3].update(window)
|
||||||
if inst.getState() ~= cachedState then
|
if inst.getState() ~= cachedState then
|
||||||
window.reset(genPlayer(inst))
|
window.reset(genPlayer(inst))
|
||||||
elseif lcl ~= cachedLabel then
|
elseif lcl ~= cachedLabel then
|
||||||
elems[#elems].update(window)
|
elems[2].update(window)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local n = neoux.tcwindow(20, 5, elems, function (w)
|
local n = neoux.tcwindow(40, 5, elems, function (w)
|
||||||
updateTick = nil
|
updateTick = nil
|
||||||
running = false
|
running = false
|
||||||
w.close()
|
w.close()
|
||||||
end, 0xFFFFFF, 0)
|
end, 0xFFFFFF, 0)
|
||||||
return 20, 5, inst.address, function (a, ...)
|
return 40, 5, inst.address, function (a, ...)
|
||||||
if a == "focus" then
|
if a == "focus" then
|
||||||
focused = (...) or true
|
focused = (...) or true
|
||||||
end
|
end
|
||||||
@ -178,12 +280,12 @@ end
|
|||||||
local function genList()
|
local function genList()
|
||||||
local elems = {}
|
local elems = {}
|
||||||
for k, v in ipairs(tapes) do
|
for k, v in ipairs(tapes) do
|
||||||
elems[k] = neoux.tcbutton(1, k, v.address, function (w)
|
elems[k] = neoux.tcbutton(1, k, v.address:sub(1, 38), function (w)
|
||||||
window.reset(genPlayer(v))
|
window.reset(genPlayer(v))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
tapes = nil
|
tapes = nil
|
||||||
return 40, #elems, "choose", neoux.tcwindow(40, #elems, elems, function (w)
|
return 40, #elems, nil, neoux.tcwindow(40, #elems, elems, function (w)
|
||||||
running = false
|
running = false
|
||||||
w.close()
|
w.close()
|
||||||
end, 0xFFFFFF, 0)
|
end, 0xFFFFFF, 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user