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

index 50bd50c844856dde3d1215c2940e917e7372cbcd..0fc5011da0ec256194dc942a79f7576aade57b26 100644 (file)
@@ -78,6 +78,7 @@ enum {
         */
        PATTERN_SQUARE,
        PATTERN_SINE,
+       PATTERN_TRIANGLE,
 };
 
 static const char *logic_pattern_str[] = {
@@ -91,6 +92,7 @@ static const char *logic_pattern_str[] = {
 static const char *analog_pattern_str[] = {
        "square",
        "sine",
+       "triangle",
 };
 
 struct analog_gen {
@@ -216,6 +218,21 @@ static void generate_analog_pattern(const struct sr_probe_group *probe_group, ui
                                                sin(2 * M_PI * frequency * t);
                }
 
+               ag->num_samples = num_samples;
+               break;
+
+       case PATTERN_TRIANGLE:
+               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 / M_PI) *
+                                               asin(sin(2 * M_PI * frequency * t));
+               }
+
                ag->num_samples = num_samples;
                break;
        }