From: poljar (Damir Jelić) Date: Tue, 14 Jan 2014 22:03:09 +0000 (+0100) Subject: demo: Add triangle pattern. X-Git-Tag: libsigrok-0.3.0~249 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=091c9621275fed7b0a418b644de46efec709d47b;p=libsigrok.git demo: Add triangle pattern. --- diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index 50bd50c8..0fc5011d 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -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; }