Skip to content

Commit

Permalink
Implemented stateless looping buttons (second page, front buttons); R…
Browse files Browse the repository at this point in the history
…educed anti-bouncing filter.
  • Loading branch information
caltabid committed Jun 5, 2021
1 parent c174481 commit 9903ca7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 24 deletions.
Binary file modified Documents/Disc407.bin
Binary file not shown.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ I got great inspiration from 2 open source projects:
* Button CC values (excluded Looper/Page2 Btn)
* {51, 52, 53, 54, 55, 56, 57, 58, 59}
* {61, 62, 63, 64, 65, 66, 67, 68, 69}
* Buttons 65 to 69 (Second page, front buttons) are stateless and only send value=127, this is better for some looping commands
* Potentiometers CC values (excluded Mode Pot)
* {18, 19, 20, 21, 22, 23, 24};
* Expression pedal CC values
Expand Down
3 changes: 2 additions & 1 deletion stm32/Core/Inc/CStompBtn.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ class CStompBtn
uint16_t LedPin;
uint8_t CC;
uint8_t OldValue, State;
int Mode;
public:
CStompBtn();
virtual ~CStompBtn();
void Init(GPIO_TypeDef *BtnPort, uint16_t BtnPin, GPIO_TypeDef *LedPort, uint16_t LedPin, uint8_t CC, uint8_t OldValue, uint8_t State);
void Init(GPIO_TypeDef *BtnPort, uint16_t BtnPin, GPIO_TypeDef *LedPort, uint16_t LedPin, uint8_t CC, uint8_t OldValue, uint8_t State, int Mode);
int Update(int Polarity);
int GetState(void);
};
Expand Down
38 changes: 19 additions & 19 deletions stm32/Core/Src/CAllDevices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ CAllDevices::CAllDevices()
};
uint8_t ExpCCvalues[2] = {16, 17};
uint8_t PotCCvalues[8] = {18, 19, 20, 21, 22, 23, 24, 0};
this->StompLooper.Init(StompBtn05_GPIO_Port, StompBtn05_Pin, StompLED05_GPIO_Port, StompLED05_Pin, 0, 0, 0);
this->StompLooper.Init(StompBtn05_GPIO_Port, StompBtn05_Pin, StompLED05_GPIO_Port, StompLED05_Pin, 0, 0, 0, 0);

