static void doGbr (int argc, char *argv []) { int channel ; if (argc != 3) { fprintf (stderr, "Usage: %s gbr <channel>\n", argv [0]) ; exit (1) ; } channel = atoi (argv [2]) ; if ((channel < 0) || (channel > 1)) { fprintf (stderr, "%s: channel must be 0 or 1\n", argv [0]) ; exit (1) ; } if (gertboardSPISetup () == -1) { fprintf (stderr, "Unable to initialise the Gertboard SPI interface: %s\n", strerror (errno)) ; exit (1) ; } printf ("%d\n",gertboardAnalogRead (channel)) ; }
static void sample (void) { unsigned int tFuture ; // Calculate the future sample time tFuture = tPeriod + tNextSampleTime ; // Wait until the next sample time while (micros () < tNextSampleTime) ; buffer [bPtr] = gertboardAnalogRead (0) ; tNextSampleTime = tFuture ; }