I’ve been reading the controller code in hopes of addressing a feedback performance issue I’ve been having, and I noticed something possibly performance-related in EncoderInputs::Read
which I’m ~80% sure is a bug.
I think it’s probably not causing my issue but it might be worth looking at. Forgive me if this is the intended behavior and I’m just missing something!
So encoders.ino
lines 237-265 handle the “priority system.” I think the idea is to avoid checking all encoder modules while one or two are being actively used. 237-240 handle the timeout and 241-265 pick which modules to read over SPI using digitalRead()
.
Here’s the logic in v0.13 (where priorityCount can only be 0, 1 or 2):
// The priority system adds to a priority list up to 2 modules to read if they are being used.
// If the list is empty, the first two modules that are detected to have a change are added to the list
// If the list is not empty, the only modules that are read via SPI are the ones that are on the priority list
if(priorityCount >= 1) {
// read the first priority module, if there is one
}
if(priorityCount == 2){
// read the second priority module, if there is one
}else{
// READ ALL MODULE'S STATE
for (int n = 0; n < nModules; n++){
// read the n-th module's state
}
}
Isn’t that reaching the third code block and therefore reading all modules when priorityCount==1
, including a second read of whatever the first priority module was? I suspect it was written this way to avoid repeating the first module read in the second module’s case, but to match the comment it seems like it should be:
if(priorityCount >= 1) {
// read pri #1
}
if(priorityCount == 2){
// read pri #2
}else if (priorityCount == 0){
// read all
}
Or you just flip the order and do:
if(priorityCount == 2) {
// read #2
}
if(priorityCount >= 1){
// read #1
}else{
// read all
}
Please forgive me if I’m misunderstanding the goal (or the code) here! Just thought I’d mention it.