Skip to content

Commit

Permalink
Merge pull request #7 from ghostintranslation/v2
Browse files Browse the repository at this point in the history
v2.0.0-beta2
  • Loading branch information
ghostintranslation committed Aug 11, 2024
2 parents 729ac1e + 95f4f90 commit 8297142
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
34 changes: 19 additions & 15 deletions firmware/src/Drone/Motherboard/InputRotary.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
/**
* Rotary Encoder type of input
* Pins should be connected this way:
* - Out A -> 20k -> Input
* - Out A -> 1k -> Input
* - Out B -> 10k -> Input
* - The pin in the middle to GND
* - Switch pin 1 -> Input
* - Switch pin 2 -> GND
* - There should be a pull up of 2k on the Input
* - There should be a pull up of 10k on the Input
*/
class InputRotary : public Input, public Registrar<InputRotary>
{
Expand All @@ -32,10 +32,12 @@ class InputRotary : public Input, public Registrar<InputRotary>
private:
uint8_t index;
int state = 0;
int16_t thresholdA = 22000;
int16_t thresholdB = 19000;
int16_t thresholdC = 15000;
int16_t thresholdD = -30000;
int8_t thresholdA = -100;
int8_t thresholdB = -120;
int8_t thresholdC = 10;
int8_t thresholdD = -10;
int8_t thresholdE = -125;
int8_t thresholdF = 125;
uint16_t value;
bool isPushed;
elapsedMillis millisSincePushed;
Expand All @@ -60,32 +62,34 @@ inline void InputRotary::update(void)

inline int16_t *&InputRotary::updateBefore(int16_t *&blockData)
{

int8_t val = blockData[0] >> 8;
for (int i = 0; i < AUDIO_BLOCK_SAMPLES; i++)
{
// Serial.println(blockData[i]);

int8_t val = blockData[i] >> 8;

switch (state)
{
case 0:
if (blockData[i] < thresholdA && blockData[i] > thresholdB)
if (val < thresholdA && val > thresholdB)
{
state = 1;
// Serial.println(state);
}
else if (blockData[i] < thresholdB && blockData[i] > thresholdC)
else if (val < thresholdC && val > thresholdD)
{
state = -1;
// Serial.println(state);
}
break;
case 1:
if (blockData[i] < thresholdC)
if (val < thresholdC && val > thresholdD)
{
state = 2;
}
break;
case -1:
if (blockData[i] < thresholdC)
if (val < thresholdA && val > thresholdB)
{
state = -2;
}
Expand Down Expand Up @@ -126,7 +130,7 @@ inline int16_t *&InputRotary::updateBefore(int16_t *&blockData)
break;
}

if (!isPushed && blockData[i] < thresholdD)
if (!isPushed && val < thresholdE)
{
isPushed = true;
millisSincePushed = 0;
Expand All @@ -135,7 +139,7 @@ inline int16_t *&InputRotary::updateBefore(int16_t *&blockData)
this->onPushCallback();
}
}
else if (isPushed && blockData[i] > thresholdD)
else if (isPushed && val > thresholdE)
{
isPushed = false;
if (this->onReleaseCallback)
Expand All @@ -158,7 +162,7 @@ inline int16_t *&InputRotary::updateBefore(int16_t *&blockData)
}
}

if (blockData[i] > thresholdA)
if (blockData[i] > thresholdF)
{
state = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/Drone/Motherboard/Output.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ inline void Output::timerCallback()
}
}

SPI.beginTransaction(SPISettings(50000000, MSBFIRST, SPI_MODE0));
SPI.beginTransaction(SPISettings(50000000, MSBFIRST, SPI_MODE0)); // 50000000

// Set the latch to low (activate the shift registers)
digitalWriteFast(REGISTERS_LATCH_PIN, LOW);
Expand Down

0 comments on commit 8297142

Please sign in to comment.