Kaynağa Gözat

Allow measuring of voltages

anfractuosity 3 yıl önce
ebeveyn
işleme
cfcc6d9bec
5 değiştirilmiş dosya ile 85 ekleme ve 16 silme
  1. 1 1
      scenes/scope_scene_about.c
  2. 34 3
      scenes/scope_scene_run.c
  3. 23 1
      scenes/scope_scene_setup.c
  4. 2 0
      scope.c
  5. 25 11
      scope_app_i.h

+ 1 - 1
scenes/scope_scene_about.c

@@ -40,7 +40,7 @@ void scope_scene_about_on_enter(void* context) {
         14,
         AlignCenter,
         AlignBottom,
-        "\e#\e!         Flipperscope            \e!\n",
+        "\e#\e!          flipperscope             \e!\n",
         false);
     widget_add_text_scroll_element(app->widget, 0, 16, 128, 50, furi_string_get_cstr(temp_str));
     furi_string_free(temp_str);

+ 34 - 3
scenes/scope_scene_run.c

@@ -35,6 +35,7 @@ const uint32_t MSIRangeTable[16UL] = {100000UL, 200000UL, 400000UL, 800000UL, 10
                                       4000000UL, 8000000UL, 16000000UL, 24000000UL, 32000000UL, 48000000UL, 0UL, 0UL, 0UL, 0UL}; /* 0UL values are incorrect cases */
 char * time;
 uint8_t pause=0;
+enum measureenum type;
 
 void Error_Handler()
 {
@@ -229,10 +230,39 @@ void HAL_ADC_ErrorCallback(ADC_HandleTypeDef * hadc)
 static void app_draw_callback(Canvas * canvas, void *ctx)
 {
     UNUSED(ctx);
-    char buf[50];
-    snprintf(buf, 50, "Time: %s", time);
+    switch(type){
+        case m_time:
+            {
+                char buf[50];
+                snprintf(buf, 50, "Time: %s", time);
+                canvas_draw_str(canvas, 10, 10, buf);
+            }
+            break;
+        case m_voltage:
+            {
+                char buf1[50];
+                char buf2[50];
+                char buf3[50];
+                double max = 0.0;
+                double min = 100.0;
+                for(uint32_t x = 0; x < ADC_CONVERTED_DATA_BUFFER_SIZE; x++){
+                    if(mvoltDisplay[x] < min)
+                        min = mvoltDisplay[x];
+                    if(mvoltDisplay[x] > max)
+                        max = mvoltDisplay[x];
+                }
+                snprintf(buf1, 50, "Max: %.2fV", max/1000);
+                canvas_draw_str(canvas, 10, 10, buf1);
+                snprintf(buf2, 50, "Min: %.2fV", min/1000);
+                canvas_draw_str(canvas, 10, 20, buf2);
+                snprintf(buf3, 50, "Vpp: %.2fV", (max - min)/1000);
+                canvas_draw_str(canvas, 10, 30, buf3);
+            }
+            break;
+        default:
+            break;
+    }
 
-    canvas_draw_str(canvas, 10, 10, buf);
     for(uint32_t x = 1; x < ADC_CONVERTED_DATA_BUFFER_SIZE; x++){
         uint32_t prev = 64 - (mvoltDisplay[x-1] / (VDDA_APPLI / 64));
         uint32_t cur = 64 - (mvoltDisplay[x] / (VDDA_APPLI / 64));
@@ -269,6 +299,7 @@ void scope_scene_run_on_enter(void* context) {
         }
     }
     pause = 0;
+    type = app->measurement;
 
     __disable_irq();
     memcpy(ramVector, (uint32_t*)(FLASH_BASE | SCB->VTOR), sizeof(uint32_t) * TABLE_SIZE);

+ 23 - 1
scenes/scope_scene_setup.c

@@ -12,7 +12,6 @@ void scope_scene_setup_widget_callback(
 }
 
 static void timeperiod_cb(VariableItem* item) {
-    UNUSED(item);
     ScopeApp* app = variable_item_get_context(item);
     furi_assert(app);
     uint8_t index = variable_item_get_current_value_index(item);
@@ -20,6 +19,14 @@ static void timeperiod_cb(VariableItem* item) {
     app->time = time_list[index].time;
 }
 
+static void measurement_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, measurement_list[index].str);
+    app->measurement = measurement_list[index].type;
+}
+
 void scope_scene_setup_on_enter(void* context) {
     ScopeApp* app = context;
     VariableItemList* var_item_list = app->variable_item_list;
@@ -39,6 +46,21 @@ void scope_scene_setup_on_enter(void* context) {
         }
     }
 
+    item = variable_item_list_add(
+        var_item_list,
+        "Measurement",
+        COUNT_OF(measurement_list),
+        measurement_cb,
+        app);
+
+    for (uint32_t i = 0; i < COUNT_OF(measurement_list); i++){
+        if(measurement_list[i].type == app->measurement){
+            variable_item_set_current_value_index(item, i);
+            variable_item_set_current_value_text(item, measurement_list[i].str);
+            break;
+        }
+    }
+
     view_dispatcher_switch_to_view(app->view_dispatcher, ScopeViewVariableItemList);
 }
 

+ 2 - 0
scope.c

@@ -79,6 +79,8 @@ ScopeApp* scope_app_alloc() {
         app->view_dispatcher, ScopeViewWidget, widget_get_view(app->widget));
 
     app->time = 0.001;
+    app->measurement = m_time;
+
     scene_manager_next_scene(app->scene_manager, ScopeSceneStart);
     return app;
 }

+ 25 - 11
scope_app_i.h

@@ -13,17 +13,6 @@
 
 typedef struct ScopeApp ScopeApp;
 
-struct ScopeApp {
-    Gui* gui;
-    ViewDispatcher* view_dispatcher;
-    SceneManager* scene_manager;
-    NotificationApp* notifications;
-    VariableItemList* variable_item_list;
-    Submenu* submenu;
-    Widget* widget;
-    double time ;
-};
-
 typedef struct {
     double time;
     char * str;
@@ -37,3 +26,28 @@ static const timeperiod time_list[] = {
     {1e-6, "1us"},
     {0.5e-6, "0.5us"}
 };
+
+enum measureenum {m_time, m_voltage};
+
+typedef struct {
+    enum measureenum type;
+    char * str;
+} measurement;
+
+static const measurement measurement_list[] = {
+    {m_time,  "Time"},
+    {m_voltage, "Voltage"}
+};
+
+struct ScopeApp {
+    Gui* gui;
+    ViewDispatcher* view_dispatcher;
+    SceneManager* scene_manager;
+    NotificationApp* notifications;
+    VariableItemList* variable_item_list;
+    Submenu* submenu;
+    Widget* widget;
+    double time ;
+    enum measureenum measurement;
+};
+