Skip to content

Commit

Permalink
added round for GPS + mod after PR
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsnti committed Apr 20, 2020
1 parent 2f598a1 commit 5a7e78a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
47 changes: 35 additions & 12 deletions farl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
local displayGPS = false

-- Drone locator & Power ouput
local displayQuadLocator = false
local displayPowerOutput = false
local displayQuadLocator = true
local displayPowerOutput = true

-- Will be displayed only if displayGPS, Quad locator and PowerOuput are set to false
local displayFillingText = true
Expand Down Expand Up @@ -55,6 +55,15 @@ local function convertVoltageToPercentage(voltage)
return curVolPercent
end

-- Round routine for GPS
local function round(num, idp)
local temp = 10^(idp or 0)
if num >= 0 then
return math.floor(num * temp + 0.5) / temp
else
return math.ceil(num * temp - 0.5) / temp end
end

-- A little animation / frame counter to help us with various animations
local function setAnimationIncrement()
animationIncrement = math.fmod(math.ceil(math.fmod(getTime() / 100, 2) * 8), 4)
Expand Down Expand Up @@ -456,11 +465,8 @@ local function gatherInput(event)
-- Get our current transmitter voltage
currentVoltage = getValue('tx-voltage')

-- Armed / Disarm / Buzzer switch
armed = getValue('sa')

-- Our "mode" switch
mode = getValue('sc')
flight_mode = getValue("FM")

-- Do some event handling to figure out what button(s) were pressed :)
if event > 0 then
Expand Down Expand Up @@ -503,12 +509,29 @@ end

local function getModeText()
local modeText = "Unknown"
if mode < -512 then
modeText = "Angle"
elseif mode > -100 and mode < 100 then
modeText = "Acro"
elseif mode > 512 then
modeText = "Horizon"

if flight_mode == "!ERR" or flight_mode == "!ERR*" then
modeText = "----"
elseif flight_mode == "!FS!" or flight_mode == "!FS!*" then
modeText = "FAILSAFE"
elseif flight_mode == "RTH"then
modeText = "RTH"
elseif flight_mode == "MANU"then
modeText = "MANUAL"
elseif flight_mode == "STAB"then
modeText = "ANGLE"
elseif flight_mode == "HOR" then
modeText = "HORIZON"
elseif flight_mode == "AIR" then
modeText = "AIR"
elseif flight_mode == "ACRO" then
modeText = "ACRO"
elseif flight_mode == "WAIT" or flight_mode == "WAIT*" then
modeText = "WgAIT"
elseif ((string.sub(flight_mode,-1) == "*") and (flight_mode ~= "!ERR*") and (flight_mode ~= "!FS!*") and (flight_mode ~= "WAIT*")) then
modeText = "DISARM"
else
modeText = "----"
end
return modeText
end
Expand Down
10 changes: 4 additions & 6 deletions farlfh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,8 @@ local function gatherInput(event)
-- Get our current transmitter voltage
currentVoltage = getValue('tx-voltage')

-- Armed / Disarm / Buzzer switch
-- armed = getValue('sa') -- no longer needed

-- Our "mode" switch -- uses actual telemetry

flight_mode = getValue("FM")

-- Do some event handling to figure out what button(s) were pressed :)
Expand Down Expand Up @@ -476,9 +474,9 @@ end


local function getModeText() -- modified to use actual flight mode from CrossFire telemetry and make modes more legible
local modeText = "DISARM"
local modeText = "NONE"
if flight_mode == "!ERR" or flight_mode == "!ERR*" then
modeText = "ERROR"
modeText = "----"
elseif flight_mode == "!FS!" or flight_mode == "!FS!*" then
modeText = "FAILSAFE"
elseif flight_mode == "RTH"then
Expand All @@ -498,7 +496,7 @@ local function getModeText() -- modified to use actual flight mode from CrossFir
elseif ((string.sub(flight_mode,-1) == "*") and (flight_mode ~= "!ERR*") and (flight_mode ~= "!FS!*") and (flight_mode ~= "WAIT*")) then
modeText = "DISARM"
else
modeText = "UNKNOWN"
modeText = "----"
end
return modeText
end
Expand Down

0 comments on commit 5a7e78a

Please sign in to comment.