Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flights: add option to invert arm switch #151

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0b2f353
new Rotary Gauge widget
offer-shmuely-cognyte Apr 26, 2022
cbf4c49
Rotary Gauge widget: less ticks on small size
offer-shmuely-cognyte May 1, 2022
4b6b883
new Rotary Gauge widget
offer-shmuely-cognyte May 1, 2022
4da81b3
new Rotary Gauge widget
offer-shmuely-cognyte May 6, 2022
74724ee
Merge branch 'EdgeTX:master' into master
offer-shmuely May 12, 2022
de3a49d
Merge branch 'EdgeTX:master' into master
offer-shmuely Jul 9, 2022
556da6c
Merge branch 'EdgeTX:master' into master
offer-shmuely Jul 24, 2022
371c347
Merge branch 'EdgeTX:master' into master
offer-shmuely Aug 21, 2022
6810b35
Merge branch 'EdgeTX:master' into master
offer-shmuely Sep 12, 2022
e4c197e
Merge branch 'EdgeTX:master' into master
offer-shmuely Oct 1, 2022
1a4f3e0
Merge branch 'EdgeTX:master' into master
offer-shmuely Oct 18, 2022
05212a0
Merge branch 'EdgeTX:master' into master
offer-shmuely Oct 19, 2022
cfaa10e
Merge branch 'EdgeTX:master' into master
offer-shmuely Dec 30, 2022
a065761
Merge branch 'EdgeTX:master' into master
offer-shmuely Jan 26, 2023
bfe1248
Merge branch 'EdgeTX:master' into master
offer-shmuely Feb 1, 2023
07b65c8
Merge branch 'EdgeTX:master' into master
offer-shmuely Feb 23, 2023
7f46640
Merge branch 'EdgeTX:master' into master
offer-shmuely Mar 31, 2023
f879578
Merge branch 'EdgeTX:master' into master
offer-shmuely May 30, 2023
833cd22
Merge branch 'EdgeTX:master' into master
offer-shmuely Jun 16, 2023
fe180b0
Merge branch 'EdgeTX:master' into master
offer-shmuely Aug 5, 2023
d3c2f1f
Merge branch 'EdgeTX:master' into master
offer-shmuely Sep 11, 2023
e1743fa
Merge branch 'EdgeTX:master' into master
offer-shmuely Nov 25, 2023
73a3b15
Merge branch 'EdgeTX:master' into master
offer-shmuely Dec 11, 2023
14ab8e2
Merge branch 'EdgeTX:master' into master
offer-shmuely Feb 1, 2024
1ccacca
Merge branch 'EdgeTX:master' into master
offer-shmuely Feb 7, 2024
266ddfc
Merge branch 'EdgeTX:master' into master
offer-shmuely Apr 1, 2024
8c8753c
Merge branch 'EdgeTX:master' into master
offer-shmuely Apr 8, 2024
b28c2b8
Merge branch 'EdgeTX:master' into master
offer-shmuely Jun 10, 2024
63f659c
flights: reduce time log file open (due to bug in file system)
offer-shmuely Jun 10, 2024
73be981
flights: add option to invert arm_switch
offer-shmuely Jun 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions sdcard/c480x272/WIDGETS/Flights/lib_flights_history.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ function M.writeHeaderIfNeeded()
return
end

-- write csv header
local hFile = io.open(hist_file_name, "a")
if hFile == nil then
M.m_log.info("failed to write file, probably dir is not exist: %s", hist_file_name)
return
end
local headline = string.format(line_format,
"flight_date",
"model_name",
"flight_count",
"duration",
"model_id"
)

-- write csv header
local hFile = io.open(hist_file_name, "a")
if hFile == nil then
M.m_log.info("failed to write file, probably dir is not exist: %s", hist_file_name)
return
end
io.write(hFile, headline)
local ver_line = "# api_ver=1\n"
io.write(hFile, ver_line)

io.close(hFile)
end

Expand All @@ -58,12 +58,6 @@ function M.addFlightLog(flight_start_date_time, duration, flight_count)

M.writeHeaderIfNeeded()

