Optimize for performance and percision

This commit is contained in:
Tomislav Kopić 2024-06-16 09:52:35 +02:00
parent e022c33a5c
commit 3eac4d03fa

View File

@ -34,7 +34,7 @@
// If game time is going faster than it should, increase this value by 1 to slow it down. // If game time is going faster than it should, increase this value by 1 to slow it down.
// fixed microsecond sleep between each cycle used to fine tune the emulator time drift even more // fixed microsecond sleep between each cycle used to fine tune the emulator time drift even more
#define FINE_TUNING_DELAY 22 #define FINE_TUNING_DELAY 16
// If game time is going faster than it should, increase this value // If game time is going faster than it should, increase this value
/**************************************************************************/ /**************************************************************************/
@ -380,37 +380,45 @@ void setup() {
uint32_t middle_long_press_started = 0; uint32_t middle_long_press_started = 0;
uint32_t right_long_press_started = 0; uint32_t right_long_press_started = 0;
bool is_display_off = false; bool is_display_off = false;
const uint32_t AUTO_SAVE_INTERVAL = AUTO_SAVE_MINUTES * 60 * 1000;
void loop() { void loop() {
tamalib_mainloop_step_by_step(); tamalib_mainloop_step_by_step();
unsigned long currentMillis = millis();
#ifdef AUTO_SAVE_MINUTES #ifdef AUTO_SAVE_MINUTES
if ((millis() - lastSaveTimestamp) > (AUTO_SAVE_MINUTES * 60 * 1000)) { if ((currentMillis - lastSaveTimestamp) > AUTO_SAVE_INTERVAL) {
lastSaveTimestamp = millis(); lastSaveTimestamp = currentMillis;
saveStateToEEPROM(&cpuState); saveStateToEEPROM(&cpuState);
} }
#endif #endif
if (digitalRead(PIN_BTN_M) == HIGH && digitalRead(PIN_BTN_L) == HIGH) {
if (millis() - middle_long_press_started > 2000) { bool middleLeftPressed = (digitalRead(PIN_BTN_M) == HIGH) && (digitalRead(PIN_BTN_L) == HIGH);
bool rightPressed = (digitalRead(PIN_BTN_R) == HIGH);
if (middleLeftPressed) {
if ((currentMillis - middle_long_press_started) > 2000) {
eraseStateFromEEPROM(); eraseStateFromEEPROM();
#if defined(ESP8266) || defined(ESP32) #if defined(ESP8266) || defined(ESP32)
ESP.restart(); ESP.restart();
#endif #endif
} }
} else {
middle_long_press_started = currentMillis;
} }
else {
middle_long_press_started = millis(); if (rightPressed) {
} if ((currentMillis - right_long_press_started) > 2000) {
if (digitalRead(PIN_BTN_R) == HIGH) { if (!is_display_off) {
if (millis() - right_long_press_started > 2000) {
display.sleepOn(); display.sleepOn();
is_display_off = true; is_display_off = true;
} }
else if (is_display_off) { } else if (is_display_off) {
display.sleepOff(); display.sleepOff();
is_display_off = false; is_display_off = false;
} }
} } else {
else { right_long_press_started = currentMillis;
right_long_press_started = millis();
} }
} }