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:
19
gravity.cpp
19
gravity.cpp
@ -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
|
||||
|
||||
Reference in New Issue
Block a user