Skip to content

encoderIn change direction first step problem #274

@HamidSaffari

Description

@HamidSaffari

Hi, there.
I found small problem in your encoder stream read function routine which lead to encoder reading bug when changing direction. and that is don't executing until next step after changing direction which instead of one step now it execute two steps.
I resolve that by adding this in your read() function line 67:
if(d>0 && oldPos<=0){
d+=sensivity;
}else if (d<0 && oldPos>=0){
d-=sensivity;
}

so your entire read function become like this:

  int read() override {
    int d=enc.pos-oldPos;
	
	if(d>0 && oldPos<=0){
		d+=sensivity;
	}else if (d<0 && oldPos>=0){
		d-=sensivity;
	}
	
    if (d<=-sensivity) {
      oldPos-=sensivity;
      return options->navCodes[downCmd].ch;
    }
    if (d>=sensivity) {
      oldPos+=sensivity;
      return options->navCodes[upCmd].ch;
    }
    return -1;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions