Initial battery telemetry working
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
local lastMessage = 0
|
||||
|
||||
local botState = {
|
||||
cpuBattery = nil,
|
||||
servoBattery = nil,
|
||||
}
|
||||
|
||||
function love.draw2()
|
||||
love.graphics.setBackgroundColor(0, 0, 0)
|
||||
|
||||
@@ -7,14 +12,35 @@ function love.draw2()
|
||||
if lastMessage == 0 then
|
||||
time = "Never"
|
||||
else
|
||||
time = love.timer.getTime() - time "s ago"
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user