this->StompsL1[0].Init(StompBtn01_GPIO_Port, StompBtn01_Pin, StompLED01_GPIO_Port, StompLED01_Pin, StompCCvalues[0][0], 0, 0);
this->StompsL1[1].Init(StompBtn02_GPIO_Port, StompBtn02_Pin, StompLED02_GPIO_Port, StompLED02_Pin, StompCCvalues[0][1], 0, 0);
this->StompsL1[2].Init(StompBtn03_GPIO_Port, StompBtn03_Pin, StompLED03_GPIO_Port, StompLED03_Pin, StompCCvalues[0][2], 0, 0);
this->StompsL1[3].Init(StompBtn04_GPIO_Port, StompBtn04_Pin, StompLED04_GPIO_Port, StompLED04_Pin, StompCCvalues[0][3], 0, 0);
this->StompsL1[4].Init(StompBtn06_GPIO_Port, StompBtn06_Pin, StompLED06_GPIO_Port, StompLED06_Pin, StompCCvalues[0][4], 0, 0);
this->StompsL1[5].Init(StompBtn07_GPIO_Port, StompBtn07_Pin, StompLED07_GPIO_Port, StompLED07_Pin, StompCCvalues[0][5], 0, 0);
this->StompsL1[6].Init(StompBtn08_GPIO_Port, StompBtn08_Pin, StompLED08_GPIO_Port, StompLED08_Pin, StompCCvalues[0][6], 0, 0);
this->StompsL1[7].Init(StompBtn09_GPIO_Port, StompBtn09_Pin, StompLED09_GPIO_Port, StompLED09_Pin, StompCCvalues[0][7], 0, 0);
this->StompsL1[8].Init(StompBtn10_GPIO_Port, StompBtn10_Pin, StompLED10_GPIO_Port, StompLED10_Pin, StompCCvalues[0][8], 0, 0);
this->StompsL1[0].Init(StompBtn01_GPIO_Port, StompBtn01_Pin, StompLED01_GPIO_Port, StompLED01_Pin, StompCCvalues[0][0], 0, 0, 0);
this->StompsL1[1].Init(StompBtn02_GPIO_Port, StompBtn02_Pin, StompLED02_GPIO_Port, StompLED02_Pin, StompCCvalues[0][1], 0, 0, 0);
this->StompsL1[2].Init(StompBtn03_GPIO_Port, StompBtn03_Pin, StompLED03_GPIO_Port, StompLED03_Pin, StompCCvalues[0][2], 0, 0, 0);
this->StompsL1[3].Init(StompBtn04_GPIO_Port, StompBtn04_Pin, StompLED04_GPIO_Port, StompLED04_Pin, StompCCvalues[0][3], 0, 0, 0);
this->StompsL1[4].Init(StompBtn06_GPIO_Port, StompBtn06_Pin, StompLED06_GPIO_Port, StompLED06_Pin, StompCCvalues[0][4], 0, 0, 0);
this->StompsL1[5].Init(StompBtn07_GPIO_Port, StompBtn07_Pin, StompLED07_GPIO_Port, StompLED07_Pin, StompCCvalues[0][5], 0, 0, 0);
this->StompsL1[6].Init(StompBtn08_GPIO_Port, StompBtn08_Pin, StompLED08_GPIO_Port, StompLED08_Pin, StompCCvalues[0][6], 0, 0, 0);
this->StompsL1[7].Init(StompBtn09_GPIO_Port, StompBtn09_Pin, StompLED09_GPIO_Port, StompLED09_Pin, StompCCvalues[0][7], 0, 0, 0);
this->StompsL1[8].Init(StompBtn10_GPIO_Port, StompBtn10_Pin, StompLED10_GPIO_Port, StompLED10_Pin, StompCCvalues[0][8], 0, 0, 0);

this->StompsL2[0].Init(StompBtn01_GPIO_Port, StompBtn01_Pin, StompLED01_GPIO_Port, StompLED01_Pin, StompCCvalues[1][0], 0, 0);
this->StompsL2[1].Init(StompBtn02_GPIO_Port, StompBtn02_Pin, StompLED02_GPIO_Port, StompLED02_Pin, StompCCvalues[1][1], 0, 0);
this->StompsL2[2].Init(StompBtn03_GPIO_Port, StompBtn03_Pin, StompLED03_GPIO_Port, StompLED03_Pin, StompCCvalues[1][2], 0, 0);
this->StompsL2[3].Init(StompBtn04_GPIO_Port, StompBtn04_Pin, StompLED04_GPIO_Port, StompLED04_Pin, StompCCvalues[1][3], 0, 0);
this->StompsL2[4].Init(StompBtn06_GPIO_Port, StompBtn06_Pin, StompLED06_GPIO_Port, StompLED06_Pin, StompCCvalues[1][4], 0, 0);
this->StompsL2[5].Init(StompBtn07_GPIO_Port, StompBtn07_Pin, StompLED07_GPIO_Port, StompLED07_Pin, StompCCvalues[1][5], 0, 0);
this->StompsL2[6].Init(StompBtn08_GPIO_Port, StompBtn08_Pin, StompLED08_GPIO_Port, StompLED08_Pin, StompCCvalues[1][6], 0, 0);
this->StompsL2[7].Init(StompBtn09_GPIO_Port, StompBtn09_Pin, StompLED09_GPIO_Port, StompLED09_Pin, StompCCvalues[1][7], 0, 0);
this->StompsL2[8].Init(StompBtn10_GPIO_Port, StompBtn10_Pin, StompLED10_GPIO_Port, StompLED10_Pin, StompCCvalues[1][8], 0, 0);
this->StompsL2[0].Init(StompBtn01_GPIO_Port, StompBtn01_Pin, StompLED01_GPIO_Port, StompLED01_Pin, StompCCvalues[1][0], 0, 0, 0);
this->StompsL2[1].Init(StompBtn02_GPIO_Port, StompBtn02_Pin, StompLED02_GPIO_Port, StompLED02_Pin, StompCCvalues[1][1], 0, 0, 0);
this->StompsL2[2].Init(StompBtn03_GPIO_Port, StompBtn03_Pin, StompLED03_GPIO_Port, StompLED03_Pin, StompCCvalues[1][2], 0, 0, 0);
this->StompsL2[3].Init(StompBtn04_GPIO_Port, StompBtn04_Pin, StompLED04_GPIO_Port, StompLED04_Pin, StompCCvalues[1][3], 0, 0, 0);
this->StompsL2[4].Init(StompBtn06_GPIO_Port, StompBtn06_Pin, StompLED06_GPIO_Port, StompLED06_Pin, StompCCvalues[1][4], 0, 0, 1);
this->StompsL2[5].Init(StompBtn07_GPIO_Port, StompBtn07_Pin, StompLED07_GPIO_Port, StompLED07_Pin, StompCCvalues[1][5], 0, 0, 1);
this->StompsL2[6].Init(StompBtn08_GPIO_Port, StompBtn08_Pin, StompLED08_GPIO_Port, StompLED08_Pin, StompCCvalues[1][6], 0, 0, 1);
this->StompsL2[7].Init(StompBtn09_GPIO_Port, StompBtn09_Pin, StompLED09_GPIO_Port, StompLED09_Pin, StompCCvalues[1][7], 0, 0, 1);
this->StompsL2[8].Init(StompBtn10_GPIO_Port, StompBtn10_Pin, StompLED10_GPIO_Port, StompLED10_Pin, StompCCvalues[1][8], 0, 0, 1);

