kitchen-timer/l5-mockup/main.lua

66 lines
2 KiB
Lua

require("L5")
local bgImg
local pads = {
["S1"] = { 98, 25, 68, 48, img = 1 },
["S2"] = { 175, 25, 68, 48, img = 1 },
["S3"] = { 98, 83, 68, 48, img = 1 },
["S4"] = { 175, 83, 68, 48, img = 1 },
["C1"] = { 262, 23, 71, 110, img = 1 },
["W1"] = { 346, 60, 79, 84, img = 1 },
["F1"] = { 0, 0, 47, 159, img = 1 },
["F2"] = { 0, 162, 129, 29, img = 1 },
["A1"] = { 282, 202, 90, 58, img = 1 },
["A2"] = { 376, 202, 90, 58, img = 1 },
["A3"] = { 284, 262, 90, 58, img = 1 },
["A4"] = { 413, 260, 67, 60, img = 1 },
}
local selectedKeyPad = "S1"
local padScrollOrder = {}
-- TODO: replace this with ideal scroll order
for key, _ in pairs(pads) do
table.insert(padScrollOrder, key)
end
function setup()
size(480, 320) -- the size of the LCD screen
windowTitle("Kitchen Timer Mockup")
-- Sets print command output to display in window
printToScreen()
describe('Draws a yellow background!!!!')
bgImg = loadImage('images/bg.png')
local padsImg1 = loadImage('images/pads_001.png')
local padsImg2 = loadImage('images/pads_002.png')
for _, pad in pairs(pads) do
if pad.img == 1 then
pad.img = padsImg1
elseif pad.img == 2 then
pad.img = padsImg2
end
end
end
local function drawPad(padId)
local pad = pads[padId]
if pad then
copy(pad.img, pad[1], pad[2], pad[3], pad[4], pad[1], pad[2], pad[3], pad[4])
end
end
function draw()
image(bgImg, 0, 0)
drawPad(selectedKeyPad)
end
local padScrollIndex = 1
function mouseWheel(upDown)
local scrollDirection = upDown == 1 and "up" or "down"
if scrollDirection == "up" and padScrollIndex == #padScrollOrder then
padScrollIndex = 1
elseif scrollDirection == "down" and padScrollIndex == 1 then
padScrollIndex = #padScrollOrder
else
padScrollIndex = padScrollIndex + (scrollDirection == "up" and 1 or -1)
end
selectedKeyPad = padScrollOrder[padScrollIndex]
end