Files
Momentum-Firmware/applications/main/subghz/scenes/subghz_scene_show_gps.c
Willy-JL ef2c955995 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
2024-03-30 03:38:59 +00:00

85 lines
2.9 KiB
C

#include "../subghz_i.h"
#include "../helpers/subghz_custom_event.h"
void subghz_scene_show_gps_draw_satellites(void* context) {
SubGhz* subghz = context;
DateTime datetime;
furi_hal_rtc_get_datetime(&datetime);
if((datetime.second - subghz->gps->fix_second) > 15) {
subghz->gps->latitude = NAN;
subghz->gps->longitude = NAN;
subghz->gps->satellites = 0;
subghz->gps->fix_hour = 0;
subghz->gps->fix_minute = 0;
subghz->gps->fix_second = 0;
}
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 {
latitude = subghz_history_get_latitude(subghz->history, subghz->idx_menu_chosen);
longitude = subghz_history_get_longitude(subghz->history, subghz->idx_menu_chosen);
}
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) {
SubGhz* subghz = context;
widget_reset(subghz->widget);
subghz_scene_show_gps_draw_satellites(subghz);
}
void subghz_scene_show_gps_on_enter(void* context) {
SubGhz* subghz = context;
subghz_scene_show_gps_draw_satellites(subghz);
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->gps) {
if(subghz->gps->satellites > 0) {
notification_message(subghz->notifications, &sequence_blink_green_10);
} else {
notification_message(subghz->notifications, &sequence_blink_red_10);
}
} else {
notification_message(subghz->notifications, &sequence_blink_cyan_10);
}
}
}
return false;
}
void subghz_scene_show_gps_on_exit(void* context) {
SubGhz* subghz = context;
if(subghz->gps) {
furi_timer_stop(subghz->gps->timer);
furi_timer_free(subghz->gps->timer);
}
widget_reset(subghz->widget);
}