Fixed 255/-256 encoder bug.

This commit is contained in:
Mark Smith 2020-01-11 11:15:47 -08:00
parent 228b5d9589
commit 858205b4cd
2 changed files with 4 additions and 13 deletions

View File

@ -635,7 +635,7 @@ int enc_read(void) {
/* /*
* SmittyHalibut's encoder handling, using interrupts. Should be quicker, smoother handling. * SmittyHalibut's encoder handling, using interrupts. Should be quicker, smoother handling.
*/ */
int enc_count; int8_t enc_count;
uint8_t prev_enc; uint8_t prev_enc;
uint8_t enc_state (void) { uint8_t enc_state (void) {
@ -699,18 +699,9 @@ ISR (PCINT1_vect) {
} }
int enc_read(void) { int enc_read(void) {
int ret = enc_count; int8_t ret = enc_count;
enc_count = 0; enc_count = 0;
if (ret == 255 || ret == -256) { return int(ret);
// FIXME I (@SmittyHalibut) can't figure out why we occasionally get
// either a 255 or -256 return value here. It's like it's occasionally
// treating an int as an unsigned value while incrementing or decrementing.
// I can't figure out why, but I can detect it and skip it. So that's
// what we're doing.
//Serial.println("255 error in encoder.");
return 0;
}
return ret;
} }

View File

@ -526,7 +526,7 @@ void doTuning(){
if (!s) if (!s)
return; return;
//Serial.print(s); //Serial.println(s);
doingCAT = 0; // go back to manual mode if you were doing CAT doingCAT = 0; // go back to manual mode if you were doing CAT
prev_freq = frequency; prev_freq = frequency;