Skip to content

Commit

Permalink
v0.8&v0.2
Browse files Browse the repository at this point in the history
v0.8&v0.2
  • Loading branch information
Jiki-Mo committed Nov 25, 2024
1 parent d9dd623 commit 2078624
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 54 deletions.
48 changes: 26 additions & 22 deletions tool-logcurve/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
LogCurve tool for ETHOS X14
FlyDragon Mo
Release:
v0.1 2024-11-15
v0.1 2024-11-15, First version.
v0.2 2024-11-25, Added reading prompts.
]]

--Script information
local NAME = "LogCurve"
local VERSION = "0.1"
local DATE = "2024-11-15"
local VERSION = "0.2"
local DATE = "2024-11-25"

local BACK_COLOR = lcd.RGB(40, 40, 40)
local SELECT_COLOR = lcd.RGB(248, 176, 56)
Expand Down Expand Up @@ -199,6 +200,7 @@ local function event(widget, category, value, x, y)
if value == KEY_ENTER_FIRST then
if widget.display_mode == 0 and widget.folder_total > 0 then
widget.file_total = 0
widget.file_pointer = 0
log_files = system.listFiles(widget.model_file_path .. log_folders[widget.folder_pointer + 1])
if log_files ~= nil then
if #log_files > 1 then
Expand Down Expand Up @@ -319,8 +321,6 @@ local function wakeup(widget)
widget.cursor_x_max = 0
end
widget.read_data_flag = false
--Refresh the interface
lcd.invalidate()
end
elseif widget.display_mode == 2 then
if widget.steps == 1 then
Expand Down Expand Up @@ -366,7 +366,7 @@ local function wakeup(widget)
maxmin_data[7] = value
end
end
rpm_zoom = (maxmin_data[6] + 100) / CURSOR_H_MAX
rpm_zoom = (maxmin_data[6] + 200) / CURSOR_H_MAX
maxmin_str[1] = tostring(maxmin_data[1]) .. 'V'
maxmin_str[2] = tostring(maxmin_data[2]) .. 'V'
maxmin_str[3] = tostring(maxmin_data[3]) .. '°C'
Expand Down Expand Up @@ -430,22 +430,26 @@ local function paint(widget)
elseif widget.display_mode == 1 then --Log file
list_control(5, 5, t_w, tile .. " / " .. log_folders[widget.folder_pointer + 1], BACK_COLOR, LEFT)
list_control(5 + t_w + 5, 5, l_w, tostring(widget.file_pointer) .. '/' .. tostring(widget.file_total) .. " [" .. tostring(widget.file_page) .. ']', BACK_COLOR, CENTERED)
if widget.file_total > 0 then
st = (widget.file_page - 1) * 28 + 1
for s = st, widget.file_total, 1 do
color = BACK_COLOR
if s == widget.file_pointer then
color = SELECT_COLOR
end
local file_str = log_files[s + 1]
list_control(sx, sy, l_w, file_str:sub(1, -5), color, CENTERED)
sx = sx + l_w + 5
if s % 4 == 0 then
sy = sy + 38
sx = 5
end
if s == st + 27 then
break
if widget.read_data_flag then
list_control(w / 2 - 80, h / 2, 160, "Reading log file...", BACK_COLOR, CENTERED)
else
if widget.file_total > 0 then
st = (widget.file_page - 1) * 28 + 1
for s = st, widget.file_total, 1 do
color = BACK_COLOR
if s == widget.file_pointer then
color = SELECT_COLOR
end
local file_str = log_files[s + 1]
list_control(sx, sy, l_w, file_str:sub(1, -5), color, CENTERED)
sx = sx + l_w + 5
if s % 4 == 0 then
sy = sy + 38
sx = 5
end
if s == st + 27 then
break
end
end
end
end
Expand Down
Binary file modified tool-logcurve/main.luac
Binary file not shown.
67 changes: 35 additions & 32 deletions widget-flylog/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ v0.4 2024-10-22, Support Chinese and English low voltage alarm; add ESC status m
v0.5 2024-10-26, Get the telemetry value through appid.
v0.6 2024-11-03, Voice Report Capacity Percentage.
v0.7 2024-11-15, Added log file writing function.
v0.8 2024-11-25, The recorded data is averaged once and then recorded.
CLI:
set crsf_telemetry_mode = CUSTOM
set crsf_telemetry_link_rate = 500
Expand All @@ -18,13 +19,13 @@ set crsf_telemetry_sensors = 3,43,4,5,6,60,15,50,52,93,90,27,28,21,0,0,0,0,0,0,0

