Skip to content

Commit

Permalink
Apply frequency/modulation changes on view exit.
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Jan 10, 2023
1 parent 0cc1128 commit 06997d7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
7 changes: 7 additions & 0 deletions app.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ static void app_switch_view(ProtoViewApp *app, SwitchViewDirection dir) {
/* Call the enter/exit view callbacks if needed. */
if (old == ViewDirectSampling) view_exit_direct_sampling(app);
if (new == ViewDirectSampling) view_enter_direct_sampling(app);
/* The frequency/modulation settings are actually a single view:
* as long as the user stays between the two modes of this view we
* don't need to call the exit-view callback. */
if ((old == ViewFrequencySettings && new != ViewModulationSettings) ||
(old == ViewModulationSettings && new != ViewFrequencySettings))
view_exit_settings(app);
}

/* Allocate the application state and initialize a number of stuff.
Expand Down Expand Up @@ -123,6 +129,7 @@ ProtoViewApp* protoview_app_alloc() {
app->txrx = malloc(sizeof(ProtoViewTxRx));

/* 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;
Expand Down
6 changes: 5 additions & 1 deletion app.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ extern ProtoViewModulation ProtoViewModulations[]; /* In app_subghz.c */
* It receives data and we get our protocol "feed" callback called
* with the level (1 or 0) and duration. */
struct ProtoViewTxRx {
int debug_direct_sampling; /* Ready from GDO0 in a busy loop. Only
bool freq_mod_changed; /* The user changed frequency and/or modulation
from the interface. There is to restart the
radio with the right parameters. */
bool debug_direct_sampling; /* Read data from GDO0 in a busy loop. Only
for testing. */
SubGhzWorker* worker; /* Our background worker. */
FuriThread *ds_thread; /* Direct sampling thread. */
Expand Down Expand Up @@ -166,6 +169,7 @@ void render_view_direct_sampling(Canvas *const canvas, ProtoViewApp *app);
void process_input_direct_sampling(ProtoViewApp *app, InputEvent input);
void view_enter_direct_sampling(ProtoViewApp *app);
void view_exit_direct_sampling(ProtoViewApp *app);
void view_exit_settings(ProtoViewApp *app);

/* ui.c */
void canvas_draw_str_with_border(Canvas* canvas, uint8_t x, uint8_t y, const char* str, Color text_color, Color border_color);
22 changes: 14 additions & 8 deletions app_subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ int32_t direct_sampling_thread(void *ctx) {
bool last_level = false;
uint32_t last_change_time = DWT->CYCCNT;

if (0) while(app->txrx->ds_thread_running) furi_delay_ms(1);

while(app->txrx->ds_thread_running) {
uint32_t d[10];
uint16_t d[50]; uint8_t l[50];
for (uint32_t j = 0; j < 500; j++) {
uint32_t maxloops = 50000;
volatile uint32_t maxloops = 50000;
while(maxloops-- && app->txrx->ds_thread_running) {
bool l = furi_hal_gpio_read(&gpio_cc1101_g0);
if (l != last_level) break;
Expand All @@ -125,18 +127,22 @@ int32_t direct_sampling_thread(void *ctx) {
uint32_t now = DWT->CYCCNT;
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;
}

last_level = !last_level; /* What g0 is now. */
last_change_time = now;
if (j < 10) d[j] = dur;
if (!app->txrx->ds_thread_running) break;
}

for (uint32_t j = 0; j < 10; j++) {
FURI_LOG_E(TAG, "dur[%u]: %u",
(unsigned int)j, (unsigned int)d[j]);
}
furi_delay_tick(200);
for (uint32_t j = 0; j < 50; j++)
printf("%d=%u ", (unsigned int)l[j], (unsigned int)d[j]);
printf("\n");
furi_delay_ms(50);
}
FURI_LOG_E(TAG, "Exiting DS thread");
return 0;
Expand Down
19 changes: 14 additions & 5 deletions view_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,18 @@ void process_input_settings(ProtoViewApp *app, InputEvent input) {
return;
}

/* Apply changes. */
FURI_LOG_E(TAG, "Setting view, setting frequency/modulation to %lu %s", app->frequency, ProtoViewModulations[app->modulation].name);
radio_rx_end(app);
radio_begin(app);
radio_rx(app);
/* Apply changes when switching to other views. */
app->txrx->freq_mod_changed = true;
}

/* When the user switches to some other view, if they changed the parameters
* we need to restart the radio with the right frequency and modulation. */
void view_exit_settings(ProtoViewApp *app) {
if (app->txrx->freq_mod_changed) {
FURI_LOG_E(TAG, "Setting view, setting frequency/modulation to %lu %s", app->frequency, ProtoViewModulations[app->modulation].name);
radio_rx_end(app);
radio_begin(app);
radio_rx(app);
app->txrx->freq_mod_changed = false;
}
}

0 comments on commit 06997d7

Please sign in to comment.