From 8038e90aefdbddd68a9775aea4f588bdd89894fe Mon Sep 17 00:00:00 2001 From: Daniel Ribeiro Date: Fri, 21 Jan 2011 12:52:12 -0200 Subject: [PATCH] add a sine wave to demo.c --- hardware/demo/demo.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index c18161f0..e117e6a5 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -19,12 +19,13 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -//#define DEMO_ANALOG +#define DEMO_ANALOG #include #include #include #include +#include #ifdef _WIN32 #include #include @@ -49,6 +50,7 @@ enum { GENMODE_DEFAULT, GENMODE_RANDOM, GENMODE_INC, + GENMODE_SINE, }; GIOChannel *channels[2]; @@ -74,6 +76,7 @@ static int capabilities[] = { static const char *patternmodes[] = { "random", "incremental", + "sine", NULL, }; @@ -206,6 +209,9 @@ static int hw_set_configuration(int device_index, int capability, void *value) } else if (!strcmp(stropt, "incremental")) { default_genmode = GENMODE_INC; ret = SIGROK_OK; + } else if (!strcmp(stropt, "sine")) { + default_genmode = GENMODE_SINE; + ret = SIGROK_OK; } else { ret = SIGROK_ERR; } @@ -235,6 +241,13 @@ static void samples_generator(uint8_t *buf, uint64_t size, void *data) switch (mydata->sample_generator) { default: case GENMODE_DEFAULT: + case GENMODE_SINE: + for (i = 0; i < size * 3; i += 3) { + *(buf + i) = i / 3; + *(uint16_t *) (buf + i + 1) = + (uint16_t) (sin(i / 3) * 256 * 30); + } + break; case GENMODE_RANDOM: for (i = 0; i < size * 3; i += 3) { *(buf + i) = (uint8_t)(rand() & 0xff);