]> sigrok.org Git - libsigrok.git/commitdiff
demo: Add analog sawtooth pattern.
authorpoljar (Damir Jelić) <redacted>
Tue, 14 Jan 2014 22:03:10 +0000 (23:03 +0100)
committerBert Vermeulen <redacted>
Fri, 17 Jan 2014 13:30:28 +0000 (14:30 +0100)
hardware/demo/demo.c

index 0fc5011da0ec256194dc942a79f7576aade57b26..cf82630adfca221cd73be987e85a611f3c2da439 100644 (file)
@@ -79,6 +79,7 @@ enum {
        PATTERN_SQUARE,
        PATTERN_SINE,
        PATTERN_TRIANGLE,
+       PATTERN_SAWTOOTH,
 };
 
 static const char *logic_pattern_str[] = {
@@ -93,6 +94,7 @@ static const char *analog_pattern_str[] = {
        "square",
        "sine",
        "triangle",
+       "sawtooth",
 };
 
 struct analog_gen {
@@ -233,6 +235,21 @@ static void generate_analog_pattern(const struct sr_probe_group *probe_group, ui
                                                asin(sin(2 * M_PI * frequency * t));
                }
 
+               ag->num_samples = num_samples;
+               break;
+
+       case PATTERN_SAWTOOTH:
+               frequency = sample_rate / ANALOG_SAMPLES_PER_PERIOD;
+
+               while (num_samples % ANALOG_SAMPLES_PER_PERIOD != 0)
+                       num_samples--;
+
+               for (i = 0; i < num_samples; i++) {
+                       t = (double) i / (double) sample_rate;
+                       ag->pattern_data[i] = 2 * ANALOG_AMPLITUDE *
+                                               ((t * frequency) - floor(0.5f + t * frequency));
+               }
+
                ag->num_samples = num_samples;
                break;
        }