Completed merge

This commit is contained in:
Kacper 2022-03-24 22:18:18 +00:00
parent b1854a3ca4
commit c425de4fa5
5 changed files with 62 additions and 125 deletions

View file

@ -10,10 +10,12 @@ class Knob {
public: public:
Knob(int minimum, int max); Knob(int minimum, int max);
Knob(int minimum, int max, int initialRotation);
int getRotation(); int getRotation();
void updateRotation(bool ANew, bool BNew); void updateRotation(bool ANew, bool BNew);
void changeLimitsVolume(int newMinimum, int newMaximum);
}; };
#endif #endif

View file

@ -10,6 +10,16 @@ Knob::Knob(int minimum, int maximum) {
Knob::rotation = 0; Knob::rotation = 0;
} }
Knob::Knob(int minimum, int maximum, int initialRotation) {
Knob::minimum = minimum;
Knob::maximum = maximum;
Knob::A = false;
Knob::B = false;
Knob::rotPlusOnePrev = false;
Knob::rotMinOnePrev = false;
Knob::rotation = initialRotation;
}
int Knob::getRotation() { int Knob::getRotation() {
return Knob::rotation; return Knob::rotation;
}; };
@ -31,9 +41,9 @@ void Knob::updateRotation(bool ANew, bool BNew) {
(B && A && !BNew && !ANew); (B && A && !BNew && !ANew);
if (rotPlusOneNew || (impossibleState && rotPlusOnePrev)) if (rotPlusOneNew || (impossibleState && rotPlusOnePrev))
rotation += 2; rotation += 1;
if (rotMinOneNew || (impossibleState && rotMinOnePrev)) if (rotMinOneNew || (impossibleState && rotMinOnePrev))
rotation -= 2; rotation -= 1;
if (rotation < minimum) if (rotation < minimum)
rotation = minimum; rotation = minimum;
if (rotation > maximum) if (rotation > maximum)
@ -46,3 +56,13 @@ void Knob::updateRotation(bool ANew, bool BNew) {
rotMinOnePrev = rotMinOneNew; rotMinOnePrev = rotMinOneNew;
} }
} }
void Knob::changeLimitsVolume(int newMinimum, int newMaximum) {
if(newMaximum>maximum){
rotation = rotation<<1;
}else if(newMaximum<maximum){
rotation = rotation>>1;
}else{}
minimum = newMinimum;
maximum = newMaximum;
};

View file

@ -1,64 +0,0 @@
#include "knob.h"
Knob::Knob(int minimum, int maximum) {
Knob::minimum = minimum;
Knob::maximum = maximum;
Knob::A = false;
Knob::B = false;
Knob::rotPlusOnePrev = false;
Knob::rotMinOnePrev = false;
Knob::rotation = 0;
}
Knob::Knob(int minimum, int maximum, int initialRotation) {
Knob::minimum = minimum;
Knob::maximum = maximum;
Knob::A = false;
Knob::B = false;
Knob::rotPlusOnePrev = false;
Knob::rotMinOnePrev = false;
Knob::rotation = initialRotation;
}
int Knob::getRotation() {
return Knob::rotation;
};
void Knob::updateRotation(bool ANew, bool BNew) {
bool rotPlusOneNew = (!B && !A && !BNew && ANew) ||
(!B && A && BNew && ANew) ||
(B && !A && !BNew && !ANew) ||
(B && A && BNew && !ANew);
bool rotMinOneNew = (!B && !A && BNew && !ANew) ||
(!B && A && !BNew && !ANew) ||
(B && !A && BNew && ANew) ||
(B && A && !BNew && ANew);
bool impossibleState = (!B && !A && BNew && ANew) ||
(!B && A && BNew && !ANew) ||
(B && !A && !BNew && ANew) ||
(B && A && !BNew && !ANew);
if (rotPlusOneNew || (impossibleState && rotPlusOnePrev)) rotation += 1;
if (rotMinOneNew || (impossibleState && rotMinOnePrev)) rotation -= 1;
if (rotation < minimum) rotation = minimum;
if (rotation > maximum) rotation = maximum;
A = ANew;
B = BNew;
if (!impossibleState) {
rotPlusOnePrev = rotPlusOneNew;
rotMinOnePrev = rotMinOneNew;
}
};
void Knob::changeLimitsVolume(int newMinimum, int newMaximum) {
if(newMaximum>maximum){
rotation = rotation<<1;
}else if(newMaximum<maximum){
rotation = rotation>>1;
}else{}
minimum = newMinimum;
maximum = newMaximum;
};

View file

@ -1,22 +0,0 @@
#ifndef KNOB_H
#define KNOB_H
class Knob {
private:
int rotation;
int minimum, maximum;
bool A, B;
bool rotPlusOnePrev, rotMinOnePrev;
public:
Knob(int minimum, int max);
Knob(int minimum, int max, int initialRotation);
int getRotation();
void updateRotation(bool ANew, bool BNew);
void changeLimitsVolume(int newMinimum, int newMaximum);
};
#endif

View file