this->LedMain.Init(LD_PWR_GPIO_Port, LD_PWR_Pin);
this->LedMain.Set(0, 1000, 200);
Expand Down
17 changes: 13 additions & 4 deletions stm32/Core/Src/CStompBtn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CStompBtn::~CStompBtn()
{
}

void CStompBtn::Init(GPIO_TypeDef *BtnPort, uint16_t BtnPin, GPIO_TypeDef *LedPort, uint16_t LedPin, uint8_t CC, uint8_t OldValue, uint8_t State)
void CStompBtn::Init(GPIO_TypeDef *BtnPort, uint16_t BtnPin, GPIO_TypeDef *LedPort, uint16_t LedPin, uint8_t CC, uint8_t OldValue, uint8_t State, int Mode)
{
this->BtnPort = BtnPort ;
this->BtnPin = BtnPin ;
Expand All @@ -25,7 +25,8 @@ void CStompBtn::Init(GPIO_TypeDef *BtnPort, uint16_t BtnPin, GPIO_TypeDef *LedPo
this->CC = CC ;
this->OldValue = OldValue;
this->State = State ;
this->Debounce.Init(100, 0);
this->Mode = Mode ;
this->Debounce.Init(50, 0);
}

int CStompBtn::Update(int Polarity) // 0: active, 1: bypass
Expand All @@ -38,14 +39,22 @@ int CStompBtn::Update(int Polarity) // 0: active, 1: bypass
if (CurrentValue) { // rising edge
this->State = !this->State; // toggle state
if (this->CC>0) {
Command = Polarity?!this->State:this->State;
if (this->Mode) {
Command = 1;
} else {
Command = Polarity?!this->State:this->State;
}
sendMidiCC(0, this->CC, 127*Command);
}
ret=1;
}
this->OldValue = CurrentValue;
}
HAL_GPIO_WritePin(this->LedPort, this->LedPin, (GPIO_PinState)this->State); // always refresh led status
if (this->Mode) {
HAL_GPIO_WritePin(this->LedPort, this->LedPin, (GPIO_PinState)NewValue);
} else {
HAL_GPIO_WritePin(this->LedPort, this->LedPin, (GPIO_PinState)this->State);
}
return ret;
}

Expand Down

0 comments on commit 9903ca7

Please sign in to comment.