- Allow other scripts / inputs to control AP heading too
- Fix failure if rp2040_hid is connected above 32767 feet
This commit is contained in:
@@ -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)
|
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_altmode = 0
|
||||||
local prev_status_machmode = status_machmode
|
local prev_status_machmode = status_machmode
|
||||||
|
local prev_ap_hdg = ap_hdg
|
||||||
|
local prev_report_ap_hdg = 0
|
||||||
function usb_app()
|
function usb_app()
|
||||||
local send_hdg = -1
|
local send_hdg = -1
|
||||||
local send_alt = -1
|
local send_alt = -1
|
||||||
@@ -157,9 +159,15 @@ else
|
|||||||
mag_hdg_int = math.floor(mag_hdg + 0.5)
|
mag_hdg_int = math.floor(mag_hdg + 0.5)
|
||||||
ap_hdg = mag_hdg_int
|
ap_hdg = mag_hdg_int
|
||||||
send_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]
|
ap_hdg = app_report[1]
|
||||||
end
|
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
|
-- autopilot altitude
|
||||||
if button(button_offset + button_alt_sync) and not last_button(button_offset + button_alt_sync) then
|
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)
|
cur_alt_int = math.floor(cur_alt + 0.5)
|
||||||
@@ -213,4 +221,10 @@ else
|
|||||||
end
|
end
|
||||||
|
|
||||||
do_every_frame("usb_app()")
|
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
|
end
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ __attribute__((packed)) struct app_report {
|
|||||||
struct __attribute__((packed)) {
|
struct __attribute__((packed)) {
|
||||||
int16_t hdg;
|
int16_t hdg;
|
||||||
int16_t leds;
|
int16_t leds;
|
||||||
int16_t alt;
|
uint16_t alt;
|
||||||
int16_t vs;
|
int16_t vs;
|
||||||
int16_t as;
|
int16_t as;
|
||||||
} update;
|
} update;
|
||||||
@@ -228,7 +228,7 @@ static void hid_task(void)
|
|||||||
|
|
||||||
if (start_ms % 10 == 0 && send_heading_reports) {
|
if (start_ms % 10 == 0 && send_heading_reports) {
|
||||||
struct app_report report = { .type = APP_UPDATE | mach_mode ? APP_FLAG_MACH : 0,
|
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)
|
if (send_heading_reports)
|
||||||
report.update.hdg = hdg;
|
report.update.hdg = hdg;
|
||||||
if (send_alt_reports)
|
if (send_alt_reports)
|
||||||
@@ -271,7 +271,7 @@ static void app_update_report(struct app_report const *report)
|
|||||||
update_hdg_display();
|
update_hdg_display();
|
||||||
send_heading_reports = true;
|
send_heading_reports = true;
|
||||||
}
|
}
|
||||||
if (report->update.alt >= 0) {
|
if (report->update.alt != 0xffff) {
|
||||||
alt = report->update.alt;
|
alt = report->update.alt;
|
||||||
update_alt_display();
|
update_alt_display();
|
||||||
send_alt_reports = true;
|
send_alt_reports = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user