393ce3c0ed
lua_app.cpp had grown to 701 lines holding every binding, the module loader and the app lifecycle, so new bindings landed wherever the cursor was. Each Lua table now has its own file under bindings/, and the app is recovered from the lua_State's extra space instead of a file-static, so a second state cannot reach the wrong app. Three tests each redeclared the binding surface, which broke twice this session when a binding changed; test/fake_device.lua is now the single stub. `make test` runs all four suites and pins Lua 5.4, matching the vendored interpreter rather than the 5.2 the tests had silently been using.
103 lines
3.3 KiB
Lua
103 lines
3.3 KiB
Lua
-- Stand-in for the firmware bindings, so host tests exercise the real ui.lua.
|
|
--
|
|
-- One definition of the binding surface: when a binding is added or renamed, this is
|
|
-- the file that changes. Tests mutate the returned table to steer the device, and may
|
|
-- overwrite any stub function outright for a single assertion.
|
|
|
|
local device = {
|
|
-- Text metrics chosen to match the firmware's default GLCD font, since layout
|
|
-- assertions are written in real pixels.
|
|
fontHeight = 8,
|
|
charWidth = 6,
|
|
now = 0,
|
|
rotation = 0,
|
|
theme = "light",
|
|
raw = nil, -- pending raw touch reading, {x, y} or nil
|
|
networks = {}, -- what wifi.scan() returns
|
|
status = {state = "disconnected", ssid = "", ip = "", rssi = 0},
|
|
painted = {}, -- every drawText call, in order
|
|
calibration = nil, -- last sys.setCalibration()
|
|
connected = nil, -- last wifi.connect()
|
|
exited = false,
|
|
launched = nil,
|
|
saveFails = false, -- make every persisting call report failure
|
|
}
|
|
|
|
local function saved()
|
|
return not device.saveFails
|
|
end
|
|
|
|
function device.install()
|
|
device.painted = {}
|
|
|
|
gui = {
|
|
color = function(r, g, b) return r * 65536 + g * 256 + b end,
|
|
-- Rotation swaps the frame, exactly as TFT_eSPI reports it.
|
|
width = function() return device.rotation % 180 == 0 and 320 or 480 end,
|
|
height = function() return device.rotation % 180 == 0 and 480 or 320 end,
|
|
clear = function() end,
|
|
fillRect = function() end,
|
|
drawRect = function() end,
|
|
fillCircle = function() end,
|
|
drawLine = function() end,
|
|
roundRect = function() end,
|
|
drawText = function(label, x, y)
|
|
device.painted[#device.painted + 1] = {label = label, x = x, y = y}
|
|
end,
|
|
fontHeight = function() return device.fontHeight end,
|
|
textWidth = function(text) return #text * device.charWidth end,
|
|
setRotation = function() end,
|
|
}
|
|
|
|
sys = {
|
|
millis = function() return device.now end,
|
|
exit = function() device.exited = true end,
|
|
launch = function(path) device.launched = path end,
|
|
getRotation = function() return device.rotation end,
|
|
setRotation = function(degrees)
|
|
if degrees % 90 ~= 0 or degrees < 0 or degrees > 270 then return false end
|
|
device.rotation = degrees
|
|
return saved()
|
|
end,
|
|
getTheme = function() return device.theme end,
|
|
setTheme = function(name) device.theme = name return saved() end,
|
|
setCalibration = function(...) device.calibration = {...} return saved() end,
|
|
}
|
|
|
|
input = {
|
|
touched = function() return device.raw ~= nil end,
|
|
getTouch = function()
|
|
if not device.raw then return nil end
|
|
return device.raw[1], device.raw[2]
|
|
end,
|
|
getRawTouch = function()
|
|
if not device.raw then return nil end
|
|
return device.raw[1], device.raw[2]
|
|
end,
|
|
}
|
|
|
|
fs = {
|
|
readFile = function() return nil end,
|
|
writeFile = function() return saved() end,
|
|
exists = function() return false end,
|
|
listFiles = function() return {} end,
|
|
listDirs = function() return {} end,
|
|
}
|
|
|
|
wifi = {
|
|
scan = function() return device.networks end,
|
|
status = function() return device.status end,
|
|
connect = function(ssid, password)
|
|
device.connected = {ssid, password}
|
|
return saved()
|
|
end,
|
|
forget = function() device.connected = nil return saved() end,
|
|
}
|
|
|
|
log = {info = function() end}
|
|
|
|
return device
|
|
end
|
|
|
|
return device
|