mirror of
https://protopirate.net/ProtoPirate/ProtoPirate.git
synced 2026-09-25 15:03:43 +00:00
Merge pull request 'Config Plugin HOST API' (#51) from RalphWiggum/ProtoPirate:config_host_api into main
FAP Build / ufbt: Build for Momentum dev (push) Canceled after 0s
FAP Build / ufbt: Build for Momentum release (push) Canceled after 0s
FAP Build / ufbt: Build for OFW dev channel (push) Canceled after 0s
FAP Build / ufbt: Build for OFW release channel (push) Canceled after 0s
FAP Build / ufbt: Build for Unleashed dev (push) Canceled after 0s
FAP Build / ufbt: Build for Unleashed release (push) Canceled after 0s
FAP Build / ufbt: Build for Momentum dev (push) Canceled after 0s
FAP Build / ufbt: Build for Momentum release (push) Canceled after 0s
FAP Build / ufbt: Build for OFW dev channel (push) Canceled after 0s
FAP Build / ufbt: Build for OFW release channel (push) Canceled after 0s
FAP Build / ufbt: Build for Unleashed dev (push) Canceled after 0s
FAP Build / ufbt: Build for Unleashed release (push) Canceled after 0s
Reviewed-on: http://protopirate.net/ProtoPirate/ProtoPirate/pulls/51 Reviewed-by: MMX <mmx@no-reply.protopirate.net>
This commit is contained in:
@@ -428,11 +428,8 @@ App(
|
||||
entry_point="protopirate_config_plugin_ep",
|
||||
requires=["proto_pirate"],
|
||||
sources=[
|
||||
"helpers/protopirate_protocol_plugin_host.c",
|
||||
"helpers/protopirate_models.c",
|
||||
"helpers/protopirate_txrx.c",
|
||||
"helpers/variable_item_list.c",
|
||||
"protocols/protocol_items.c",
|
||||
"scenes/plugins/protopirate_config_plugin.c",
|
||||
],
|
||||
fal_embedded=True,
|
||||
|
||||
@@ -89,6 +89,7 @@ bool car_model_get_by_index(
|
||||
//Set the Custom preset name.
|
||||
furi_string_set_str(preset_name, "Custom");
|
||||
custom_preset = true;
|
||||
flipper_format_rewind(ff);
|
||||
} else {
|
||||
//Get the built in preset if it exists
|
||||
const char* preset_name_long = furi_string_get_cstr(preset_name);
|
||||
@@ -162,37 +163,38 @@ bool car_model_get_by_index(
|
||||
}
|
||||
|
||||
/* Custom_preset_data (only if present) */
|
||||
if(custom_preset &&
|
||||
flipper_format_get_value_count(ff, preset_data_index, &preset_data_size) &&
|
||||
preset_data_size > 0) {
|
||||
if(preset_data_size >= 1024) {
|
||||
FURI_LOG_E(
|
||||
"ProtoPirate",
|
||||
"%s too large: %lu",
|
||||
preset_data_index,
|
||||
(unsigned long)preset_data_size);
|
||||
break;
|
||||
if(custom_preset) {
|
||||
if(flipper_format_get_value_count(ff, preset_data_index, &preset_data_size) &&
|
||||
preset_data_size > 0) {
|
||||
if(preset_data_size >= 1024) {
|
||||
FURI_LOG_E(
|
||||
"ProtoPirate",
|
||||
"%s too large: %lu",
|
||||
preset_data_index,
|
||||
(unsigned long)preset_data_size);
|
||||
break;
|
||||
}
|
||||
|
||||
preset_data = malloc(preset_data_size);
|
||||
if(!preset_data) {
|
||||
FURI_LOG_E(
|
||||
"ProtoPirate",
|
||||
"Malloc failed: %s (%lu bytes)",
|
||||
preset_data_index,
|
||||
(unsigned long)preset_data_size);
|
||||
break;
|
||||
}
|
||||
|
||||
flipper_format_rewind(ff);
|
||||
if(!flipper_format_read_hex(ff, preset_data_index, preset_data, preset_data_size)) {
|
||||
break;
|
||||
}
|
||||
|
||||
FURI_LOG_D(TAG, "Using Custom Preset Data from Models File...");
|
||||
|
||||
//Yay, we made it...
|
||||
error = false;
|
||||
}
|
||||
|
||||
preset_data = malloc(preset_data_size);
|
||||
if(!preset_data) {
|
||||
FURI_LOG_E(
|
||||
"ProtoPirate",
|
||||
"Malloc failed: %s (%lu bytes)",
|
||||
preset_data_index,
|
||||
(unsigned long)preset_data_size);
|
||||
break;
|
||||
}
|
||||
|
||||
flipper_format_rewind(ff);
|
||||
if(!flipper_format_read_hex(ff, preset_data_index, preset_data, preset_data_size)) {
|
||||
break;
|
||||
}
|
||||
|
||||
FURI_LOG_D(TAG, "Using Custom Preset Data from Models File...");
|
||||
|
||||
//Yay, we made it...
|
||||
error = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-2
@@ -1,7 +1,7 @@
|
||||
Filetype: ProtoPirate Car Models Database
|
||||
Version: 2
|
||||
|
||||
ModelCount: 7
|
||||
ModelCount: 8
|
||||
|
||||
ModelName1: 433.92 Mhz AM650
|
||||
Frequency1: 433920000
|
||||
@@ -27,7 +27,12 @@ ModelName6: Ford Territory SX-SYII
|
||||
Frequency6: 433920000
|
||||
PresetName6: FuriHalSubGhzPresetOok650Async
|
||||
|
||||
ModelName7: Example With Honda Preset
|
||||
ModelName7: Honda 433.92 Mhz
|
||||
Frequency7: 433920000
|
||||
PresetName7: FuriHalSubGhzPresetCustom
|
||||
CustomPresetData7: 02 0D 0B 06 08 32 07 04 14 00 13 02 12 07 11 36 10 E9 15 32 18 18 19 16 1D 92 1C 40 1B 03 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00
|
||||
|
||||
ModelName8: Honda 315 Mhz
|
||||
Frequency8: 315000000
|
||||
PresetName8: FuriHalSubGhzPresetCustom
|
||||
CustomPresetData8: 02 0D 0B 06 08 32 07 04 14 00 13 02 12 07 11 36 10 E9 15 32 18 18 19 16 1D 92 1C 40 1B 03 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00
|
||||
|
||||
+5
-2
@@ -31,7 +31,9 @@ void config_plugin_unload(ProtoPirateApp* app) {
|
||||
}
|
||||
}
|
||||
|
||||
bool config_plugin_load(ProtoPirateApp* app) {
|
||||
bool config_plugin_load(
|
||||
ProtoPirateApp* app,
|
||||
const ProtoPirateConfigSceneHostApi* protopirate_config_scene_host_api) {
|
||||
furi_check(app);
|
||||
|
||||
if(app->config_plugin) return true;
|
||||
@@ -76,6 +78,7 @@ bool config_plugin_load(ProtoPirateApp* app) {
|
||||
app->plugin_resolver = resolver;
|
||||
app->plugin_manager = manager;
|
||||
app->config_plugin = plugin;
|
||||
plugin->set_host_api(protopirate_config_scene_host_api);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -221,7 +224,7 @@ ProtoPirateApp* protopirate_app_alloc() {
|
||||
settings.auto_save,
|
||||
settings.hopping_enabled);
|
||||
|
||||
config_plugin_load(app);
|
||||
config_plugin_load(app, NULL);
|
||||
app->car_models_count = app->config_plugin->car_model_get_count();
|
||||
app->selected_model = malloc(sizeof(ProtoPirateCarModel));
|
||||
app->selected_model->name = furi_string_alloc();
|
||||
|
||||
+3
-1
@@ -141,7 +141,9 @@ bool protopirate_tool_scene_on_event(void* app, SceneManagerEvent event);
|
||||
void protopirate_tool_scene_on_exit(void* app);
|
||||
void protopirate_tool_scene_plugin_release(ProtoPirateApp* app);
|
||||
|
||||
bool config_plugin_load(ProtoPirateApp* app);
|
||||
bool config_plugin_load(
|
||||
ProtoPirateApp* app,
|
||||
const ProtoPirateConfigSceneHostApi* protopirate_config_scene_host_api);
|
||||
void config_plugin_unload(ProtoPirateApp* app);
|
||||
|
||||
void protopirate_app_free(ProtoPirateApp* app);
|
||||
|
||||
@@ -2,6 +2,15 @@
|
||||
#include "../../protopirate_app_i.h"
|
||||
#include "../../helpers/protopirate_models.h"
|
||||
|
||||
static const ProtoPirateConfigSceneHostApi* g_config_scene_host_api = NULL;
|
||||
|
||||
#define protopirate_preset_init(app, preset_name, frequency, preset_data, preset_data_size) \
|
||||
g_config_scene_host_api->protopirate_preset_init( \
|
||||
app, preset_name, frequency, preset_data, preset_data_size)
|
||||
|
||||
#define protopirate_refresh_protocol_registry(app, ensure_receiver_ready) \
|
||||
g_config_scene_host_api->protopirate_refresh_protocol_registry(app, ensure_receiver_ready)
|
||||
|
||||
#define ON_OFF_COUNT 2
|
||||
const char* const on_off_text[ON_OFF_COUNT] = {
|
||||
"OFF",
|
||||
@@ -476,11 +485,16 @@ static void plugin_on_enter(void* context) {
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, ProtoPirateViewVariableItemList);
|
||||
}
|
||||
|
||||
void config_plugin_set_host_api(const ProtoPirateConfigSceneHostApi* host_api) {
|
||||
g_config_scene_host_api = host_api;
|
||||
}
|
||||
|
||||
static const ProtoPirateConfigPlugin protopirate_config_plugin = {
|
||||
.plugin_name = "ProtoPirate Config",
|
||||
.car_model_get_by_index = car_model_get_by_index,
|
||||
.car_model_get_count = car_model_get_count,
|
||||
.on_enter = plugin_on_enter,
|
||||
.set_host_api = config_plugin_set_host_api,
|
||||
};
|
||||
|
||||
static const FlipperAppPluginDescriptor protopirate_config_plugin_descriptor = {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#include "helpers/protopirate_models.h"
|
||||
#include <lib/flipper_application/flipper_application.h>
|
||||
#include "helpers/variable_item_list.h"
|
||||
@@ -22,6 +21,17 @@ enum ProtoPirateSettingIndex {
|
||||
ProtoPirateSettingIndexLock,
|
||||
};
|
||||
|
||||
typedef struct ProtoPirateApp ProtoPirateApp;
|
||||
typedef struct ProtoPirateConfigSceneHostApi {
|
||||
bool (*protopirate_refresh_protocol_registry)(ProtoPirateApp* app, bool ensure_receiver_ready);
|
||||
void (*protopirate_preset_init)(
|
||||
void* context,
|
||||
const char* preset_name,
|
||||
uint32_t frequency,
|
||||
uint8_t* preset_data,
|
||||
size_t preset_data_size);
|
||||
} ProtoPirateConfigSceneHostApi;
|
||||
|
||||
typedef struct ProtoPirateConfigPlugin {
|
||||
const char* plugin_name;
|
||||
bool (*car_model_get_by_index)(
|
||||
@@ -31,4 +41,5 @@ typedef struct ProtoPirateConfigPlugin {
|
||||
SubGhzSetting* app_settings);
|
||||
uint16_t (*car_model_get_count)(void);
|
||||
void (*on_enter)(void* app);
|
||||
void (*set_host_api)(const ProtoPirateConfigSceneHostApi* host_api);
|
||||
} ProtoPirateConfigPlugin;
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
// scenes/protopirate_scene_receiver_config.c
|
||||
#include "../protopirate_app_i.h"
|
||||
#include "protopirate_app_i.h"
|
||||
#include "plugins/protopirate_config_plugin.h"
|
||||
#include "../helpers/protopirate_protocol_plugin_host.h"
|
||||
|
||||
static const ProtoPirateConfigSceneHostApi protopirate_config_scene_host_api = {
|
||||
.protopirate_refresh_protocol_registry = protopirate_refresh_protocol_registry,
|
||||
.protopirate_preset_init = protopirate_preset_init,
|
||||
};
|
||||
|
||||
void protopirate_scene_receiver_config_on_enter(void* context) {
|
||||
ProtoPirateApp* app = context;
|
||||
|
||||
if(!config_plugin_load(app)) {
|
||||
if(!config_plugin_load(app, &protopirate_config_scene_host_api)) {
|
||||
notification_message(app->notifications, &sequence_error);
|
||||
scene_manager_previous_scene(app->scene_manager);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user