Skip to content

Commit

Permalink
Allow switching between normal and debug DS mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Jan 10, 2023
1 parent 06997d7 commit b879bb9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
46 changes: 19 additions & 27 deletions app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]. */
Expand Down
13 changes: 9 additions & 4 deletions app_subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion view_direct_sampling.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions view_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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))
{
Expand Down

0 comments on commit b879bb9

Please sign in to comment.