@ -14,7 +14,7 @@ const uint32_t canID = 0x123;
// Variables // Variables
std::atomic<int32_t> currentStepSize; std::atomic<int32_t> currentStepSize;
std::atomic<uint8_t> keyArray[7]; std::atomic<uint8_t> keyArray[7];
std::atomic<uint8_t> octave = 4; // Octave to start on std::atomic<uint8_t> octave;
std::atomic<int8_t> volume; std::atomic<int8_t> volume;
std::atomic<bool> volumeFiner; std::atomic<bool> volumeFiner;
std::atomic<int8_t> wave; std::atomic<int8_t> wave;
@ -170,35 +170,35 @@ void sampleISR(){
analogWrite(OUTR_PIN, Vout + 128); analogWrite(OUTR_PIN, Vout + 128);
} }
void CAN_RX_ISR() { // void CAN_RX_ISR() {
uint8_t ISR_RX_Message[8]; // uint8_t ISR_RX_Message[8];
uint32_t ISR_rxID; // uint32_t ISR_rxID;
CAN_RX(ISR_rxID, ISR_RX_Message); // CAN_RX(ISR_rxID, ISR_RX_Message);
xQueueSendFromISR(msgInQ, ISR_RX_Message, nullptr); // xQueueSendFromISR(msgInQ, ISR_RX_Message, nullptr);
} // }
void decodeTask(void *pvParameters) { // void decodeTask(void *pvParameters) {
while (1) { // while (1) {
xQueueReceive(msgInQ, RX_Message, portMAX_DELAY); // xQueueReceive(msgInQ, RX_Message, portMAX_DELAY);
if (RX_Message[0] == 0x50) { // Pressed // if (RX_Message[0] == 0x50) { // Pressed
currentStepSize = notes[(RX_Message[1] - 1) * 12 + RX_Message[2]].stepSize; // currentStepSize = notes[(RX_Message[1] - 1) * 12 + RX_Message[2]].stepSize;
} else { // Released // } else { // Released
currentStepSize = 0; // currentStepSize = 0;
} // }
} // }
} // }
void keyChangedSendTXMessage(uint8_t octave, uint8_t key, bool pressed) { // void keyChangedSendTXMessage(uint8_t octave, uint8_t key, bool pressed) {
uint8_t TX_Message[8] = {0}; // uint8_t TX_Message[8] = {0};
if (pressed) { // if (pressed) {
TX_Message[0] = 0x50; // "P" // TX_Message[0] = 0x50; // "P"
} else { // } else {
TX_Message[0] = 0x52; // "R" // TX_Message[0] = 0x52; // "R"
} // }
TX_Message[1] = octave; // TX_Message[1] = octave;
TX_Message[2] = key; // TX_Message[2] = key;
CAN_TX(canID, TX_Message); // CAN_TX(canID, TX_Message);
} // }
// Task to update keyArray values at a higher priority // Task to update keyArray values at a higher priority
void scanKeysTask(void *pvParameters) { void scanKeysTask(void *pvParameters) {
@ -217,7 +217,7 @@ void scanKeysTask(void *pvParameters) {
keyArray[i] = newRow; keyArray[i] = newRow;
for (uint8_t j = 0; j < 4; j++) { for (uint8_t j = 0; j < 4; j++) {
if ((oldRow & (0x1 << j)) ^ (newRow & (0x1 << j))) { if ((oldRow & (0x1 << j)) ^ (newRow & (0x1 << j))) {
keyChangedSendTXMessage(octave, i * 4 + j + 1, newRow & (0x1 << j)); //keyChangedSendTXMessage(octave, i * 4 + j + 1, newRow & (0x1 << j));
} }
} }
} }
@ -303,6 +303,7 @@ void displayUpdateTask(void *pvParameters) {
} }
void setup() { void setup() {
octave = 4;
#pragma region Pin Setup #pragma region Pin Setup
pinMode(RA0_PIN, OUTPUT); pinMode(RA0_PIN, OUTPUT);
pinMode(RA1_PIN, OUTPUT); pinMode(RA1_PIN, OUTPUT);
@ -330,13 +331,13 @@ void setup() {
Serial.begin(115200); Serial.begin(115200);
Serial.println("Hello World"); Serial.println("Hello World");
#pragma endregion #pragma endregion
#pragma region CAN Setup // #pragma region CAN Setup
msgInQ = xQueueCreate(36, 8); // msgInQ = xQueueCreate(36, 8);
CAN_Init(true); // CAN_Init(true);
setCANFilter(0x123, 0x7ff); // setCANFilter(0x123, 0x7ff);
CAN_RegisterRX_ISR(CAN_RX_ISR); // CAN_RegisterRX_ISR(CAN_RX_ISR);
CAN_Start(); // CAN_Start();
#pragma endregion // #pragma endregion
#pragma region Task Scheduler Setup #pragma region Task Scheduler Setup
TIM_TypeDef *Instance = TIM1; TIM_TypeDef *Instance = TIM1;
HardwareTimer *sampleTimer = new HardwareTimer(Instance); HardwareTimer *sampleTimer = new HardwareTimer(Instance);