neu-rah / ArduinoMenu

Arduino generic menu/interactivity system
GNU Lesser General Public License v2.1
951 stars 191 forks source link

encoderIn change direction first step problem #274

Closed HamidSaffari closed 4 years ago

HamidSaffari commented 4 years ago

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;
  }
neu-rah commented 4 years ago

Hi! Thanks want to make a pull request with that?