joeycastillo / Sensor-Watch

A board replacement for the classic Casio F-91W wristwatch
Other
1.17k stars 233 forks source link

finetune: Prevent fc overflow #304

Open howey opened 11 months ago

howey commented 11 months ago

fc is a int16, check limits before setting.

I have a watch with a really bad oscillator, and setting with finetune will actually go beyond int16 and roll over to negative. I was confused for a while until I finally realized the problem. Added a check in finetune to prevent this from happening. I believe my watch has too big of an error for FREQCORR to correct, but that is another issue.

matheusmoreira commented 7 months ago

Possible solution: get the compiler to do this for us by using integer overflow builtins.