diff --git a/application.fam b/application.fam index c6f4104..9684ec7 100644 --- a/application.fam +++ b/application.fam @@ -13,12 +13,15 @@ def ProtoPirateDefineEnabled(name, app_manifest_path=app_manifest_path): _ENABLE_TIMING_TUNER = ProtoPirateDefineEnabled("ENABLE_TIMING_TUNER_SCENE") +_ENABLE_EMULATE = ProtoPirateDefineEnabled("ENABLE_EMULATE_FEATURE") _MAIN_APP_SOURCES = [ "*.c*", "!protocols/plugins", "!scenes/plugins", "!protocols", + "!protopirate_emulate_plugin.c", + "!protopirate_psa_bf_plugin.c", "protocols/protocol_items.c", "protocols/protocols_common.c", "!raw_file_reader.c", @@ -30,6 +33,11 @@ if not _ENABLE_TIMING_TUNER: "!protocol_timings.c", ] +if not _ENABLE_EMULATE: + _MAIN_APP_SOURCES += [ + "!protopirate_scene_emulate.c", + ] + App( appid="proto_pirate", name="ProtoPirate", @@ -165,7 +173,11 @@ def ProtoPirateTxProtocolPlugin( App=App, FlipperAppType=FlipperAppType, tx_plugin_sources=_TX_PLUGIN_SOURCES, + enable_emulate=_ENABLE_EMULATE, ): + if not enable_emulate: + return + App( appid=f"protopirate_tx_{key}_plugin", apptype=FlipperAppType.PLUGIN, @@ -370,17 +382,18 @@ if _ENABLE_TIMING_TUNER: fal_embedded=True, ) -App( - appid="protopirate_emulate_plugin", - apptype=FlipperAppType.PLUGIN, - entry_point="protopirate_emulate_plugin_ep", - requires=["proto_pirate"], - sources=[ - "scenes/plugins/protopirate_emulate_plugin.c", - "protocols/protocol_items.c", - ], - fal_embedded=True, -) +if _ENABLE_EMULATE: + App( + appid="protopirate_emulate_plugin", + apptype=FlipperAppType.PLUGIN, + entry_point="protopirate_emulate_plugin_ep", + requires=["proto_pirate"], + sources=[ + "scenes/plugins/protopirate_emulate_plugin.c", + "protocols/protocol_items.c", + ], + fal_embedded=True, + ) App( appid="protopirate_psa_bf_plugin", diff --git a/helpers/protopirate_protocol_plugin_host.c b/helpers/protopirate_protocol_plugin_host.c index 6b1630f..14b8b0e 100644 --- a/helpers/protopirate_protocol_plugin_host.c +++ b/helpers/protopirate_protocol_plugin_host.c @@ -7,7 +7,9 @@ #include #define TAG "ProtoPirateProtocolPlugin" +#ifdef ENABLE_EMULATE_FEATURE #define PROTOPIRATE_TX_PLUGIN_PATH_MAX 160U +#endif static const char* protopirate_get_registry_plugin_path(ProtoPirateProtocolRegistryRoute route) { switch(route) { @@ -25,6 +27,7 @@ static const char* protopirate_get_registry_plugin_path(ProtoPirateProtocolRegis } } +#ifdef ENABLE_EMULATE_FEATURE static bool protopirate_build_tx_protocol_plugin_path( const char* tx_key, char* plugin_path, @@ -40,6 +43,7 @@ static bool protopirate_build_tx_protocol_plugin_path( tx_key); return (written > 0) && ((size_t)written < plugin_path_size); } +#endif static const SubGhzProtocolRegistry protopirate_empty_protocol_registry = { .items = NULL, @@ -165,6 +169,7 @@ static bool protopirate_ensure_protocol_registry_plugin( return true; } +#ifdef ENABLE_EMULATE_FEATURE static bool protopirate_ensure_tx_protocol_plugin( ProtoPirateApp* app, const char* protocol_name, @@ -264,6 +269,7 @@ static bool protopirate_ensure_tx_protocol_plugin( *registry = plugin->registry; return true; } +#endif bool protopirate_refresh_protocol_registry(ProtoPirateApp* app, bool ensure_receiver_ready) { furi_check(app); @@ -378,6 +384,7 @@ bool protopirate_apply_protocol_registry_for_context( } if(protocol_name && protocol_name[0] != '\0') { +#ifdef ENABLE_EMULATE_FEATURE const char* registry_name = protopirate_protocol_catalog_canonical_name(protocol_name); if(!registry_name || !protopirate_protocol_catalog_can_tx(protocol_name)) { FURI_LOG_E(TAG, "No TX protocol plugin for %s", protocol_name); @@ -410,6 +417,9 @@ bool protopirate_apply_protocol_registry_for_context( subghz_environment_set_protocol_registry(app->txrx->environment, tx_registry); app->txrx->protocol_registry = tx_registry; return true; +#else + return false; +#endif } ProtoPirateProtocolRegistryRoute route = protopirate_get_protocol_registry_route( diff --git a/helpers/protopirate_settings.c b/helpers/protopirate_settings.c index bc3f444..79bf087 100644 --- a/helpers/protopirate_settings.c +++ b/helpers/protopirate_settings.c @@ -103,12 +103,14 @@ void protopirate_settings_load(ProtoPirateSettings* settings) { } settings->hopping_enabled = (hopping_temp == 1); +#ifdef ENABLE_EMULATE_FEATURE uint32_t emulate_temp = 0; if(!flipper_format_read_uint32(ff, "EmulateFeature", &emulate_temp, 1)) { FURI_LOG_I(TAG, "EmulateFeature key missing, defaulting to disabled"); emulate_temp = 0; } settings->emulate_feature_enabled = (emulate_temp == 1); +#endif uint32_t check_saved_temp = 0; if(!flipper_format_read_uint32(ff, "CheckSaved", &check_saved_temp, 1)) { @@ -185,11 +187,13 @@ void protopirate_settings_save(ProtoPirateSettings* settings) { break; } +#ifdef ENABLE_EMULATE_FEATURE uint32_t emulate_temp = settings->emulate_feature_enabled ? 1 : 0; if(!flipper_format_write_uint32(ff, "EmulateFeature", &emulate_temp, 1)) { FURI_LOG_E(TAG, "Failed to write emulate feature flag"); break; } +#endif uint32_t check_saved_temp = settings->check_saved ? 1 : 0; if(!flipper_format_write_uint32(ff, "CheckSaved", &check_saved_temp, 1)) { diff --git a/protocols/protocol_items.c b/protocols/protocol_items.c index a3657ec..5445c2f 100644 --- a/protocols/protocol_items.c +++ b/protocols/protocol_items.c @@ -3,6 +3,8 @@ #include #include +#include "../defines.h" + #define TAG "ProtoPirateCatalog" #define PROTOPIRATE_CC1101_REG_MDMCFG2 0x12U @@ -17,6 +19,12 @@ #define PROTOPIRATE_COUNT_OF(array) (sizeof(array) / sizeof((array)[0])) +#ifdef ENABLE_EMULATE_FEATURE +#define PROTOPIRATE_TX_KEY(key) key +#else +#define PROTOPIRATE_TX_KEY(key) NULL +#endif + typedef enum { ProtoPirateProtocolCatalogModulationAM = 0, ProtoPirateProtocolCatalogModulationFM, @@ -28,33 +36,33 @@ typedef struct { } ProtoPirateProtocolCatalogAlias; static const ProtoPirateProtocolCatalogEntry protopirate_protocol_catalog[] = { - {"Chrysler V0", ProtoPirateProtocolCatalogRouteAMDefault, "chrysler_v0"}, - {"Fiat V0", ProtoPirateProtocolCatalogRouteAMDefault, "fiat_v0"}, - {"Fiat V1", ProtoPirateProtocolCatalogRouteAMDefault, "fiat_v1"}, + {"Chrysler V0", ProtoPirateProtocolCatalogRouteAMDefault, PROTOPIRATE_TX_KEY("chrysler_v0")}, + {"Fiat V0", ProtoPirateProtocolCatalogRouteAMDefault, PROTOPIRATE_TX_KEY("fiat_v0")}, + {"Fiat V1", ProtoPirateProtocolCatalogRouteAMDefault, PROTOPIRATE_TX_KEY("fiat_v1")}, {"Fiat V2", ProtoPirateProtocolCatalogRouteAMDefault, NULL}, - {"Ford V0", ProtoPirateProtocolCatalogRouteAMDefault, "ford_v0"}, - {"Ford V1", ProtoPirateProtocolCatalogRouteFMF4, "ford_v1"}, - {"Ford V2", ProtoPirateProtocolCatalogRouteFMF4, "ford_v2"}, + {"Ford V0", ProtoPirateProtocolCatalogRouteAMDefault, PROTOPIRATE_TX_KEY("ford_v0")}, + {"Ford V1", ProtoPirateProtocolCatalogRouteFMF4, PROTOPIRATE_TX_KEY("ford_v1")}, + {"Ford V2", ProtoPirateProtocolCatalogRouteFMF4, PROTOPIRATE_TX_KEY("ford_v2")}, {"Ford V3", ProtoPirateProtocolCatalogRouteFMF4, NULL}, - {"Honda Static", ProtoPirateProtocolCatalogRouteFMHonda1, "honda_static"}, - {"Honda V1", ProtoPirateProtocolCatalogRouteAMDefault, "honda_v1"}, - {"Kia V0", ProtoPirateProtocolCatalogRouteFMDefault, "kia_v0"}, - {"Kia V1", ProtoPirateProtocolCatalogRouteAMDefault, "kia_v1"}, - {"Kia V2", ProtoPirateProtocolCatalogRouteAMDefault, "kia_v2"}, - {"Kia V3/V4", ProtoPirateProtocolCatalogRouteFMDefault, "kia_v3_v4"}, - {"Kia V5", ProtoPirateProtocolCatalogRouteFMDefault, "kia_v5"}, - {"Kia V6", ProtoPirateProtocolCatalogRouteFMDefault, "kia_v6"}, - {"Kia V7", ProtoPirateProtocolCatalogRouteFMDefault, "kia_v7"}, - {"Honda V2", ProtoPirateProtocolCatalogRouteFMF4, "honda_v2"}, - {"Mazda V0", ProtoPirateProtocolCatalogRouteByModulation, "mazda_v0"}, + {"Honda Static", ProtoPirateProtocolCatalogRouteFMHonda1, PROTOPIRATE_TX_KEY("honda_static")}, + {"Honda V1", ProtoPirateProtocolCatalogRouteAMDefault, PROTOPIRATE_TX_KEY("honda_v1")}, + {"Kia V0", ProtoPirateProtocolCatalogRouteFMDefault, PROTOPIRATE_TX_KEY("kia_v0")}, + {"Kia V1", ProtoPirateProtocolCatalogRouteAMDefault, PROTOPIRATE_TX_KEY("kia_v1")}, + {"Kia V2", ProtoPirateProtocolCatalogRouteAMDefault, PROTOPIRATE_TX_KEY("kia_v2")}, + {"Kia V3/V4", ProtoPirateProtocolCatalogRouteFMDefault, PROTOPIRATE_TX_KEY("kia_v3_v4")}, + {"Kia V5", ProtoPirateProtocolCatalogRouteFMDefault, PROTOPIRATE_TX_KEY("kia_v5")}, + {"Kia V6", ProtoPirateProtocolCatalogRouteFMDefault, PROTOPIRATE_TX_KEY("kia_v6")}, + {"Kia V7", ProtoPirateProtocolCatalogRouteFMDefault, PROTOPIRATE_TX_KEY("kia_v7")}, + {"Honda V2", ProtoPirateProtocolCatalogRouteFMF4, PROTOPIRATE_TX_KEY("honda_v2")}, + {"Mazda V0", ProtoPirateProtocolCatalogRouteByModulation, PROTOPIRATE_TX_KEY("mazda_v0")}, {"Mitsubishi V0", ProtoPirateProtocolCatalogRouteFMDefault, NULL}, {"Porsche Touareg", ProtoPirateProtocolCatalogRouteAMDefault, NULL}, - {"PSA", ProtoPirateProtocolCatalogRouteByModulation, "psa"}, - {"Renault V0", ProtoPirateProtocolCatalogRouteAMDefault, "renault_v0"}, + {"PSA", ProtoPirateProtocolCatalogRouteByModulation, PROTOPIRATE_TX_KEY("psa")}, + {"Renault V0", ProtoPirateProtocolCatalogRouteAMDefault, PROTOPIRATE_TX_KEY("renault_v0")}, {"Scher-Khan", ProtoPirateProtocolCatalogRouteFMDefault, NULL}, - {"Star Line", ProtoPirateProtocolCatalogRouteAMDefault, "star_line"}, - {"Subaru", ProtoPirateProtocolCatalogRouteAMDefault, "subaru"}, - {"VAG", ProtoPirateProtocolCatalogRouteAMVag, "vag"}, + {"Star Line", ProtoPirateProtocolCatalogRouteAMDefault, PROTOPIRATE_TX_KEY("star_line")}, + {"Subaru", ProtoPirateProtocolCatalogRouteAMDefault, PROTOPIRATE_TX_KEY("subaru")}, + {"VAG", ProtoPirateProtocolCatalogRouteAMVag, PROTOPIRATE_TX_KEY("vag")}, }; static const ProtoPirateProtocolCatalogAlias protopirate_protocol_catalog_aliases[] = { diff --git a/protopirate_app.c b/protopirate_app.c index 5e98512..e5f7291 100644 --- a/protopirate_app.c +++ b/protopirate_app.c @@ -90,7 +90,11 @@ ProtoPirateApp* protopirate_app_alloc() { app->auto_save = settings.auto_save; app->check_saved = settings.check_saved; app->tx_power = settings.tx_power; +#ifdef ENABLE_EMULATE_FEATURE app->emulate_feature_enabled = settings.emulate_feature_enabled; +#else + app->emulate_feature_enabled = false; +#endif // Init setting - KEEP THIS, it's small app->setting = subghz_setting_alloc(); @@ -175,7 +179,11 @@ void protopirate_app_free(ProtoPirateApp* app) { settings.check_saved = app->check_saved; settings.tx_power = app->tx_power; settings.hopping_enabled = (app->txrx->hopper_state != ProtoPirateHopperStateOFF); +#ifdef ENABLE_EMULATE_FEATURE settings.emulate_feature_enabled = app->emulate_feature_enabled; +#else + settings.emulate_feature_enabled = false; +#endif // Find current preset index settings.preset_index = 0; @@ -273,14 +281,18 @@ int32_t protopirate_app(char* p) { //We now jump straight to emulate scene from Browser. If the user wanted the key to look at, just click back. if(load_saved) { +#ifdef ENABLE_EMULATE_FEATURE if(protopirate_app->emulate_feature_enabled) { view_dispatcher_send_custom_event( protopirate_app->view_dispatcher, ProtoPirateCustomEventSavedInfoEmulate); notification_message(protopirate_app->notifications, &sequence_success); } else { +#endif view_dispatcher_send_custom_event( protopirate_app->view_dispatcher, ProtoPirateCustomEventReceiverInfoSave); +#ifdef ENABLE_EMULATE_FEATURE } +#endif } view_dispatcher_run(protopirate_app->view_dispatcher); diff --git a/scenes/protopirate_scene_about.c b/scenes/protopirate_scene_about.c index 48040f2..469fa0f 100644 --- a/scenes/protopirate_scene_about.c +++ b/scenes/protopirate_scene_about.c @@ -12,6 +12,7 @@ #define CREDIT_LINE_HEIGHT 10 #define SCROLL_SPEED 1 +#ifdef ENABLE_EMULATE_FEATURE static const InputKey EMULATE_TOGGLE_COMBO[] = { InputKeyUp, InputKeyUp, @@ -23,6 +24,7 @@ static const InputKey EMULATE_TOGGLE_COMBO[] = { InputKeyRight, }; #define EMULATE_TOGGLE_COMBO_LEN (sizeof(EMULATE_TOGGLE_COMBO) / sizeof(EMULATE_TOGGLE_COMBO[0])) +#endif static const char* credits[] = { "", @@ -62,7 +64,9 @@ typedef struct { uint8_t frame; uint8_t seed; int16_t scroll_offset; +#ifdef ENABLE_EMULATE_FEATURE uint8_t combo_progress; +#endif } GlitchState; static GlitchState g_state = {0}; @@ -159,6 +163,7 @@ static void about_draw_callback(Canvas* canvas, void* context) { static bool about_input_callback(InputEvent* event, void* context) { furi_check(context); +#ifdef ENABLE_EMULATE_FEATURE ProtoPirateApp* app = context; if(event->type != InputTypePress) { @@ -184,8 +189,13 @@ static bool about_input_callback(InputEvent* event, void* context) { } return true; +#else + UNUSED(event); + return false; +#endif } +#ifdef ENABLE_EMULATE_FEATURE static void about_show_emulate_toggle_popup(ProtoPirateApp* app) { const bool now_enabled = app->emulate_feature_enabled; @@ -204,6 +214,7 @@ static void about_show_emulate_toggle_popup(ProtoPirateApp* app) { dialog_message_show(app->dialogs, message); dialog_message_free(message); } +#endif void protopirate_scene_about_on_enter(void* context) { furi_check(context); @@ -218,7 +229,9 @@ void protopirate_scene_about_on_enter(void* context) { g_state.frame = 0; g_state.seed = furi_get_tick() & 0xFF; g_state.scroll_offset = 0; +#ifdef ENABLE_EMULATE_FEATURE g_state.combo_progress = 0; +#endif view_set_draw_callback(app->view_about, about_draw_callback); view_set_input_callback(app->view_about, about_input_callback); @@ -245,7 +258,9 @@ bool protopirate_scene_about_on_event(void* context, SceneManagerEvent event) { view_commit_model(app->view_about, true); consumed = true; - } else if(event.type == SceneManagerEventTypeCustom) { + } +#ifdef ENABLE_EMULATE_FEATURE + else if(event.type == SceneManagerEventTypeCustom) { if(event.event == ProtoPirateCustomEventAboutToggleEmulate) { app->emulate_feature_enabled = !app->emulate_feature_enabled; @@ -262,6 +277,7 @@ bool protopirate_scene_about_on_event(void* context, SceneManagerEvent event) { consumed = true; } } +#endif return consumed; } diff --git a/scenes/protopirate_scene_sub_decode.c b/scenes/protopirate_scene_sub_decode.c index f27cfe8..6195443 100644 --- a/scenes/protopirate_scene_sub_decode.c +++ b/scenes/protopirate_scene_sub_decode.c @@ -1205,7 +1205,9 @@ bool protopirate_scene_sub_decode_on_event(void* context, SceneManagerEvent even app); ctx->signal_info_left_is_emulate = false; +#ifdef ENABLE_EMULATE_FEATURE bool left_button_used = false; +#endif app->emulate_disabled_for_loaded = true; // Store reference to history item's flipper format for saving @@ -1239,7 +1241,9 @@ bool protopirate_scene_sub_decode_on_event(void* context, SceneManagerEvent even "Brute force", protopirate_scene_sub_decode_widget_callback, app); +#ifdef ENABLE_EMULATE_FEATURE left_button_used = true; +#endif } } }