mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
SubGHz: Rework GPS as plugin, fix VGM (#5)
- Streamlined atomic init and deinit - Load from plugin into RAM dynamically - Don't attempt load if VGM / Expansion is connected - Deduplicated some code, cleaned up some other bits
This commit is contained in:
@@ -4,9 +4,6 @@
|
||||
void subghz_scene_show_gps_draw_satellites(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
FuriString* text = furi_string_alloc();
|
||||
FuriString* time_text = furi_string_alloc();
|
||||
|
||||
DateTime datetime;
|
||||
furi_hal_rtc_get_datetime(&datetime);
|
||||
if((datetime.second - subghz->gps->fix_second) > 15) {
|
||||
@@ -18,81 +15,20 @@ void subghz_scene_show_gps_draw_satellites(void* context) {
|
||||
subghz->gps->fix_second = 0;
|
||||
}
|
||||
|
||||
subghz_history_get_time_item_menu(subghz->history, time_text, subghz->idx_menu_chosen);
|
||||
|
||||
double distance = subghz_gps_calc_distance(
|
||||
(double)subghz_history_get_latitude(subghz->history, subghz->idx_menu_chosen),
|
||||
(double)subghz_history_get_longitude(subghz->history, subghz->idx_menu_chosen),
|
||||
(double)subghz->gps->latitude,
|
||||
(double)subghz->gps->longitude);
|
||||
|
||||
float angle = subghz_gps_calc_angle(
|
||||
(double)subghz_history_get_latitude(subghz->history, subghz->idx_menu_chosen),
|
||||
(double)subghz_history_get_longitude(subghz->history, subghz->idx_menu_chosen),
|
||||
(double)subghz->gps->latitude,
|
||||
(double)subghz->gps->longitude);
|
||||
|
||||
char* angle_str = "?";
|
||||
if(angle > -22.5 && angle <= 22.5) {
|
||||
angle_str = "E";
|
||||
} else if(angle > 22.5 && angle <= 67.5) {
|
||||
angle_str = "NE";
|
||||
} else if(angle > 67.5 && angle <= 112.5) {
|
||||
angle_str = "N";
|
||||
} else if(angle > 112.5 && angle <= 157.5) {
|
||||
angle_str = "NW";
|
||||
} else if(angle < -22.5 && angle >= -67.5) {
|
||||
angle_str = "SE";
|
||||
} else if(angle < -67.5 && angle >= -112.5) {
|
||||
angle_str = "S";
|
||||
} else if(angle < -112.5 && angle >= -157.5) {
|
||||
angle_str = "SW";
|
||||
} else if(angle < -157.5 || angle >= 157.5) {
|
||||
angle_str = "W";
|
||||
}
|
||||
|
||||
FuriString* lat_str = furi_string_alloc();
|
||||
FuriString* lon_str = furi_string_alloc();
|
||||
|
||||
if(isnan(subghz_history_get_latitude(subghz->history, subghz->idx_menu_chosen))) {
|
||||
furi_string_printf(lat_str, "N/A");
|
||||
float latitude, longitude;
|
||||
// Get from saved file or from history
|
||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneShowGps)) {
|
||||
latitude = subghz_txrx_get_latitude(subghz->txrx);
|
||||
longitude = subghz_txrx_get_longitude(subghz->txrx);
|
||||
} else {
|
||||
furi_string_printf(
|
||||
lat_str,
|
||||
"%f",
|
||||
(double)subghz_history_get_latitude(subghz->history, subghz->idx_menu_chosen));
|
||||
latitude = subghz_history_get_latitude(subghz->history, subghz->idx_menu_chosen);
|
||||
longitude = subghz_history_get_longitude(subghz->history, subghz->idx_menu_chosen);
|
||||
}
|
||||
|
||||
if(isnan(subghz_history_get_longitude(subghz->history, subghz->idx_menu_chosen))) {
|
||||
furi_string_printf(lon_str, "N/A");
|
||||
} else {
|
||||
furi_string_printf(
|
||||
lon_str,
|
||||
"%f",
|
||||
(double)subghz_history_get_longitude(subghz->history, subghz->idx_menu_chosen));
|
||||
}
|
||||
|
||||
furi_string_printf(
|
||||
text,
|
||||
"Captured at: %s,\r\n%s Time: %s\r\n\r\nRealtime: Sats: %d\r\nDistance: %.2f%s Dir: %s\r\nGPS time: %02d:%02d:%02d UTC",
|
||||
furi_string_get_cstr(lat_str),
|
||||
furi_string_get_cstr(lon_str),
|
||||
furi_string_get_cstr(time_text),
|
||||
subghz->gps->satellites,
|
||||
subghz->gps->satellites > 0 ? distance > 1 ? distance : distance * 1000 : 0,
|
||||
distance > 1 ? "km" : "m",
|
||||
angle_str,
|
||||
subghz->gps->fix_hour,
|
||||
subghz->gps->fix_minute,
|
||||
subghz->gps->fix_second);
|
||||
|
||||
widget_add_text_scroll_element(subghz->widget, 0, 0, 128, 64, furi_string_get_cstr(text));
|
||||
|
||||
furi_string_free(lat_str);
|
||||
furi_string_free(lon_str);
|
||||
|
||||
furi_string_free(text);
|
||||
furi_string_free(time_text);
|
||||
FuriString* text_str = furi_string_alloc();
|
||||
subghz->gps->get_descr(subghz->gps, text_str, latitude, longitude);
|
||||
widget_add_text_scroll_element(subghz->widget, 0, 0, 128, 64, furi_string_get_cstr(text_str));
|
||||
furi_string_free(text_str);
|
||||
}
|
||||
|
||||
void subghz_scene_show_gps_refresh_screen(void* context) {
|
||||
@@ -106,18 +42,24 @@ void subghz_scene_show_gps_on_enter(void* context) {
|
||||
|
||||
subghz_scene_show_gps_draw_satellites(subghz);
|
||||
|
||||
if(subghz->last_settings->gps_baudrate != 0) {
|
||||
if(subghz->gps) {
|
||||
subghz->gps->timer =
|
||||
furi_timer_alloc(subghz_scene_show_gps_refresh_screen, FuriTimerTypePeriodic, subghz);
|
||||
furi_timer_start(subghz->gps->timer, 1000);
|
||||
}
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
|
||||
}
|
||||
|
||||
bool subghz_scene_show_gps_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
// No rx blink if opened from saved file
|
||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneShowGps)) return false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeTick) {
|
||||
if(subghz->state_notifications == SubGhzNotificationStateRx) {
|
||||
if(subghz->last_settings->gps_baudrate != 0) {
|
||||
if(subghz->gps) {
|
||||
if(subghz->gps->satellites > 0) {
|
||||
notification_message(subghz->notifications, &sequence_blink_green_10);
|
||||
} else {
|
||||
@@ -134,7 +76,7 @@ bool subghz_scene_show_gps_on_event(void* context, SceneManagerEvent event) {
|
||||
void subghz_scene_show_gps_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(subghz->last_settings->gps_baudrate != 0) {
|
||||
if(subghz->gps) {
|
||||
furi_timer_stop(subghz->gps->timer);
|
||||
furi_timer_free(subghz->gps->timer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user