From b879bb945aa14e7f725a1ef9543ae67c36e5e8ea Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 10 Jan 2023 09:51:22 +0100 Subject: [PATCH] Allow switching between normal and debug DS mode. --- app.c | 46 +++++++++++++++++------------------------- app_subghz.c | 13 ++++++++---- view_direct_sampling.c | 2 +- view_settings.c | 7 +++++++ 4 files changed, 36 insertions(+), 32 deletions(-) diff --git a/app.c b/app.c index a590f79fdd3..12397992e5f 100644 --- a/app.c +++ b/app.c @@ -130,33 +130,25 @@ ProtoViewApp* protoview_app_alloc() { /* Setup rx worker and environment. */ app->txrx->freq_mod_changed = false; - app->txrx->debug_direct_sampling = true; - if (app->txrx->debug_direct_sampling) { - app->txrx->ds_thread = NULL; - } else { - app->txrx->worker = subghz_worker_alloc(); - #ifdef PROTOVIEW_DISABLE_SUBGHZ_FILTER - app->txrx->worker->filter_running = 0; - #endif - - app->txrx->environment = subghz_environment_alloc(); - - subghz_environment_set_protocol_registry( - app->txrx->environment, (void*)&protoview_protocol_registry); - - app->txrx->receiver = - subghz_receiver_alloc_init(app->txrx->environment); - - subghz_receiver_set_filter(app->txrx->receiver, - SubGhzProtocolFlag_Decodable); - subghz_worker_set_overrun_callback( - app->txrx->worker, - (SubGhzWorkerOverrunCallback)subghz_receiver_reset); - - subghz_worker_set_pair_callback( - app->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode); - subghz_worker_set_context(app->txrx->worker, app->txrx->receiver); - } + app->txrx->debug_direct_sampling = false; + app->txrx->ds_thread = NULL; + app->txrx->worker = subghz_worker_alloc(); +#ifdef PROTOVIEW_DISABLE_SUBGHZ_FILTER + app->txrx->worker->filter_running = 0; +#endif + app->txrx->environment = subghz_environment_alloc(); + subghz_environment_set_protocol_registry( + app->txrx->environment, (void*)&protoview_protocol_registry); + app->txrx->receiver = + subghz_receiver_alloc_init(app->txrx->environment); + subghz_receiver_set_filter(app->txrx->receiver, + SubGhzProtocolFlag_Decodable); + subghz_worker_set_overrun_callback( + app->txrx->worker, + (SubGhzWorkerOverrunCallback)subghz_receiver_reset); + subghz_worker_set_pair_callback( + app->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode); + subghz_worker_set_context(app->txrx->worker, app->txrx->receiver); app->frequency = subghz_setting_get_default_frequency(app->setting); app->modulation = 0; /* Defaults to ProtoViewModulations[0]. */ diff --git a/app_subghz.c b/app_subghz.c index 49127063a21..52ebc37a53d 100644 --- a/app_subghz.c +++ b/app_subghz.c @@ -128,10 +128,15 @@ int32_t direct_sampling_thread(void *ctx) { uint32_t dur = now - last_change_time; dur /= furi_hal_cortex_instructions_per_microsecond(); - raw_samples_add(RawSamples, last_level, dur); - if (j < 50) { - l[j] = last_level; - d[j] = dur; + if (dur > 20) { + raw_samples_add(RawSamples, last_level, dur); + if (j < 50) { + l[j] = last_level; + d[j] = dur; + } + } else { + last_level = !last_level; + continue; } last_level = !last_level; /* What g0 is now. */ diff --git a/view_direct_sampling.c b/view_direct_sampling.c index 01e4cb1d35f..edf31500279 100644 --- a/view_direct_sampling.c +++ b/view_direct_sampling.c @@ -16,7 +16,7 @@ void render_view_direct_sampling(Canvas *const canvas, ProtoViewApp *app) { /* Busy loop: this is a terrible approach as it blocks * everything else, but for now it's the best we can do * to obtain direct data with some spacing. */ - // uint32_t x = 500; while(x--); + uint32_t x = 250; while(x--); } } canvas_set_font(canvas, FontSecondary); diff --git a/view_settings.c b/view_settings.c index b61de9b7114..b7c07741e52 100644 --- a/view_settings.c +++ b/view_settings.c @@ -20,6 +20,9 @@ void render_view_settings(Canvas *const canvas, ProtoViewApp *app) { canvas_set_font(canvas, FontSecondary); canvas_draw_str(canvas,10,61,"Use up and down to modify"); + if (app->txrx->debug_direct_sampling) + canvas_draw_str(canvas,3,54,"(DEBUG direct sampling is ON)"); + /* Show frequency. We can use big numbers font since it's just a number. */ if (app->current_view == ViewFrequencySettings) { char buf[16]; @@ -40,6 +43,10 @@ void process_input_settings(ProtoViewApp *app, InputEvent input) { * modulation. */ app->frequency = subghz_setting_get_default_frequency(app->setting); app->modulation = 0; + } else if (input.type == InputTypeLong && input.key == InputKeyDown) { + /* Long pressing to down switches between normal and debug + * direct sampling mode. */ + app->txrx->debug_direct_sampling = !app->txrx->debug_direct_sampling; } else if (input.type == InputTypePress && (input.key != InputKeyDown || input.key != InputKeyUp)) {