local hFile = io.open(hist_file_name, "a")
if hFile == nil then
M.m_log.info("failed to write file, probably dir is not exist: %s", hist_file_name)
return
end

-- flight_date =
local dt = flight_start_date_time
local flight_date = string.format("%04d-%02d-%02d %02d:%02d", dt.year, dt.mon, dt.day, dt.hour, dt.min)
Expand All @@ -82,8 +76,13 @@ function M.addFlightLog(flight_start_date_time, duration, flight_count)
model_id
)
m_log.info("adding flight history line to csv: [%s]", line)
io.write(hFile, line)

local hFile = io.open(hist_file_name, "a")
if hFile == nil then
M.m_log.info("failed to write file, probably dir is not exist: %s", hist_file_name)
return
end
io.write(hFile, line)
io.close(hFile)
end

Expand Down
31 changes: 16 additions & 15 deletions sdcard/c480x272/WIDGETS/Flights/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
]]

local app_name = "Flights"
local app_ver = "1.1"
local app_ver = "1.3"


------------------------------------------------------------------------------------------------------------------
Expand All @@ -68,7 +68,7 @@ local enable_count_announcement_on_end = 1 -- 0=no voice, 1=play the count upo
local enable_dbg_dots = 1 -- 0=do not show dots, 1=show dbg dots
local use_telemetry = 1 -- 0=do not use telemetry, 1=use telemetry in state machine
local use_flights_history = 1 -- 0=do not write flights-history, 1=write flights-history
local inverted_arm_switch_logic = 1 -- 0=armed when SF down, 1=armed when SF up
-- local inverted_arm_switch_logic = 1 -- 0=armed when SF down, 1=armed when SF up
------------------------------------------------------------------------------------------------------------------


Expand All @@ -84,7 +84,7 @@ local function getSwitchIds(key)
["2.7"] = {SA=112, SB=113, SC=114, SD=115, SE=116, SF=117, CH3 = 204},
["2.8"] = {SA=120, SB=121, SC=122, SD=123, SE=124, SF=125, CH3 = 212},
["2.9"] = {SA=120, SB=121, SC=122, SD=123, SE=124, SF=125, CH3 = 212},
["2.10"] = {SA=127, SB=128, SC=129, SD=130, SE=131, SF=132, CH3 = 229},
["2.10"] = {SA=126, SB=127, SC=128, SD=129, SE=130, SF=131, CH3 = 228},
}
local ver, radio, maj, minor, rev, osname = getVersion()
local os1 = string.format("%d.%d", maj, minor)
Expand All @@ -95,12 +95,13 @@ local DEFAULT_ARM_SWITCH_ID = getSwitchIds("SF") -- arm/safety switch=SF
local DEFAULT_MOTOR_CHANNEL_ID = getSwitchIds("CH3") -- motor_channel=CH3

local options = {
{ "switch", SOURCE, DEFAULT_ARM_SWITCH_ID },
{ "arm_switch", SOURCE, DEFAULT_ARM_SWITCH_ID },
{ "motor_channel", SOURCE, DEFAULT_MOTOR_CHANNEL_ID },
{ "min_flight_duration", VALUE, default_flight_starting_duration, 2, 120 },
--{ "enable_sounds" , BOOL , 1 }, -- enable sound on adding succ flight, and on end of flight
{ "text_color", COLOR, COLOR_THEME_PRIMARY2 },
--{ "debug", BOOL, 0 } -- show status on screen
{ "non_invert_arm_switch", BOOL, 0 } -- 0=armed when SF down, 1=armed when SF up
}

local function log(fmt, ...)
Expand Down Expand Up @@ -133,17 +134,17 @@ local function update(wgt, options)
wgt.status.heli_mode = false -- ignore motor direction detection, and throttle position

--log("TimerNumB:" .. options.Timer)
if (wgt.options.switch == nil) then
wgt.options.switch = "sf"
if (wgt.options.arm_switch == nil) then
wgt.options.arm_switch = "sf"
end

