1
0
mirror of https://github.com/20kdc/OC-KittenOS.git synced 2024-11-08 19:48:07 +11:00
OC-KittenOS/repository/apps/app-eeprog.lua

49 lines
1.4 KiB
Lua
Raw Normal View History

-- This is released into the public domain.
-- No warranty is provided, implied or otherwise.
-- app-eeprom: Tiny EEPROM flasher
-- Example of a tiny app a user could write relatively quickly if they have NEO system knowledge
-- Note the high amount of synchronous routines used here.
-- For a tiny app like this, it's fine, and KittenOS NEO makes sure it won't interfere.
-- (Plus, this isn't a library, so that's not a concern)
-- Really, in KittenOS NEO, the only program you break is your own
local event = require("event")(neo)
local neoux = require("neoux")(event, neo)
local eeprom = neo.requestAccess("c.eeprom")
if eeprom then
eeprom = eeprom.list()()
end
if not eeprom then
error("No EEPROM access")
end
neoux.startDialog("NOTE: If this program is used improperly, it can require EEPROM replacement.\nOnly use trusted EEPROMs.", "eeprom-flash", true)
local fd = neoux.fileDialog(false)
if not fd then return end
local eepromCode = fd.read("*a")
fd.close()
eeprom.set(eepromCode)
neoux.startDialog("The flash was successful - the next dialog can change the label.", "eeprom-flash", true)
-- text dialog
local done = false
neoux.create(20, 1, "label", neoux.tcwindow(20, 1, {
neoux.tcfield(1, 1, 20, function (nv)
if not nv then
return eeprom.getLabel()
end
eeprom.setLabel(nv)
end)
}, function (w)
w.close()
done = true
end, 0xFFFFFF, 0))
while not done do
event.pull()
end