Преглед изворни кода

Apply frequency/modulation changes on view exit.

antirez пре 3 година
родитељ
комит
06997d72d3
4 измењених фајлова са 40 додато и 14 уклоњено
  1. 7 0
      app.c
  2. 5 1
      app.h
  3. 14 8
      app_subghz.c
  4. 14 5
      view_settings.c

+ 7 - 0
app.c

@@ -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.
@@ -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;

+ 5 - 1
app.h

@@ -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. */
@@ -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);

+ 14 - 8
app_subghz.c

@@ -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;
@@ -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;

+ 14 - 5
view_settings.c

@@ -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;
+    }
 }