From fc622a1663edaf0b7d593891d3727e42dab219ff Mon Sep 17 00:00:00 2001 From: Oleksiy Date: Sun, 6 Aug 2023 00:18:31 +0300 Subject: [PATCH] Added "Factory Reset" --- Software/Gravity/Gravity.ino | 145 ++++++++++++++++-------------- Software/Gravity/Interactions.ino | 7 +- 2 files changed, 80 insertions(+), 72 deletions(-) diff --git a/Software/Gravity/Gravity.ino b/Software/Gravity/Gravity.ino index 2f1f8b0..8dae3e6 100644 --- a/Software/Gravity/Gravity.ino +++ b/Software/Gravity/Gravity.ino @@ -3,6 +3,7 @@ #include #include #include +#include #define VERSION "0.9b" @@ -141,7 +142,7 @@ const uint8_t velvetscreen[437] U8G2_FONT_SECTION("velvetscreen") = void setup() { - Serial.begin(9600); + //Serial.begin(9600); pinMode(ENC_BTN_PIN, INPUT_PULLUP); pinMode(START_STOP_BTN_PIN, INPUT_PULLUP); @@ -153,78 +154,15 @@ void setup() { pinMode(outsPins[i], OUTPUT); } - //check last bit in eeprom to know if the correct settings were stored - if (EEPROM.read(1023) == memCode) { - int addr = 0; - EEPROM.get(addr, bpm); - addr = addr + sizeof(bpm); - EEPROM.get(addr, bpmModulationChannel); - addr = addr + sizeof(bpmModulationChannel); - EEPROM.get(addr, bpmModulationRange); - addr = addr + sizeof(bpmModulationRange); - EEPROM.get(addr, masterClockMode); - addr = addr + sizeof(masterClockMode); - EEPROM.get(addr, channels); - addr = addr + sizeof(channels); - EEPROM.get(addr, seqA1); - addr = addr + sizeof(seqA1); - EEPROM.get(addr, seqA2); - addr = addr + sizeof(seqA2); - EEPROM.get(addr, seqA3); - addr = addr + sizeof(seqA3); - EEPROM.get(addr, seqA4); - addr = addr + sizeof(seqA4); - EEPROM.get(addr, seqA5); - addr = addr + sizeof(seqA5); - EEPROM.get(addr, seqA6); - addr = addr + sizeof(seqA6); - EEPROM.get(addr, seqA7); - addr = addr + sizeof(seqA7); - EEPROM.get(addr, seqA8); - addr = addr + sizeof(seqA8); - EEPROM.get(addr, seqB1); - addr = addr + sizeof(seqB1); - EEPROM.get(addr, seqB2); - addr = addr + sizeof(seqB2); - EEPROM.get(addr, seqB3); - addr = addr + sizeof(seqB3); - EEPROM.get(addr, seqB4); - addr = addr + sizeof(seqB4); - EEPROM.get(addr, seqB5); - addr = addr + sizeof(seqB5); - EEPROM.get(addr, seqB6); - addr = addr + sizeof(seqB6); - EEPROM.get(addr, seqB7); - addr = addr + sizeof(seqB7); - EEPROM.get(addr, seqB8); - addr = addr + sizeof(seqB8); - EEPROM.get(addr, CV1Calibration); - addr = addr + sizeof(CV1Calibration); - EEPROM.get(addr, CV2Calibration); - addr = addr + sizeof(CV2Calibration); - EEPROM.get(addr, rotateScreen); - } else { - //calibrateCVs(); - saveState(); - EEPROM.write(1023, memCode); - } - - //calibrateCVs(); //Just for the testing + loadState(); u8g2.begin(); - - if (rotateScreen) { - u8g2.setDisplayRotation(U8G2_R0); - } else { - u8g2.setDisplayRotation(U8G2_R2); - } - + checkScreenRotation(); updateScreen(); + calculateCycles(); calculateBPMTiming(); - displayScreen = 0; - FlexiTimer2::set(1, 1.0 / 1000, clock); // 1.0/1000 = 1ms period. If other than 1ms calculateBPMTiming() might need tweaking FlexiTimer2::start(); } @@ -233,8 +171,6 @@ void loop() { checkInputs(); } -//void reset() { asm volatile ("jmp 0x7800"); } - void clock() { if (isPlaying) { @@ -514,7 +450,78 @@ void saveState() { EEPROM.put(addr, rotateScreen); } +void loadState() { + //check last bit in eeprom to know if the correct settings were stored + if (EEPROM.read(1023) == memCode) { + int addr = 0; + EEPROM.get(addr, bpm); + addr = addr + sizeof(bpm); + EEPROM.get(addr, bpmModulationChannel); + addr = addr + sizeof(bpmModulationChannel); + EEPROM.get(addr, bpmModulationRange); + addr = addr + sizeof(bpmModulationRange); + EEPROM.get(addr, masterClockMode); + addr = addr + sizeof(masterClockMode); + EEPROM.get(addr, channels); + addr = addr + sizeof(channels); + EEPROM.get(addr, seqA1); + addr = addr + sizeof(seqA1); + EEPROM.get(addr, seqA2); + addr = addr + sizeof(seqA2); + EEPROM.get(addr, seqA3); + addr = addr + sizeof(seqA3); + EEPROM.get(addr, seqA4); + addr = addr + sizeof(seqA4); + EEPROM.get(addr, seqA5); + addr = addr + sizeof(seqA5); + EEPROM.get(addr, seqA6); + addr = addr + sizeof(seqA6); + EEPROM.get(addr, seqA7); + addr = addr + sizeof(seqA7); + EEPROM.get(addr, seqA8); + addr = addr + sizeof(seqA8); + EEPROM.get(addr, seqB1); + addr = addr + sizeof(seqB1); + EEPROM.get(addr, seqB2); + addr = addr + sizeof(seqB2); + EEPROM.get(addr, seqB3); + addr = addr + sizeof(seqB3); + EEPROM.get(addr, seqB4); + addr = addr + sizeof(seqB4); + EEPROM.get(addr, seqB5); + addr = addr + sizeof(seqB5); + EEPROM.get(addr, seqB6); + addr = addr + sizeof(seqB6); + EEPROM.get(addr, seqB7); + addr = addr + sizeof(seqB7); + EEPROM.get(addr, seqB8); + addr = addr + sizeof(seqB8); + EEPROM.get(addr, CV1Calibration); + addr = addr + sizeof(CV1Calibration); + EEPROM.get(addr, CV2Calibration); + addr = addr + sizeof(CV2Calibration); + EEPROM.get(addr, rotateScreen); + } else { + //calibrateCVs(); + saveState(); + EEPROM.write(1023, memCode); + } +} + +void resetFunc() { + wdt_enable(WDTO_15MS); // 8 ms watchdog + while(true); // infinite loop without feeding the dog, should reset in 8ms +} + void calibrateCVs() { CV1Calibration = 511 - analogRead(ANALOGUE_INPUT_1_PIN); CV2Calibration = 511 - analogRead(ANALOGUE_INPUT_2_PIN); +} + +void checkScreenRotation() { + if (rotateScreen) { + u8g2.setDisplayRotation(U8G2_R0); + } else { + u8g2.setDisplayRotation(U8G2_R2); + } } \ No newline at end of file diff --git a/Software/Gravity/Interactions.ino b/Software/Gravity/Interactions.ino index 2470f45..e3df7e9 100644 --- a/Software/Gravity/Interactions.ino +++ b/Software/Gravity/Interactions.ino @@ -57,11 +57,12 @@ void checkInputs() { } else if (displayScreen == 2 && menuItem == 1) { rotateScreen = !rotateScreen; saveState(); - setup(); + checkScreenRotation(); + //setup(); + //resetFunc(); } else if (displayScreen == 2 && menuItem == 2) { EEPROM.put(1023, memCode - 1); - //delay(500); - //setup(); + resetFunc(); } updateScreen(); } else if (encReleasedTime - encPressedTime < 2000) { // longer press (<2s) is for navigating back. longer than 2s presses are ignored