Kaynağa Gözat

Make time period more understandable

anfractuosity 3 yıl önce
ebeveyn
işleme
fe93e0e119
3 değiştirilmiş dosya ile 27 ekleme ve 22 silme
  1. 10 5
      scenes/scope_scene_run.c
  2. 4 17
      scenes/scope_scene_setup.c
  3. 13 0
      scope_app_i.h

+ 10 - 5
scenes/scope_scene_run.c

@@ -33,7 +33,7 @@ const uint32_t AHBPrescTable[16UL] = {1UL, 3UL, 5UL, 1UL, 1UL, 6UL, 10UL, 32UL,
 const uint32_t APBPrescTable[8UL]  = {0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL};
 const uint32_t APBPrescTable[8UL]  = {0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL};
 const uint32_t MSIRangeTable[16UL] = {100000UL, 200000UL, 400000UL, 800000UL, 1000000UL, 2000000UL, \
 const uint32_t MSIRangeTable[16UL] = {100000UL, 200000UL, 400000UL, 800000UL, 1000000UL, 2000000UL, \
                                       4000000UL, 8000000UL, 16000000UL, 24000000UL, 32000000UL, 48000000UL, 0UL, 0UL, 0UL, 0UL}; /* 0UL values are incorrect cases */
                                       4000000UL, 8000000UL, 16000000UL, 24000000UL, 32000000UL, 48000000UL, 0UL, 0UL, 0UL, 0UL}; /* 0UL values are incorrect cases */
-double time;
+char * time;
 uint8_t pause=0;
 uint8_t pause=0;
 
 
 void Error_Handler()
 void Error_Handler()
@@ -230,7 +230,7 @@ static void app_draw_callback(Canvas * canvas, void *ctx)
 {
 {
     UNUSED(ctx);
     UNUSED(ctx);
     char buf[50];
     char buf[50];
-    snprintf(buf, 50, "Time: %.5f", time);
+    snprintf(buf, 50, "Time: %s", time);
 
 
     canvas_draw_str(canvas, 10, 10, buf);
     canvas_draw_str(canvas, 10, 10, buf);
     for(uint32_t x = 1; x < ADC_CONVERTED_DATA_BUFFER_SIZE; x++){
     for(uint32_t x = 1; x < ADC_CONVERTED_DATA_BUFFER_SIZE; x++){
@@ -262,9 +262,12 @@ void scope_scene_run_widget_callback(
 
 
 void scope_scene_run_on_enter(void* context) {
 void scope_scene_run_on_enter(void* context) {
     ScopeApp* app = context;
     ScopeApp* app = context;
-    time = app->time;
-    UNUSED(app);
-
+    for (uint32_t i = 0; i < COUNT_OF(time_list); i++){
+        if(time_list[i].time == app->time){
+            time = time_list[i].str;
+            break;
+        }
+    }
     pause = 0;
     pause = 0;
 
 
     __disable_irq();
     __disable_irq();
@@ -299,6 +302,8 @@ void scope_scene_run_on_enter(void* context) {
          tmp_index_adc_converted_data++) {
          tmp_index_adc_converted_data++) {
         aADCxConvertedData[tmp_index_adc_converted_data] =
         aADCxConvertedData[tmp_index_adc_converted_data] =
             VAR_CONVERTED_DATA_INIT_VALUE;
             VAR_CONVERTED_DATA_INIT_VALUE;
+        aADCxConvertedData_Voltage_mVoltA[tmp_index_adc_converted_data] = 0;
+        aADCxConvertedData_Voltage_mVoltB[tmp_index_adc_converted_data] = 0;
     }
     }
 
 
     if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED) != HAL_OK) {
     if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED) != HAL_OK) {

+ 4 - 17
scenes/scope_scene_setup.c

@@ -1,14 +1,6 @@
 #include "../scope_app_i.h"
 #include "../scope_app_i.h"
 #include "../helpers/scope_types.h"
 #include "../helpers/scope_types.h"
 
 
-static const double time_list[] = {
-    1.0,
-    0.1,
-    0.01,
-    0.001,
-    0.0005
-};
-
 void scope_scene_setup_widget_callback(
 void scope_scene_setup_widget_callback(
     GuiButtonType result,
     GuiButtonType result,
     InputType type,
     InputType type,
@@ -24,10 +16,8 @@ static void timeperiod_cb(VariableItem* item) {
     ScopeApp* app = variable_item_get_context(item);
     ScopeApp* app = variable_item_get_context(item);
     furi_assert(app);
     furi_assert(app);
     uint8_t index = variable_item_get_current_value_index(item);
     uint8_t index = variable_item_get_current_value_index(item);
-    char tmp[8];
-    snprintf(tmp, 7, "%3.4f", time_list[index]);
-    variable_item_set_current_value_text(item, tmp);
-    app->time = time_list[index];
+    variable_item_set_current_value_text(item, time_list[index].str);
+    app->time = time_list[index].time;
 }
 }
 
 
 void scope_scene_setup_on_enter(void* context) {
 void scope_scene_setup_on_enter(void* context) {
@@ -41,13 +31,10 @@ void scope_scene_setup_on_enter(void* context) {
         timeperiod_cb,
         timeperiod_cb,
         app);
         app);
 
 
-    char tmp[8];
-    snprintf(tmp, 7, "%3.4f", app->time);
-
     for (uint32_t i = 0; i < COUNT_OF(time_list); i++){
     for (uint32_t i = 0; i < COUNT_OF(time_list); i++){
-        if(time_list[i] == app->time){
+        if(time_list[i].time == app->time){
             variable_item_set_current_value_index(item, i);
             variable_item_set_current_value_index(item, i);
-            variable_item_set_current_value_text(item, tmp);
+            variable_item_set_current_value_text(item, time_list[i].str);
             break;
             break;
         }
         }
     }
     }

+ 13 - 0
scope_app_i.h

@@ -24,3 +24,16 @@ struct ScopeApp {
     double time ;
     double time ;
 };
 };
 
 
+typedef struct {
+    double time;
+    char * str;
+} timeperiod;
+
+static const timeperiod time_list[] = {
+    {1.0,  "1s"},
+    {0.1,  "0.1s"},
+    {1e-3, "1ms"},
+    {0.1e-3, "0.1ms"},
+    {1e-6, "1us"},
+    {0.5e-6, "0.5us"}
+};