From eb32f46ea3ca12e9215afe6cd0cd16056bcf9986 Mon Sep 17 00:00:00 2001 From: Oleksiy Date: Sat, 5 Aug 2023 23:04:11 +0300 Subject: [PATCH] Added screen rotation setting --- Software/Gravity/Gravity.ino | 22 ++++++++++++++++++---- Software/Gravity/Interactions.ino | 19 ++++++++++++++++++- Software/Gravity/UI.ino | 19 ++++++++++++++++++- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/Software/Gravity/Gravity.ino b/Software/Gravity/Gravity.ino index 0f92e83..2f1f8b0 100644 --- a/Software/Gravity/Gravity.ino +++ b/Software/Gravity/Gravity.ino @@ -12,7 +12,6 @@ #define PULSE_LENGTH 12 //ms (with 12 ms you can't get higher than 208bpm) #define MAXBPM 200 //250 at 24ppqn with 5ms pulse will be 50/50 square wave #define MINBPM 20 -#define SCREEN_TIMEOUT 600000 //Turn display off after 5 min // Rev 2 and 3 Config #define ENC_BTN_PIN 14 @@ -27,6 +26,7 @@ const byte outsPins[6] = { 7, 8, 10, 6, 9, 11 }; int CV1Calibration = 0; int CV2Calibration = 0; +bool rotateScreen = false; const int subDivs[17] = { -24, -12, -8, -6, -4, -3, -2, 1, 2, 3, 4, 5, 6, 7, 8, 16, 32 }; //positive - divide, negative - multiply, 0 - off @@ -75,7 +75,7 @@ byte currentStep = 0; byte stepNumSelected = 0; bool *patternToEdit; -byte memCode = 'a'; //Change to different letter if you changed the data structure +byte memCode = 'A'; //Change to different letter if you changed the data structure unsigned int channelPulseCount[6]; unsigned int channelPulsesPerCycle[6]; @@ -201,6 +201,8 @@ void setup() { EEPROM.get(addr, CV1Calibration); addr = addr + sizeof(CV1Calibration); EEPROM.get(addr, CV2Calibration); + addr = addr + sizeof(CV2Calibration); + EEPROM.get(addr, rotateScreen); } else { //calibrateCVs(); saveState(); @@ -211,10 +213,18 @@ void setup() { u8g2.begin(); + if (rotateScreen) { + u8g2.setDisplayRotation(U8G2_R0); + } else { + u8g2.setDisplayRotation(U8G2_R2); + } + 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(); } @@ -223,6 +233,8 @@ void loop() { checkInputs(); } +//void reset() { asm volatile ("jmp 0x7800"); } + void clock() { if (isPlaying) { @@ -498,9 +510,11 @@ void saveState() { EEPROM.put(addr, CV1Calibration); addr = addr + sizeof(CV1Calibration); EEPROM.put(addr, CV2Calibration); + addr = addr + sizeof(CV2Calibration); + EEPROM.put(addr, rotateScreen); } void calibrateCVs() { - CV1Calibration = 255 - (analogRead(ANALOGUE_INPUT_1_PIN) / 2); - CV2Calibration = 255 - (analogRead(ANALOGUE_INPUT_2_PIN) / 2); + CV1Calibration = 511 - analogRead(ANALOGUE_INPUT_1_PIN); + CV2Calibration = 511 - analogRead(ANALOGUE_INPUT_2_PIN); } \ No newline at end of file diff --git a/Software/Gravity/Interactions.ino b/Software/Gravity/Interactions.ino index 221772b..2470f45 100644 --- a/Software/Gravity/Interactions.ino +++ b/Software/Gravity/Interactions.ino @@ -52,6 +52,16 @@ void checkInputs() { isRecording = 1; } else if (displayScreen == 1 && isRecording) { isRecording = 0; + } else if (displayScreen == 2 && menuItem == 0) { + calibrateCVs(); + } else if (displayScreen == 2 && menuItem == 1) { + rotateScreen = !rotateScreen; + saveState(); + setup(); + } else if (displayScreen == 2 && menuItem == 2) { + EEPROM.put(1023, memCode - 1); + //delay(500); + //setup(); } updateScreen(); } else if (encReleasedTime - encPressedTime < 2000) { // longer press (<2s) is for navigating back. longer than 2s presses are ignored @@ -63,7 +73,7 @@ void checkInputs() { isRecording = 0; } updateScreen(); - } else if (encReleasedTime - encPressedTime > 2000 && shiftBtnPushed) { + } else if (encReleasedTime - encPressedTime > 2000 && shiftBtnPushed) { //2s+ combo with shift to open the settings displayScreen = 2; updateScreen(); } @@ -226,6 +236,13 @@ void checkInputs() { } else if (stepNumSelected > 15) { stepNumSelected = 0; } + } else if (displayScreen == 2 && !shiftBtnPushed) { + menuItem = menuItem + change; + if (menuItem > 100) { //for "negative" values + menuItem = 0; + } else if (menuItem > lastMenuItem) { + menuItem = lastMenuItem; + } } updateScreen(); diff --git a/Software/Gravity/UI.ino b/Software/Gravity/UI.ino index 77f6984..87a1dbf 100644 --- a/Software/Gravity/UI.ino +++ b/Software/Gravity/UI.ino @@ -232,7 +232,6 @@ void updateScreen() { } else { u8g2.drawButtonUTF8(96, 26, U8G2_BTN_BW0|U8G2_BTN_HCENTER, 56, 0, 0, valueChar ); } - } //Tabs @@ -316,6 +315,24 @@ void updateScreen() { //Settings Screen else if (displayScreen == 2) { u8g2.drawButtonUTF8(64, 5, U8G2_BTN_BW1|U8G2_BTN_HCENTER, 128, 0, 2, "SETTINGS" ); + lastMenuItem = 2; + byte menuItemWidth = 112; + if (menuItem == 0) { + u8g2.drawButtonUTF8(8, 18, U8G2_BTN_BW0|U8G2_BTN_INV, menuItemWidth, 2, 2, "CALIBRATE CV INS" ); + } else { + u8g2.drawButtonUTF8(8, 18, U8G2_BTN_BW0, menuItemWidth, 2, 2, "CALIBRATE CV INS" ); + } + if (menuItem == 1) { + u8g2.drawButtonUTF8(8, 32, U8G2_BTN_BW0|U8G2_BTN_INV, menuItemWidth, 2, 2, "ROTATE SCREEN" ); + } else { + u8g2.drawButtonUTF8(8, 32, U8G2_BTN_BW0, menuItemWidth, 2, 2, "ROTATE SCREEN" ); + } + if (menuItem == 2) { + u8g2.drawButtonUTF8(8, 46, U8G2_BTN_BW0|U8G2_BTN_INV, menuItemWidth, 2, 2, "FACTORY RESET" ); + } else { + u8g2.drawButtonUTF8(8, 46, U8G2_BTN_BW0, menuItemWidth, 2, 2, "FACTORY RESET" ); + } + } } while ( u8g2.nextPage() );