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:
71
applications/main/subghz/helpers/subghz_gps_plugin.c
Normal file
71
applications/main/subghz/helpers/subghz_gps_plugin.c
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "subghz_gps.h"
|
||||
|
||||
#include <expansion/expansion.h>
|
||||
#include <loader/firmware_api/firmware_api.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#define TAG "SubGhzGPS"
|
||||
|
||||
SubGhzGPS* subghz_gps_plugin_init(uint32_t baudrate) {
|
||||
bool connected = expansion_is_connected(furi_record_open(RECORD_EXPANSION));
|
||||
furi_record_close(RECORD_EXPANSION);
|
||||
if(connected) return NULL;
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperApplication* plugin_app = flipper_application_alloc(storage, firmware_api_interface);
|
||||
do {
|
||||
FlipperApplicationPreloadStatus preload_res = flipper_application_preload(
|
||||
plugin_app, EXT_PATH("apps_data/subghz/plugins/subghz_gps.fal"));
|
||||
|
||||
if(preload_res != FlipperApplicationPreloadStatusSuccess) {
|
||||
FURI_LOG_E(TAG, "Failed to preload GPS plugin. Code: %d\r\n", preload_res);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_application_is_plugin(plugin_app)) {
|
||||
FURI_LOG_E(TAG, "GPS plugin file is not a library\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
FlipperApplicationLoadStatus load_status = flipper_application_map_to_memory(plugin_app);
|
||||
if(load_status != FlipperApplicationLoadStatusSuccess) {
|
||||
FURI_LOG_E(TAG, "Failed to load GPS plugin file. Code %d\r\n", load_status);
|
||||
break;
|
||||
}
|
||||
|
||||
const FlipperAppPluginDescriptor* app_descriptor =
|
||||
flipper_application_plugin_get_descriptor(plugin_app);
|
||||
|
||||
if(strcmp(app_descriptor->appid, "subghz_gps") != 0) {
|
||||
FURI_LOG_E(TAG, "GPS plugin type doesn't match\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if(app_descriptor->ep_api_version != 1) {
|
||||
FURI_LOG_E(
|
||||
TAG,
|
||||
"GPS plugin version %" PRIu32 " doesn't match\r\n",
|
||||
app_descriptor->ep_api_version);
|
||||
break;
|
||||
}
|
||||
|
||||
void (*subghz_gps_init)(SubGhzGPS* subghz_gps, uint32_t baudrate) =
|
||||
app_descriptor->entry_point;
|
||||
|
||||
SubGhzGPS* subghz_gps = malloc(sizeof(SubGhzGPS));
|
||||
subghz_gps->plugin_app = plugin_app;
|
||||
subghz_gps_init(subghz_gps, baudrate);
|
||||
return subghz_gps;
|
||||
|
||||
} while(false);
|
||||
flipper_application_free(plugin_app);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void subghz_gps_plugin_deinit(SubGhzGPS* subghz_gps) {
|
||||
subghz_gps->deinit(subghz_gps);
|
||||
flipper_application_free(subghz_gps->plugin_app);
|
||||
free(subghz_gps);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
Reference in New Issue
Block a user