- Allow other scripts / inputs to control AP heading too

- Fix failure if rp2040_hid is connected above 32767 feet
This commit is contained in:
2023-05-14 12:52:40 +02:00
parent 474bcef755
commit 56b4a2bd7b
2 changed files with 18 additions and 4 deletions

View File

@@ -130,6 +130,8 @@ else
send_app_report(device, math.floor(ap_hdg + 0.5), build_leds(), math.floor(ap_alt + 0.5), -2, -2, status_machmode == 1)
local prev_status_altmode = 0
local prev_status_machmode = status_machmode
local prev_ap_hdg = ap_hdg
local prev_report_ap_hdg = 0
function usb_app()
local send_hdg = -1
local send_alt = -1
@@ -157,9 +159,15 @@ else
mag_hdg_int = math.floor(mag_hdg + 0.5)
ap_hdg = mag_hdg_int
send_hdg = mag_hdg_int
elseif app_report_good and app_report[1] ~= 0xffff then
elseif prev_ap_hdg ~= ap_hdg then
send_hdg = ap_hdg
elseif app_report_good and app_report[1] ~= 0xffff and prev_report_ap_hdg ~= app_report[1] then
ap_hdg = app_report[1]
end
prev_ap_hdg = ap_hdg
if app_report_good and app_report[1] ~= 0xffff then
prev_report_ap_hdg = app_report[1]
end
-- autopilot altitude
if button(button_offset + button_alt_sync) and not last_button(button_offset + button_alt_sync) then
cur_alt_int = math.floor(cur_alt + 0.5)
@@ -213,4 +221,10 @@ else
end
do_every_frame("usb_app()")
function exit_handler()
send_app_report(device, -2, 0, -2, -2, -2, 0)
end
do_on_exit('exit_handler()')
end

View File

@@ -36,7 +36,7 @@ __attribute__((packed)) struct app_report {
struct __attribute__((packed)) {
int16_t hdg;
int16_t leds;
int16_t alt;
uint16_t alt;
int16_t vs;
int16_t as;
} update;
@@ -228,7 +228,7 @@ static void hid_task(void)
if (start_ms % 10 == 0 && send_heading_reports) {
struct app_report report = { .type = APP_UPDATE | mach_mode ? APP_FLAG_MACH : 0,
.update = { .hdg = -1, .alt = -1, .vs = -1, .as = -1 } };
.update = { .hdg = -1, .alt = 0xffff, .vs = -1, .as = -1 } };
if (send_heading_reports)
report.update.hdg = hdg;
if (send_alt_reports)
@@ -271,7 +271,7 @@ static void app_update_report(struct app_report const *report)
update_hdg_display();
send_heading_reports = true;
}
if (report->update.alt >= 0) {
if (report->update.alt != 0xffff) {
alt = report->update.alt;
update_alt_display();
send_alt_reports = true;