Introduce StateManager to persist state between power cycles (#6)

- add reset state menu option to return all settings back to default values.
- add reverse encoder menu option and save state
- make saving to EEPROM safer by wrapping put calls with noInterrupts()
- improve save state behavior by using a mutex flag and update check with debounce in main loop
- refactor gravity.h global const definitions to be static and more readable.
- improve usage of EncoderDir in ISR with pointer to instance and static isr() method.
- reduce u8g2 memory usage by using single page buffer

Reviewed-on: https://git.pinkduck.xyz/adam/libGravity/pulls/6
Co-authored-by: Adam Wonak <adam.wonak@gmail.com>
Co-committed-by: Adam Wonak <adam.wonak@gmail.com>
This commit is contained in:
2025-06-16 02:47:25 +00:00
committed by adam
parent 07ed4b3d9a
commit d12764313b
10 changed files with 378 additions and 105 deletions

View File

@ -11,6 +11,10 @@
#include "gravity.h"
// Initialize the static pointer for the EncoderDir class to null. We want to
// have a static pointer to decouple the ISR from the global gravity object.
EncoderDir* EncoderDir::_instance = nullptr;
void Gravity::Init() {
initClock();
initInputs();
@ -68,18 +72,13 @@ void Gravity::Process() {
}
}
void ReadEncoder() {
gravity.encoder.UpdateEncoder();
}
// Define Encoder pin ISR.
// Pin Change Interrupt on Port C (D17/A3).
ISR(PCINT2_vect) {
ReadEncoder();
};
// Pin Change Interrupt on Port D (D4).
ISR(PCINT2_vect) {
EncoderDir::isr();
};
// Pin Change Interrupt on Port C (D17/A3).
ISR(PCINT1_vect) {
ReadEncoder();
EncoderDir::isr();
};
// Singleton