sinneb / pyo

Automatically exported from code.google.com/p/pyo
GNU General Public License v3.0
1 stars 0 forks source link

Counter does not behave as expected. #35

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. See attached c.py

What is the expected output? What do you see instead?
1.I expect the count to increment with the first trigger
2.I don't expect to see -1

What version of the product are you using? On what operating system?
Latest svn.

Please provide any additional information below.
I have attached my fix for this. Look for PJL comments

Original issue reported on code.google.com by PaulJohnLeonard on 14 Jun 2012 at 11:07

Attachments:

GoogleCodeExporter commented 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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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