Hmm, it's difficult. When I did it, I'd assumed that my particular encoder was non-standard in that it effectively jumped two positions for each 'click', but I haven't yet seen an encoder that doesn't do that :)
Of course my problem is that the module is now in use by people, who presumably have worked around that behaviour.
I think it's probably correct to change it though - and hopefully users can just remove the /2 from their code. Or maybe instead of returning +1 and -1 it could actually return +2 and -2? It might then work fine for everyone?
Your code looks great! I just tried it on an encoder here, and it still calls the callback twice for each 'click'. Is that the same for you?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hmm, it's difficult. When I did it, I'd assumed that my particular encoder was non-standard in that it effectively jumped two positions for each 'click', but I haven't yet seen an encoder that doesn't do that :)
Of course my problem is that the module is now in use by people, who presumably have worked around that behaviour.
I think it's probably correct to change it though - and hopefully users can just remove the
/2
from their code. Or maybe instead of returning+1
and-1
it could actually return+2
and-2
? It might then work fine for everyone?Your code looks great! I just tried it on an encoder here, and it still calls the callback twice for each 'click'. Is that the same for you?
The old one called it 4 times though!