]> sigrok.org Git - libsigrok.git/commitdiff
link-mso19: Refactor mso_limit_trigger_level to mso_set_trigger_level
authorPaul Kasemir <redacted>
Mon, 12 Dec 2022 18:54:25 +0000 (11:54 -0700)
committerSoeren Apel <redacted>
Wed, 16 Oct 2024 22:10:19 +0000 (00:10 +0200)
Function acts as a setter now, instead of updating devc based on
existing settings.

Min and max limits are now easier to understand.

src/hardware/link-mso19/api.c

index 2a70adb3e8b7276792a4f54889a2892f05f5b5ad..afb9003cb4db516d86d5ad3e3b24ebf9e2fce0ac 100644 (file)
@@ -139,23 +139,26 @@ static void mso_update_trigger_slope(struct dev_context *devc)
        }
 }
 
-static void mso_limit_trigger_level(struct dev_context *devc)
+static void mso_set_trigger_level(struct dev_context *devc,
+               double trigger_level)
 {
-       double max_level = 2.0 * devc->dso_probe_factor;
-       double min_level = -max_level;
-       max_level -= devc->dso_offset_adjusted;
-       min_level -= devc->dso_offset_adjusted;
+       double voltage_range, max_level, min_level;
 
-       if (devc->dso_trigger_level < min_level) {
+       voltage_range = 2.0 * devc->dso_probe_factor;
+       max_level = voltage_range - devc->dso_offset_adjusted;
+       min_level = -voltage_range - devc->dso_offset_adjusted;
+
+       devc->dso_trigger_level = trigger_level;
+
+       if (trigger_level < min_level)
                devc->dso_trigger_adjusted = min_level;
-       } else if (devc->dso_trigger_level > max_level) {
+       else if (trigger_level > max_level)
                devc->dso_trigger_adjusted = max_level;
-       } else if (devc->dso_trigger_level != devc->dso_trigger_adjusted){
-               devc->dso_trigger_adjusted = devc->dso_trigger_level;
-       } else {
-               return;
-       }
-       sr_info("Adjusted dso trigger level to %f", devc->dso_trigger_adjusted);
+       else
+               devc->dso_trigger_adjusted = trigger_level;
+
+       if (trigger_level != devc->dso_trigger_adjusted)
+               sr_info("Adjusted dso trigger level to %f", devc->dso_trigger_adjusted);
 }
 
 static void mso_set_trigger_pos(struct dev_context *devc, double trigger_pos)
@@ -203,7 +206,8 @@ static void mso_set_offset_value(struct dev_context *devc, double offset)
        if (limited_value != scaled_value) {
                sr_info("Adjusted dso offset to %f", devc->dso_offset_adjusted);
        }
-       mso_limit_trigger_level(devc);
+       /* offset affects trigger level, so recalculate */
+       mso_set_trigger_level(devc, devc->dso_trigger_level);
 
 }
 
@@ -486,8 +490,7 @@ static int config_set(uint32_t key, GVariant *data,
        case SR_CONF_TRIGGER_LEVEL:
                if (!CG_IS_ANALOG(cg))
                        return SR_ERR_ARG;
-               devc->dso_trigger_level = g_variant_get_double(data);
-               mso_limit_trigger_level(devc);
+               mso_set_trigger_level(devc, g_variant_get_double(data));
                break;
        case SR_CONF_OFFSET:
                if (!CG_IS_ANALOG(cg))