diff --git a/.lua-format b/.lua-format new file mode 100644 index 0000000..e35fbc8 --- /dev/null +++ b/.lua-format @@ -0,0 +1,32 @@ +column_limit: 120 +indent_width: 1 +use_tab: true +tab_width: 8 +continuation_indent_width: 8 +spaces_before_call: 1 +keep_simple_control_block_one_line: true +keep_simple_function_one_line: true +align_args: true +break_after_functioncall_lp: false +break_before_functioncall_rp: false +spaces_inside_functioncall_parens: false +spaces_inside_functiondef_parens: false +align_parameter: true +chop_down_parameter: false +break_after_functiondef_lp: false +break_before_functiondef_rp: false +align_table_field: true +break_after_table_lb: true +break_before_table_rb: true +chop_down_table: false +chop_down_kv_table: true +table_sep: "," +column_table_limit: 0 +extra_sep_at_table_end: false +spaces_inside_table_braces: false +break_after_operator: true +double_quote_to_single_quote: false +single_quote_to_double_quote: false +spaces_around_equals_in_field: true +line_breaks_after_function_body: 1 +line_separator: input diff --git a/T16/GPS stats T16.lua b/T16/GPS stats T16.lua index 90a4bb2..c844d22 100644 --- a/T16/GPS stats T16.lua +++ b/T16/GPS stats T16.lua @@ -1,238 +1,220 @@ ---[[############################################################################# +--[[###################################################################### GPS stats viewer v1.2 -Copyright (C) by mosch -License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html +Copyright (C) by mosch +License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html GITHUB: https://github.com/moschotto?tab=repositories Description: reads the "GPSpositions.txt" log-file which was generated by the GPS.lua script. -useful if want to check the last GPS coordinates after a crash, power loss etc. +useful if want to check the last GPS coordinates after a crash, power loss etc. copy "GPSviewer.lua" to the /SCRIPTS/TOOLS/ folder -################################################################################]] - - + ######################################################################]] -- local toolName = "TNS|GPS stats T16|TNE" local log_filename = "/LOGS/GPSpositions.txt" local file_exist = false local string_gmatch = string.gmatch -local coordinates = {} -local coordinates_tmp = {} +local coordinates = {} +local coordinates_tmp = {} local linectr = 0 local item = 0 local function splitstring(text) if text ~= nil then - local text_split = {} - local i=0 - --split by "," and store into array/table - for word in string_gmatch(text, "([^,]+)") do + local text_split = {} + local i = 0 + -- split by "," and store into array/table + for word in string_gmatch(text, "([^,]+)") do text_split[i] = word - i = i + 1 - end + i = i + 1 + end return text_split - end + end end local function Viewer_Draw_LCD(item) - + -- display T16: 480*272px - lcd.clear() - - lcd.setColor(CUSTOM_COLOR, lcd.RGB(0x9D, 0xD6, 0x00)) - lcd.drawFilledRectangle(1,0, 480, 28, CUSTOM_COLOR) - lcd.setColor(CUSTOM_COLOR, lcd.RGB(0x00, 0x00, 0x00)) - - lcd.drawLine(125,29, 125, 95, SOLID, CUSTOM_COLOR) - lcd.drawText(0,0,"GPS stats viewer v1.2" ,MIDSIZE) - lcd.drawLine(0,28,480,28, SOLID, CUSTOM_COLOR) - - lcd.drawText(2,45, "No# " ..(linectr -item).."/" .. linectr,MIDSIZE) - lcd.drawText(130,28, "Sats: ",MIDSIZE) - lcd.drawLine(125,60, 480, 60, SOLID, CUSTOM_COLOR) - - lcd.drawText(130,63, "ALT: ",MIDSIZE) - lcd.drawText(290,63, "Speed: ",MIDSIZE) - lcd.drawLine(0,95, 480, 95, SOLID, CUSTOM_COLOR) - + lcd.clear() + + lcd.setColor(CUSTOM_COLOR, lcd.RGB(0x9D, 0xD6, 0x00)) + lcd.drawFilledRectangle(1, 0, 480, 28, CUSTOM_COLOR) + lcd.setColor(CUSTOM_COLOR, lcd.RGB(0x00, 0x00, 0x00)) + + lcd.drawLine(125, 29, 125, 95, SOLID, CUSTOM_COLOR) + lcd.drawText(0, 0, "GPS stats viewer v1.2", MIDSIZE) + lcd.drawLine(0, 28, 480, 28, SOLID, CUSTOM_COLOR) + + lcd.drawText(2, 45, "No# " .. (linectr - item) .. "/" .. linectr, MIDSIZE) + lcd.drawText(130, 28, "Sats: ", MIDSIZE) + lcd.drawLine(125, 60, 480, 60, SOLID, CUSTOM_COLOR) + + lcd.drawText(130, 63, "ALT: ", MIDSIZE) + lcd.drawText(290, 63, "Speed: ", MIDSIZE) + lcd.drawLine(0, 95, 480, 95, SOLID, CUSTOM_COLOR) + if linectr > 4 then - + if item < 4 then - --first 4 rows static + -- first 4 rows static local line0 = splitstring(coordinates[0]) local line1 = splitstring(coordinates[1]) local line2 = splitstring(coordinates[2]) local line3 = splitstring(coordinates[3]) - + if item == 0 then - lcd.drawText(290,28, "Time: " .. string.gsub(line0[3], "%s+", ""), MIDSIZE ) - lcd.drawText(130,28, "Sats: " .. string.gsub(line0[4], "%s+","") ,MIDSIZE) - lcd.drawText(130,63, "ALT: " .. string.gsub(line0[5] , "%s+", "") .."m", MIDSIZE ) - lcd.drawText(290,63, "Speed: " .. string.gsub(line0[6], "%s+","") .."kmh",MIDSIZE) - lcd.drawText(2,100, "# ".. line0[1] ..", " .. line0[2] ,DBLSIZE + BLINK + INVERS) + lcd.drawText(290, 28, "Time: " .. string.gsub(line0[3], "%s+", ""), MIDSIZE) + lcd.drawText(130, 28, "Sats: " .. string.gsub(line0[4], "%s+", ""), MIDSIZE) + lcd.drawText(130, 63, "ALT: " .. string.gsub(line0[5], "%s+", "") .. "m", MIDSIZE) + lcd.drawText(290, 63, "Speed: " .. string.gsub(line0[6], "%s+", "") .. "kmh", MIDSIZE) + lcd.drawText(2, 100, "# " .. line0[1] .. ", " .. line0[2], DBLSIZE + BLINK + INVERS) else - lcd.drawText(2,100, "# ".. line0[1] ..", " .. line0[2] ,DBLSIZE) - end - + lcd.drawText(2, 100, "# " .. line0[1] .. ", " .. line0[2], DBLSIZE) + end + if item == 1 then - lcd.drawText(290,28, "Time: " .. string.gsub(line1[3], "%s+", ""), MIDSIZE) - lcd.drawText(130,28, "Sats: " .. string.gsub(line1[4], "%s+","") ,MIDSIZE) - lcd.drawText(130,63, "ALT: " .. string.gsub(line1[5] , "%s+", "").."m", MIDSIZE ) - lcd.drawText(290,63, "Speed: " .. string.gsub(line1[6] , "%s+","") .."kmh",MIDSIZE) - lcd.drawText(2,140, "# ".. line1[1] ..", " .. line1[2] ,DBLSIZE + BLINK + INVERS) + lcd.drawText(290, 28, "Time: " .. string.gsub(line1[3], "%s+", ""), MIDSIZE) + lcd.drawText(130, 28, "Sats: " .. string.gsub(line1[4], "%s+", ""), MIDSIZE) + lcd.drawText(130, 63, "ALT: " .. string.gsub(line1[5], "%s+", "") .. "m", MIDSIZE) + lcd.drawText(290, 63, "Speed: " .. string.gsub(line1[6], "%s+", "") .. "kmh", MIDSIZE) + lcd.drawText(2, 140, "# " .. line1[1] .. ", " .. line1[2], DBLSIZE + BLINK + INVERS) else - lcd.drawText(2,140, "# ".. line1[1] ..", " .. line1[2] ,DBLSIZE) - end - + lcd.drawText(2, 140, "# " .. line1[1] .. ", " .. line1[2], DBLSIZE) + end + if item == 2 then - lcd.drawText(290,28, "Time: " .. string.gsub(line2[3], "%s+", ""), MIDSIZE) - lcd.drawText(130,28, "Sats: " .. string.gsub(line2[4], "%s+","") ,MIDSIZE) - lcd.drawText(130,63, "ALT: " .. string.gsub(line2[5] ,"%s+", "").."m", MIDSIZE ) - lcd.drawText(290,63, "Speed: " .. string.gsub(line2[6], "%s+","") .."kmh",MIDSIZE) - lcd.drawText(2,180, "# ".. line2[1] ..", " .. line2[2] ,DBLSIZE + BLINK + INVERS) + lcd.drawText(290, 28, "Time: " .. string.gsub(line2[3], "%s+", ""), MIDSIZE) + lcd.drawText(130, 28, "Sats: " .. string.gsub(line2[4], "%s+", ""), MIDSIZE) + lcd.drawText(130, 63, "ALT: " .. string.gsub(line2[5], "%s+", "") .. "m", MIDSIZE) + lcd.drawText(290, 63, "Speed: " .. string.gsub(line2[6], "%s+", "") .. "kmh", MIDSIZE) + lcd.drawText(2, 180, "# " .. line2[1] .. ", " .. line2[2], DBLSIZE + BLINK + INVERS) else - lcd.drawText(2,180, "# ".. line2[1] ..", " .. line2[2] ,DBLSIZE) - end - + lcd.drawText(2, 180, "# " .. line2[1] .. ", " .. line2[2], DBLSIZE) + end + if item == 3 then - lcd.drawText(290,28, "Time: " .. string.gsub(line3[3], "%s+", ""), MIDSIZE) - lcd.drawText(130,28, "Sats: " .. string.gsub(line3[4], "%s+","") ,MIDSIZE) - lcd.drawText(130,63, "ALT: " .. string.gsub(line3[5], "%s+", "").."m", MIDSIZE ) - lcd.drawText(290,63, "Speed: " .. string.gsub(line3[6] , "%s+","") .."kmh",MIDSIZE) - lcd.drawText(2,220, "# ".. line3[1] ..", " .. line3[2] ,DBLSIZE + BLINK + INVERS) + lcd.drawText(290, 28, "Time: " .. string.gsub(line3[3], "%s+", ""), MIDSIZE) + lcd.drawText(130, 28, "Sats: " .. string.gsub(line3[4], "%s+", ""), MIDSIZE) + lcd.drawText(130, 63, "ALT: " .. string.gsub(line3[5], "%s+", "") .. "m", MIDSIZE) + lcd.drawText(290, 63, "Speed: " .. string.gsub(line3[6], "%s+", "") .. "kmh", MIDSIZE) + lcd.drawText(2, 220, "# " .. line3[1] .. ", " .. line3[2], DBLSIZE + BLINK + INVERS) else - lcd.drawText(2,220, "# ".. line3[1] ..", " .. line3[2] ,DBLSIZE) - end + lcd.drawText(2, 220, "# " .. line3[1] .. ", " .. line3[2], DBLSIZE) + end else - - local line0 = splitstring(coordinates[item-3]) - local line1 = splitstring(coordinates[item-2]) - local line2 = splitstring(coordinates[item-1]) + + local line0 = splitstring(coordinates[item - 3]) + local line1 = splitstring(coordinates[item - 2]) + local line2 = splitstring(coordinates[item - 1]) local line3 = splitstring(coordinates[item]) - - lcd.drawText(290,28, "Time: " .. string.gsub(line3[3], "%s+", ""), MIDSIZE) - lcd.drawText(130,28, "Sats: " .. string.gsub(line3[4], "%s+","") ,MIDSIZE) - lcd.drawText(130,63, "ALT: " .. string.gsub(line3[5] , "%s+", "").."m", MIDSIZE ) - lcd.drawText(290,63, "Speed: " .. string.gsub(line3[6] , "%s+","").."kmh" ,MIDSIZE) - lcd.drawText(2,100, "# ".. line0[1] ..", " .. line0[2] ,DBLSIZE) - lcd.drawText(2,140, "# ".. line1[1] ..", " .. line1[2] ,DBLSIZE) - lcd.drawText(2,180, "# ".. line2[1] ..", " .. line2[2] ,DBLSIZE) - lcd.drawText(2,220, "# ".. line3[1] ..", " .. line3[2] ,DBLSIZE + BLINK + INVERS) - - end - - else - --display error message - lcd.clear() - lcd.setColor(CUSTOM_COLOR, lcd.RGB(0x9D, 0xD6, 0x00)) - lcd.drawFilledRectangle(1,0, 480, 28, CUSTOM_COLOR) - lcd.setColor(CUSTOM_COLOR, lcd.RGB(0x00, 0x00, 0x00)) - lcd.drawText(2,1,"GPS stats viewer" ,MIDSIZE) - lcd.drawText(10,70, "more than 4 entries in GPS logfile needed", MIDSIZE + BLINK + INVERS) - lcd.drawText(10,110, log_filename, MIDSIZE + BLINK + INVERS) - end + lcd.drawText(290, 28, "Time: " .. string.gsub(line3[3], "%s+", ""), MIDSIZE) + lcd.drawText(130, 28, "Sats: " .. string.gsub(line3[4], "%s+", ""), MIDSIZE) + lcd.drawText(130, 63, "ALT: " .. string.gsub(line3[5], "%s+", "") .. "m", MIDSIZE) + lcd.drawText(290, 63, "Speed: " .. string.gsub(line3[6], "%s+", "") .. "kmh", MIDSIZE) + lcd.drawText(2, 100, "# " .. line0[1] .. ", " .. line0[2], DBLSIZE) + lcd.drawText(2, 140, "# " .. line1[1] .. ", " .. line1[2], DBLSIZE) + lcd.drawText(2, 180, "# " .. line2[1] .. ", " .. line2[2], DBLSIZE) + lcd.drawText(2, 220, "# " .. line3[1] .. ", " .. line3[2], DBLSIZE + BLINK + INVERS) + + end + + else + -- display error message + lcd.clear() + lcd.setColor(CUSTOM_COLOR, lcd.RGB(0x9D, 0xD6, 0x00)) + lcd.drawFilledRectangle(1, 0, 480, 28, CUSTOM_COLOR) + lcd.setColor(CUSTOM_COLOR, lcd.RGB(0x00, 0x00, 0x00)) + lcd.drawText(2, 1, "GPS stats viewer", MIDSIZE) + lcd.drawText(10, 70, "more than 4 entries in GPS logfile needed", MIDSIZE + BLINK + INVERS) + lcd.drawText(10, 110, log_filename, MIDSIZE + BLINK + INVERS) + end end local function Viewer_Init() - - lcd.clear() - local f2 = io.open(log_filename, "r") - - --check if file exists + + lcd.clear() + local f2 = io.open(log_filename, "r") + + -- check if file exists if f2 ~= nil then - + file_exist = true buffer = io.read(f2, 4096) io.close(f2) - --read file contents into array/table - for line in string_gmatch(buffer, "([^\n]+)\n") do - if not string.find(line, "Number") then --exclude logfile headline - coordinates[linectr] = line + -- read file contents into array/table + for line in string_gmatch(buffer, "([^\n]+)\n") do + if not string.find(line, "Number") then -- exclude logfile headline + coordinates[linectr] = line linectr = linectr + 1 - end - end - - --reverse array/table contents - for k in pairs (coordinates) do coordinates_tmp[k] = coordinates[k] end - j=0 - for i = linectr,1,-1 do - coordinates[j] = coordinates_tmp[i-1] - j = j + 1 - end - - --draw inital screen + end + end + + -- reverse array/table contents + for k in pairs(coordinates) do coordinates_tmp[k] = coordinates[k] end + j = 0 + for i = linectr, 1, -1 do + coordinates[j] = coordinates_tmp[i - 1] + j = j + 1 + end + + -- draw inital screen Viewer_Draw_LCD(0) - + else - file_exist = false + file_exist = false end - end - +end -- Main local function Viewer_Run(event, touchState) - + if event == nil then error("Cannot be run as a model script!") return 2 - else - - if file_exist == true then - - Viewer_Draw_LCD(item) - --handle scroll counter - if event == EVT_ROT_RIGHT or event == EVT_PLUS_FIRST then - if item < linectr-1 then - item = item + 1 - end - end - if event == EVT_ROT_LEFT or event == EVT_MINUS_FIRST then - if item > 0 then - item = item - 1 - end - end - - --handle touch events - if touchState then - if event == EVT_TOUCH_SLIDE then - + else + + if file_exist == true then + + Viewer_Draw_LCD(item) + -- handle scroll counter + if event == EVT_ROT_RIGHT or event == EVT_PLUS_FIRST then if item < linectr - 1 then item = item + 1 end end + if event == EVT_ROT_LEFT or event == EVT_MINUS_FIRST then if item > 0 then item = item - 1 end end + + -- handle touch events + if touchState then + if event == EVT_TOUCH_SLIDE then + if touchState.swipeUp then - if item < linectr-1 then - item = item + 1 - end + if item < linectr - 1 then item = item + 1 end elseif touchState.swipeDown then - if item > 0 then - item = item - 1 - end + if item > 0 then item = item - 1 end end - end + end end - + else - --display error message - lcd.clear() - lcd.drawLine(0,0,0,64, SOLID, CUSTOM_COLOR) - lcd.drawLine(480,0,480,64, SOLID, CUSTOM_COLOR) - lcd.drawText(2,1,"GPS stats viewer" ,MIDSIZE) - lcd.drawText(0,94, "Logfile does not exist", MIDSIZE) - lcd.drawText(0,128, log_filename, MIDSIZE + BLINK) - lcd.drawLine(0,62, 480, 62, SOLID, CUSTOM_COLOR) + -- display error message + lcd.clear() + lcd.drawLine(0, 0, 0, 64, SOLID, CUSTOM_COLOR) + lcd.drawLine(480, 0, 480, 64, SOLID, CUSTOM_COLOR) + lcd.drawText(2, 1, "GPS stats viewer", MIDSIZE) + lcd.drawText(0, 94, "Logfile does not exist", MIDSIZE) + lcd.drawText(0, 128, log_filename, MIDSIZE + BLINK) + lcd.drawLine(0, 62, 480, 62, SOLID, CUSTOM_COLOR) end - - if event == EVT_VIRTUAL_EXIT then - return 2 - end - + + if event == EVT_VIRTUAL_EXIT then return 2 end + end - return 0 + return 0 end -return { init=Viewer_Init, run=Viewer_Run } +return {init = Viewer_Init, run = Viewer_Run} diff --git a/T16/GPS/main.lua b/T16/GPS/main.lua index d219c02..c96b6d5 100644 --- a/T16/GPS/main.lua +++ b/T16/GPS/main.lua @@ -1,14 +1,14 @@ ---[[############################################################################# +--[[###################################################################### GPS Telemetry Widget for Jumper TX16 etc (480x272 displays) -Copyright (C) by mosch -License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html -GITHUB: https://github.com/moschotto?tab=repositories +Copyright (C) by mosch +License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html +GITHUB: https://github.com/moschotto?tab=repositories + +"TELEMETRY screen - GPS last known postions v2.5" -"TELEMETRY screen - GPS last known postions v2.5" - Description: -How to find your model in case of a crash, power loss etc? Right, check the last +How to find your model in case of a crash, power loss etc? Right, check the last GPS coordinates and type it into to your mobile phone... - Shows and logs GPS related information. log file will be generated in @@ -24,427 +24,413 @@ Install: - copy the GPS folder (inculding subfolders) to /WIDGETS/GPS - Setup 1/2 widget screen and select "GPS" -################################################################################]] - - + ######################################################################]] -- log_filename = "/LOGS/GPSpositions.txt" local background_img -local sat_img -local dis_img -local disT_img -local home_img +local sat_img +local dis_img +local disT_img +local home_img local drone_img local newtext_color = BLACK local newline_color = WHITE +-- [ #################################################################### +-- [ functions +-- [ #################################################################### ---[ #################################################################### ---[ functions ---[ #################################################################### +-- [ #################################################################### +-- [ rounding function +-- [ #################################################################### - --[ #################################################################### - --[ rounding function - --[ #################################################################### - - local function rnd(v,d) - if d then - return math.floor((v*10^d)+0.5)/(10^d) - else - return math.floor(v+0.5) - end +local function rnd(v, d) + if d then + return math.floor((v * 10 ^ d) + 0.5) / (10 ^ d) + else + return math.floor(v + 0.5) end +end - --[ #################################################################### - --[ seconds format - --[ #################################################################### +-- [ #################################################################### +-- [ seconds format +-- [ #################################################################### - local function SecondsToClock(seconds) - local seconds = tonumber(seconds) +local function SecondsToClock(seconds) + local seconds = tonumber(seconds) - if seconds <= 0 then + if seconds <= 0 then return "00:00:00"; - else - hours = string.format("%02.f", math.floor(seconds/3600)); - mins = string.format("%02.f", math.floor(seconds/60 - (hours*60))); - secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60)); - return hours..":"..mins..":"..secs - end - end - - --[ #################################################################### - --[ write logfile - --[ #################################################################### - local function write_log(wgt) - - now = getTime() - if wgt.old_time_write + wgt.log_write_wait_time < now then - - wgt.ctr = wgt.ctr + 1 - time_power_on = SecondsToClock(getGlobalTimer()["session"]) - - --write logfile - file = io.open(log_filename, "a") - - io.write(file, wgt.coordinates_current ..",".. time_power_on ..", ".. wgt.gpsSATS..", ".. wgt.gpsALT ..", ".. wgt.gpsSpeed, "\r\n") - io.close(file) - - if wgt.ctr >= 99 then - wgt.ctr = 0 - --clear log and add headline - file = io.open(log_filename, "w") - io.write(file, "Number,LAT,LON,radio_time,satellites,GPSalt,GPSspeed", "\r\n") - io.close(file) - - --reopen log for appending data - file = io.open(log_filename, "a") - end - wgt.old_time_write = now - end + else + hours = string.format("%02.f", math.floor(seconds / 3600)); + mins = string.format("%02.f", math.floor(seconds / 60 - (hours * 60))); + secs = string.format("%02.f", math.floor(seconds - hours * 3600 - mins * 60)); + return hours .. ":" .. mins .. ":" .. secs end +end - --[ #################################################################### - --[ get telemetry IDs - --[ #################################################################### +-- [ #################################################################### +-- [ write logfile +-- [ #################################################################### +local function write_log(wgt) - local function getTelemetryId(name) - field = getFieldInfo(name) - if field then - return field.id - else - return-1 + now = getTime() + if wgt.old_time_write + wgt.log_write_wait_time < now then + + wgt.ctr = wgt.ctr + 1 + time_power_on = SecondsToClock(getGlobalTimer()["session"]) + + -- write logfile + file = io.open(log_filename, "a") + + io.write(file, + wgt.coordinates_current .. "," .. time_power_on .. ", " .. wgt.gpsSATS .. ", " .. wgt.gpsALT .. ", " .. + wgt.gpsSpeed, "\r\n") + io.close(file) + + if wgt.ctr >= 99 then + wgt.ctr = 0 + -- clear log and add headline + file = io.open(log_filename, "w") + io.write(file, "Number,LAT,LON,radio_time,satellites,GPSalt,GPSspeed", "\r\n") + io.close(file) + + -- reopen log for appending data + file = io.open(log_filename, "a") end + wgt.old_time_write = now end +end - --[ #################################################################### - --[ calculate distance - --[ #################################################################### - local function calc_Distance(LatPos, LonPos, LatHome, LonHome) - local d2r = math.pi/180 - local d_lon = (LonPos - LonHome) * d2r - local d_lat = (LatPos - LatHome) * d2r - local a = math.pow(math.sin(d_lat/2.0), 2) + math.cos(LatHome*d2r) * math.cos(LatPos*d2r) * math.pow(math.sin(d_lon/2.0), 2) - local c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) - local dist = (6371000 * c) / 1000 - return rnd(dist,2) - end - - --[ #################################################################### - --[ ETX and OTX compatible draw text with color - --[ #################################################################### - local function lcl_drawText(x, y, txt, flags, color) - lcd.setColor(CUSTOM_COLOR, color) - lcd.drawText(x, y, txt, flags + CUSTOM_COLOR) - end - - --[ #################################################################### - --[ ETX and OTX compatible draw filled rect with color - --[ #################################################################### - local function lcl_drawFilledRectangle(x1, y1, x2, y2, color) - lcd.setColor(CUSTOM_COLOR, color) - lcd.drawFilledRectangle(x1, y1, x2, y2, CUSTOM_COLOR) - end - - --[ #################################################################### - --[ ETX and OTX compatible draw line with color - --[ #################################################################### - local function lcl_drawLine(x1, y1, x2, y2, pattern, flags, color) - lcd.setColor(CUSTOM_COLOR, color) - lcd.drawLine(x1, y1, x2, y2, pattern, flags + CUSTOM_COLOR) +-- [ #################################################################### +-- [ get telemetry IDs +-- [ #################################################################### + +local function getTelemetryId(name) + field = getFieldInfo(name) + if field then + return field.id + else + return -1 end - +end + +-- [ #################################################################### +-- [ calculate distance +-- [ #################################################################### +local function calc_Distance(LatPos, LonPos, LatHome, LonHome) + local d2r = math.pi / 180 + local d_lon = (LonPos - LonHome) * d2r + local d_lat = (LatPos - LatHome) * d2r + local a = math.pow(math.sin(d_lat / 2.0), 2) + math.cos(LatHome * d2r) * math.cos(LatPos * d2r) * + math.pow(math.sin(d_lon / 2.0), 2) + local c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) + local dist = (6371000 * c) / 1000 + return rnd(dist, 2) +end + +-- [ #################################################################### +-- [ ETX and OTX compatible draw text with color +-- [ #################################################################### +local function lcl_drawText(x, y, txt, flags, color) + lcd.setColor(CUSTOM_COLOR, color) + lcd.drawText(x, y, txt, flags + CUSTOM_COLOR) +end +-- [ #################################################################### +-- [ ETX and OTX compatible draw filled rect with color +-- [ #################################################################### +local function lcl_drawFilledRectangle(x1, y1, x2, y2, color) + lcd.setColor(CUSTOM_COLOR, color) + lcd.drawFilledRectangle(x1, y1, x2, y2, CUSTOM_COLOR) +end ---############################################################################ -local options = { - { "TextColor", COLOR, BLACK }, - { "LineColor", COLOR, WHITE }, - { "Debug", BOOL, 0 } -} +-- [ #################################################################### +-- [ ETX and OTX compatible draw line with color +-- [ #################################################################### +local function lcl_drawLine(x1, y1, x2, y2, pattern, flags, color) + lcd.setColor(CUSTOM_COLOR, color) + lcd.drawLine(x1, y1, x2, y2, pattern, flags + CUSTOM_COLOR) +end + +-- ############################################################################ +local options = {{"TextColor", COLOR, BLACK}, {"LineColor", COLOR, WHITE}, {"Debug", BOOL, 0}} local function create(zone, options) - local wgt = { - zone=zone, - options=options, - counter=0, - gpsId=0, - gpssatId=0, - gpsspeedId=0, - gpsaltId=0, - gpsLAT = 0, - gpsLON = 0, - gpsLAT_H = 0, - gpsLON_H = 0, - gpsPrevLAT = 0, - gpsPrevLON = 0, - gpsSATS = 0, - gpsSpeed = 0, - gpsALT = 0, - gpsFIX = 0, - gpsDtH = 0, - gpsTotalDist = 0, - log_write_wait_time = 10, - old_time_write = 0, - update = true, - reset_home = false, - string_gmatch = string.gmatch, - now = 0, - ctr = 0, - coordinates_prev = 0, - coordinates_current = 0, - old_time_write2 = 0, - wait = 100, - sat_img = 0, - drone_img = 0, - home_img = 0, - dis_img = 0, - disT_img = 0 + local wgt = { + zone = zone, + options = options, + counter = 0, + gpsId = 0, + gpssatId = 0, + gpsspeedId = 0, + gpsaltId = 0, + gpsLAT = 0, + gpsLON = 0, + gpsLAT_H = 0, + gpsLON_H = 0, + gpsPrevLAT = 0, + gpsPrevLON = 0, + gpsSATS = 0, + gpsSpeed = 0, + gpsALT = 0, + gpsFIX = 0, + gpsDtH = 0, + gpsTotalDist = 0, + log_write_wait_time = 10, + old_time_write = 0, + update = true, + reset_home = false, + string_gmatch = string.gmatch, + now = 0, + ctr = 0, + coordinates_prev = 0, + coordinates_current = 0, + old_time_write2 = 0, + wait = 100, + sat_img = 0, + drone_img = 0, + home_img = 0, + dis_img = 0, + disT_img = 0 } - - --load images + + -- load images sat_img = Bitmap.open("/WIDGETS/GPS/BMP/sat128.png") dis_img = Bitmap.open("/WIDGETS/GPS/BMP/distance128.png") disT_img = Bitmap.open("/WIDGETS/GPS/BMP/distanceT128.png") home_img = Bitmap.open("/WIDGETS/GPS/BMP/home128.png") drone_img = Bitmap.open("/WIDGETS/GPS/BMP/drone128.png") background_img = Bitmap.open("/WIDGETS/GPS/BMP/background.png") - - + return wgt end local function update(wgt, options) - if (wgt == nil) then - print("GPS_Debug", "Widget not initialized - 1") + if (wgt == nil) then + print("GPS_Debug", "Widget not initialized - 1") return end - - wgt.options = options -end + wgt.options = options -local function background(wgt) - return end +local function background(wgt) return end + local function get_data(wgt) - - - --#################################################################### - --get Sensor IDs - --#################################################################### + + -- #################################################################### + -- get Sensor IDs + -- #################################################################### wgt.gpsId = getTelemetryId("GPS") - - --number of satellites crossfire + + -- number of satellites crossfire wgt.gpssatId = getTelemetryId("Sats") - - --get IDs GPS Speed and GPS altitude - wgt.gpsspeedId = getTelemetryId("GSpd") --GPS ground speed m/s - wgt.gpsaltId = getTelemetryId("Alt") --GPS altitude m - - --if "ALT" can't be read, try to read "GAlt" - if (wgt.gpsaltId == -1) then gpsaltId = getTelemetryId("GAlt") end - - --if Stats can't be read, try to read Tmp2 (number of satellites SBUS/FRSKY) - if (wgt.gpssatId == -1) then wgt.gpssatId = getTelemetryId("Tmp2") end - - - --#################################################################### - --get Latitude, Longitude, Speed and Altitude - --#################################################################### + + -- get IDs GPS Speed and GPS altitude + wgt.gpsspeedId = getTelemetryId("GSpd") -- GPS ground speed m/s + wgt.gpsaltId = getTelemetryId("Alt") -- GPS altitude m + + -- if "ALT" can't be read, try to read "GAlt" + if (wgt.gpsaltId == -1) then gpsaltId = getTelemetryId("GAlt") end + + -- if Stats can't be read, try to read Tmp2 (number of satellites SBUS/FRSKY) + if (wgt.gpssatId == -1) then wgt.gpssatId = getTelemetryId("Tmp2") end + + -- #################################################################### + -- get Latitude, Longitude, Speed and Altitude + -- #################################################################### wgt.gpsLatLon = getValue(wgt.gpsId) - - if (type(wgt.gpsLatLon) == "table") then - wgt.gpsLAT = rnd(wgt.gpsLatLon["lat"],6) - wgt.gpsLON = rnd(wgt.gpsLatLon["lon"],6) - wgt.gpsSpeed = rnd(getValue(wgt.gpsspeedId) * 1.852,1) - wgt.gpsALT = rnd(getValue(wgt.gpsaltId),0) - - - --set home postion only if more than 5 sats available + + if (type(wgt.gpsLatLon) == "table") then + wgt.gpsLAT = rnd(wgt.gpsLatLon["lat"], 6) + wgt.gpsLON = rnd(wgt.gpsLatLon["lon"], 6) + wgt.gpsSpeed = rnd(getValue(wgt.gpsspeedId) * 1.852, 1) + wgt.gpsALT = rnd(getValue(wgt.gpsaltId), 0) + + -- set home postion only if more than 5 sats available if (tonumber(wgt.gpsSATS) > 5) and (wgt.reset_home == true) then - wgt.gpsLAT_H = rnd(wgt.gpsLatLon["lat"],6) - wgt.gpsLON_H = rnd(wgt.gpsLatLon["lon"],6) - wgt.reset_home = false - end + wgt.gpsLAT_H = rnd(wgt.gpsLatLon["lat"], 6) + wgt.gpsLON_H = rnd(wgt.gpsLatLon["lon"], 6) + wgt.reset_home = false + end - wgt.update = true + wgt.update = true else wgt.update = false end - - --#################################################################### - --get number of satellites and GPS fix type - --#################################################################### + + -- #################################################################### + -- get number of satellites and GPS fix type + -- #################################################################### wgt.gpsSATS = getValue(wgt.gpssatId) - - if string.len(wgt.gpsSATS) > 2 then + + if string.len(wgt.gpsSATS) > 2 then -- smartport Example 1014: -> 1= GPS fix | 0=lowest accuracy | 14=14 active satellites - --[ Sats / Tmp2 : GPS lock status, accuracy, home reset trigger, and number of satellites. - --[ Number is sent as ABCD detailed below. ABCD = 1014 - --[ A : 1 = GPS fix, 2 = GPS home fix, 4 = home reset (numbers are additive) - --[ B : GPS accuracy based on HDOP (0 = lowest to 9 = highest accuracy) - --[ C : number of satellites locked (first digit) - --[ D : number of satellites locked (second digit) - --[ for example: "1014" C = 1 & D = 4 => 14 satellites - wgt.gpsSATS = string.sub (wgt.gpsSATS, 3,6) + -- [ Sats / Tmp2 : GPS lock status, accuracy, home reset trigger, and number of satellites. + -- [ Number is sent as ABCD detailed below. ABCD = 1014 + -- [ A : 1 = GPS fix, 2 = GPS home fix, 4 = home reset (numbers are additive) + -- [ B : GPS accuracy based on HDOP (0 = lowest to 9 = highest accuracy) + -- [ C : number of satellites locked (first digit) + -- [ D : number of satellites locked (second digit) + -- [ for example: "1014" C = 1 & D = 4 => 14 satellites + wgt.gpsSATS = string.sub(wgt.gpsSATS, 3, 6) else - --CROSSFIRE stores only the active GPS satellite - wgt.gpsSATS = string.sub (wgt.gpsSATS, 0,3) - end - - --status message "guess" + -- CROSSFIRE stores only the active GPS satellite + wgt.gpsSATS = string.sub(wgt.gpsSATS, 0, 3) + end + + -- status message "guess" -- 2D Mode - A 2D (two dimensional) position fix that includes only horizontal coordinates. It requires a minimum of three visible satellites.) -- 3D Mode - A 3D (three dimensional) position fix that includes horizontal coordinates plus altitude. It requires a minimum of four visible satellites. if (tonumber(wgt.gpsSATS) < 2) then wgt.gpsFIX = "no GPS fix" end - if (tonumber(wgt.gpsSATS) >= 3) and (tonumber(wgt.gpsSATS) <= 4) then wgt.gpsFIX = "GPS 2D fix" end + if (tonumber(wgt.gpsSATS) >= 3) and (tonumber(wgt.gpsSATS) <= 4) then wgt.gpsFIX = "GPS 2D fix" end if (tonumber(wgt.gpsSATS) >= 5) then wgt.gpsFIX = "GPS 3D fix" end - - - --#################################################################### - --get calculate distance from home and write log - --#################################################################### + + -- #################################################################### + -- get calculate distance from home and write log + -- #################################################################### if (tonumber(wgt.gpsSATS) >= 5) then - - if (wgt.gpsLAT ~= wgt.gpsPrevLAT) and (wgt.gpsLON ~= wgt.gpsPrevLON) then - --if (string.len(gpsLAT) > 4) and (string.len(gpsLON) > 4) and (tonumber(gpsSATS) > 5) then - - --distance to home - if (wgt.gpsLAT_H ~= 0) and (wgt.gpsLON_H ~= 0) then - - wgt.gpsDtH = rnd(calc_Distance(wgt.gpsLAT, wgt.gpsLON, wgt.gpsLAT_H, wgt.gpsLON_H),2) - wgt.gpsDtH = string.format("%.2f",wgt.gpsDtH) - - --total distance traveled - if (wgt.gpsPrevLAT ~= 0) and (wgt.gpsPrevLON ~= 0) then - - wgt.gpsTotalDist = rnd(tonumber(wgt.gpsTotalDist) + calc_Distance(wgt.gpsLAT,wgt.gpsLON,wgt.gpsPrevLAT,wgt.gpsPrevLON),2) - wgt.gpsTotalDist = string.format("%.2f",wgt.gpsTotalDist) + + if (wgt.gpsLAT ~= wgt.gpsPrevLAT) and (wgt.gpsLON ~= wgt.gpsPrevLON) then + -- if (string.len(gpsLAT) > 4) and (string.len(gpsLON) > 4) and (tonumber(gpsSATS) > 5) then + + -- distance to home + if (wgt.gpsLAT_H ~= 0) and (wgt.gpsLON_H ~= 0) then + + wgt.gpsDtH = rnd(calc_Distance(wgt.gpsLAT, wgt.gpsLON, wgt.gpsLAT_H, wgt.gpsLON_H), 2) + wgt.gpsDtH = string.format("%.2f", wgt.gpsDtH) + + -- total distance traveled + if (wgt.gpsPrevLAT ~= 0) and (wgt.gpsPrevLON ~= 0) then + + wgt.gpsTotalDist = rnd(tonumber(wgt.gpsTotalDist) + + calc_Distance(wgt.gpsLAT, wgt.gpsLON, wgt.gpsPrevLAT, wgt.gpsPrevLON), 2) + wgt.gpsTotalDist = string.format("%.2f", wgt.gpsTotalDist) end - + end - --data for displaying the - wgt.coordinates_prev = string.format("%02d",wgt.ctr) ..", ".. wgt.gpsPrevLAT..", " .. wgt.gpsPrevLON - wgt.coordinates_current = string.format("%02d",wgt.ctr+1) ..", ".. wgt.gpsLAT..", " .. wgt.gpsLON - + -- data for displaying the + wgt.coordinates_prev = string.format("%02d", wgt.ctr) .. ", " .. wgt.gpsPrevLAT .. ", " .. wgt.gpsPrevLON + wgt.coordinates_current = string.format("%02d", wgt.ctr + 1) .. ", " .. wgt.gpsLAT .. ", " .. wgt.gpsLON + wgt.gpsPrevLAT = wgt.gpsLAT - wgt.gpsPrevLON = wgt.gpsLON - - --write logfile + wgt.gpsPrevLON = wgt.gpsLON + + -- write logfile write_log(wgt) - end - end - - + end + end + end ---function refresh(wgt) +-- function refresh(wgt) function refresh(wgt, event, touchState) - - if (wgt == nil) then - print("GPS_Debug", "Widget not initialized - 2") + + if (wgt == nil) then + print("GPS_Debug", "Widget not initialized - 2") return - end + end -- set the colours newtext_color = wgt.options.TextColor - newline_color = wgt.options.LineColor - - - get_data(wgt) + newline_color = wgt.options.LineColor + + get_data(wgt) - --workaround to reset telemetry data via global session timer - --reset via "long press enter" -> statistics -> "long press enter" exit menu under 10 seconds + -- workaround to reset telemetry data via global session timer + -- reset via "long press enter" -> statistics -> "long press enter" exit menu under 10 seconds if (SecondsToClock(getGlobalTimer()["session"]) == "00:00:10") then wgt.gpsDtH = 0 wgt.gpsTotalDist = 0 wgt.gpsLAT_H = 0 - wgt.gpsLON_H = 0 + wgt.gpsLON_H = 0 wgt.reset_home = true - end - + end + if wgt.options.Debug == 0 then - - -- display T16: 480*272px / 1/2 Zone size: 220x152 - --headline - if wgt.update == true then - lcl_drawFilledRectangle(wgt.zone.x + 0, wgt.zone.y + 0, 225, 25, lcd.RGB(0x9D, 0xD6, 0x00)) - lcl_drawText(wgt.zone.x + 5,wgt.zone.y + 5,wgt.gpsFIX , LEFT + SMLSIZE , newtext_color) - elseif wgt.update == false then - lcl_drawFilledRectangle(wgt.zone.x + 0, wgt.zone.y + 0, 225, 25, lcd.RGB(0xE6, 0x32, 24)) - lcl_drawText(wgt.zone.x + 5,wgt.zone.y + 5, "no GPS data available", LEFT + SMLSIZE , newtext_color) + + -- display T16: 480*272px / 1/2 Zone size: 220x152 + -- headline + if wgt.update == true then + lcl_drawFilledRectangle(wgt.zone.x + 0, wgt.zone.y + 0, 225, 25, lcd.RGB(0x9D, 0xD6, 0x00)) + lcl_drawText(wgt.zone.x + 5, wgt.zone.y + 5, wgt.gpsFIX, LEFT + SMLSIZE, newtext_color) + elseif wgt.update == false then + lcl_drawFilledRectangle(wgt.zone.x + 0, wgt.zone.y + 0, 225, 25, lcd.RGB(0xE6, 0x32, 24)) + lcl_drawText(wgt.zone.x + 5, wgt.zone.y + 5, "no GPS data available", LEFT + SMLSIZE, newtext_color) end - - --satellites + + -- satellites lcd.drawBitmap(sat_img, wgt.zone.x, wgt.zone.y + 30, 35) - lcl_drawText(wgt.zone.x + 42,wgt.zone.y + 40, wgt.gpsSATS, LEFT + MIDSIZE , newtext_color) - - --distance to home + lcl_drawText(wgt.zone.x + 42, wgt.zone.y + 40, wgt.gpsSATS, LEFT + MIDSIZE, newtext_color) + + -- distance to home lcd.drawBitmap(dis_img, wgt.zone.x + 80, wgt.zone.y + 30, 35) - lcl_drawText(wgt.zone.x + 145 , wgt.zone.y + 30, wgt.gpsDtH, RIGHT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 145 , wgt.zone.y + 50, "km", RIGHT + SMLSIZE , newtext_color) - - --total total travel + lcl_drawText(wgt.zone.x + 145, wgt.zone.y + 30, wgt.gpsDtH, RIGHT + SMLSIZE, newtext_color) + lcl_drawText(wgt.zone.x + 145, wgt.zone.y + 50, "km", RIGHT + SMLSIZE, newtext_color) + + -- total total travel lcd.drawBitmap(disT_img, wgt.zone.x + 155, wgt.zone.y + 30, 35) - lcl_drawText(wgt.zone.x + 222, wgt.zone.y +30, wgt.gpsTotalDist, RIGHT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 222, wgt.zone.y +50, "km", RIGHT + SMLSIZE , newtext_color) - - --line horz. + lcl_drawText(wgt.zone.x + 222, wgt.zone.y + 30, wgt.gpsTotalDist, RIGHT + SMLSIZE, newtext_color) + lcl_drawText(wgt.zone.x + 222, wgt.zone.y + 50, "km", RIGHT + SMLSIZE, newtext_color) + + -- line horz. lcl_drawLine(wgt.zone.x + 0, wgt.zone.y + 85, wgt.zone.x + 224, wgt.zone.y + 85, SOLID, 0, newline_color) - - --home location + -- home location lcd.drawBitmap(home_img, wgt.zone.x, wgt.zone.y + 95, 30) - - if (wgt.gpsLAT_H ~= 0) and (wgt.gpsLON_H ~= 0) then - lcl_drawText(wgt.zone.x + 50, wgt.zone.y + 110, wgt.gpsLAT_H .. ", " .. wgt.gpsLON_H, LEFT + SMLSIZE, newtext_color) + + if (wgt.gpsLAT_H ~= 0) and (wgt.gpsLON_H ~= 0) then + lcl_drawText(wgt.zone.x + 50, wgt.zone.y + 110, wgt.gpsLAT_H .. ", " .. wgt.gpsLON_H, LEFT + SMLSIZE, newtext_color) else - lcl_drawText(wgt.zone.x + 50, wgt.zone.y + 90, "home not set" , LEFT + SMLSIZE + BLINK, newtext_color) - lcl_drawText(wgt.zone.x + 50, wgt.zone.y + 105, "reset STATS once a", LEFT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 50, wgt.zone.y + 120, "GPS fix is obtained", LEFT + SMLSIZE , newtext_color) + lcl_drawText(wgt.zone.x + 50, wgt.zone.y + 90, "home not set", LEFT + SMLSIZE + BLINK, newtext_color) + lcl_drawText(wgt.zone.x + 50, wgt.zone.y + 105, "reset STATS once a", LEFT + SMLSIZE, newtext_color) + lcl_drawText(wgt.zone.x + 50, wgt.zone.y + 120, "GPS fix is obtained", LEFT + SMLSIZE, newtext_color) end - - --line horz. + + -- line horz. lcl_drawLine(wgt.zone.x + 0, wgt.zone.y + 145, wgt.zone.x + 224, wgt.zone.y + 145, SOLID, 0, newline_color) - - --drone location (current and previous) + + -- drone location (current and previous) lcd.drawBitmap(drone_img, wgt.zone.x, wgt.zone.y + 150, 40) - lcl_drawText(wgt.zone.x + 50,wgt.zone.y + 158, wgt.coordinates_prev,LEFT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 50,wgt.zone.y + 180, wgt.coordinates_current,LEFT + SMLSIZE , newtext_color) - - + lcl_drawText(wgt.zone.x + 50, wgt.zone.y + 158, wgt.coordinates_prev, LEFT + SMLSIZE, newtext_color) + lcl_drawText(wgt.zone.x + 50, wgt.zone.y + 180, wgt.coordinates_current, LEFT + SMLSIZE, newtext_color) + elseif wgt.options.Debug == 1 then - - if (type(wgt.gpsLatLon) == "table") then - - lcl_drawText(wgt.zone.x + 5,wgt.zone.y,"Debug view:", LEFT + SMLSIZE , newtext_color) - - lcl_drawText(wgt.zone.x + 5,wgt.zone.y + 15,"Lat: " .. rnd(wgt.gpsLatLon["lat"],6) , LEFT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 5,wgt.zone.y + 30,"Lon: " .. rnd(wgt.gpsLatLon["lon"],6) , LEFT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 5,wgt.zone.y + 45,"P lat: " .. rnd(wgt.gpsLatLon["pilot-lat"],6) , LEFT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 5,wgt.zone.y + 60,"P lon: " .. rnd(wgt.gpsLatLon["pilot-lon"],6) , LEFT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 5,wgt.zone.y + 75,"Home lat: " .. wgt.gpsLAT_H , LEFT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 5,wgt.zone.y + 90,"Home lon: " .. wgt.gpsLON_H , LEFT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 5,wgt.zone.y + 105,"Satellites: " .. wgt.gpsSATS , LEFT + SMLSIZE , newtext_color) - - lcl_drawText(wgt.zone.x + 5,wgt.zone.y + 120,"Dist home: " .. wgt.gpsDtH , LEFT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 120,wgt.zone.y + 120,"ALT: " .. wgt.gpsALT , LEFT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 5,wgt.zone.y + 135,"Dist travel: " .. wgt.gpsTotalDist , LEFT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 120,wgt.zone.y + 135,"SPD: " .. wgt.gpsSpeed , LEFT + SMLSIZE , newtext_color) - - lcl_drawText(wgt.zone.x + 5,wgt.zone.y + 150,"GPS ID: " .. wgt.gpsId, LEFT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 120,wgt.zone.y + 150,"SAT ID: " .. wgt.gpssatId, LEFT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 5,wgt.zone.y + 165,"SPD ID: " .. wgt.gpsspeedId , LEFT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 120,wgt.zone.y + 165,"ALT ID: " .. wgt.gpsaltId , LEFT + SMLSIZE , newtext_color) - - else - lcl_drawText(wgt.zone.x + 5,wgt.zone.y + 60,"No GPS data available" , LEFT + SMLSIZE , newtext_color) - lcl_drawText(wgt.zone.x + 5,wgt.zone.y + 75,"Please check the sensors" , LEFT + SMLSIZE , newtext_color) + + if (type(wgt.gpsLatLon) == "table") then + + lcl_drawText(wgt.zone.x + 5, wgt.zone.y, "Debug view:", LEFT + SMLSIZE, newtext_color) + + lcl_drawText(wgt.zone.x + 5, wgt.zone.y + 15, "Lat: " .. rnd(wgt.gpsLatLon["lat"], 6), LEFT + SMLSIZE, newtext_color) + lcl_drawText(wgt.zone.x + 5, wgt.zone.y + 30, "Lon: " .. rnd(wgt.gpsLatLon["lon"], 6), LEFT + SMLSIZE, newtext_color) + lcl_drawText(wgt.zone.x + 5, wgt.zone.y + 45, "P lat: " .. rnd(wgt.gpsLatLon["pilot-lat"], 6), LEFT + SMLSIZE, + newtext_color) + lcl_drawText(wgt.zone.x + 5, wgt.zone.y + 60, "P lon: " .. rnd(wgt.gpsLatLon["pilot-lon"], 6), LEFT + SMLSIZE, + newtext_color) + lcl_drawText(wgt.zone.x + 5, wgt.zone.y + 75, "Home lat: " .. wgt.gpsLAT_H, LEFT + SMLSIZE, newtext_color) + lcl_drawText(wgt.zone.x + 5, wgt.zone.y + 90, "Home lon: " .. wgt.gpsLON_H, LEFT + SMLSIZE, newtext_color) + lcl_drawText(wgt.zone.x + 5, wgt.zone.y + 105, "Satellites: " .. wgt.gpsSATS, LEFT + SMLSIZE, newtext_color) + + lcl_drawText(wgt.zone.x + 5, wgt.zone.y + 120, "Dist home: " .. wgt.gpsDtH, LEFT + SMLSIZE, newtext_color) + lcl_drawText(wgt.zone.x + 120, wgt.zone.y + 120, "ALT: " .. wgt.gpsALT, LEFT + SMLSIZE, newtext_color) + lcl_drawText(wgt.zone.x + 5, wgt.zone.y + 135, "Dist travel: " .. wgt.gpsTotalDist, LEFT + SMLSIZE, newtext_color) + lcl_drawText(wgt.zone.x + 120, wgt.zone.y + 135, "SPD: " .. wgt.gpsSpeed, LEFT + SMLSIZE, newtext_color) + + lcl_drawText(wgt.zone.x + 5, wgt.zone.y + 150, "GPS ID: " .. wgt.gpsId, LEFT + SMLSIZE, newtext_color) + lcl_drawText(wgt.zone.x + 120, wgt.zone.y + 150, "SAT ID: " .. wgt.gpssatId, LEFT + SMLSIZE, newtext_color) + lcl_drawText(wgt.zone.x + 5, wgt.zone.y + 165, "SPD ID: " .. wgt.gpsspeedId, LEFT + SMLSIZE, newtext_color) + lcl_drawText(wgt.zone.x + 120, wgt.zone.y + 165, "ALT ID: " .. wgt.gpsaltId, LEFT + SMLSIZE, newtext_color) + + else + lcl_drawText(wgt.zone.x + 5, wgt.zone.y + 60, "No GPS data available", LEFT + SMLSIZE, newtext_color) + lcl_drawText(wgt.zone.x + 5, wgt.zone.y + 75, "Please check the sensors", LEFT + SMLSIZE, newtext_color) end - + end - + end -return { name="GPS", options=options, create=create, update=update, refresh=refresh, background=background } +return {name = "GPS", options = options, create = create, update = update, refresh = refresh, background = background} diff --git a/TBS_Tango/GPSviewerT.lua b/TBS_Tango/GPSviewerT.lua index 84304ab..add8ab1 100644 --- a/TBS_Tango/GPSviewerT.lua +++ b/TBS_Tango/GPSviewerT.lua @@ -1,185 +1,170 @@ ---[[############################################################################# +--[[###################################################################### GPS Position viewer v1.1 -Copyright (C) by mosch -License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html +Copyright (C) by mosch +License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html GITHUB: https://github.com/moschotto?tab=repositories Description: reads the "GPSpositions.txt" log-file which was generated by the GPS.lua script. -useful if want to check the last GPS coordinates after a crash, power loss etc. +useful if want to check the last GPS coordinates after a crash, power loss etc. copy "GPSviewer.lua" to the /SCRIPTS/TOOLS/ folder -################################################################################]] - - + ######################################################################]] -- local toolName = "TNS|GPSTLog Viewer|TNE" local log_filename = "/LOGS/GPSpositions.txt" local file_exist = false local string_gmatch = string.gmatch -local coordinates = {} +local coordinates = {} local linectr = 0 local item = 0 local function splitstring(text) if text ~= nil then - local text_split = {} - local i=0 - --split by "," and store into array/table - for word in string_gmatch(text, "([^,]+)") do + local text_split = {} + local i = 0 + -- split by "," and store into array/table + for word in string_gmatch(text, "([^,]+)") do text_split[i] = word - i = i + 1 - end + i = i + 1 + end return text_split - end + end end local function Viewer_Draw_LCD(item) - - lcd.clear() - lcd.drawLine(0,0,0,95, SOLID, FORCE) - lcd.drawLine(127,0,127,95, SOLID, FORCE) - lcd.drawText(2,1,"GPS Position viewer v1.1" ,SMLSIZE) - lcd.drawFilledRectangle(1,0, 126, 9, GREY_DEFAULT) - - - lcd.drawLine(60,8, 60, 19, SOLID, FORCE) - lcd.drawText(64,11, "Sats:",SMLSIZE) - lcd.drawLine(97,8, 97, 19, SOLID, FORCE) - lcd.drawLine(0,19, 128, 19, SOLID, FORCE) - lcd.drawText(100,11, (item + 1).."/" .. linectr,SMLSIZE) - + + lcd.clear() + lcd.drawLine(0, 0, 0, 95, SOLID, FORCE) + lcd.drawLine(127, 0, 127, 95, SOLID, FORCE) + lcd.drawText(2, 1, "GPS Position viewer v1.1", SMLSIZE) + lcd.drawFilledRectangle(1, 0, 126, 9, GREY_DEFAULT) + + lcd.drawLine(60, 8, 60, 19, SOLID, FORCE) + lcd.drawText(64, 11, "Sats:", SMLSIZE) + lcd.drawLine(97, 8, 97, 19, SOLID, FORCE) + lcd.drawLine(0, 19, 128, 19, SOLID, FORCE) + lcd.drawText(100, 11, (item + 1) .. "/" .. linectr, SMLSIZE) + if item < 4 then - --first 4 rows static + -- first 4 rows static local line0 = splitstring(coordinates[0]) local line1 = splitstring(coordinates[1]) local line2 = splitstring(coordinates[2]) local line3 = splitstring(coordinates[3]) - + if item == 0 then - lcd.drawText(2,11, "Time:" .. string.gsub(line0[3], "%s+", ""), SMLSIZE) - lcd.drawText(64,11, "Sats:" .. string.gsub(line0[4], "%s+","") ,SMLSIZE) - lcd.drawText(2,24, line0[1] .."," .. line0[2] ,SMLSIZE + BLINK + INVERS) + lcd.drawText(2, 11, "Time:" .. string.gsub(line0[3], "%s+", ""), SMLSIZE) + lcd.drawText(64, 11, "Sats:" .. string.gsub(line0[4], "%s+", ""), SMLSIZE) + lcd.drawText(2, 24, line0[1] .. "," .. line0[2], SMLSIZE + BLINK + INVERS) else - lcd.drawText(2,24, line0[1] .."," .. line0[2] ,SMLSIZE) - end - + lcd.drawText(2, 24, line0[1] .. "," .. line0[2], SMLSIZE) + end + if item == 1 then - lcd.drawText(2,11, "Time:" .. string.gsub(line1[3], "%s+",""), SMLSIZE) - lcd.drawText(64,11, "Sats:" .. string.gsub(line1[4], "%s+","") ,SMLSIZE) - lcd.drawText(2,44, line1[1] .."," .. line1[2] ,SMLSIZE + BLINK + INVERS) + lcd.drawText(2, 11, "Time:" .. string.gsub(line1[3], "%s+", ""), SMLSIZE) + lcd.drawText(64, 11, "Sats:" .. string.gsub(line1[4], "%s+", ""), SMLSIZE) + lcd.drawText(2, 44, line1[1] .. "," .. line1[2], SMLSIZE + BLINK + INVERS) else - lcd.drawText(2,44, line1[1] .."," .. line1[2] ,SMLSIZE) - end - + lcd.drawText(2, 44, line1[1] .. "," .. line1[2], SMLSIZE) + end + if item == 2 then - lcd.drawText(2,11, "Time:" .. string.gsub(line2[3], "%s+",""), SMLSIZE) - lcd.drawText(64,11, "Sats:" .. string.gsub(line2[4], "%s+","") ,SMLSIZE) - lcd.drawText(2,64, line2[1] .."," .. line2[2] ,SMLSIZE + BLINK + INVERS) + lcd.drawText(2, 11, "Time:" .. string.gsub(line2[3], "%s+", ""), SMLSIZE) + lcd.drawText(64, 11, "Sats:" .. string.gsub(line2[4], "%s+", ""), SMLSIZE) + lcd.drawText(2, 64, line2[1] .. "," .. line2[2], SMLSIZE + BLINK + INVERS) else - lcd.drawText(2,64, line2[1] .."," .. line2[2] ,SMLSIZE) - end - + lcd.drawText(2, 64, line2[1] .. "," .. line2[2], SMLSIZE) + end + if item == 3 then - lcd.drawText(2,11, "Time:" .. string.gsub(line3[3], "%s+",""), SMLSIZE) - lcd.drawText(64,11, "Sats:" .. string.gsub(line3[4], "%s+","") ,SMLSIZE) - lcd.drawText(2,84, line3[1] .."," .. line3[2] ,SMLSIZE + BLINK + INVERS) + lcd.drawText(2, 11, "Time:" .. string.gsub(line3[3], "%s+", ""), SMLSIZE) + lcd.drawText(64, 11, "Sats:" .. string.gsub(line3[4], "%s+", ""), SMLSIZE) + lcd.drawText(2, 84, line3[1] .. "," .. line3[2], SMLSIZE + BLINK + INVERS) else - lcd.drawText(2,84, line3[1] .."," .. line3[2] ,SMLSIZE) - end + lcd.drawText(2, 84, line3[1] .. "," .. line3[2], SMLSIZE) + end else - - local line0 = splitstring(coordinates[item-3]) - local line1 = splitstring(coordinates[item-2]) - local line2 = splitstring(coordinates[item-1]) + + local line0 = splitstring(coordinates[item - 3]) + local line1 = splitstring(coordinates[item - 2]) + local line2 = splitstring(coordinates[item - 1]) local line3 = splitstring(coordinates[item]) - - lcd.drawText(2,11, "Time:" .. string.gsub(line3[3], "%s+",""), SMLSIZE) - lcd.drawText(64,11, "Sats:" .. string.gsub(line3[4], "%s+","") ,SMLSIZE) - lcd.drawText(2,24, line0[1] .."," .. line0[2],SMLSIZE) - lcd.drawText(2,44, line1[1] .."," .. line1[2],SMLSIZE) - lcd.drawText(2,64, line2[1] .."," .. line2[2],SMLSIZE) - lcd.drawText(2,84, line3[1] .."," .. line3[2],SMLSIZE + BLINK + INVERS) - - end - - lcd.drawLine(0,95,127,95, SOLID, FORCE) - + + lcd.drawText(2, 11, "Time:" .. string.gsub(line3[3], "%s+", ""), SMLSIZE) + lcd.drawText(64, 11, "Sats:" .. string.gsub(line3[4], "%s+", ""), SMLSIZE) + lcd.drawText(2, 24, line0[1] .. "," .. line0[2], SMLSIZE) + lcd.drawText(2, 44, line1[1] .. "," .. line1[2], SMLSIZE) + lcd.drawText(2, 64, line2[1] .. "," .. line2[2], SMLSIZE) + lcd.drawText(2, 84, line3[1] .. "," .. line3[2], SMLSIZE + BLINK + INVERS) + + end + + lcd.drawLine(0, 95, 127, 95, SOLID, FORCE) end local function Viewer_Init() - - lcd.clear() - local f2 = io.open(log_filename, "r") - - --check if file exists + + lcd.clear() + local f2 = io.open(log_filename, "r") + + -- check if file exists if f2 ~= nil then - + file_exist = true buffer = io.read(f2, 4096) io.close(f2) - --read file contents into array/table - for line in string_gmatch(buffer, "([^\n]+)\n") do - coordinates[linectr] = line - linectr = linectr + 1 - end - - --draw inital screen + -- read file contents into array/table + for line in string_gmatch(buffer, "([^\n]+)\n") do + coordinates[linectr] = line + linectr = linectr + 1 + end + + -- draw inital screen Viewer_Draw_LCD(0) - + else - file_exist = false + file_exist = false end - end - +end -- Main local function Viewer_Run(event) - + if event == nil then error("Cannot be run as a model script!") return 2 - else - - if file_exist == true then - - Viewer_Draw_LCD(item) - --handle scroll counter - if event == EVT_ROT_RIGHT or event == EVT_PLUS_FIRST then - if item < linectr-1 then - item = item + 1 - end - end - if event == EVT_ROT_LEFT or event == EVT_MINUS_FIRST then - if item > 0 then - item = item - 1 - end - end - + else + + if file_exist == true then + + Viewer_Draw_LCD(item) + -- handle scroll counter + if event == EVT_ROT_RIGHT or event == EVT_PLUS_FIRST then if item < linectr - 1 then item = item + 1 end end + if event == EVT_ROT_LEFT or event == EVT_MINUS_FIRST then if item > 0 then item = item - 1 end end + else - --display error message - lcd.clear() - lcd.drawLine(0,0,0,64, SOLID, FORCE) - lcd.drawLine(127,0,127,64, SOLID, FORCE) - lcd.drawText(2,1,"GPS Postion viewer" ,SMLSIZE) - lcd.drawFilledRectangle(1,0, 126, 9, GREY_DEFAULT) - lcd.drawText(10,20, "Logfile does not exist", SMLSIZE) - lcd.drawText(10,30, log_filename, SMLSIZE + BLINK) - lcd.drawLine(0,62, 128, 62, SOLID, FORCE) - end - - if event == EVT_VIRTUAL_EXIT then - return 2 + -- display error message + lcd.clear() + lcd.drawLine(0, 0, 0, 64, SOLID, FORCE) + lcd.drawLine(127, 0, 127, 64, SOLID, FORCE) + lcd.drawText(2, 1, "GPS Postion viewer", SMLSIZE) + lcd.drawFilledRectangle(1, 0, 126, 9, GREY_DEFAULT) + lcd.drawText(10, 20, "Logfile does not exist", SMLSIZE) + lcd.drawText(10, 30, log_filename, SMLSIZE + BLINK) + lcd.drawLine(0, 62, 128, 62, SOLID, FORCE) end - + + if event == EVT_VIRTUAL_EXIT then return 2 end + end - return 0 + return 0 end -return { init=Viewer_Init, run=Viewer_Run } +return {init = Viewer_Init, run = Viewer_Run} diff --git a/TBS_Tango/GPSxT.lua b/TBS_Tango/GPSxT.lua index f489727..1ddbfa9 100644 --- a/TBS_Tango/GPSxT.lua +++ b/TBS_Tango/GPSxT.lua @@ -1,14 +1,14 @@ ---[[############################################################################# +--[[###################################################################### GPS Telemetry Screen for TBS tango 2 (for 128x96 displays) -Copyright (C) by mosch -License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html -GITHUB: https://github.com/moschotto?tab=repositories +Copyright (C) by mosch +License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html +GITHUB: https://github.com/moschotto?tab=repositories + +"TELEMETRY screen - GPS last known postions v2.5" -"TELEMETRY screen - GPS last known postions v2.5" - Description: -How to find your model in case of a crash, power loss etc? Right, check the last +How to find your model in case of a crash, power loss etc? Right, check the last GPS coordinates and type it into to your mobile phone... - Shows and logs GPS related information. log file will be generated in @@ -27,8 +27,7 @@ copy GPS.lua to /SCRIPTS/TELEMETRY copy the ICON folder to /SCRIPTS/TELEMETRY/BMP Setup a "screen (DIsplay 13/13)" and select GPS.lua -################################################################################]] - + ######################################################################]] -- log_filename = "/LOGS/GPSpositions.txt" local gpsLAT = 0 @@ -54,246 +53,241 @@ local coordinates_current = 0 local old_time_write2 = 0 local wait = 100 -local function rnd(v,d) +local function rnd(v, d) if d then - return math.floor((v*10^d)+0.5)/(10^d) + return math.floor((v * 10 ^ d) + 0.5) / (10 ^ d) else - return math.floor(v+0.5) + return math.floor(v + 0.5) end end local function SecondsToClock(seconds) - local seconds = tonumber(seconds) - - if seconds <= 0 then - return "00:00:00"; - else - hours = string.format("%02.f", math.floor(seconds/3600)); - mins = string.format("%02.f", math.floor(seconds/60 - (hours*60))); - secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60)); - return hours..":"..mins..":"..secs - end -end + local seconds = tonumber(seconds) + if seconds <= 0 then + return "00:00:00"; + else + hours = string.format("%02.f", math.floor(seconds / 3600)); + mins = string.format("%02.f", math.floor(seconds / 60 - (hours * 60))); + secs = string.format("%02.f", math.floor(seconds - hours * 3600 - mins * 60)); + return hours .. ":" .. mins .. ":" .. secs + end +end local function write_log() - now = getTime() - if old_time_write + log_write_wait_time < now then - - ctr = ctr + 1 + now = getTime() + if old_time_write + log_write_wait_time < now then + + ctr = ctr + 1 time_power_on = SecondsToClock(getGlobalTimer()["session"]) - - --write logfile - file = io.open(log_filename, "a") - io.write(file, coordinates_current ..",".. time_power_on ..", ".. gpsSATS, "\r\n") - io.close(file) + + -- write logfile + file = io.open(log_filename, "a") + io.write(file, coordinates_current .. "," .. time_power_on .. ", " .. gpsSATS, "\r\n") + io.close(file) if ctr >= 99 then - ctr = 0 - --clear log - file = io.open(log_filename, "w") - io.close(file) - - --reopen log for appending data - file = io.open(log_filename, "a") - end + ctr = 0 + -- clear log + file = io.open(log_filename, "w") + io.close(file) + + -- reopen log for appending data + file = io.open(log_filename, "a") + end old_time_write = now - end + end end - -local function getTelemetryId(name) +local function getTelemetryId(name) field = getFieldInfo(name) if field then return field.id else - return-1 + return -1 end end - ---[ #################################################################### ---[ calculate distance ---[ #################################################################### +-- [ #################################################################### +-- [ calculate distance +-- [ #################################################################### local function calc_Distance(LatPos, LonPos, LatHome, LonHome) - local d2r = math.pi/180 - local d_lon = (LonPos - LonHome) * d2r - local d_lat = (LatPos - LatHome) * d2r - local a = math.pow(math.sin(d_lat/2.0), 2) + math.cos(LatHome*d2r) * math.cos(LatPos*d2r) * math.pow(math.sin(d_lon/2.0), 2) - local c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) - local dist = (6371000 * c) / 1000 - return rnd(dist,2) + local d2r = math.pi / 180 + local d_lon = (LonPos - LonHome) * d2r + local d_lat = (LatPos - LatHome) * d2r + local a = math.pow(math.sin(d_lat / 2.0), 2) + math.cos(LatHome * d2r) * math.cos(LatPos * d2r) * + math.pow(math.sin(d_lon / 2.0), 2) + local c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) + local dist = (6371000 * c) / 1000 + return rnd(dist, 2) end -local function init() +local function init() gpsId = getTelemetryId("GPS") - --number of satellites crossfire + -- number of satellites crossfire gpssatId = getTelemetryId("Sats") - --if Stats can't be read, try to read Tmp2 (number of satellites SBUS/FRSKY) - if (gpssatId == -1) then gpssatId = getTelemetryId("Tmp2") end + -- if Stats can't be read, try to read Tmp2 (number of satellites SBUS/FRSKY) + if (gpssatId == -1) then gpssatId = getTelemetryId("Tmp2") end end -local function background() +local function background() - --#################################################################### - --get Latitude, Longitude - --#################################################################### + -- #################################################################### + -- get Latitude, Longitude + -- #################################################################### gpsLatLon = getValue(gpsId) - - if (type(gpsLatLon) == "table") then - gpsLAT = rnd(gpsLatLon["lat"],6) - gpsLON = rnd(gpsLatLon["lon"],6) - - --set home postion only if more than 5 sats available + + if (type(gpsLatLon) == "table") then + gpsLAT = rnd(gpsLatLon["lat"], 6) + gpsLON = rnd(gpsLatLon["lon"], 6) + + -- set home postion only if more than 5 sats available if (tonumber(gpsSATS) > 5) and (reset == true) then - --gpsLAT_H = rnd(gpsLatLon["pilot-lat"],6) - --gpsLON_H = rnd(gpsLatLon["pilot-lon"],6) - gpsLAT_H = rnd(gpsLatLon["lat"],6) - gpsLON_H = rnd(gpsLatLon["lon"],6) + -- gpsLAT_H = rnd(gpsLatLon["pilot-lat"],6) + -- gpsLON_H = rnd(gpsLatLon["pilot-lon"],6) + gpsLAT_H = rnd(gpsLatLon["lat"], 6) + gpsLON_H = rnd(gpsLatLon["lon"], 6) reset = false - end + end - update = true + update = true else update = false end - - --#################################################################### - --get number of satellites and GPS fix type - --#################################################################### + + -- #################################################################### + -- get number of satellites and GPS fix type + -- #################################################################### gpsSATS = getValue(gpssatId) - - if string.len(gpsSATS) > 2 then + + if string.len(gpsSATS) > 2 then -- SBUS Example 1013: -> 1= GPS fix 0=lowest accuracy 13=13 active satellites - --[ Sats / Tmp2 : GPS lock status, accuracy, home reset trigger, and number of satellites. Number is sent as ABCD detailed below. Typical minimum - --[ A : 1 = GPS fix, 2 = GPS home fix, 4 = home reset (numbers are additive) - --[ B : GPS accuracy based on HDOP (0 = lowest to 9 = highest accuracy) - --[ C : number of satellites locked (digit C & D are the number of locked satellites) - --[ D : number of satellites locked (if 14 satellites are locked, C = 1 & D = 4) - gpsSATS = string.sub (gpsSATS, 3,6) + -- [ Sats / Tmp2 : GPS lock status, accuracy, home reset trigger, and number of satellites. Number is sent as ABCD detailed below. Typical minimum + -- [ A : 1 = GPS fix, 2 = GPS home fix, 4 = home reset (numbers are additive) + -- [ B : GPS accuracy based on HDOP (0 = lowest to 9 = highest accuracy) + -- [ C : number of satellites locked (digit C & D are the number of locked satellites) + -- [ D : number of satellites locked (if 14 satellites are locked, C = 1 & D = 4) + gpsSATS = string.sub(gpsSATS, 3, 6) else - --CROSSFIRE stores only the active GPS satellite - gpsSATS = string.sub (gpsSATS, 0,3) - end - - --status message "guess" + -- CROSSFIRE stores only the active GPS satellite + gpsSATS = string.sub(gpsSATS, 0, 3) + end + + -- status message "guess" -- 2D Mode - A 2D (two dimensional) position fix that includes only horizontal coordinates. It requires a minimum of three visible satellites.) -- 3D Mode - A 3D (three dimensional) position fix that includes horizontal coordinates plus altitude. It requires a minimum of four visible satellites. if (tonumber(gpsSATS) < 2) then gpsFIX = "no GPS fix" end - if (tonumber(gpsSATS) >= 3) and (tonumber(gpsSATS) <= 4) then gpsFIX = "GPS 2D fix" end + if (tonumber(gpsSATS) >= 3) and (tonumber(gpsSATS) <= 4) then gpsFIX = "GPS 2D fix" end if (tonumber(gpsSATS) >= 5) then gpsFIX = "GPS 3D fix" end - - - --#################################################################### - --get calculate distance from home and write log - --#################################################################### + + -- #################################################################### + -- get calculate distance from home and write log + -- #################################################################### if (tonumber(gpsSATS) >= 5) then - - if (gpsLAT ~= gpsPrevLAT) and (gpsLON ~= gpsPrevLON) then - --if (string.len(gpsLAT) > 4) and (string.len(gpsLON) > 4) and (tonumber(gpsSATS) > 5) then - - if (gpsLAT_H ~= 0) and (gpsLON_H ~= 0) then - --distance to home - gpsDtH = rnd(calc_Distance(gpsLAT, gpsLON, gpsLAT_H, gpsLON_H),2) - gpsDtH = string.format("%.2f",gpsDtH) - - --total distance traveled - if (gpsPrevLAT ~= 0) and (gpsPrevLON ~= 0) and (gpsLAT ~= 0) and (gpsLON ~= 0)then - --print("GPS_Debug_Prev", gpsPrevLAT,gpsPrevLON) - --print("GPS_Debug_curr", gpsLAT,gpsLON) - - gpsTotalDist = rnd(tonumber(gpsTotalDist) + calc_Distance(gpsLAT,gpsLON,gpsPrevLAT,gpsPrevLON),2) - gpsTotalDist = string.format("%.2f",gpsTotalDist) + + if (gpsLAT ~= gpsPrevLAT) and (gpsLON ~= gpsPrevLON) then + -- if (string.len(gpsLAT) > 4) and (string.len(gpsLON) > 4) and (tonumber(gpsSATS) > 5) then + + if (gpsLAT_H ~= 0) and (gpsLON_H ~= 0) then + -- distance to home + gpsDtH = rnd(calc_Distance(gpsLAT, gpsLON, gpsLAT_H, gpsLON_H), 2) + gpsDtH = string.format("%.2f", gpsDtH) + + -- total distance traveled + if (gpsPrevLAT ~= 0) and (gpsPrevLON ~= 0) and (gpsLAT ~= 0) and (gpsLON ~= 0) then + -- print("GPS_Debug_Prev", gpsPrevLAT,gpsPrevLON) + -- print("GPS_Debug_curr", gpsLAT,gpsLON) + + gpsTotalDist = rnd(tonumber(gpsTotalDist) + calc_Distance(gpsLAT, gpsLON, gpsPrevLAT, gpsPrevLON), 2) + gpsTotalDist = string.format("%.2f", gpsTotalDist) end end - - --data for displaying the - coordinates_prev = string.format("%02d",ctr) ..", ".. gpsPrevLAT..", " .. gpsPrevLON - coordinates_current = string.format("%02d",ctr+1) ..", ".. gpsLAT..", " .. gpsLON - + + -- data for displaying the + coordinates_prev = string.format("%02d", ctr) .. ", " .. gpsPrevLAT .. ", " .. gpsPrevLON + coordinates_current = string.format("%02d", ctr + 1) .. ", " .. gpsLAT .. ", " .. gpsLON + gpsPrevLAT = gpsLAT - gpsPrevLON = gpsLON - + gpsPrevLON = gpsLON + write_log() - end - end - - + end + end + end ---main function -local function run(event) - lcd.clear() - background() - - --reset telemetry data / total distance on "long press enter" +-- main function +local function run(event) + lcd.clear() + background() + + -- reset telemetry data / total distance on "long press enter" if event == EVT_ENTER_LONG then gpsDtH = 0 gpsTotalDist = 0 gpsLAT_H = 0 gpsLON_H = 0 reset = true - end - + end + -- create screen - lcd.drawLine(0,0,0,95, SOLID, FORCE) - lcd.drawLine(127,0,127,95, SOLID, FORCE) - - lcd.drawText(2,1,"State: " ,SMLSIZE) - lcd.drawFilledRectangle(1,0, 126, 8, GREY_DEFAULT) - - lcd.drawPixmap(2,10, "/SCRIPTS/TELEMETRY/BMP/Sat16.bmp") - lcd.drawLine(42,8, 42, 32, SOLID, FORCE) - lcd.drawPixmap(44,9, "/SCRIPTS/TELEMETRY/BMP/distance16.bmp") - lcd.drawLine(84,8, 84, 32, SOLID, FORCE) - lcd.drawPixmap(86,9, "/SCRIPTS/TELEMETRY/BMP/total_distance16.bmp") - - lcd.drawLine(0,32, 128, 32, SOLID, FORCE) - lcd.drawPixmap(2,38, "/SCRIPTS/TELEMETRY/BMP/home16.bmp") - - lcd.drawLine(0,60, 128, 60, SOLID, FORCE) - - lcd.drawPixmap(2,68, "/SCRIPTS/TELEMETRY/BMP/drone16.bmp") - lcd.drawLine(0,95,127,95, SOLID, FORCE) - - --update screen data + lcd.drawLine(0, 0, 0, 95, SOLID, FORCE) + lcd.drawLine(127, 0, 127, 95, SOLID, FORCE) + + lcd.drawText(2, 1, "State: ", SMLSIZE) + lcd.drawFilledRectangle(1, 0, 126, 8, GREY_DEFAULT) + + lcd.drawPixmap(2, 10, "/SCRIPTS/TELEMETRY/BMP/Sat16.bmp") + lcd.drawLine(42, 8, 42, 32, SOLID, FORCE) + lcd.drawPixmap(44, 9, "/SCRIPTS/TELEMETRY/BMP/distance16.bmp") + lcd.drawLine(84, 8, 84, 32, SOLID, FORCE) + lcd.drawPixmap(86, 9, "/SCRIPTS/TELEMETRY/BMP/total_distance16.bmp") + + lcd.drawLine(0, 32, 128, 32, SOLID, FORCE) + lcd.drawPixmap(2, 38, "/SCRIPTS/TELEMETRY/BMP/home16.bmp") + + lcd.drawLine(0, 60, 128, 60, SOLID, FORCE) + + lcd.drawPixmap(2, 68, "/SCRIPTS/TELEMETRY/BMP/drone16.bmp") + lcd.drawLine(0, 95, 127, 95, SOLID, FORCE) + + -- update screen data if update == true then - - lcd.drawText(32,1,gpsFIX ,SMLSIZE + INVERS) - lcd.drawText(22,14, gpsSATS, SMLSIZE) - lcd.drawText(60,10, gpsDtH, SMLSIZE) - lcd.drawText(73,20, "km" , SMLSIZE) - lcd.drawText(103,10, gpsTotalDist, SMLSIZE) - lcd.drawText(116,20, "km" , SMLSIZE) - - if (gpsLAT_H ~= 0) and (gpsLON_H ~= 0) then - lcd.drawText(20,43, gpsLAT_H .. ", " .. gpsLON_H, SMLSIZE) + + lcd.drawText(32, 1, gpsFIX, SMLSIZE + INVERS) + lcd.drawText(22, 14, gpsSATS, SMLSIZE) + lcd.drawText(60, 10, gpsDtH, SMLSIZE) + lcd.drawText(73, 20, "km", SMLSIZE) + lcd.drawText(103, 10, gpsTotalDist, SMLSIZE) + lcd.drawText(116, 20, "km", SMLSIZE) + + if (gpsLAT_H ~= 0) and (gpsLON_H ~= 0) then + lcd.drawText(20, 43, gpsLAT_H .. ", " .. gpsLON_H, SMLSIZE) else - lcd.drawText(20,29, "home not set. reset", SMLSIZE + INVERS + BLINK) - lcd.drawText(20,37, "telem. after GPS FIX!", SMLSIZE + INVERS + BLINK) - end - - - lcd.drawText(20,68, coordinates_prev,SMLSIZE) - lcd.drawText(20,82, coordinates_current,SMLSIZE) - - --blink if telemetry stops + lcd.drawText(20, 29, "home not set. reset", SMLSIZE + INVERS + BLINK) + lcd.drawText(20, 37, "telem. after GPS FIX!", SMLSIZE + INVERS + BLINK) + end + + lcd.drawText(20, 68, coordinates_prev, SMLSIZE) + lcd.drawText(20, 82, coordinates_current, SMLSIZE) + + -- blink if telemetry stops elseif update == false then - - lcd.drawText(32,1,"no GPS data available" ,SMLSIZE + INVERS) - lcd.drawText(22,14, gpsSATS, SMLSIZE + INVERS + BLINK ) - lcd.drawText(60,10, gpsDtH , SMLSIZE + INVERS + BLINK) - lcd.drawText(73,20, "km" , SMLSIZE) - lcd.drawText(103,10, gpsTotalDist , SMLSIZE) - lcd.drawText(116,20, "km" , SMLSIZE) - - lcd.drawText(20,43, gpsLAT_H .. ", " .. gpsLON_H, SMLSIZE) - - lcd.drawText(20,68, coordinates_prev, SMLSIZE + INVERS + BLINK) - lcd.drawText(20,82, coordinates_current, SMLSIZE + INVERS + BLINK) - - end + + lcd.drawText(32, 1, "no GPS data available", SMLSIZE + INVERS) + lcd.drawText(22, 14, gpsSATS, SMLSIZE + INVERS + BLINK) + lcd.drawText(60, 10, gpsDtH, SMLSIZE + INVERS + BLINK) + lcd.drawText(73, 20, "km", SMLSIZE) + lcd.drawText(103, 10, gpsTotalDist, SMLSIZE) + lcd.drawText(116, 20, "km", SMLSIZE) + + lcd.drawText(20, 43, gpsLAT_H .. ", " .. gpsLON_H, SMLSIZE) + + lcd.drawText(20, 68, coordinates_prev, SMLSIZE + INVERS + BLINK) + lcd.drawText(20, 82, coordinates_current, SMLSIZE + INVERS + BLINK) + + end end - -return {init=init, run=run, background=background} + +return {init = init, run = run, background = background} diff --git a/x7_x9lite/GPS Stats X9L.lua b/x7_x9lite/GPS Stats X9L.lua index 04d7c6b..75b1631 100644 --- a/x7_x9lite/GPS Stats X9L.lua +++ b/x7_x9lite/GPS Stats X9L.lua @@ -1,216 +1,199 @@ ---[[############################################################################# +--[[###################################################################### GPS Position viewer v1.2 -Copyright (C) by mosch -License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html +Copyright (C) by mosch +License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html GITHUB: https://github.com/moschotto?tab=repositories Description: reads the "GPSpositions.txt" log-file which was generated by the GPS.lua script. -useful if want to check the last GPS coordinates after a crash, power loss etc. +useful if want to check the last GPS coordinates after a crash, power loss etc. copy "GPSviewer.lua" to the /SCRIPTS/TOOLS/ folder -################################################################################]] - - + ######################################################################]] -- local toolName = "TNS|GPS Stats X9L|TNE" local log_filename = "/LOGS/GPSpositions.txt" local file_exist = false local string_gmatch = string.gmatch -local coordinates = {} +local coordinates = {} local linectr = 0 local item = 0 local function splitstring(text) if text ~= nil then - local text_split = {} - local i=0 - --split by "," and store into array/table - for word in string_gmatch(text, "([^,]+)") do + local text_split = {} + local i = 0 + -- split by "," and store into array/table + for word in string_gmatch(text, "([^,]+)") do text_split[i] = word - i = i + 1 - end + i = i + 1 + end return text_split - end + end end local function Viewer_Draw_LCD(item) - - lcd.clear() - lcd.drawLine(0,0,0,64, SOLID, FORCE) - lcd.drawLine(127,0,127,64, SOLID, FORCE) - lcd.drawText(2,1,"GPS stats viewer v1.2" ,SMLSIZE) - lcd.drawFilledRectangle(1,0, 126, 9, GREY_DEFAULT) - - - lcd.drawText(18,11, "Sats:",SMLSIZE) - lcd.drawText(18,22, "ALT:",SMLSIZE) - lcd.drawText(68,11, "Time:", SMLSIZE) - lcd.drawText(68,22, "Spd:",SMLSIZE) - - lcd.drawText(2,9, (item + 1),MIDSIZE + BLINK + INVERS) - lcd.drawText(4,23, linectr,SMLSIZE) - - - lcd.drawLine(16,8, 16, 28, SOLID, FORCE) --vertical line - lcd.drawLine(2,21, 14, 21, SOLID, FORCE) --horizontal line - lcd.drawLine(16,19, 128, 19, SOLID, FORCE) --horizontal line - - - lcd.drawLine(0,30, 128, 30, SOLID, FORCE) - + + lcd.clear() + lcd.drawLine(0, 0, 0, 64, SOLID, FORCE) + lcd.drawLine(127, 0, 127, 64, SOLID, FORCE) + lcd.drawText(2, 1, "GPS stats viewer v1.2", SMLSIZE) + lcd.drawFilledRectangle(1, 0, 126, 9, GREY_DEFAULT) + + lcd.drawText(18, 11, "Sats:", SMLSIZE) + lcd.drawText(18, 22, "ALT:", SMLSIZE) + lcd.drawText(68, 11, "Time:", SMLSIZE) + lcd.drawText(68, 22, "Spd:", SMLSIZE) + + lcd.drawText(2, 9, (item + 1), MIDSIZE + BLINK + INVERS) + lcd.drawText(4, 23, linectr, SMLSIZE) + + lcd.drawLine(16, 8, 16, 28, SOLID, FORCE) -- vertical line + lcd.drawLine(2, 21, 14, 21, SOLID, FORCE) -- horizontal line + lcd.drawLine(16, 19, 128, 19, SOLID, FORCE) -- horizontal line + + lcd.drawLine(0, 30, 128, 30, SOLID, FORCE) + if linectr > 3 then - + if item < 3 then - --first 4 rows static + -- first 4 rows static local line0 = splitstring(coordinates[0]) local line1 = splitstring(coordinates[1]) local line2 = splitstring(coordinates[2]) - - + if item == 0 then - lcd.drawText(68,11, "Time:" .. string.gsub(line0[3], "%s+",""), SMLSIZE) - lcd.drawText(18,11, "Sats:" .. string.gsub(line0[4], "%s+","") ,SMLSIZE) - lcd.drawText(18,22, "ALT:" .. string.gsub(line0[5].."m", "%s+","") ,SMLSIZE) - lcd.drawText(68,22, "Spd:" .. string.gsub(line0[6].."kmh", "%s+","") ,SMLSIZE) - lcd.drawText(2,34, line0[1] .."," .. line0[2] ,SMLSIZE + BLINK + INVERS) + lcd.drawText(68, 11, "Time:" .. string.gsub(line0[3], "%s+", ""), SMLSIZE) + lcd.drawText(18, 11, "Sats:" .. string.gsub(line0[4], "%s+", ""), SMLSIZE) + lcd.drawText(18, 22, "ALT:" .. string.gsub(line0[5] .. "m", "%s+", ""), SMLSIZE) + lcd.drawText(68, 22, "Spd:" .. string.gsub(line0[6] .. "kmh", "%s+", ""), SMLSIZE) + lcd.drawText(2, 34, line0[1] .. "," .. line0[2], SMLSIZE + BLINK + INVERS) else - lcd.drawText(2,34, line0[1] .."," .. line0[2] ,SMLSIZE) - end - + lcd.drawText(2, 34, line0[1] .. "," .. line0[2], SMLSIZE) + end + if item == 1 then - lcd.drawText(68,11, "Time:" .. string.gsub(line1[3], "%s+",""), SMLSIZE) - lcd.drawText(18,11, "Sats:" .. string.gsub(line1[4], "%s+","") ,SMLSIZE) - lcd.drawText(18,22, "ALT:" .. string.gsub(line1[5].."m", "%s+","") ,SMLSIZE) - lcd.drawText(68,22, "Spd:" .. string.gsub(line1[6], "%s+","").."kmh" ,SMLSIZE) - lcd.drawText(2,44, line1[1] .."," .. line1[2] ,SMLSIZE + BLINK + INVERS) + lcd.drawText(68, 11, "Time:" .. string.gsub(line1[3], "%s+", ""), SMLSIZE) + lcd.drawText(18, 11, "Sats:" .. string.gsub(line1[4], "%s+", ""), SMLSIZE) + lcd.drawText(18, 22, "ALT:" .. string.gsub(line1[5] .. "m", "%s+", ""), SMLSIZE) + lcd.drawText(68, 22, "Spd:" .. string.gsub(line1[6], "%s+", "") .. "kmh", SMLSIZE) + lcd.drawText(2, 44, line1[1] .. "," .. line1[2], SMLSIZE + BLINK + INVERS) else - lcd.drawText(2,44, line1[1] .."," .. line1[2] ,SMLSIZE) - end - + lcd.drawText(2, 44, line1[1] .. "," .. line1[2], SMLSIZE) + end + if item == 2 then - lcd.drawText(68,11, "Time:" .. string.gsub(line2[3], "%s+",""), SMLSIZE) - lcd.drawText(18,11, "Sats:" .. string.gsub(line2[4], "%s+","") ,SMLSIZE) - lcd.drawText(18,22, "ALT:" .. string.gsub(line2[5].."m", "%s+","") ,SMLSIZE) - lcd.drawText(68,22, "Spd:" .. string.gsub(line2[6], "%s+","").."kmh" ,SMLSIZE) - lcd.drawText(2,54, line2[1] .."," .. line2[2] ,SMLSIZE + BLINK + INVERS) + lcd.drawText(68, 11, "Time:" .. string.gsub(line2[3], "%s+", ""), SMLSIZE) + lcd.drawText(18, 11, "Sats:" .. string.gsub(line2[4], "%s+", ""), SMLSIZE) + lcd.drawText(18, 22, "ALT:" .. string.gsub(line2[5] .. "m", "%s+", ""), SMLSIZE) + lcd.drawText(68, 22, "Spd:" .. string.gsub(line2[6], "%s+", "") .. "kmh", SMLSIZE) + lcd.drawText(2, 54, line2[1] .. "," .. line2[2], SMLSIZE + BLINK + INVERS) else - lcd.drawText(2,54, line2[1] .."," .. line2[2] ,SMLSIZE) - end + lcd.drawText(2, 54, line2[1] .. "," .. line2[2], SMLSIZE) + end else - - local line0 = splitstring(coordinates[item-2]) - local line1 = splitstring(coordinates[item-1]) - local line2 = splitstring(coordinates[item]) - - lcd.drawText(68,11, "Time:" .. string.gsub(line2[3], "%s+",""), SMLSIZE) - lcd.drawText(18,11, "Sats:" .. string.gsub(line2[4], "%s+","") ,SMLSIZE) - lcd.drawText(18,22, "ALT:" .. string.gsub(line2[5].."m", "%s+","") ,SMLSIZE) - lcd.drawText(68,22, "Spd:" .. string.gsub(line2[6], "%s+","") .."kmh",SMLSIZE) - lcd.drawText(2,34, line0[1] .."," .. line0[2],SMLSIZE) - lcd.drawText(2,44, line1[1] .."," .. line1[2],SMLSIZE) - lcd.drawText(2,54, line2[1] .."," .. line2[2],SMLSIZE + BLINK + INVERS) - - end + + local line0 = splitstring(coordinates[item - 2]) + local line1 = splitstring(coordinates[item - 1]) + local line2 = splitstring(coordinates[item]) + + lcd.drawText(68, 11, "Time:" .. string.gsub(line2[3], "%s+", ""), SMLSIZE) + lcd.drawText(18, 11, "Sats:" .. string.gsub(line2[4], "%s+", ""), SMLSIZE) + lcd.drawText(18, 22, "ALT:" .. string.gsub(line2[5] .. "m", "%s+", ""), SMLSIZE) + lcd.drawText(68, 22, "Spd:" .. string.gsub(line2[6], "%s+", "") .. "kmh", SMLSIZE) + lcd.drawText(2, 34, line0[1] .. "," .. line0[2], SMLSIZE) + lcd.drawText(2, 44, line1[1] .. "," .. line1[2], SMLSIZE) + lcd.drawText(2, 54, line2[1] .. "," .. line2[2], SMLSIZE + BLINK + INVERS) + + end else - --display error message - lcd.clear() - lcd.drawLine(0,0,0,64, SOLID, FORCE) - lcd.drawLine(127,0,127,64, SOLID, FORCE) - lcd.drawText(2,1,"GPS stats viewer" ,SMLSIZE) - lcd.drawFilledRectangle(1,0, 126, 9, GREY_DEFAULT) - lcd.drawText(10,20, "more than 4 entries", SMLSIZE + BLINK) - lcd.drawText(10,27, "in GPS logfile needed", SMLSIZE + BLINK) - lcd.drawText(10,40, log_filename, SMLSIZE + BLINK) - lcd.drawLine(0,68, 128, 68, SOLID, FORCE) - + -- display error message + lcd.clear() + lcd.drawLine(0, 0, 0, 64, SOLID, FORCE) + lcd.drawLine(127, 0, 127, 64, SOLID, FORCE) + lcd.drawText(2, 1, "GPS stats viewer", SMLSIZE) + lcd.drawFilledRectangle(1, 0, 126, 9, GREY_DEFAULT) + lcd.drawText(10, 20, "more than 4 entries", SMLSIZE + BLINK) + lcd.drawText(10, 27, "in GPS logfile needed", SMLSIZE + BLINK) + lcd.drawText(10, 40, log_filename, SMLSIZE + BLINK) + lcd.drawLine(0, 68, 128, 68, SOLID, FORCE) + end - - lcd.drawLine(0,68, 128, 68, SOLID, FORCE) + + lcd.drawLine(0, 68, 128, 68, SOLID, FORCE) end local function Viewer_Init() - - lcd.clear() - local f2 = io.open(log_filename, "r") - - --check if file exists + + lcd.clear() + local f2 = io.open(log_filename, "r") + + -- check if file exists if f2 ~= nil then - + file_exist = true buffer = io.read(f2, 4096) io.close(f2) - --read file contents into array/table - for line in string_gmatch(buffer, "([^\n]+)\n") do - if not string.find(line, "Number") then --exclude logfile headline - coordinates[linectr] = line - linectr = linectr + 1 + -- read file contents into array/table + for line in string_gmatch(buffer, "([^\n]+)\n") do + if not string.find(line, "Number") then -- exclude logfile headline + coordinates[linectr] = line + linectr = linectr + 1 end - end - - --draw inital screen + end + + -- draw inital screen Viewer_Draw_LCD(0) - + else - file_exist = false + file_exist = false end - end - +end -- Main local function Viewer_Run(event) - + if event == nil then error("Cannot be run as a model script!") return 2 - else - - if file_exist == true then - - Viewer_Draw_LCD(item) - --handle scroll counter - if event == EVT_VIRTUAL_INC then - if item < linectr-1 then - item = item + 1 - end - if item == (linectr-1) then - item = 0 - end - end - - if event == EVT_VIRTUAL_DEC then - if item > 0 then - item = item - 1 - end - if item == 0 then - item = linectr-1 - end + else + + if file_exist == true then + + Viewer_Draw_LCD(item) + -- handle scroll counter + if event == EVT_VIRTUAL_INC then + if item < linectr - 1 then item = item + 1 end + if item == (linectr - 1) then item = 0 end + end + + if event == EVT_VIRTUAL_DEC then + if item > 0 then item = item - 1 end + if item == 0 then item = linectr - 1 end end - + else - --display error message - lcd.clear() - lcd.drawLine(0,0,0,64, SOLID, FORCE) - lcd.drawLine(127,0,127,64, SOLID, FORCE) - lcd.drawText(2,1,"GPS Postion viewer" ,SMLSIZE) - lcd.drawFilledRectangle(1,0, 126, 9, GREY_DEFAULT) - lcd.drawText(10,20, "Logfile does not exist", SMLSIZE) - lcd.drawText(10,28, log_filename, SMLSIZE + BLINK) - lcd.drawLine(0,68, 128, 68, SOLID, FORCE) - end - - if event == EVT_VIRTUAL_EXIT then - return 2 + -- display error message + lcd.clear() + lcd.drawLine(0, 0, 0, 64, SOLID, FORCE) + lcd.drawLine(127, 0, 127, 64, SOLID, FORCE) + lcd.drawText(2, 1, "GPS Postion viewer", SMLSIZE) + lcd.drawFilledRectangle(1, 0, 126, 9, GREY_DEFAULT) + lcd.drawText(10, 20, "Logfile does not exist", SMLSIZE) + lcd.drawText(10, 28, log_filename, SMLSIZE + BLINK) + lcd.drawLine(0, 68, 128, 68, SOLID, FORCE) end - + + if event == EVT_VIRTUAL_EXIT then return 2 end + end - return 0 + return 0 end -return { init=Viewer_Init, run=Viewer_Run } +return {init = Viewer_Init, run = Viewer_Run} diff --git a/x7_x9lite/GPSx9L.lua b/x7_x9lite/GPSx9L.lua index d9eb503..1f884b4 100644 --- a/x7_x9lite/GPSx9L.lua +++ b/x7_x9lite/GPSx9L.lua @@ -1,14 +1,14 @@ ---[[############################################################################# +--[[###################################################################### GPS Telemetry Screen for Taranis x7 / x9 lite (128x64 displays) -Copyright (C) by mosch -License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html -GITHUB: https://github.com/moschotto?tab=repositories +Copyright (C) by mosch +License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html +GITHUB: https://github.com/moschotto?tab=repositories + +"TELEMETRY screen - GPS last known postions v2.5" -"TELEMETRY screen - GPS last known postions v2.5" - Description: -How to find your model in case of a crash, power loss etc? Right, check the last +How to find your model in case of a crash, power loss etc? Right, check the last GPS coordinates and type it into to your mobile phone... - Shows and logs GPS related information. log file will be generated in @@ -27,8 +27,7 @@ copy GPS.lua to /SCRIPTS/TELEMETRY copy the ICON folder to /SCRIPTS/TELEMETRY/BMP Setup a "screen (DIsplay 13/13)" and select GPS.lua -################################################################################]] - + ######################################################################]] -- log_filename = "/LOGS/GPSpositions.txt" local gpsLAT = 0 @@ -59,257 +58,254 @@ local coordinates_current = 0 local old_time_write2 = 0 local wait = 100 -local function rnd(v,d) +local function rnd(v, d) if d then - return math.floor((v*10^d)+0.5)/(10^d) + return math.floor((v * 10 ^ d) + 0.5) / (10 ^ d) else - return math.floor(v+0.5) + return math.floor(v + 0.5) end end local function SecondsToClock(seconds) - local seconds = tonumber(seconds) - - if seconds <= 0 then - return "00:00:00"; - else - hours = string.format("%02.f", math.floor(seconds/3600)); - mins = string.format("%02.f", math.floor(seconds/60 - (hours*60))); - secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60)); - return hours..":"..mins..":"..secs - end -end + local seconds = tonumber(seconds) + if seconds <= 0 then + return "00:00:00"; + else + hours = string.format("%02.f", math.floor(seconds / 3600)); + mins = string.format("%02.f", math.floor(seconds / 60 - (hours * 60))); + secs = string.format("%02.f", math.floor(seconds - hours * 3600 - mins * 60)); + return hours .. ":" .. mins .. ":" .. secs + end +end local function write_log() - now = getTime() - if old_time_write + log_write_wait_time < now then - - ctr = ctr + 1 + now = getTime() + if old_time_write + log_write_wait_time < now then + + ctr = ctr + 1 time_power_on = SecondsToClock(getGlobalTimer()["session"]) - - --write logfile - file = io.open(log_filename, "a") - io.write(file, coordinates_current ..",".. time_power_on ..", ".. gpsSATS..", ".. gpsALT ..", ".. gpsSpeed, "\r\n") - io.close(file) + + -- write logfile + file = io.open(log_filename, "a") + io.write(file, coordinates_current .. "," .. time_power_on .. ", " .. gpsSATS .. ", " .. gpsALT .. ", " .. gpsSpeed, + "\r\n") + io.close(file) if ctr >= 99 then - ctr = 0 - --clear log - file = io.open(log_filename, "w") - io.write(file, "Number,LAT,LON,radio_time,satellites,GPSalt,GPSspeed", "\r\n") - io.close(file) - - --reopen log for appending data - file = io.open(log_filename, "a") - end + ctr = 0 + -- clear log + file = io.open(log_filename, "w") + io.write(file, "Number,LAT,LON,radio_time,satellites,GPSalt,GPSspeed", "\r\n") + io.close(file) + + -- reopen log for appending data + file = io.open(log_filename, "a") + end old_time_write = now - end + end end - -local function getTelemetryId(name) +local function getTelemetryId(name) field = getFieldInfo(name) if field then return field.id else - return-1 + return -1 end end - ---[ #################################################################### ---[ calculate distance ---[ #################################################################### +-- [ #################################################################### +-- [ calculate distance +-- [ #################################################################### local function calc_Distance(LatPos, LonPos, LatHome, LonHome) - local d2r = math.pi/180 - local d_lon = (LonPos - LonHome) * d2r - local d_lat = (LatPos - LatHome) * d2r - local a = math.pow(math.sin(d_lat/2.0), 2) + math.cos(LatHome*d2r) * math.cos(LatPos*d2r) * math.pow(math.sin(d_lon/2.0), 2) - local c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) - local dist = (6371000 * c) / 1000 - return rnd(dist,2) + local d2r = math.pi / 180 + local d_lon = (LonPos - LonHome) * d2r + local d_lat = (LatPos - LatHome) * d2r + local a = math.pow(math.sin(d_lat / 2.0), 2) + math.cos(LatHome * d2r) * math.cos(LatPos * d2r) * + math.pow(math.sin(d_lon / 2.0), 2) + local c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) + local dist = (6371000 * c) / 1000 + return rnd(dist, 2) end -local function init() +local function init() gpsId = getTelemetryId("GPS") - --number of satellites crossfire + -- number of satellites crossfire gpssatId = getTelemetryId("Sats") - --get IDs GPS Speed and GPS altitude - gpsspeedId = getTelemetryId("GSpd") --GPS ground speed m/s - gpsaltId = getTelemetryId("Alt") --GPS altitude m - - --if "ALT" can't be read, try to read "GAlt" - if (gpsaltId == -1) then gpsaltId = getTelemetryId("GAlt") end - - --if Stats can't be read, try to read Tmp2 (number of satellites SBUS/FRSKY) - if (gpssatId == -1) then gpssatId = getTelemetryId("Tmp2") end + -- get IDs GPS Speed and GPS altitude + gpsspeedId = getTelemetryId("GSpd") -- GPS ground speed m/s + gpsaltId = getTelemetryId("Alt") -- GPS altitude m + + -- if "ALT" can't be read, try to read "GAlt" + if (gpsaltId == -1) then gpsaltId = getTelemetryId("GAlt") end + + -- if Stats can't be read, try to read Tmp2 (number of satellites SBUS/FRSKY) + if (gpssatId == -1) then gpssatId = getTelemetryId("Tmp2") end end -local function background() +local function background() - --#################################################################### - --get Latitude, Longitude, Speed and Altitude - --#################################################################### + -- #################################################################### + -- get Latitude, Longitude, Speed and Altitude + -- #################################################################### gpsLatLon = getValue(gpsId) - - if (type(gpsLatLon) == "table") then - gpsLAT = rnd(gpsLatLon["lat"],6) - gpsLON = rnd(gpsLatLon["lon"],6) - gpsSpeed = rnd(getValue(gpsspeedId) * 1.852,1) - gpsALT = rnd(getValue(gpsaltId),0) - - --set home postion only if more than 5 sats available + + if (type(gpsLatLon) == "table") then + gpsLAT = rnd(gpsLatLon["lat"], 6) + gpsLON = rnd(gpsLatLon["lon"], 6) + gpsSpeed = rnd(getValue(gpsspeedId) * 1.852, 1) + gpsALT = rnd(getValue(gpsaltId), 0) + + -- set home postion only if more than 5 sats available if (tonumber(gpsSATS) > 5) and (reset == true) then - --gpsLAT_H = rnd(gpsLatLon["pilot-lat"],6) - --gpsLON_H = rnd(gpsLatLon["pilot-lon"],6) - gpsLAT_H = rnd(gpsLatLon["lat"],6) - gpsLON_H = rnd(gpsLatLon["lon"],6) + -- gpsLAT_H = rnd(gpsLatLon["pilot-lat"],6) + -- gpsLON_H = rnd(gpsLatLon["pilot-lon"],6) + gpsLAT_H = rnd(gpsLatLon["lat"], 6) + gpsLON_H = rnd(gpsLatLon["lon"], 6) reset = false - end + end - update = true + update = true else update = false end - - --#################################################################### - --get number of satellites and GPS fix type - --#################################################################### + + -- #################################################################### + -- get number of satellites and GPS fix type + -- #################################################################### gpsSATS = getValue(gpssatId) - - if string.len(gpsSATS) > 2 then + + if string.len(gpsSATS) > 2 then -- SBUS Example 1013: -> 1= GPS fix 0=lowest accuracy 13=13 active satellites - --[ Sats / Tmp2 : GPS lock status, accuracy, home reset trigger, and number of satellites. Number is sent as ABCD detailed below. Typical minimum - --[ A : 1 = GPS fix, 2 = GPS home fix, 4 = home reset (numbers are additive) - --[ B : GPS accuracy based on HDOP (0 = lowest to 9 = highest accuracy) - --[ C : number of satellites locked (digit C & D are the number of locked satellites) - --[ D : number of satellites locked (if 14 satellites are locked, C = 1 & D = 4) - gpsSATS = string.sub (gpsSATS, 3,6) + -- [ Sats / Tmp2 : GPS lock status, accuracy, home reset trigger, and number of satellites. Number is sent as ABCD detailed below. Typical minimum + -- [ A : 1 = GPS fix, 2 = GPS home fix, 4 = home reset (numbers are additive) + -- [ B : GPS accuracy based on HDOP (0 = lowest to 9 = highest accuracy) + -- [ C : number of satellites locked (digit C & D are the number of locked satellites) + -- [ D : number of satellites locked (if 14 satellites are locked, C = 1 & D = 4) + gpsSATS = string.sub(gpsSATS, 3, 6) else - --CROSSFIRE stores only the active GPS satellite - gpsSATS = string.sub (gpsSATS, 0,3) - end - - --status message "guess" + -- CROSSFIRE stores only the active GPS satellite + gpsSATS = string.sub(gpsSATS, 0, 3) + end + + -- status message "guess" -- 2D Mode - A 2D (two dimensional) position fix that includes only horizontal coordinates. It requires a minimum of three visible satellites.) -- 3D Mode - A 3D (three dimensional) position fix that includes horizontal coordinates plus altitude. It requires a minimum of four visible satellites. if (tonumber(gpsSATS) < 2) then gpsFIX = "no GPS fix" end - if (tonumber(gpsSATS) >= 3) and (tonumber(gpsSATS) <= 4) then gpsFIX = "GPS 2D fix" end + if (tonumber(gpsSATS) >= 3) and (tonumber(gpsSATS) <= 4) then gpsFIX = "GPS 2D fix" end if (tonumber(gpsSATS) >= 5) then gpsFIX = "GPS 3D fix" end - - - --#################################################################### - --get calculate distance from home and write log - --#################################################################### + + -- #################################################################### + -- get calculate distance from home and write log + -- #################################################################### if (tonumber(gpsSATS) >= 5) then - - if (gpsLAT ~= gpsPrevLAT) and (gpsLON ~= gpsPrevLON) then - - if (gpsLAT_H ~= 0) and (gpsLON_H ~= 0) then - - --distance to home - gpsDtH = rnd(calc_Distance(gpsLAT, gpsLON, gpsLAT_H, gpsLON_H),2) - gpsDtH = string.format("%.2f",gpsDtH) - - --total distance traveled - if (gpsPrevLAT ~= 0) and (gpsPrevLON ~= 0) and (gpsLAT ~= 0) and (gpsLON ~= 0)then - --print("GPS_Debug_Prev", gpsPrevLAT,gpsPrevLON) - --print("GPS_Debug_curr", gpsLAT,gpsLON) - - gpsTotalDist = rnd(tonumber(gpsTotalDist) + calc_Distance(gpsLAT,gpsLON,gpsPrevLAT,gpsPrevLON),2) - gpsTotalDist = string.format("%.2f",gpsTotalDist) + + if (gpsLAT ~= gpsPrevLAT) and (gpsLON ~= gpsPrevLON) then + + if (gpsLAT_H ~= 0) and (gpsLON_H ~= 0) then + + -- distance to home + gpsDtH = rnd(calc_Distance(gpsLAT, gpsLON, gpsLAT_H, gpsLON_H), 2) + gpsDtH = string.format("%.2f", gpsDtH) + + -- total distance traveled + if (gpsPrevLAT ~= 0) and (gpsPrevLON ~= 0) and (gpsLAT ~= 0) and (gpsLON ~= 0) then + -- print("GPS_Debug_Prev", gpsPrevLAT,gpsPrevLON) + -- print("GPS_Debug_curr", gpsLAT,gpsLON) + + gpsTotalDist = rnd(tonumber(gpsTotalDist) + calc_Distance(gpsLAT, gpsLON, gpsPrevLAT, gpsPrevLON), 2) + gpsTotalDist = string.format("%.2f", gpsTotalDist) end end - --data for displaying the - coordinates_prev = string.format("%02d",ctr) ..", ".. gpsPrevLAT..", " .. gpsPrevLON - coordinates_current = string.format("%02d",ctr+1) ..", ".. gpsLAT..", " .. gpsLON - + -- data for displaying the + coordinates_prev = string.format("%02d", ctr) .. ", " .. gpsPrevLAT .. ", " .. gpsPrevLON + coordinates_current = string.format("%02d", ctr + 1) .. ", " .. gpsLAT .. ", " .. gpsLON + gpsPrevLAT = gpsLAT - gpsPrevLON = gpsLON - + gpsPrevLON = gpsLON + write_log() - end - end - - + end + end + end ---main function -local function run(event) - lcd.clear() - background() - - --reset telemetry data / total distance on "long press enter" +-- main function +local function run(event) + lcd.clear() + background() + + -- reset telemetry data / total distance on "long press enter" if event == EVT_ENTER_LONG then gpsDtH = 0 gpsTotalDist = 0 gpsLAT_H = 0 gpsLON_H = 0 reset = true - - end - + + end + -- create screen - lcd.drawLine(0,0,0,64, SOLID, FORCE) - lcd.drawLine(127,0,127,64, SOLID, FORCE) - - lcd.drawText(2,1,"State: " ,SMLSIZE) - lcd.drawFilledRectangle(1,0, 126, 8, GREY_DEFAULT) - - lcd.drawPixmap(2,10, "/SCRIPTS/TELEMETRY/BMP/Sat16.bmp") - lcd.drawLine(42,8, 42, 27, SOLID, FORCE) - lcd.drawPixmap(44,9, "/SCRIPTS/TELEMETRY/BMP/distance16.bmp") - lcd.drawLine(84,8, 84, 27, SOLID, FORCE) - lcd.drawPixmap(86,9, "/SCRIPTS/TELEMETRY/BMP/total_distance16.bmp") - - lcd.drawLine(0,27, 128, 27, SOLID, FORCE) - - lcd.drawPixmap(2,28, "/SCRIPTS/TELEMETRY/BMP/home16.bmp") - lcd.drawLine(0,44, 128, 44, SOLID, FORCE) - - lcd.drawPixmap(2,47, "/SCRIPTS/TELEMETRY/BMP/drone16.bmp") - lcd.drawLine(0,63,127,63, SOLID, FORCE) - - --update screen data + lcd.drawLine(0, 0, 0, 64, SOLID, FORCE) + lcd.drawLine(127, 0, 127, 64, SOLID, FORCE) + + lcd.drawText(2, 1, "State: ", SMLSIZE) + lcd.drawFilledRectangle(1, 0, 126, 8, GREY_DEFAULT) + + lcd.drawPixmap(2, 10, "/SCRIPTS/TELEMETRY/BMP/Sat16.bmp") + lcd.drawLine(42, 8, 42, 27, SOLID, FORCE) + lcd.drawPixmap(44, 9, "/SCRIPTS/TELEMETRY/BMP/distance16.bmp") + lcd.drawLine(84, 8, 84, 27, SOLID, FORCE) + lcd.drawPixmap(86, 9, "/SCRIPTS/TELEMETRY/BMP/total_distance16.bmp") + + lcd.drawLine(0, 27, 128, 27, SOLID, FORCE) + + lcd.drawPixmap(2, 28, "/SCRIPTS/TELEMETRY/BMP/home16.bmp") + lcd.drawLine(0, 44, 128, 44, SOLID, FORCE) + + lcd.drawPixmap(2, 47, "/SCRIPTS/TELEMETRY/BMP/drone16.bmp") + lcd.drawLine(0, 63, 127, 63, SOLID, FORCE) + + -- update screen data if update == true then - - lcd.drawText(32,1,gpsFIX ,SMLSIZE + INVERS) - lcd.drawText(22,14, gpsSATS, SMLSIZE) - lcd.drawText(60,10, gpsDtH, SMLSIZE) - lcd.drawText(73,20, "km" , SMLSIZE) - lcd.drawText(103,10, gpsTotalDist, SMLSIZE) - lcd.drawText(116,20, "km" , SMLSIZE) - - if (gpsLAT_H ~= 0) and (gpsLON_H ~= 0) then - lcd.drawText(20,33, gpsLAT_H .. ", " .. gpsLON_H, SMLSIZE) + + lcd.drawText(32, 1, gpsFIX, SMLSIZE + INVERS) + lcd.drawText(22, 14, gpsSATS, SMLSIZE) + lcd.drawText(60, 10, gpsDtH, SMLSIZE) + lcd.drawText(73, 20, "km", SMLSIZE) + lcd.drawText(103, 10, gpsTotalDist, SMLSIZE) + lcd.drawText(116, 20, "km", SMLSIZE) + + if (gpsLAT_H ~= 0) and (gpsLON_H ~= 0) then + lcd.drawText(20, 33, gpsLAT_H .. ", " .. gpsLON_H, SMLSIZE) else - lcd.drawText(20,29, "home not set. reset", SMLSIZE + INVERS + BLINK) - lcd.drawText(20,37, "telem. after GPS FIX!", SMLSIZE + INVERS + BLINK) + lcd.drawText(20, 29, "home not set. reset", SMLSIZE + INVERS + BLINK) + lcd.drawText(20, 37, "telem. after GPS FIX!", SMLSIZE + INVERS + BLINK) end - - lcd.drawText(20,47, coordinates_prev,SMLSIZE) - lcd.drawText(20,56, coordinates_current,SMLSIZE) - - --blink if telemetry stops + + lcd.drawText(20, 47, coordinates_prev, SMLSIZE) + lcd.drawText(20, 56, coordinates_current, SMLSIZE) + + -- blink if telemetry stops elseif update == false then - - lcd.drawText(32,1,"no GPS data available" ,SMLSIZE + INVERS) - lcd.drawText(22,14, gpsSATS, SMLSIZE + INVERS + BLINK ) - lcd.drawText(60,10, gpsDtH , SMLSIZE + INVERS + BLINK) - lcd.drawText(73,20, "km" , SMLSIZE) - lcd.drawText(103,10, gpsTotalDist , SMLSIZE) - lcd.drawText(116,20, "km" , SMLSIZE) - - lcd.drawText(20,33, gpsLAT_H .. ", " .. gpsLON_H, SMLSIZE) - - lcd.drawText(20,47, coordinates_prev, SMLSIZE + INVERS + BLINK) - lcd.drawText(20,56, coordinates_current, SMLSIZE + INVERS + BLINK) - - end + + lcd.drawText(32, 1, "no GPS data available", SMLSIZE + INVERS) + lcd.drawText(22, 14, gpsSATS, SMLSIZE + INVERS + BLINK) + lcd.drawText(60, 10, gpsDtH, SMLSIZE + INVERS + BLINK) + lcd.drawText(73, 20, "km", SMLSIZE) + lcd.drawText(103, 10, gpsTotalDist, SMLSIZE) + lcd.drawText(116, 20, "km", SMLSIZE) + + lcd.drawText(20, 33, gpsLAT_H .. ", " .. gpsLON_H, SMLSIZE) + + lcd.drawText(20, 47, coordinates_prev, SMLSIZE + INVERS + BLINK) + lcd.drawText(20, 56, coordinates_current, SMLSIZE + INVERS + BLINK) + + end end - -return {init=init, run=run, background=background} + +return {init = init, run = run, background = background} diff --git a/x9/GPS Stats X9.lua b/x9/GPS Stats X9.lua index a053990..7549972 100644 --- a/x9/GPS Stats X9.lua +++ b/x9/GPS Stats X9.lua @@ -1,214 +1,190 @@ ---[[############################################################################# +--[[###################################################################### GPS stats viewer v1.2 -Copyright (C) by mosch -License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html +Copyright (C) by mosch +License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html GITHUB: https://github.com/moschotto?tab=repositories Description: reads the "GPSpositions.txt" log-file which was generated by the GPS.lua script. -useful if want to check the last GPS coordinates after a crash, power loss etc. +useful if want to check the last GPS coordinates after a crash, power loss etc. copy "GPSviewer.lua" to the /SCRIPTS/TOOLS/ folder -################################################################################]] - - + ######################################################################]] -- local toolName = "TNS|GPS Stats X9|TNE" local log_filename = "/LOGS/GPSpositions.txt" local file_exist = false local string_gmatch = string.gmatch -local coordinates = {} +local coordinates = {} local linectr = 0 local item = 0 local function splitstring(text) if text ~= nil then - local text_split = {} - local i=0 - --split by "," and store into array/table - for word in string_gmatch(text, "([^,]+)") do + local text_split = {} + local i = 0 + -- split by "," and store into array/table + for word in string_gmatch(text, "([^,]+)") do text_split[i] = word - i = i + 1 - end + i = i + 1 + end return text_split - end + end end local function Viewer_Draw_LCD(item) - - lcd.clear() - lcd.drawLine(0,0,0,64, SOLID, FORCE) - lcd.drawLine(211,0,211,64, SOLID, FORCE) - lcd.drawText(2,1,"GPS stats viewer v1.2" ,SMLSIZE) - lcd.drawFilledRectangle(1,0, 210, 9, GREY_DEFAULT) - - lcd.drawText(2,16, "No# " ..(item + 1).." / " .. linectr,SMLSIZE) - - - lcd.drawText(60,11, "Sats:",SMLSIZE) - lcd.drawText(60,22, "ALT:",SMLSIZE) - lcd.drawText(130,11, "Time:", SMLSIZE) - lcd.drawText(130,22, "Spd:",SMLSIZE) - - lcd.drawLine(55,19, 212, 19, SOLID, FORCE) - lcd.drawLine(55,8, 55, 28, SOLID, FORCE) --vertical line - lcd.drawLine(0,30, 212, 30, SOLID, FORCE) --horizontal line - - if linectr > 3 then + + lcd.clear() + lcd.drawLine(0, 0, 0, 64, SOLID, FORCE) + lcd.drawLine(211, 0, 211, 64, SOLID, FORCE) + lcd.drawText(2, 1, "GPS stats viewer v1.2", SMLSIZE) + lcd.drawFilledRectangle(1, 0, 210, 9, GREY_DEFAULT) + + lcd.drawText(2, 16, "No# " .. (item + 1) .. " / " .. linectr, SMLSIZE) + + lcd.drawText(60, 11, "Sats:", SMLSIZE) + lcd.drawText(60, 22, "ALT:", SMLSIZE) + lcd.drawText(130, 11, "Time:", SMLSIZE) + lcd.drawText(130, 22, "Spd:", SMLSIZE) + + lcd.drawLine(55, 19, 212, 19, SOLID, FORCE) + lcd.drawLine(55, 8, 55, 28, SOLID, FORCE) -- vertical line + lcd.drawLine(0, 30, 212, 30, SOLID, FORCE) -- horizontal line + + if linectr > 3 then if item < 3 then - --first 4 rows static + -- first 4 rows static local line0 = splitstring(coordinates[0]) local line1 = splitstring(coordinates[1]) local line2 = splitstring(coordinates[2]) - + if item == 0 then - lcd.drawText(130,11, "Time:" .. string.gsub(line0[3], "%s+",""), SMLSIZE) - lcd.drawText(60,11, "Sats:" .. string.gsub(line0[4], "%s+","") ,SMLSIZE) - lcd.drawText(60,22, "ALT:" .. string.gsub(line0[5].."m", "%s+","") ,SMLSIZE) - lcd.drawText(130,22, "Spd:" .. string.gsub(line0[6].."kmh", "%s+","") ,SMLSIZE) - lcd.drawText(2,34, line0[1] .."," .. line0[2] ,SMLSIZE + BLINK + INVERS) + lcd.drawText(130, 11, "Time:" .. string.gsub(line0[3], "%s+", ""), SMLSIZE) + lcd.drawText(60, 11, "Sats:" .. string.gsub(line0[4], "%s+", ""), SMLSIZE) + lcd.drawText(60, 22, "ALT:" .. string.gsub(line0[5] .. "m", "%s+", ""), SMLSIZE) + lcd.drawText(130, 22, "Spd:" .. string.gsub(line0[6] .. "kmh", "%s+", ""), SMLSIZE) + lcd.drawText(2, 34, line0[1] .. "," .. line0[2], SMLSIZE + BLINK + INVERS) else - lcd.drawText(2,34, line0[1] .."," .. line0[2] ,SMLSIZE) - end - + lcd.drawText(2, 34, line0[1] .. "," .. line0[2], SMLSIZE) + end + if item == 1 then - lcd.drawText(130,11, "Time:" .. string.gsub(line1[3], "%s+",""), SMLSIZE) - lcd.drawText(60,11, "Sats:" .. string.gsub(line1[4], "%s+","") ,SMLSIZE) - lcd.drawText(60,22, "ALT:" .. string.gsub(line1[5].."m", "%s+","") ,SMLSIZE) - lcd.drawText(130,22, "Spd:" .. string.gsub(line1[6], "%s+","").."kmh" ,SMLSIZE) - lcd.drawText(2,44, line1[1] .."," .. line1[2] ,SMLSIZE + BLINK + INVERS) + lcd.drawText(130, 11, "Time:" .. string.gsub(line1[3], "%s+", ""), SMLSIZE) + lcd.drawText(60, 11, "Sats:" .. string.gsub(line1[4], "%s+", ""), SMLSIZE) + lcd.drawText(60, 22, "ALT:" .. string.gsub(line1[5] .. "m", "%s+", ""), SMLSIZE) + lcd.drawText(130, 22, "Spd:" .. string.gsub(line1[6], "%s+", "") .. "kmh", SMLSIZE) + lcd.drawText(2, 44, line1[1] .. "," .. line1[2], SMLSIZE + BLINK + INVERS) else - lcd.drawText(2,44, line1[1] .."," .. line1[2] ,SMLSIZE) - end - + lcd.drawText(2, 44, line1[1] .. "," .. line1[2], SMLSIZE) + end + if item == 2 then - lcd.drawText(130,11, "Time:" .. string.gsub(line2[3], "%s+",""), SMLSIZE) - lcd.drawText(60,11, "Sats:" .. string.gsub(line2[4], "%s+","") ,SMLSIZE) - lcd.drawText(60,22, "ALT:" .. string.gsub(line2[5].."m", "%s+","") ,SMLSIZE) - lcd.drawText(130,22, "Spd:" .. string.gsub(line2[6], "%s+","").."kmh" ,SMLSIZE) - lcd.drawText(2,54, line2[1] .."," .. line2[2] ,SMLSIZE + BLINK + INVERS) + lcd.drawText(130, 11, "Time:" .. string.gsub(line2[3], "%s+", ""), SMLSIZE) + lcd.drawText(60, 11, "Sats:" .. string.gsub(line2[4], "%s+", ""), SMLSIZE) + lcd.drawText(60, 22, "ALT:" .. string.gsub(line2[5] .. "m", "%s+", ""), SMLSIZE) + lcd.drawText(130, 22, "Spd:" .. string.gsub(line2[6], "%s+", "") .. "kmh", SMLSIZE) + lcd.drawText(2, 54, line2[1] .. "," .. line2[2], SMLSIZE + BLINK + INVERS) else - lcd.drawText(2,54, line2[1] .."," .. line2[2] ,SMLSIZE) - end + lcd.drawText(2, 54, line2[1] .. "," .. line2[2], SMLSIZE) + end else - - local line0 = splitstring(coordinates[item-2]) - local line1 = splitstring(coordinates[item-1]) - local line2 = splitstring(coordinates[item]) - - lcd.drawText(130,11, "Time: " .. string.gsub(line2[3], "%s+", ""), SMLSIZE) - lcd.drawText(60,11, "Sats:" .. string.gsub(line2[4], "%s+","") ,SMLSIZE) - lcd.drawText(60,22, "ALT:" .. string.gsub(line2[5].."m", "%s+","") ,SMLSIZE) - lcd.drawText(130,22, "Spd:" .. string.gsub(line2[6], "%s+","") .."kmh",SMLSIZE) - lcd.drawText(2,34, line0[1] .."," .. line0[2],SMLSIZE) - lcd.drawText(2,44, line1[1] .."," .. line1[2],SMLSIZE) - lcd.drawText(2,54, line2[1] .."," .. line2[2],SMLSIZE + BLINK + INVERS) - - end + + local line0 = splitstring(coordinates[item - 2]) + local line1 = splitstring(coordinates[item - 1]) + local line2 = splitstring(coordinates[item]) + + lcd.drawText(130, 11, "Time: " .. string.gsub(line2[3], "%s+", ""), SMLSIZE) + lcd.drawText(60, 11, "Sats:" .. string.gsub(line2[4], "%s+", ""), SMLSIZE) + lcd.drawText(60, 22, "ALT:" .. string.gsub(line2[5] .. "m", "%s+", ""), SMLSIZE) + lcd.drawText(130, 22, "Spd:" .. string.gsub(line2[6], "%s+", "") .. "kmh", SMLSIZE) + lcd.drawText(2, 34, line0[1] .. "," .. line0[2], SMLSIZE) + lcd.drawText(2, 44, line1[1] .. "," .. line1[2], SMLSIZE) + lcd.drawText(2, 54, line2[1] .. "," .. line2[2], SMLSIZE + BLINK + INVERS) + + end else - --display error message - lcd.clear() - lcd.drawLine(0,0,0,64, SOLID, FORCE) - - lcd.drawText(2,1,"GPS stats viewer" ,SMLSIZE) - lcd.drawFilledRectangle(1,0, 211, 9, GREY_DEFAULT) - lcd.drawText(10,20, "more than 4 entries in GPS logfile needed", SMLSIZE + BLINK) - lcd.drawText(10,30, log_filename, SMLSIZE + BLINK) - lcd.drawLine(0,68, 128, 68, SOLID, FORCE) - + -- display error message + lcd.clear() + lcd.drawLine(0, 0, 0, 64, SOLID, FORCE) + + lcd.drawText(2, 1, "GPS stats viewer", SMLSIZE) + lcd.drawFilledRectangle(1, 0, 211, 9, GREY_DEFAULT) + lcd.drawText(10, 20, "more than 4 entries in GPS logfile needed", SMLSIZE + BLINK) + lcd.drawText(10, 30, log_filename, SMLSIZE + BLINK) + lcd.drawLine(0, 68, 128, 68, SOLID, FORCE) + end - - lcd.drawLine(0,62, 212, 62, SOLID, FORCE) + + lcd.drawLine(0, 62, 212, 62, SOLID, FORCE) end local function Viewer_Init() - - lcd.clear() - local f2 = io.open(log_filename, "r") - - --check if file exists + + lcd.clear() + local f2 = io.open(log_filename, "r") + + -- check if file exists if f2 ~= nil then - + file_exist = true buffer = io.read(f2, 4096) io.close(f2) - --read file contents into array/table - for line in string_gmatch(buffer, "([^\n]+)\n") do - if not string.find(line, "Number") then --exclude logfile headline - coordinates[linectr] = line - linectr = linectr + 1 + -- read file contents into array/table + for line in string_gmatch(buffer, "([^\n]+)\n") do + if not string.find(line, "Number") then -- exclude logfile headline + coordinates[linectr] = line + linectr = linectr + 1 end - end - - --draw inital screen + end + + -- draw inital screen Viewer_Draw_LCD(0) - + else - file_exist = false + file_exist = false end - end - +end -- Main local function Viewer_Run(event) - + if event == nil then error("Cannot be run as a model script!") return 2 - else - - if file_exist == true then - - Viewer_Draw_LCD(item) - --handle scroll counter - if event == EVT_PLUS_FIRST or event == EVT_PLUS_REPT then - if item < linectr-1 then - item = item + 1 - end - end - if event == EVT_MINUS_FIRST or event == EVT_MINUS_REPT then - if item > 0 then - item = item - 1 - end - end - - if event == EVT_ROT_RIGHT or event == EVT_PLUS_FIRST then - if item < linectr-1 then - item = item + 1 - end - end - if event == EVT_ROT_LEFT or event == EVT_MINUS_FIRST then - if item > 0 then - item = item - 1 - end - end - + else + + if file_exist == true then + + Viewer_Draw_LCD(item) + -- handle scroll counter + if event == EVT_PLUS_FIRST or event == EVT_PLUS_REPT then if item < linectr - 1 then item = item + 1 end end + if event == EVT_MINUS_FIRST or event == EVT_MINUS_REPT then if item > 0 then item = item - 1 end end + + if event == EVT_ROT_RIGHT or event == EVT_PLUS_FIRST then if item < linectr - 1 then item = item + 1 end end + if event == EVT_ROT_LEFT or event == EVT_MINUS_FIRST then if item > 0 then item = item - 1 end end - else - --display error message - lcd.clear() - lcd.drawLine(0,0,0,64, SOLID, FORCE) - lcd.drawLine(127,0,127,64, SOLID, FORCE) - lcd.drawText(2,1,"GPS Postion viewer" ,SMLSIZE) - lcd.drawFilledRectangle(1,0, 126, 9, GREY_DEFAULT) - lcd.drawText(10,20, "Logfile does not exist", SMLSIZE) - lcd.drawText(10,30, log_filename, SMLSIZE + BLINK) - lcd.drawLine(0,62, 128, 62, SOLID, FORCE) - end - - if event == EVT_VIRTUAL_EXIT then - return 2 + -- display error message + lcd.clear() + lcd.drawLine(0, 0, 0, 64, SOLID, FORCE) + lcd.drawLine(127, 0, 127, 64, SOLID, FORCE) + lcd.drawText(2, 1, "GPS Postion viewer", SMLSIZE) + lcd.drawFilledRectangle(1, 0, 126, 9, GREY_DEFAULT) + lcd.drawText(10, 20, "Logfile does not exist", SMLSIZE) + lcd.drawText(10, 30, log_filename, SMLSIZE + BLINK) + lcd.drawLine(0, 62, 128, 62, SOLID, FORCE) end - + + if event == EVT_VIRTUAL_EXIT then return 2 end + end - return 0 + return 0 end -return { init=Viewer_Init, run=Viewer_Run } +return {init = Viewer_Init, run = Viewer_Run} diff --git a/x9/GPSx9.lua b/x9/GPSx9.lua index c503053..bf54045 100644 --- a/x9/GPSx9.lua +++ b/x9/GPSx9.lua @@ -1,14 +1,14 @@ ---[[############################################################################# +--[[###################################################################### GPS Telemetry Screen for Taranis x9d/x9+/x9E (212x64 displays) -Copyright (C) by mosch -License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html -GITHUB: https://github.com/moschotto?tab=repositories +Copyright (C) by mosch +License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html +GITHUB: https://github.com/moschotto?tab=repositories + +"TELEMETRY screen - GPS last known postions v2.5" -"TELEMETRY screen - GPS last known postions v2.5" - Description: -How to find your model in case of a crash, power loss etc? Right, check the last +How to find your model in case of a crash, power loss etc? Right, check the last GPS coordinates and type it into to your mobile phone... - Shows and logs GPS related information. log file will be generated in @@ -27,8 +27,7 @@ copy GPS.lua to /SCRIPTS/TELEMETRY copy the ICON folder to /SCRIPTS/TELEMETRY/BMP Setup a "screen (DIsplay 13/13)" and select GPS.lua -################################################################################]] - + ######################################################################]] -- log_filename = "/LOGS/GPSpositions.txt" local gpsLAT = 0 @@ -59,252 +58,248 @@ local coordinates_current = 0 local old_time_write2 = 0 local wait = 100 -local function rnd(v,d) +local function rnd(v, d) if d then - return math.floor((v*10^d)+0.5)/(10^d) + return math.floor((v * 10 ^ d) + 0.5) / (10 ^ d) else - return math.floor(v+0.5) + return math.floor(v + 0.5) end end local function SecondsToClock(seconds) - local seconds = tonumber(seconds) - - if seconds <= 0 then - return "00:00:00"; - else - hours = string.format("%02.f", math.floor(seconds/3600)); - mins = string.format("%02.f", math.floor(seconds/60 - (hours*60))); - secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60)); - return hours..":"..mins..":"..secs - end -end + local seconds = tonumber(seconds) + if seconds <= 0 then + return "00:00:00"; + else + hours = string.format("%02.f", math.floor(seconds / 3600)); + mins = string.format("%02.f", math.floor(seconds / 60 - (hours * 60))); + secs = string.format("%02.f", math.floor(seconds - hours * 3600 - mins * 60)); + return hours .. ":" .. mins .. ":" .. secs + end +end local function write_log() - now = getTime() - if old_time_write + log_write_wait_time < now then - - ctr = ctr + 1 + now = getTime() + if old_time_write + log_write_wait_time < now then + + ctr = ctr + 1 time_power_on = SecondsToClock(getGlobalTimer()["session"]) - - --write logfile - file = io.open(log_filename, "a") - io.write(file, coordinates_current ..",".. time_power_on ..", ".. gpsSATS..", ".. gpsALT ..", ".. gpsSpeed, "\r\n") - io.close(file) + + -- write logfile + file = io.open(log_filename, "a") + io.write(file, coordinates_current .. "," .. time_power_on .. ", " .. gpsSATS .. ", " .. gpsALT .. ", " .. gpsSpeed, + "\r\n") + io.close(file) if ctr >= 99 then - ctr = 0 - --clear log - file = io.open(log_filename, "w") - io.write(file, "Number,LAT,LON,radio_time,satellites,GPSalt,GPSspeed", "\r\n") - io.close(file) - - --reopen log for appending data - file = io.open(log_filename, "a") - end + ctr = 0 + -- clear log + file = io.open(log_filename, "w") + io.write(file, "Number,LAT,LON,radio_time,satellites,GPSalt,GPSspeed", "\r\n") + io.close(file) + + -- reopen log for appending data + file = io.open(log_filename, "a") + end old_time_write = now - end + end end - -local function getTelemetryId(name) +local function getTelemetryId(name) field = getFieldInfo(name) if field then return field.id else - return-1 + return -1 end end - ---[ #################################################################### ---[ calculate distance ---[ #################################################################### +-- [ #################################################################### +-- [ calculate distance +-- [ #################################################################### local function calc_Distance(LatPos, LonPos, LatHome, LonHome) - local d2r = math.pi/180 - local d_lon = (LonPos - LonHome) * d2r - local d_lat = (LatPos - LatHome) * d2r - local a = math.pow(math.sin(d_lat/2.0), 2) + math.cos(LatHome*d2r) * math.cos(LatPos*d2r) * math.pow(math.sin(d_lon/2.0), 2) - local c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) - local dist = (6371000 * c) / 1000 - return rnd(dist,2) + local d2r = math.pi / 180 + local d_lon = (LonPos - LonHome) * d2r + local d_lat = (LatPos - LatHome) * d2r + local a = math.pow(math.sin(d_lat / 2.0), 2) + math.cos(LatHome * d2r) * math.cos(LatPos * d2r) * + math.pow(math.sin(d_lon / 2.0), 2) + local c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) + local dist = (6371000 * c) / 1000 + return rnd(dist, 2) end -local function init() +local function init() gpsId = getTelemetryId("GPS") - --number of satellites crossfire + -- number of satellites crossfire gpssatId = getTelemetryId("Sats") - - --get IDs GPS Speed and GPS altitude - gpsspeedId = getTelemetryId("GSpd") --GPS ground speed m/s - gpsaltId = getTelemetryId("GAlt") --GPS altitude m - - --if "ALT" can't be read, try to read "GAlt" - if (gpsaltId == -1) then gpsaltId = getTelemetryId("GAlt") end - - --if Stats can't be read, try to read Tmp2 (number of satellites SBUS/FRSKY) - if (gpssatId == -1) then gpssatId = getTelemetryId("Tmp2") end + + -- get IDs GPS Speed and GPS altitude + gpsspeedId = getTelemetryId("GSpd") -- GPS ground speed m/s + gpsaltId = getTelemetryId("GAlt") -- GPS altitude m + + -- if "ALT" can't be read, try to read "GAlt" + if (gpsaltId == -1) then gpsaltId = getTelemetryId("GAlt") end + + -- if Stats can't be read, try to read Tmp2 (number of satellites SBUS/FRSKY) + if (gpssatId == -1) then gpssatId = getTelemetryId("Tmp2") end end -local function background() +local function background() - --#################################################################### - --get Latitude, Longitude - --#################################################################### + -- #################################################################### + -- get Latitude, Longitude + -- #################################################################### gpsLatLon = getValue(gpsId) - - if (type(gpsLatLon) == "table") then - gpsLAT = rnd(gpsLatLon["lat"],6) - gpsLON = rnd(gpsLatLon["lon"],6) - gpsSpeed = rnd(getValue(gpsspeedId) * 1.852,1) - gpsALT = rnd(getValue(gpsaltId),0) - - --set home postion only if more than 5 sats available + + if (type(gpsLatLon) == "table") then + gpsLAT = rnd(gpsLatLon["lat"], 6) + gpsLON = rnd(gpsLatLon["lon"], 6) + gpsSpeed = rnd(getValue(gpsspeedId) * 1.852, 1) + gpsALT = rnd(getValue(gpsaltId), 0) + + -- set home postion only if more than 5 sats available if (tonumber(gpsSATS) > 5) and (reset == true) then - --gpsLAT_H = rnd(gpsLatLon["pilot-lat"],6) - --gpsLON_H = rnd(gpsLatLon["pilot-lon"],6) - gpsLAT_H = rnd(gpsLatLon["lat"],6) - gpsLON_H = rnd(gpsLatLon["lon"],6) + -- gpsLAT_H = rnd(gpsLatLon["pilot-lat"],6) + -- gpsLON_H = rnd(gpsLatLon["pilot-lon"],6) + gpsLAT_H = rnd(gpsLatLon["lat"], 6) + gpsLON_H = rnd(gpsLatLon["lon"], 6) reset = false - end + end - update = true + update = true else update = false end - - --#################################################################### - --get number of satellites and GPS fix type - --#################################################################### + + -- #################################################################### + -- get number of satellites and GPS fix type + -- #################################################################### gpsSATS = getValue(gpssatId) - - if string.len(gpsSATS) > 2 then + + if string.len(gpsSATS) > 2 then -- SBUS Example 1013: -> 1= GPS fix 0=lowest accuracy 13=13 active satellites - --[ Sats / Tmp2 : GPS lock status, accuracy, home reset trigger, and number of satellites. Number is sent as ABCD detailed below. Typical minimum - --[ A : 1 = GPS fix, 2 = GPS home fix, 4 = home reset (numbers are additive) - --[ B : GPS accuracy based on HDOP (0 = lowest to 9 = highest accuracy) - --[ C : number of satellites locked (digit C & D are the number of locked satellites) - --[ D : number of satellites locked (if 14 satellites are locked, C = 1 & D = 4) - gpsSATS = string.sub (gpsSATS, 3,6) + -- [ Sats / Tmp2 : GPS lock status, accuracy, home reset trigger, and number of satellites. Number is sent as ABCD detailed below. Typical minimum + -- [ A : 1 = GPS fix, 2 = GPS home fix, 4 = home reset (numbers are additive) + -- [ B : GPS accuracy based on HDOP (0 = lowest to 9 = highest accuracy) + -- [ C : number of satellites locked (digit C & D are the number of locked satellites) + -- [ D : number of satellites locked (if 14 satellites are locked, C = 1 & D = 4) + gpsSATS = string.sub(gpsSATS, 3, 6) else - --CROSSFIRE stores only the active GPS satellite - gpsSATS = string.sub (gpsSATS, 0,3) - end - - --status message "guess" + -- CROSSFIRE stores only the active GPS satellite + gpsSATS = string.sub(gpsSATS, 0, 3) + end + + -- status message "guess" -- 2D Mode - A 2D (two dimensional) position fix that includes only horizontal coordinates. It requires a minimum of three visible satellites.) -- 3D Mode - A 3D (three dimensional) position fix that includes horizontal coordinates plus altitude. It requires a minimum of four visible satellites. if (tonumber(gpsSATS) < 2) then gpsFIX = "no GPS fix" end - if (tonumber(gpsSATS) >= 3) and (tonumber(gpsSATS) <= 4) then gpsFIX = "GPS 2D fix" end + if (tonumber(gpsSATS) >= 3) and (tonumber(gpsSATS) <= 4) then gpsFIX = "GPS 2D fix" end if (tonumber(gpsSATS) >= 5) then gpsFIX = "GPS 3D fix" end - - - --#################################################################### - --get calculate distance from home and write log - --#################################################################### + + -- #################################################################### + -- get calculate distance from home and write log + -- #################################################################### if (tonumber(gpsSATS) >= 5) then - - if (gpsLAT ~= gpsPrevLAT) and (gpsLON ~= gpsPrevLON) then - - if (gpsLAT_H ~= 0) and (gpsLON_H ~= 0) then - - --distance to home - gpsDtH = rnd(calc_Distance(gpsLAT, gpsLON, gpsLAT_H, gpsLON_H),2) - gpsDtH = string.format("%.2f",gpsDtH) - - --total distance traveled - if (gpsPrevLAT ~= 0) and (gpsPrevLON ~= 0) and (gpsLAT ~= 0) and (gpsLON ~= 0)then - --print("GPS_Debug_Prev", gpsPrevLAT,gpsPrevLON) - --print("GPS_Debug_curr", gpsLAT,gpsLON) - - gpsTotalDist = rnd(tonumber(gpsTotalDist) + calc_Distance(gpsLAT,gpsLON,gpsPrevLAT,gpsPrevLON),2) - gpsTotalDist = string.format("%.2f",gpsTotalDist) + + if (gpsLAT ~= gpsPrevLAT) and (gpsLON ~= gpsPrevLON) then + + if (gpsLAT_H ~= 0) and (gpsLON_H ~= 0) then + + -- distance to home + gpsDtH = rnd(calc_Distance(gpsLAT, gpsLON, gpsLAT_H, gpsLON_H), 2) + gpsDtH = string.format("%.2f", gpsDtH) + + -- total distance traveled + if (gpsPrevLAT ~= 0) and (gpsPrevLON ~= 0) and (gpsLAT ~= 0) and (gpsLON ~= 0) then + -- print("GPS_Debug_Prev", gpsPrevLAT,gpsPrevLON) + -- print("GPS_Debug_curr", gpsLAT,gpsLON) + + gpsTotalDist = rnd(tonumber(gpsTotalDist) + calc_Distance(gpsLAT, gpsLON, gpsPrevLAT, gpsPrevLON), 2) + gpsTotalDist = string.format("%.2f", gpsTotalDist) end end - - --data for displaying the - coordinates_prev = string.format("%02d",ctr) ..", ".. gpsPrevLAT..", " .. gpsPrevLON - coordinates_current = string.format("%02d",ctr+1) ..", ".. gpsLAT..", " .. gpsLON - + + -- data for displaying the + coordinates_prev = string.format("%02d", ctr) .. ", " .. gpsPrevLAT .. ", " .. gpsPrevLON + coordinates_current = string.format("%02d", ctr + 1) .. ", " .. gpsLAT .. ", " .. gpsLON + gpsPrevLAT = gpsLAT - gpsPrevLON = gpsLON - + gpsPrevLON = gpsLON + write_log() - end - end - - + end + end + end ---main function -local function run(event) - lcd.clear() - background() - - --reset telemetry data / total distance on "long press enter" +-- main function +local function run(event) + lcd.clear() + background() + + -- reset telemetry data / total distance on "long press enter" if event == EVT_ENTER_LONG then gpsDtH = 0 gpsTotalDist = 0 gpsLAT_H = 0 gpsLON_H = 0 reset = true - end - + end + -- create screen - lcd.drawLine(0,0,0,64, SOLID, FORCE) - lcd.drawLine(211,0,211,64, SOLID, FORCE) - - lcd.drawText(2,1,"State: " ,SMLSIZE) - lcd.drawFilledRectangle(1,0, 210, 8, DEFAULT) - - lcd.drawPixmap(2,10, "/SCRIPTS/TELEMETRY/BMP/Sat16.bmp") - lcd.drawLine(70,8, 70, 27, SOLID, FORCE) - lcd.drawPixmap(72,9, "/SCRIPTS/TELEMETRY/BMP/distance16.bmp") - lcd.drawLine(140,8, 140, 27, SOLID, FORCE) - lcd.drawPixmap(142,9, "/SCRIPTS/TELEMETRY/BMP/total_distance16.bmp") - - lcd.drawLine(0,27, 211, 27, SOLID, FORCE) - - lcd.drawPixmap(2,28, "/SCRIPTS/TELEMETRY/BMP/home16.bmp") - lcd.drawLine(0,44, 211, 44, SOLID, FORCE) - - lcd.drawPixmap(2,47, "/SCRIPTS/TELEMETRY/BMP/drone16.bmp") - - --update screen data + lcd.drawLine(0, 0, 0, 64, SOLID, FORCE) + lcd.drawLine(211, 0, 211, 64, SOLID, FORCE) + + lcd.drawText(2, 1, "State: ", SMLSIZE) + lcd.drawFilledRectangle(1, 0, 210, 8, DEFAULT) + + lcd.drawPixmap(2, 10, "/SCRIPTS/TELEMETRY/BMP/Sat16.bmp") + lcd.drawLine(70, 8, 70, 27, SOLID, FORCE) + lcd.drawPixmap(72, 9, "/SCRIPTS/TELEMETRY/BMP/distance16.bmp") + lcd.drawLine(140, 8, 140, 27, SOLID, FORCE) + lcd.drawPixmap(142, 9, "/SCRIPTS/TELEMETRY/BMP/total_distance16.bmp") + + lcd.drawLine(0, 27, 211, 27, SOLID, FORCE) + + lcd.drawPixmap(2, 28, "/SCRIPTS/TELEMETRY/BMP/home16.bmp") + lcd.drawLine(0, 44, 211, 44, SOLID, FORCE) + + lcd.drawPixmap(2, 47, "/SCRIPTS/TELEMETRY/BMP/drone16.bmp") + + -- update screen data if update == true then - - lcd.drawText(32,1,gpsFIX ,SMLSIZE + INVERS) - lcd.drawText(22,12, gpsSATS, MIDSIZE) - lcd.drawText(90,12, gpsDtH .. " km", MIDSIZE) - lcd.drawText(160,12, gpsTotalDist .. " km", MIDSIZE) - - if (gpsLAT_H ~= 0) and (gpsLON_H ~= 0) then - lcd.drawText(20,33, gpsLAT_H .. ", " .. gpsLON_H, SMLSIZE) + + lcd.drawText(32, 1, gpsFIX, SMLSIZE + INVERS) + lcd.drawText(22, 12, gpsSATS, MIDSIZE) + lcd.drawText(90, 12, gpsDtH .. " km", MIDSIZE) + lcd.drawText(160, 12, gpsTotalDist .. " km", MIDSIZE) + + if (gpsLAT_H ~= 0) and (gpsLON_H ~= 0) then + lcd.drawText(20, 33, gpsLAT_H .. ", " .. gpsLON_H, SMLSIZE) else - lcd.drawText(20,29, "home position not set. please manual ", SMLSIZE + INVERS + BLINK) - lcd.drawText(20,37, "reset telemetry after 3D GPS FIX!", SMLSIZE + INVERS + BLINK) + lcd.drawText(20, 29, "home position not set. please manual ", SMLSIZE + INVERS + BLINK) + lcd.drawText(20, 37, "reset telemetry after 3D GPS FIX!", SMLSIZE + INVERS + BLINK) end - - - lcd.drawText(20,47, coordinates_prev,SMLSIZE) - lcd.drawText(20,56, coordinates_current,SMLSIZE) - - --blink if telemetry stops + + lcd.drawText(20, 47, coordinates_prev, SMLSIZE) + lcd.drawText(20, 56, coordinates_current, SMLSIZE) + + -- blink if telemetry stops elseif update == false then - - lcd.drawText(32,1,"no GPS data available" ,SMLSIZE + INVERS) - lcd.drawText(22,12, gpsSATS, MIDSIZE + INVERS + BLINK ) - lcd.drawText(90,12, gpsDtH .. " km", MIDSIZE + INVERS + BLINK) - lcd.drawText(160,12, gpsTotalDist .. " km" , MIDSIZE) - - lcd.drawText(20,33, gpsLAT_H .. ", " .. gpsLON_H, SMLSIZE) - - lcd.drawText(20,47, coordinates_prev, SMLSIZE + INVERS + BLINK) - lcd.drawText(20,56, coordinates_current, SMLSIZE + INVERS + BLINK) - - end + + lcd.drawText(32, 1, "no GPS data available", SMLSIZE + INVERS) + lcd.drawText(22, 12, gpsSATS, MIDSIZE + INVERS + BLINK) + lcd.drawText(90, 12, gpsDtH .. " km", MIDSIZE + INVERS + BLINK) + lcd.drawText(160, 12, gpsTotalDist .. " km", MIDSIZE) + + lcd.drawText(20, 33, gpsLAT_H .. ", " .. gpsLON_H, SMLSIZE) + + lcd.drawText(20, 47, coordinates_prev, SMLSIZE + INVERS + BLINK) + lcd.drawText(20, 56, coordinates_current, SMLSIZE + INVERS + BLINK) + + end end - -return {init=init, run=run, background=background} + +return {init = init, run = run, background = background}