idle animation & toggle alternate mode

This commit is contained in:
2022-09-25 22:58:14 +02:00
parent 90e0f98b92
commit d49ca41c83
3 changed files with 74 additions and 36 deletions

View File

@@ -30,7 +30,7 @@ MemSlot memory[] = //128 bytes for the Teensy LC
{"bt10", 11, 0},
{"bt11", 12, 0},
{"bt12", 13, 0},
{"effc", 14, 1},
{"effc", 14, 2},
{"afps", 15, 24},
{"clea", 0, 0}, // != 0 -> reset eeprom
};
@@ -141,7 +141,7 @@ int animationFrame = 0;
bool animationPlaying = false;
unsigned int animationLastFrameMillis = 0;
unsigned int animationFrameDelayMillis = 64;
bool animationLooping = false;
bool animationIdle = false;
bool animationEnabled = true;
/*
@@ -225,25 +225,30 @@ void initSevSegDisplay()
void loop()
{
//animation draw tick
if (animationIdle && !animationPlaying && animationEnabled && !isInMenu)
{
playAnimation(4);
}
if (animationEnabled && animationPlaying && (millis() > (animationLastFrameMillis + animationFrameDelayMillis)))
{
drawAnimation(animationLooping);
drawAnimation();
animationLastFrameMillis = millis();
}
//INPUTS
if (millis() > lastInputMillis + inputCoolDown)
{
char customKey = keypad.getKey();
char customKey = keypad.getKey(); //-1 because our array stars with 1 instead of 0
if (customKey)
if (customKey > 0)
{
sendInputOuput(customKey);
sendInputOuput(customKey-1);
}
if (rotaryEncoder.push() == 1) // = pressed
{
sendInputOuput(15);
sendInputOuput(14);
}
rotaryEncoderState = rotaryEncoder.rotate();
@@ -252,12 +257,12 @@ void loop()
{
if ( rotaryEncoderState == 1 ) //Turned Clockwise
{
sendInputOuput(14);
sendInputOuput(13);
}
if ( rotaryEncoderState == 2 ) //Turned Counter-Clockwise
{
sendInputOuput(13);
sendInputOuput(12);
}
}
}
@@ -430,6 +435,7 @@ void applyMemoryChange()
{
animationEnabled = (getMemorySlot("effc")->value > 0);
animationFrameDelayMillis = 1000 / max(1, getMemorySlot("afps")->value);
animationIdle = (getMemorySlot("effc")->value == 2);
}
int menuGetSelectionIndexFromPath(String path)
@@ -467,15 +473,14 @@ MemSlot* getMemorySlot(String memSlotName)
void sendInputOuput(int input)
{
int numberOfModes = sizeof(modes)/(sizeof(Action)*15);
int currentMode = (getMemorySlot("alt")->value) % numberOfModes;
//get current presetID
int currentPreset = (getMemorySlot("alt")->value) % getPresetsCount();
//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.
Action actionToRun = getAction(currentPreset, input); //getting the virtual inputs from the modes array.
//Inputs uids starts with 1, so input - 1 to get the index 0 of the array
String inputName = "bt";
inputName += input;
inputName += input +1;
MemSlot* buttonInputMem = getMemorySlot(inputName);
Serial.println(inputName);
@@ -486,16 +491,18 @@ void sendInputOuput(int input)
else
{
playAnimation(1);
//toggle mode
if (buttonInputMem != NULL)
{
if (buttonInputMem->value == 1)
{
buttonsVirtualState[input-1] = !buttonsVirtualState[input-1];
buttonsVirtualState[input] = !buttonsVirtualState[input];
actionToRun = getAction(currentPreset + (int)!buttonsVirtualState[input], input); //Toggle mode sends the next preset's input if the troggle state is true
}
if (buttonInputMem->value == 0)
{
buttonsVirtualState[input-1] = false;
buttonsVirtualState[input] = false;
}
}
@@ -517,15 +524,15 @@ void sendInputOuput(int input)
printMenu();
}
}
else if (isInMenu && input == 13) //menu prev, hardcoded input
else if (isInMenu && input == 12) //menu prev, hardcoded input :/
{
menuPrev();
}
else if (isInMenu && input == 14) //menu next, hardcoded input
else if (isInMenu && input == 13) //menu next, hardcoded input :/
{
menuNext();
}
else if (isInMenu && input == 15) //menu enter, hardcoded input
else if (isInMenu && input == 14) //menu enter, hardcoded input :/
{
menuEnter();
}
@@ -535,11 +542,12 @@ void sendInputOuput(int input)
void clickKey(int key, int modifier)
{
Serial.println(key);
Keyboard.set_modifier(modifier);
Keyboard.press(key);
Keyboard.release(key);
Keyboard.set_modifier(0);
//Keyboard.send_now(); //can't remember what's that's for
Keyboard.send_now(); //i think that helps to avoid key to stay active
}
void playAnimation(int animID)
@@ -552,7 +560,7 @@ void playAnimation(int animID)
}
}
void drawAnimation(bool looping)
void drawAnimation()
{
int currentAnimationFrameTotal = animData[currentAnimationID].animationFrameCount;
sevseg.setSegments(animData[currentAnimationID].animationPtr + (animationFrame * (sizeof(const uint8_t)*4)));
@@ -560,7 +568,7 @@ void drawAnimation(bool looping)
if (animationFrame == currentAnimationFrameTotal)
{
animationFrame = 0;
if (!looping)
if (!(animData[currentAnimationID].animationLooping))
{
animationPlaying = false;
sevseg.blank();