49 lines
1.2 KiB
Lua

local lastMessage = 0
local botState = {
cpuBattery = nil,
servoBattery = nil,
}
function love.draw2()
love.graphics.setBackgroundColor(0, 0, 0)
local time
if lastMessage == 0 then
time = "Never"
else
time = math.floor(love.timer.getTime() - lastMessage) .. "s ago"
end
love.graphics.print("Last message received: " .. time, 5, 5)
love.graphics.print("CPU Batt: " .. formatSafe("%.02f V", botState.cpuBattery), 5, 30)
love.graphics.print("Servo Batt: " .. formatSafe("%.02f V", botState.servoBattery), 5, 45)
end
function formatSafe(format, value)
if value == nil then
return "unknown"
end
return string.format(format, value)
end
function love.load()
love.graphics.setFont(love.graphics.newFont(15))
love.window.setFullscreen(true)
love.mqtt.subscribe("telemetry/#")
end
function love.mqtt.message(topic, payload)
if topic == "telemetry/cpu_battery" then
botState.cpuBattery = tonumber(payload)
lastMessage = love.timer.getTime()
elseif topic == "telemetry/servo_battery" then
botState.servoBattery = tonumber(payload)
lastMessage = love.timer.getTime()
end
end
function love.gamepadpressed(joystick, button)
print("Pressed gamepad button " .. button .. " on joystick " .. joystick:getName())
end