Closed GoogleCodeExporter closed 9 years ago
Ooops should have checked my code. I think this is OK
static void
Counter_generates(Counter *self) {
int i;
MYFLT *in = Stream_getData((Stream *)self->input_stream);
for (i=0; i<self->bufsize; i++) {
if (in[i] == 1) {
if (self->dir == 0) {
self->tmp++;
if (self->tmp >= self->max)
self->tmp = self->min;
self->value = (MYFLT)self->tmp; // PJL
}
else if (self->dir == 1) {
self->tmp--;
if (self->tmp < self->min)
self->tmp = self->max - 1;
self->value = (MYFLT)self->tmp; // PJL
}
else if (self->dir == 2) {
self->tmp = self->tmp + self->direction;
if (self->tmp >= self->max) {
self->direction = -1;
self->tmp = self->max-2; //PJL
}
else if (self->tmp < self->min) {
self->direction = 1;
self->tmp=self->min+1; //PJL
}
self->value = (MYFLT)self->tmp; // PJL
}
}
self->data[i] = self->value;
}
}
Original comment by PaulJohnLeonard
on 14 Jun 2012 at 12:19
Fixed in sources. That was a special case when dir = 2 AND count range = 2...
With your fix, you're always missing the first count. The missing count print
in your example is caused by the minimum set to 0 (same as buffer
initialization value) and the Print method set to 1 (print only on new value).
Original comment by belan...@gmail.com
on 14 Jun 2012 at 1:03
I am a bit confused.
My expectation was that the first trigger should change the state from 0 to 1.
With your version I have to send 2 triggers is this what you want?
Original comment by PaulJohnLeonard
on 14 Jun 2012 at 1:30
I just looked at the reset(value) to see if I can get what I want this way but
it appears that it would take 2 triggers to change the counters value after a
reset()? To make it do what I want I would need to inject an additional trigger
just after creation. I think intuitively I would expect the counter to start at
it's minimum value (or maximum if it was a down counter). I would then expect
it to change on every trigger. If I understand correctly at present the
counter starts with 0 even if that is not in the counters range ?
Original comment by PaulJohnLeonard
on 14 Jun 2012 at 2:11
Original issue reported on code.google.com by
PaulJohnLeonard
on 14 Jun 2012 at 11:07Attachments: