From 07e2bd50c9c922ac2a8c8065dd15500e453a10cc Mon Sep 17 00:00:00 2001 From: Jeremie GABOLDE Date: Tue, 20 Sep 2022 23:20:50 +0200 Subject: [PATCH] made each preset unique and added animations --- Maybe/Maybe.ino | 88 ++++++++++++++++++++++++++++++++++++++-------- Maybe/animations.h | 88 ++++++++++++++++++++++++++++++++++++++++++++++ Maybe/modeAction.h | 67 +++++++++++++++++------------------ 3 files changed, 194 insertions(+), 49 deletions(-) diff --git a/Maybe/Maybe.ino b/Maybe/Maybe.ino index 6804944..707e3f0 100644 --- a/Maybe/Maybe.ino +++ b/Maybe/Maybe.ino @@ -60,11 +60,11 @@ SevSeg sevseg; /* * key button matrix */ -//#include #include const byte rows = 4; //four rows const byte cols = 3; //three columns +//Hardware inputs ordered from the bottom left = 1 to the top right = 12 on the switch matrix, char keys[rows][cols] = { // assiging arbitraty uid to each button {9,5,1}, {10,6,2}, @@ -94,10 +94,13 @@ const int BUTTON_Rotary = 4; /* * custom display animations */ -//#include "animations.h" +#include "animations.h" -//int animationFrame = 0; -//bool animationLooping = true; +int animationFrame = 0; +bool animationPlaying = false; +unsigned int animationLastFrameMillis = 0; +unsigned int animationFrameDelayMillis = 64; +bool animationLooping = false; /* * time cooldown managment @@ -156,6 +159,8 @@ unsigned int sevSegCoolDown = 5000; Serial.println("setup complete"); + playAnimation(0); + } /* @@ -163,6 +168,13 @@ unsigned int sevSegCoolDown = 5000; */ void loop() { + //animation draw tick + if (animationPlaying && millis() > (animationLastFrameMillis + animationFrameDelayMillis)) + { + drawAnimation(animationLooping); + animationLastFrameMillis = millis(); + } + //INPUTS if (millis() > lastInputMillis + inputCoolDown) { @@ -197,7 +209,7 @@ void loop() //clear screen after no input delay if (millis() > lastInputMillis + sevSegCoolDown) { - sevseg.blank(); + //sevseg.blank(); } sevseg.refreshDisplay(); @@ -386,32 +398,50 @@ MemSlot* getMemorySlot(String memSlotName) void sendInputOuput(int input) { + + if (isInMenu) + { + animationPlaying = false; + } + else + { + //sevseg.setNumber(input, -1); + playAnimation(1); + } + lastInputMillis = millis(); - sevseg.setNumber(input, -1); - int mode = (getMemorySlot("prst")->value) % (sizeof(modes)/(sizeof(Action)*15)); - Action actionToRun = modes[mode][input-1]; - if (actionToRun.keyID == -1) //menu + + int numberOfModes = sizeof(modes)/(sizeof(Action)*15); + + int currentMode = (getMemorySlot("prst")->value) % numberOfModes; + //Hardware inputs ordered from the bottom left = 1 to the top right = 12 on the switch matrix, + Action actionToRun = modes[currentMode][input-1]; //getting the virtual inputs from the modes array. + //Inputs uids starts with 1, so input - 1 to get the index 0 of the array + + if (actionToRun.keyID == -1) //menu input, input mapping can be changed in modeAction.h { if (isInMenu) { menuBack(); + playAnimation(3); } else { isInMenu = true; - sevseg.blank(); + sevseg.blank(); // clear display + playAnimation(2); printMenu(); } } - else if (isInMenu && input == 13) //menu prev + else if (isInMenu && input == 13) //menu prev, hardcoded input { menuPrev(); } - else if (isInMenu && input == 14) //menu next + else if (isInMenu && input == 14) //menu next, hardcoded input { menuNext(); } - else if (isInMenu && input == 15) //menu enter + else if (isInMenu && input == 15) //menu enter, hardcoded input { menuEnter(); } @@ -419,13 +449,41 @@ void sendInputOuput(int input) { clickKey(actionToRun.keyID, actionToRun.keyModifierID); } + } void clickKey(int key, int modifier) { - if (modifier != -1) Keyboard.set_modifier(modifier); + Keyboard.set_modifier(modifier); Keyboard.press(key); Keyboard.release(key); Keyboard.set_modifier(0); - Keyboard.send_now(); + //Keyboard.send_now(); //can't remember what's that's for +} + +void playAnimation(int animID) +{ + currentAnimationID = animID; + animationFrame = 0; + animationPlaying = true; +} + +void drawAnimation(bool looping) +{ + int currentAnimationFrameTotal = animData[currentAnimationID].animationFrameCount; + sevseg.setSegments(animData[currentAnimationID].animationPtr + (animationFrame * (sizeof(const uint8_t)*4))); + animationFrame++; + if (animationFrame == currentAnimationFrameTotal) + { + animationFrame = 0; + if (!looping) + { + animationPlaying = false; + sevseg.blank(); + if (isInMenu) //not great + { + printMenu(); + } + } + } } diff --git a/Maybe/animations.h b/Maybe/animations.h index 8b13789..99b9284 100644 --- a/Maybe/animations.h +++ b/Maybe/animations.h @@ -1 +1,89 @@ +int currentAnimationID = 0; +struct AnimationData +{ + const uint8_t *animationPtr; + unsigned int animationFrameCount; +}; + +//animations created using https://jasonacox.github.io/TM1637TinyDisplay/examples/7-segment-animator.html + +/* Animation Data - HGFEDCBA Map */ +const uint8_t ANIMATION1[31][4] = { + { 0x00, 0x00, 0x00, 0x01 }, // Frame 0 + { 0x00, 0x00, 0x01, 0x00 }, // Frame 1 + { 0x00, 0x01, 0x00, 0x00 }, // Frame 2 + { 0x01, 0x00, 0x00, 0x00 }, // Frame 3 + { 0x20, 0x00, 0x00, 0x00 }, // Frame 4 + { 0x10, 0x00, 0x00, 0x00 }, // Frame 5 + { 0x08, 0x00, 0x00, 0x00 }, // Frame 6 + { 0x00, 0x08, 0x00, 0x00 }, // Frame 7 + { 0x00, 0x00, 0x08, 0x00 }, // Frame 8 + { 0x00, 0x00, 0x00, 0x08 }, // Frame 9 + { 0x00, 0x00, 0x00, 0x04 }, // Frame 10 + { 0x00, 0x00, 0x00, 0x02 }, // Frame 11 + { 0x00, 0x00, 0x01, 0x01 }, // Frame 12 + { 0x01, 0x01, 0x00, 0x00 }, // Frame 13 + { 0x30, 0x00, 0x00, 0x00 }, // Frame 14 + { 0x08, 0x08, 0x00, 0x00 }, // Frame 15 + { 0x00, 0x00, 0x08, 0x08 }, // Frame 16 + { 0x00, 0x00, 0x00, 0x06 }, // Frame 17 + { 0x00, 0x01, 0x01, 0x01 }, // Frame 18 + { 0x31, 0x00, 0x00, 0x00 }, // Frame 19 + { 0x08, 0x08, 0x08, 0x00 }, // Frame 20 + { 0x00, 0x00, 0x00, 0x0e }, // Frame 21 + { 0x01, 0x01, 0x01, 0x01 }, // Frame 22 + { 0x38, 0x08, 0x00, 0x00 }, // Frame 23 + { 0x00, 0x00, 0x08, 0x0e }, // Frame 24 + { 0x31, 0x01, 0x01, 0x01 }, // Frame 25 + { 0x08, 0x08, 0x08, 0x0e }, // Frame 26 + { 0x39, 0x09, 0x09, 0x0f }, // Frame 27 + { 0x46, 0x76, 0x76, 0x70 }, // Frame 28 + { 0x40, 0x40, 0x40, 0x40 }, // Frame 29 + { 0x00, 0x40, 0x40, 0x00 } // Frame 30 +}; + +/* Animation Data - HGFEDCBA Map */ +const uint8_t ANIMATION2[][4] = { + { 0x00, 0x40, 0x40, 0x00 }, // Frame 0 + { 0x00, 0x40, 0x40, 0x00 }, // Frame 0 + { 0x00, 0x49, 0x49, 0x00 }, // Frame 1 + { 0x40, 0x49, 0x49, 0x40 }, // Frame 2 + { 0x40, 0x09, 0x09, 0x40 }, // Frame 3 + { 0x09, 0x00, 0x00, 0x09 }, // Frame 4 +}; + +/* Animation Data - HGFEDCBA Map */ +const uint8_t ANIMATION3[][4] = { + { 0x00, 0x40, 0x40, 0x00 }, // Frame 0 + { 0x40, 0x40, 0x40, 0x40 }, // Frame 1 + { 0x40, 0x09, 0x09, 0x40 }, // Frame 2 + { 0x09, 0x09, 0x09, 0x09 }, // Frame 3 + { 0x09, 0x00, 0x00, 0x09 }, // Frame 4 + { 0x00, 0x00, 0x00, 0x00 }, // Frame 5 + { 0x39, 0x3f, 0x37, 0x71 }, + { 0x39, 0x3f, 0x37, 0x71 }, + { 0x39, 0x3f, 0x37, 0x71 }, + { 0x39, 0x3f, 0x37, 0x71 }, + { 0x39, 0x3f, 0x37, 0x71 }, + { 0x39, 0x3f, 0x37, 0x71 }, + { 0x00, 0x00, 0x00, 0x00 }, +}; + +/* Animation Data - HGFEDCBA Map */ +const uint8_t ANIMATION4[][4] = { + { 0x09, 0x00, 0x00, 0x09 }, // Frame 0 + { 0x09, 0x09, 0x09, 0x09 }, // Frame 1 + { 0x40, 0x09, 0x09, 0x40 }, // Frame 2 + { 0x40, 0x40, 0x40, 0x40 }, // Frame 3 + { 0x00, 0x40, 0x40, 0x00 }, // Frame 4 + { 0x00, 0x00, 0x00, 0x00 }, // Frame 5 +}; + +AnimationData animData[] = +{ + {(const uint8_t*)ANIMATION1, sizeof(ANIMATION1) / (sizeof(const uint8_t)*4)}, + {(const uint8_t*)ANIMATION2, sizeof(ANIMATION2) / (sizeof(const uint8_t)*4)}, + {(const uint8_t*)ANIMATION3, sizeof(ANIMATION3) / (sizeof(const uint8_t)*4)}, + {(const uint8_t*)ANIMATION4, sizeof(ANIMATION4) / (sizeof(const uint8_t)*4)} +}; diff --git a/Maybe/modeAction.h b/Maybe/modeAction.h index d9fda83..1ae1a56 100644 --- a/Maybe/modeAction.h +++ b/Maybe/modeAction.h @@ -1,46 +1,45 @@ -#include - struct Action { - int keyID; + int keyID; int keyModifierID; }; +//Hardware buttons and Actions are ordered from the bottom left to the top right matrix. Rotary encoder: left, right then press Action modes[][15] = { { - {KEY_MEDIA_PREV_TRACK, -1}, - {KEY_MEDIA_PLAY_PAUSE, -1}, - {KEY_MEDIA_NEXT_TRACK, -1}, - {KEY_F16, -1}, - {KEY_F17, -1}, - {KEY_F18, -1}, - {KEY_F19, -1}, - {KEY_F20, -1}, - {KEY_F21, -1}, - {KEY_F22, -1}, - {KEY_F23, -1}, - {-1, -1}, //menu - {KEY_MEDIA_VOLUME_DEC, -1}, - {KEY_MEDIA_VOLUME_INC, -1}, - {KEY_MEDIA_MUTE, -1} + {KEY_MEDIA_PREV_TRACK, 0}, + {KEY_MEDIA_PLAY_PAUSE, 0}, + {KEY_MEDIA_NEXT_TRACK, 0}, + {KEY_F16, 0}, + {KEY_F17, 0}, + {KEY_F18, 0}, + {KEY_F19, 0}, + {KEY_F20, 0}, + {KEY_F21, 0}, + {KEY_F22, 0}, + {KEY_F23, 0}, + {-1, 0}, //menu / back + {KEY_MEDIA_VOLUME_DEC, 0}, + {KEY_MEDIA_VOLUME_INC, 0}, + {KEY_MEDIA_MUTE, 0} }, { - {KEY_F13, -1}, - {KEY_F14, -1}, - {KEY_F15, -1}, - {KEY_F16, -1}, - {KEY_F17, -1}, - {KEY_F18, -1}, - {KEY_F19, -1}, - {KEY_F20, -1}, - {KEY_F21, -1}, - {KEY_F22, -1}, - {KEY_F23, -1}, - {-1, -1}, //menu - {KEYPAD_MINUS, -1}, - {KEYPAD_PLUS, -1}, - {KEYPAD_ENTER, -1} + {KEY_F13, MODIFIERKEY_SHIFT}, + {KEY_F14, MODIFIERKEY_SHIFT}, + {KEY_F15, MODIFIERKEY_SHIFT}, + {KEY_F16, MODIFIERKEY_SHIFT}, + {KEY_F17, MODIFIERKEY_SHIFT}, + {KEY_F18, MODIFIERKEY_SHIFT}, + {KEY_F19, MODIFIERKEY_SHIFT}, + {KEY_F20, MODIFIERKEY_SHIFT}, + {KEY_F21, MODIFIERKEY_SHIFT}, + {KEY_F22, MODIFIERKEY_SHIFT}, + {KEY_F23, MODIFIERKEY_SHIFT}, + {-1, 0}, //menu / back + {KEYPAD_MINUS, 0}, + {KEYPAD_PLUS, 0}, + {KEYPAD_ENTER, 0} }, { {KEY_F13, MODIFIERKEY_CTRL}, @@ -54,7 +53,7 @@ Action modes[][15] = {KEY_F21, MODIFIERKEY_CTRL}, {KEY_F22, MODIFIERKEY_CTRL}, {KEY_F23, MODIFIERKEY_CTRL}, - {-1, -1}, //menu + {-1, 0}, //menu / back {KEYPAD_MINUS, MODIFIERKEY_CTRL}, {KEYPAD_PLUS, MODIFIERKEY_CTRL}, {KEYPAD_ENTER, MODIFIERKEY_CTRL}