1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-11-25 17:43:44 +02:00

tools/antorcha.c (samples): move reading of X/Y samples to shared function

This commit is contained in:
Werner Almesberger 2012-06-23 14:25:08 -03:00
parent 18c7b43a59
commit 2f120fa683

View File

@ -280,6 +280,22 @@ static void image(struct atrf_dsc *dsc, const char *name)
/* ----- Samples ----------------------------------------------------------- */ /* ----- Samples ----------------------------------------------------------- */
static int read_sample(uint8_t **s, uint16_t *t_high, uint16_t *t_low,
uint16_t *last)
{
int v;
*t_low = *(*s)++;
*t_low |= *(*s)++ << 8;
if (*t_low < *last)
(*t_high)++;
*last = *t_low;
v = *(*s)++;
v |= *(*s)++ << 8;
return v;
}
static void samples(struct atrf_dsc *dsc) static void samples(struct atrf_dsc *dsc)
{ {
uint8_t buf[MAX_PSDU] = { 0, }; uint8_t buf[MAX_PSDU] = { 0, };
@ -311,26 +327,12 @@ static void samples(struct atrf_dsc *dsc)
t_high |= *s++ << 8; t_high |= *s++ << 8;
last = 0; last = 0;
while (s < buf+got-2) { while (s < buf+got-2) {
t_low = *s++; x = read_sample(&s, &t_high, &t_low, &last);
t_low |= *s++ << 8;
if (t_low < last)
t_high++;
last = t_low;
x = *s++;
x |= *s++ << 8;
if (debug) if (debug)
fprintf(stderr, "\t%11.6f %d", fprintf(stderr, "\t%11.6f %d",
(t_high << 16 | t_low)/1000000.0, x); (t_high << 16 | t_low)/1000000.0, x);
t_low = *s++; y = read_sample(&s, &t_high, &t_low, &last);
t_low |= *s++ << 8;
if (t_low < last)
t_high++;
last = t_low;
y = *s++;
y |= *s++ << 8;
if (debug) if (debug)
fprintf(stderr, "\t%11.6f %d\n", fprintf(stderr, "\t%11.6f %d\n",
(t_high << 16 | t_low)/1000000.0, y); (t_high << 16 | t_low)/1000000.0, y);