1
0
mirror of https://github.com/20kdc/OC-KittenOS.git synced 2024-11-16 23:48:05 +11:00
OC-KittenOS/code/apps/app-flash.lua

90 lines
2.3 KiB
Lua

-- This is released into the public domain.
-- No warranty is provided, implied or otherwise.
local event = require("event")(neo)
local neoux = require("neoux")(event, neo)
local eeprom = neo.requireAccess("c.eeprom")
-- note: fun coincidence makes this exactly the right size
-- 1234567890123456789012345
-- ABCDEF12 Lua BIOS
-- <get><set> <data> <label>
-- 21FEDCBA Nuclear Disk
-- <get><set> <data> <label>
local running = true
local busy = false
local regenCore
local function regenLabeller(set, get, wd)
return wd, 2, nil, neoux.tcwindow(wd, 1, {
neoux.tcfield(1, 1, wd, function (nt)
if nt then
set(nt)
end
return get()
end)
}, function (w)
busy = false
w.reset(regenCore())
end, 0xFFFFFF, 0)
end
function regenCore()
local elems = {}
local l = 1
for v in eeprom.list() do
local lbl = unicode.safeTextFormat(v.getLabel())
table.insert(elems, neoux.tcrawview(1, l, {
v.address:sub(1, 8) .. " " .. lbl
}))
table.insert(elems, neoux.tcbutton(1, l + 1, "get", function (window)
if busy then return end
busy = true
local fd = neoux.fileDialog(true)
if not fd then busy = false return end
fd.write(v.get())
fd.close()
busy = false
neoux.startDialog("Got the data!", nil, true)
end))
table.insert(elems, neoux.tcbutton(6, l + 1, "set", function (window)
if busy then return end
busy = true
local fd = neoux.fileDialog(false)
if not fd then busy = false return end
local eepromCode = fd.read("*a")
fd.close()
local wasOk, report = v.set(eepromCode)
report = (wasOk and tostring(report)) or "Flash successful.\nI recommend relabelling the EEPROM."
busy = false
neoux.startDialog(report, nil, true)
end))
local function dHandler(set, get, wd)
local setter = v[set]
local getter = v[get]
return function (window)
if busy then return end
busy = true
window.reset(regenLabeller(setter, getter, wd))
end
end
table.insert(elems, neoux.tcbutton(12, l + 1, "data", dHandler("setData", "getData", 38)))
table.insert(elems, neoux.tcbutton(19, l + 1, "label", dHandler("setLabel", "getLabel", 18)))
l = l + 2
end
return 25, l - 1, nil, neoux.tcwindow(25, l - 1, elems, function (w)
w.close()
running = false
end, 0xFFFFFF, 0)
end
local window = neoux.create(regenCore())
while running do
event.pull()
end