--log("wgt.options.switch: " .. wgt.options.switch)
local fi_sw = getFieldInfo(wgt.options.switch)
local fi_sw = getFieldInfo(wgt.options.arm_switch)
if (fi_sw == nil) then
wgt.status.switch_name = "--"
else
wgt.status.switch_name = fi_sw.name
end
log("wgt.options.arm_switch: %s, name: %s", wgt.options.arm_switch, wgt.status.switch_name)

local fi_mot = getFieldInfo(wgt.options.motor_channel)
if (fi_mot == nil) then
Expand All @@ -157,7 +158,7 @@ local function update(wgt, options)
log("1111 is_debug: %s, wgt.zone.h: %s", wgt.options.is_debug, wgt.zone.h)

-- for heli, if the motor-sw==switch-sw, then ignore motor direction detection
if (wgt.options.switch == wgt.options.motor_channel) then
if (wgt.options.arm_switch == wgt.options.motor_channel) then
wgt.status.heli_mode = true
end

Expand Down Expand Up @@ -272,17 +273,17 @@ local function updateMotorStatus(wgt)
end

local function updateSwitchStatus(wgt)
local sw_val = getValue(wgt.options.switch)
if inverted_arm_switch_logic == 1 then
local sw_val = getValue(wgt.options.arm_switch)
if wgt.options.non_invert_arm_switch == 0 then
wgt.status.switch_on = (sw_val < 0)
else
wgt.status.switch_on = (sw_val > 0)
end

--if wgt.status.switch_on then
-- log(string.format("switch status (%s): =ON", wgt.status.switch_name))
-- log(string.format("arm_switch status (%s): =ON", wgt.status.switch_name))
--else
-- log(string.format("switch status (%s): =OFF", wgt.status.switch_name))
-- log(string.format("arm_switch status (%s): =OFF", wgt.status.switch_name))
--end
end

Expand Down Expand Up @@ -546,14 +547,14 @@ local function refresh(wgt, event, touchState)
if wgt.options.is_debug == true then
local dx = 15
--lcd.drawText(wgt.zone.x + dx, wgt.zone.y + 25, string.format("DEBUG:"), SMLSIZE)
lcd.drawText(wgt.zone.x + dx, wgt.zone.y + 20, string.format("%s - switch (%s)", ternary(wgt.status.switch_on), wgt.status.switch_name), SMLSIZE)
lcd.drawText(wgt.zone.x + dx, wgt.zone.y + 20, string.format("%s - arm_switch (%s)", ternary(wgt.status.switch_on), wgt.status.switch_name), SMLSIZE)
if (wgt.status.heli_mode == false) then
lcd.drawText(wgt.zone.x + dx, wgt.zone.y + 35, string.format("%s - throttle (%s) (inv: %s)", ternary(wgt.status.motor_active), wgt.status.motor_channel_name, wgt.status.motor_channel_direction_inv), SMLSIZE)
else
lcd.drawText(wgt.zone.x + dx, wgt.zone.y + 35, string.format("%s - throttle (%s) (heli mode)", ternary(wgt.status.motor_active), wgt.status.motor_channel_name), SMLSIZE)
end
lcd.drawText(wgt.zone.x + dx, wgt.zone.y + 50, string.format("%s - telemetry(%s)", ternary(wgt.status.tele_is_available), wgt.tools.tele_src_name), SMLSIZE)
lcd.drawText(wgt.zone.x + dx, wgt.zone.y + 65, string.format("duration: %.1f/%d", wgt.status.duration_passed / 1000, wgt.tools.getDurationMili(wgt.status.periodic1) / 1000), SMLSIZE)
lcd.drawText(wgt.zone.x + dx, wgt.zone.y + 65, string.format("timer: %.1f/%d", wgt.status.duration_passed / 1000, wgt.tools.getDurationMili(wgt.status.periodic1) / 1000), SMLSIZE)
lcd.drawText(wgt.zone.x + dx, wgt.zone.y + 80, string.format("flight duration: %.1f", wgt.status.flight_duration), SMLSIZE)
--lcd.drawText(wgt.zone.x + dx, wgt.zone.y + 110, string.format("state: %s", wgt.status.flight_state), 0)

Expand Down