Просмотр исходного кода

Initial software scaling support

anfractuosity 1 год назад
Родитель
Сommit
3663e3a83e
4 измененных файлов с 52 добавлено и 5 удалено
  1. 23 5
      scenes/scope_scene_run.c
  2. 19 0
      scenes/scope_scene_setup.c
  3. 1 0
      scope.c
  4. 9 0
      scope_app_i.h

+ 23 - 5
scenes/scope_scene_run.c

@@ -68,6 +68,7 @@ const uint32_t MSIRangeTable[16UL] = {
     0UL}; /* 0UL values are incorrect cases */
 
 char* time; // Current time period text
+float scale; // Current scale
 double freq; // Current samplerate
 uint8_t pause = 0; // Whether we want to pause output or not
 enum measureenum type; // Type of measurement we are performing
@@ -392,6 +393,13 @@ void iterative_cooley_tukey(float complex* X, int N) {
     }
 }
 
+// Found from:
+// https://stackoverflow.com/questions/427477/fastest-way-to-clamp-a-real-fixed-floating-point-value
+double clamp(double d, double min, double max) {
+    const double t = d < min ? min : d;
+    return t > max ? max : t;
+}
+
 // Used to draw to display
 static void app_draw_callback(Canvas* canvas, void* ctx) {
     UNUSED(ctx);
@@ -410,9 +418,9 @@ static void app_draw_callback(Canvas* canvas, void* ctx) {
     }
 
     if(pause)
-        canvas_draw_icon(canvas, 115, 0, &I_pause_10x10);
+        canvas_draw_icon(canvas, 116, 1, &I_pause_10x10);
     else
-        canvas_draw_icon(canvas, 115, 0, &I_play_10x10);
+        canvas_draw_icon(canvas, 116, 1, &I_play_10x10);
 
     // Calculate voltage measurements
     for(uint32_t x = 0; x < adc_buffer; x++) {
@@ -424,6 +432,9 @@ static void app_draw_callback(Canvas* canvas, void* ctx) {
 
     switch(type) {
     case m_time: {
+        // Display current scale
+        snprintf(buf1, 50, "%.0fx", (double)scale);
+        canvas_draw_str(canvas, 95, 10, buf1);
         // Display current time period
         snprintf(buf1, 50, "Time: %s", time);
         canvas_draw_str(canvas, 2, 10, buf1);
@@ -486,6 +497,9 @@ static void app_draw_callback(Canvas* canvas, void* ctx) {
         canvas_draw_str(canvas, 2, 10, buf1);
     } break;
     case m_voltage: {
+        // Display current scale
+        snprintf(buf1, 50, "%.0fx", (double)scale);
+        canvas_draw_str(canvas, 95, 10, buf1);
         // Display max, min, peak-to-peak voltages
         snprintf(buf1, 50, "Max: %.2fV", (double)max);
         canvas_draw_str(canvas, 2, 10, buf1);
@@ -502,9 +516,10 @@ static void app_draw_callback(Canvas* canvas, void* ctx) {
         // Draw lines between each data point
         // y should range from 0 to 63
         for(uint32_t x = 1; x < adc_buffer; x++) {
-            uint32_t prev = 63 - (uint32_t)(((float)mvoltDisplay[x - 1] / (float)VDDA_APPLI) * 63.0f);
-            uint32_t cur = 63 - (uint32_t)(((float)mvoltDisplay[x] / (float)VDDA_APPLI) * 63.0f);
-            canvas_draw_line(canvas, x - 1, prev, x, cur);
+            int32_t prev = 63 - (uint32_t)(((float)mvoltDisplay[x - 1] / (float)VDDA_APPLI) * scale * 63.0f);
+            int32_t cur = 63 - (uint32_t)(((float)mvoltDisplay[x] / (float)VDDA_APPLI) * scale * 63.0f);
+            if(!(prev < 0 && cur < 0))
+                canvas_draw_line(canvas, x - 1, clamp(prev, 0, 63), x, clamp(cur, 0, 63));
         }
     } else {
         // Process FFT data - excluding bin 0
@@ -569,6 +584,9 @@ void scope_scene_run_on_enter(void* context) {
         }
     }
 
+    // Obtain scale value
+    scale = app->scale;
+
     // Currently un-paused
     pause = 0;
 

+ 19 - 0
scenes/scope_scene_setup.c

@@ -15,6 +15,14 @@ static void timeperiod_cb(VariableItem* item) {
     app->time = time_list[index].time;
 }
 
+static void scale_cb(VariableItem* item) {
+    ScopeApp* app = variable_item_get_context(item);
+    furi_assert(app);
+    uint8_t index = variable_item_get_current_value_index(item);
+    variable_item_set_current_value_text(item, scale_list[index].str);
+    app->scale = scale_list[index].scale;
+}
+
 static void fft_cb(VariableItem* item) {
     ScopeApp* app = variable_item_get_context(item);
     furi_assert(app);
@@ -57,6 +65,17 @@ void scope_scene_setup_on_enter(void* context) {
         }
     }
 
+    item = variable_item_list_add(
+        var_item_list, "Scale", COUNT_OF(scale_list), scale_cb, app);
+
+    for(uint32_t i = 0; i < COUNT_OF(scale_list); i++) {
+        if(scale_list[i].scale == app->scale) {
+            variable_item_set_current_value_index(item, i);
+            variable_item_set_current_value_text(item, scale_list[i].str);
+            break;
+        }
+    }
+
     item = variable_item_list_add(
         var_item_list, "Measurement", COUNT_OF(measurement_list), measurement_cb, app);
 

+ 1 - 0
scope.c

@@ -79,6 +79,7 @@ ScopeApp* scope_app_alloc() {
         app->view_dispatcher, ScopeViewSave, text_input_get_view(app->text_input));
 
     app->time = 0.001;
+    app->scale = 1.0f;
     app->fft = 256;
     app->measurement = m_time;
 

+ 9 - 0
scope_app_i.h

@@ -34,6 +34,14 @@ typedef struct {
 static const fftwindow fft_list[] =
     {{256, "256"}, {512, "512"}, {1024, "1024"}};
 
+typedef struct {
+    float scale;
+    char* str;
+} scalesize;
+
+static const scalesize scale_list[] =
+    {{1.0f, "1x"}, {2.0f, "2x"}, {4.0f, "4x"}, {10.0f, "10x"}, {100.0f, "100x"}};
+
 enum measureenum { m_time, m_voltage, m_capture, m_fft};
 
 typedef struct {
@@ -58,6 +66,7 @@ struct ScopeApp {
     TextInput* text_input;
     double time;
     int fft;
+    float scale;
     enum measureenum measurement;
     char file_name_tmp[MAX_LEN_NAME];
     uint16_t* data;