--Script information
local NAME = "FlyLog"
local VERSION = "0.7"
local DATE = "2024-11-15"
local VERSION = "0.8"
local DATE = "2024-11-25"

--Variable
--Charge Level, Consumption, Voltage, BEC Voltage, ESC Temp, Current, Headspeed, Throttle %, MCU Temp, ESC1 PWM, Rx RSSI1, Rx RSSI2, Rx Quality
local crsf_field_table = { 0x1014, 0x1013, 0x1011, 0x1081, 0x10A0, 0x1012, 0x10C0, 0x1035, 0x10A3, 0x1045, "Rx RSSI1", "Rx RSSI2", "Rx Quality" }
local data_format_table = { "%d", "%d", "%.1f", "%.1f", "%d", "%.1f", "%d", "%d", "%d", "%d", "%d", "%d", "%d" }
--Charge Level, Consumption, Voltage, BEC Voltage, ESC Temp, Current, Headspeed, Throttle %, MCU Temp, ESC1 PWM
local crsf_field_table = { 0x1014, 0x1013, 0x1011, 0x1081, 0x10A0, 0x1012, 0x10C0, 0x1035, 0x10A3, 0x1045 }
local data_format_table = { "%d", "%d", "%.1f", "%.1f", "%d", "%.1f", "%d", "%d", "%d", "%d" }
local gov_status_table = { "OFF", "IDLE", "SPOOLUP", "RECOVERY", "ACTIVE", "THR-OFF", "LOST-HS", "AUTOROT", "BAILOUT" }
local esc_id_table = { 0x00, 0xC8, 0x9B, 0x4B, 0xD0, 0xDD, 0xA0, 0xFD, 0x53, 0xA5, 0x73 }
local esc_signatures_table = { "NONE", "BLHELI32", "HW4", "KON", "OMP", "ZTW", "APD", "PL5", "TRIB", "OPENYGE", "FLYROTOR" }
Expand All @@ -38,6 +39,8 @@ local sensor = nil
local sensor_value_table = {}
local sensor_max_table = {}
local sensor_min_table = {}
local sensor_buffer_table = { 0, 0, 0, 0, 0 }
local sensor_log_pos_table = { 3, 5, 6, 7, 10 } --Voltage, ESC Temp, Current, Headspeed, ESC1 PWM
local fc_status = ""
local gov_status = ""
local esc_signatures = ""
Expand Down Expand Up @@ -192,6 +195,7 @@ local function create()
arm_flag = false,
start_timer_flag = false,
lever_tone_flag = false,
buffer_count = 0,
}
--Create a folder
if os.mkdir ~= nil and dir_exists("/scripts/widget-flylog/", "logs") == false then
Expand Down Expand Up @@ -249,7 +253,7 @@ local function paint(widget)
--Get window size
local w, h = lcd.getWindowSize() --X14: w=630 h=258 X20: w=784 h=316
lcd.color(COLOR_BLACK)
lcd.drawFilledRectangle(0, 0, w, h)
lcd.drawFilledRectangle(1, 1, w - 2, h - 2)
--Lcd type
if w < 630 or h < 258 then
widget.default_lcd_flag = false
Expand Down Expand Up @@ -319,6 +323,10 @@ local function wakeup(widget)
sensor_max_table[s] = sensor_value_table[s]
sensor_min_table[s] = sensor_value_table[s]
end
for c = 1, #sensor_buffer_table do
sensor_buffer_table[c] = 0
end
widget.buffer_count = 0
widget.second = 0
level_save = 0
play_speed = 0
Expand All @@ -329,7 +337,7 @@ local function wakeup(widget)
file_name = "[F" .. string.format("%02d", widget.flight_number + 1) .. "].csv"
f_file_path = widget.date_file_path .. file_name
f_file_obj = io.open(f_file_path, "w")
--io.write(f_file_obj, "Time,Charge Level,Consumption,Voltage,BEC Voltage,ESC Temp,Current,Headspeed,Throttle,MCU Temp,ESC1 PWM,Rx Quality\n")
--Time, Voltage, ESC Temp, Current, Headspeed, ESC1 PWM
io.write(f_file_obj, "Time,Voltage,ESC Temp,Current,Headspeed,ESC1 PWM\n")
end
else
Expand All @@ -350,11 +358,7 @@ local function wakeup(widget)
end
--Get sensor
for index, value in ipairs(crsf_field_table) do
if index < 11 then
sensor = system.getSource({ category = CATEGORY_TELEMETRY_SENSOR, appId = value })
else
sensor = system.getSource(value)
end
sensor = system.getSource({ category = CATEGORY_TELEMETRY_SENSOR, appId = value })
if sensor ~= nil then
local data = sensor:value()
if data ~= nil then
Expand Down Expand Up @@ -437,6 +441,11 @@ local function wakeup(widget)
widget.lever_tone_flag = true
end
end
--Buffer data
for c = 1, #sensor_buffer_table do
sensor_buffer_table[c] = sensor_buffer_table[c] + sensor_value_table[sensor_log_pos_table[c]]
end
widget.buffer_count = widget.buffer_count + 1
--os timer
local ostime = os.time()
if ostime_save ~= ostime then
Expand All @@ -448,26 +457,20 @@ local function wakeup(widget)
else
widget.start_timer_flag = true
end
--Warning logs->Time,Charge Level,Consumption,Voltage,BEC Voltage,ESC Temp,Current,Headspeed,Throttle,MCU Temp,ESC1 PWM,Rx Quality
--[[io.write(f_file_obj, tostring(widget.second) .. ',' ..
tostring(math.floor(sensor_value_table[1])) .. ',' ..
tostring(math.floor(sensor_value_table[2])) .. ',' ..
tostring(string.format("%.1f", sensor_value_table[3])) .. ',' ..
tostring(string.format("%.1f", sensor_value_table[4])) .. ',' ..
tostring(math.floor(sensor_value_table[5])) .. ',' ..
tostring(string.format("%.1f", sensor_value_table[6])) .. ',' ..
tostring(math.floor(sensor_value_table[7])) .. ',' ..
tostring(math.floor(sensor_value_table[8])) .. ',' ..
tostring(math.floor(sensor_value_table[9])) .. ',' ..
tostring(math.floor(sensor_value_table[10])) .. ',' ..
tostring(math.floor(sensor_value_table[13])) .. "\n"
)]]
io.write(f_file_obj, tostring(widget.second) .. ',' .. --Time
tostring(string.format("%.1f", sensor_value_table[3])) .. ',' .. --Voltage
tostring(math.floor(sensor_value_table[5])) .. ',' .. --ESC Temp
tostring(string.format("%.1f", sensor_value_table[6])) .. ',' .. --Current
tostring(math.floor(sensor_value_table[7])) .. ',' .. --Headspeed
tostring(math.floor(sensor_value_table[10])) .. "\n" --ESC1 PWM
--Average
local lod_data = {}
for a = 1, #sensor_buffer_table do
lod_data[a] = sensor_buffer_table[a] / widget.buffer_count
sensor_buffer_table[a] = 0
end
widget.buffer_count = 0
--Warning logs
io.write(f_file_obj, tostring(widget.second) .. ',' .. --Time
string.format("%.1f", lod_data[1]) .. ',' .. --Voltage
tostring(math.floor(lod_data[2])) .. ',' .. --ESC Temp
string.format("%.1f", lod_data[3]) .. ',' .. --Current
tostring(math.floor(lod_data[4])) .. ',' .. --Headspeed
tostring(math.floor(lod_data[5])) .. "\n" --ESC1 PWM
)
--Tone
play_speed = play_speed + 1
Expand Down
Binary file modified widget-flylog/main.luac
Binary file not shown.

0 comments on commit 2078624

Please sign in to comment.