mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Update subghz GPS dir finder & thread logic
also a few other finishing touches
This commit is contained in:
@@ -113,6 +113,9 @@ SubGhzGPS* subghz_gps_init() {
|
||||
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;
|
||||
|
||||
subghz_gps->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1);
|
||||
|
||||
@@ -121,7 +124,6 @@ SubGhzGPS* subghz_gps_init() {
|
||||
furi_thread_set_stack_size(subghz_gps->thread, 1024);
|
||||
furi_thread_set_context(subghz_gps->thread, subghz_gps);
|
||||
furi_thread_set_callback(subghz_gps->thread, subghz_gps_uart_worker);
|
||||
// furi_thread_start(subghz_gps->thread);
|
||||
|
||||
if(UART_CH == FuriHalUartIdUSART1) {
|
||||
furi_hal_console_disable();
|
||||
@@ -137,8 +139,6 @@ SubGhzGPS* subghz_gps_init() {
|
||||
|
||||
void subghz_gps_deinit(SubGhzGPS* subghz_gps) {
|
||||
furi_assert(subghz_gps);
|
||||
// furi_thread_flags_set(furi_thread_get_id(subghz_gps->thread), WorkerEvtStop);
|
||||
// furi_thread_join(subghz_gps->thread);
|
||||
furi_thread_free(subghz_gps->thread);
|
||||
|
||||
free(subghz_gps);
|
||||
@@ -151,6 +151,15 @@ void subghz_gps_deinit(SubGhzGPS* subghz_gps) {
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_gps_start(SubGhzGPS* subghz_gps) {
|
||||
furi_thread_start(subghz_gps->thread);
|
||||
}
|
||||
|
||||
void subghz_gps_stop(SubGhzGPS* subghz_gps) {
|
||||
furi_thread_flags_set(furi_thread_get_id(subghz_gps->thread), WorkerEvtStop);
|
||||
furi_thread_join(subghz_gps->thread);
|
||||
}
|
||||
|
||||
double subghz_gps_deg2rad(double deg) {
|
||||
return (deg * (double)M_PI / 180);
|
||||
}
|
||||
|
||||
@@ -30,10 +30,37 @@ typedef struct {
|
||||
uint8_t fix_hour;
|
||||
} SubGhzGPS;
|
||||
|
||||
/**
|
||||
* Initialize SubGhzGPS object
|
||||
*
|
||||
* @return SubGhzGPS* SubGhzGPS object
|
||||
*/
|
||||
SubGhzGPS* subghz_gps_init();
|
||||
|
||||
/**
|
||||
* Deinitialize SubGhzGPS object
|
||||
*
|
||||
* @param subghz_gps SubGhzGPS object
|
||||
* @return void
|
||||
*/
|
||||
void subghz_gps_deinit(SubGhzGPS* subghz_gps);
|
||||
|
||||
/**
|
||||
* Start GPS thread
|
||||
*
|
||||
* @param subghz_gps SubGhzGPS object
|
||||
* @return void
|
||||
*/
|
||||
void subghz_gps_start(SubGhzGPS* subghz_gps);
|
||||
|
||||
/**
|
||||
* Stop GPS thread
|
||||
*
|
||||
* @param subghz_gps SubGhzGPS object
|
||||
* @return void
|
||||
*/
|
||||
void subghz_gps_stop(SubGhzGPS* subghz_gps);
|
||||
|
||||
/**
|
||||
* Convert degree to radian
|
||||
*
|
||||
|
||||
@@ -130,6 +130,12 @@ static void subghz_scene_receiver_config_set_gps(VariableItem* item) {
|
||||
subghz->last_settings->gps_enabled = index == 1;
|
||||
subghz_last_settings_save(
|
||||
subghz->last_settings); //TODO, make it to choose baudrate. now it is 9600
|
||||
|
||||
if(subghz->last_settings->gps_enabled) {
|
||||
subghz_gps_start(subghz->gps);
|
||||
} else {
|
||||
subghz_gps_stop(subghz->gps);
|
||||
}
|
||||
}
|
||||
|
||||
static void subghz_scene_receiver_config_set_timestamp_file_names(VariableItem* item) {
|
||||
|
||||
@@ -148,10 +148,6 @@ void subghz_scene_receiver_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
SubGhzHistory* history = subghz->history;
|
||||
|
||||
if(subghz->last_settings->gps_enabled) {
|
||||
furi_thread_start(subghz->gps->thread);
|
||||
}
|
||||
|
||||
FuriString* item_name = furi_string_alloc();
|
||||
FuriString* item_time = furi_string_alloc();
|
||||
|
||||
@@ -340,9 +336,5 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
|
||||
}
|
||||
|
||||
void subghz_scene_receiver_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
if(subghz->last_settings->gps_enabled) {
|
||||
furi_thread_flags_set(furi_thread_get_id(subghz->gps->thread), WorkerEvtStop);
|
||||
furi_thread_join(subghz->gps->thread);
|
||||
}
|
||||
UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -30,26 +30,28 @@ void subghz_scene_saved_show_gps_draw_satellites(void* context) {
|
||||
float angle = subghz_gps_calc_angle(
|
||||
latitude, longitude, (double)subghz->gps->latitude, (double)subghz->gps->longitude);
|
||||
|
||||
char* angle_str = "N";
|
||||
if(angle > 22.5 && angle <= 67.5) {
|
||||
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 = "E";
|
||||
angle_str = "N";
|
||||
} else if(angle > 112.5 && angle <= 157.5) {
|
||||
angle_str = "SE";
|
||||
} else if(angle > 157.5 && angle <= 202.5) {
|
||||
angle_str = "S";
|
||||
} else if(angle > 202.5 && angle <= 247.5) {
|
||||
angle_str = "SW";
|
||||
} else if(angle > 247.5 && angle <= 292.5) {
|
||||
angle_str = "W";
|
||||
} else if(angle > 292.5 && angle <= 337.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";
|
||||
}
|
||||
|
||||
furi_string_printf(
|
||||
text_str,
|
||||
"Captured at: %f,\r\n%f\r\n\r\nRealtime: Sats: %d\r\nDistance: %.2f%s Dir: %s\r\nGPS time: %d:%d:%d UTC",
|
||||
"Captured at: %f,\r\n%f\r\n\r\nRealtime: Sats: %d\r\nDistance: %.2f%s Dir: %s\r\nGPS time: %02d:%02d:%02d UTC",
|
||||
latitude,
|
||||
longitude,
|
||||
subghz->gps->satellites,
|
||||
@@ -76,15 +78,13 @@ void subghz_scene_saved_show_gps_refresh_screen(void* context) {
|
||||
void subghz_scene_saved_show_gps_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(subghz->last_settings->gps_enabled) {
|
||||
furi_thread_start(subghz->gps->thread);
|
||||
}
|
||||
|
||||
subghz_scene_saved_show_gps_draw_satellites(subghz);
|
||||
|
||||
subghz->gps->timer = furi_timer_alloc(
|
||||
subghz_scene_saved_show_gps_refresh_screen, FuriTimerTypePeriodic, subghz);
|
||||
furi_timer_start(subghz->gps->timer, 1000);
|
||||
if(subghz->last_settings->gps_enabled) {
|
||||
subghz->gps->timer = furi_timer_alloc(
|
||||
subghz_scene_saved_show_gps_refresh_screen, FuriTimerTypePeriodic, subghz);
|
||||
furi_timer_start(subghz->gps->timer, 1000);
|
||||
}
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
|
||||
}
|
||||
@@ -99,12 +99,9 @@ void subghz_scene_saved_show_gps_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(subghz->last_settings->gps_enabled) {
|
||||
furi_thread_flags_set(furi_thread_get_id(subghz->gps->thread), WorkerEvtStop);
|
||||
furi_thread_join(subghz->gps->thread);
|
||||
furi_timer_stop(subghz->gps->timer);
|
||||
furi_timer_free(subghz->gps->timer);
|
||||
}
|
||||
|
||||
furi_timer_stop(subghz->gps->timer);
|
||||
furi_timer_free(subghz->gps->timer);
|
||||
|
||||
widget_reset(subghz->widget);
|
||||
}
|
||||
@@ -32,27 +32,29 @@ void subghz_scene_show_gps_draw_satellites(void* context) {
|
||||
(double)subghz->gps->latitude,
|
||||
(double)subghz->gps->longitude);
|
||||
|
||||
char* angle_str = "N";
|
||||
if(angle > 22.5 && angle <= 67.5) {
|
||||
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 = "E";
|
||||
angle_str = "N";
|
||||
} else if(angle > 112.5 && angle <= 157.5) {
|
||||
angle_str = "SE";
|
||||
} else if(angle > 157.5 && angle <= 202.5) {
|
||||
angle_str = "S";
|
||||
} else if(angle > 202.5 && angle <= 247.5) {
|
||||
angle_str = "SW";
|
||||
} else if(angle > 247.5 && angle <= 292.5) {
|
||||
angle_str = "W";
|
||||
} else if(angle > 292.5 && angle <= 337.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->gps->latitude)) {
|
||||
if(isnan(subghz_history_get_latitude(subghz->history, subghz->idx_menu_chosen))) {
|
||||
furi_string_printf(lat_str, "N/A");
|
||||
} else {
|
||||
furi_string_printf(
|
||||
@@ -61,7 +63,7 @@ void subghz_scene_show_gps_draw_satellites(void* context) {
|
||||
(double)subghz_history_get_latitude(subghz->history, subghz->idx_menu_chosen));
|
||||
}
|
||||
|
||||
if(isnan(subghz->gps->longitude)) {
|
||||
if(isnan(subghz_history_get_longitude(subghz->history, subghz->idx_menu_chosen))) {
|
||||
furi_string_printf(lon_str, "N/A");
|
||||
} else {
|
||||
furi_string_printf(
|
||||
@@ -72,7 +74,7 @@ void subghz_scene_show_gps_draw_satellites(void* context) {
|
||||
|
||||
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: %d:%d:%d UTC",
|
||||
"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),
|
||||
@@ -102,15 +104,13 @@ void subghz_scene_show_gps_refresh_screen(void* context) {
|
||||
void subghz_scene_show_gps_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(subghz->last_settings->gps_enabled) {
|
||||
furi_thread_start(subghz->gps->thread);
|
||||
}
|
||||
|
||||
subghz_scene_show_gps_draw_satellites(subghz);
|
||||
|
||||
subghz->gps->timer =
|
||||
furi_timer_alloc(subghz_scene_show_gps_refresh_screen, FuriTimerTypePeriodic, subghz);
|
||||
furi_timer_start(subghz->gps->timer, 1000);
|
||||
if(subghz->last_settings->gps_enabled) {
|
||||
subghz->gps->timer =
|
||||
furi_timer_alloc(subghz_scene_show_gps_refresh_screen, FuriTimerTypePeriodic, subghz);
|
||||
furi_timer_start(subghz->gps->timer, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
bool subghz_scene_show_gps_on_event(void* context, SceneManagerEvent event) {
|
||||
@@ -135,12 +135,9 @@ void subghz_scene_show_gps_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(subghz->last_settings->gps_enabled) {
|
||||
furi_thread_flags_set(furi_thread_get_id(subghz->gps->thread), WorkerEvtStop);
|
||||
furi_thread_join(subghz->gps->thread);
|
||||
furi_timer_stop(subghz->gps->timer);
|
||||
furi_timer_free(subghz->gps->timer);
|
||||
}
|
||||
|
||||
furi_timer_stop(subghz->gps->timer);
|
||||
furi_timer_free(subghz->gps->timer);
|
||||
|
||||
widget_reset(subghz->widget);
|
||||
}
|
||||
@@ -245,6 +245,9 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
|
||||
subghz->error_str = furi_string_alloc();
|
||||
|
||||
subghz->gps = subghz_gps_init();
|
||||
if(subghz->last_settings->gps_enabled) {
|
||||
subghz_gps_start(subghz->gps);
|
||||
}
|
||||
|
||||
return subghz;
|
||||
}
|
||||
@@ -317,8 +320,6 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) {
|
||||
furi_record_close(RECORD_GUI);
|
||||
subghz->gui = NULL;
|
||||
|
||||
subghz_last_settings_free(subghz->last_settings);
|
||||
|
||||
// threshold rssi
|
||||
subghz_threshold_rssi_free(subghz->threshold_rssi);
|
||||
|
||||
@@ -342,8 +343,14 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) {
|
||||
furi_string_free(subghz->file_path);
|
||||
furi_string_free(subghz->file_path_tmp);
|
||||
|
||||
// GPS
|
||||
if(subghz->last_settings->gps_enabled) {
|
||||
subghz_gps_stop(subghz->gps);
|
||||
}
|
||||
subghz_gps_deinit(subghz->gps);
|
||||
|
||||
subghz_last_settings_free(subghz->last_settings);
|
||||
|
||||
// The rest
|
||||
free(subghz);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user