mirror of
https://github.com/supleed2/ELEC60013-ES-CW2.git
synced 2024-12-22 21:55:50 +00:00
Completed merge
This commit is contained in:
parent
b1854a3ca4
commit
c425de4fa5
|
@ -10,10 +10,12 @@ class Knob {
|
|||
|
||||
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
|
|
@ -10,6 +10,16 @@ Knob::Knob(int minimum, int maximum) {
|
|||
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;
|
||||
};
|
||||
|
@ -31,9 +41,9 @@ void Knob::updateRotation(bool ANew, bool BNew) {
|
|||
(B && A && !BNew && !ANew);
|
||||
|
||||
if (rotPlusOneNew || (impossibleState && rotPlusOnePrev))
|
||||
rotation += 2;
|
||||
rotation += 1;
|
||||
if (rotMinOneNew || (impossibleState && rotMinOnePrev))
|
||||
rotation -= 2;
|
||||
rotation -= 1;
|
||||
if (rotation < minimum)
|
||||
rotation = minimum;
|
||||
if (rotation > maximum)
|
||||
|
@ -46,3 +56,13 @@ void Knob::updateRotation(bool ANew, bool BNew) {
|
|||
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;
|
||||
};
|
64
src/knob.cpp
64
src/knob.cpp
|
@ -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;
|
||||
};
|
22
src/knob.h
22
src/knob.h
|
@ -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
|
73
src/main.cpp
73
src/main.cpp
|
@ -14,7 +14,7 @@ const uint32_t canID = 0x123;
|
|||
// Variables
|
||||
std::atomic<int32_t> currentStepSize;
|
||||
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<bool> volumeFiner;
|
||||
std::atomic<int8_t> wave;
|
||||
|
@ -170,35 +170,35 @@ void sampleISR(){
|
|||
analogWrite(OUTR_PIN, Vout + 128);
|
||||
}
|
||||
|
||||
void CAN_RX_ISR() {
|
||||
uint8_t ISR_RX_Message[8];
|
||||
uint32_t ISR_rxID;
|
||||
CAN_RX(ISR_rxID, ISR_RX_Message);
|
||||
xQueueSendFromISR(msgInQ, ISR_RX_Message, nullptr);
|
||||
}
|
||||
// void CAN_RX_ISR() {
|
||||
// uint8_t ISR_RX_Message[8];
|
||||
// uint32_t ISR_rxID;
|
||||
// CAN_RX(ISR_rxID, ISR_RX_Message);
|
||||
// xQueueSendFromISR(msgInQ, ISR_RX_Message, nullptr);
|
||||
// }
|
||||
|
||||
void decodeTask(void *pvParameters) {
|
||||
while (1) {
|
||||
xQueueReceive(msgInQ, RX_Message, portMAX_DELAY);
|
||||
if (RX_Message[0] == 0x50) { // Pressed
|
||||
currentStepSize = notes[(RX_Message[1] - 1) * 12 + RX_Message[2]].stepSize;
|
||||
} else { // Released
|
||||
currentStepSize = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// void decodeTask(void *pvParameters) {
|
||||
// while (1) {
|
||||
// xQueueReceive(msgInQ, RX_Message, portMAX_DELAY);
|
||||
// if (RX_Message[0] == 0x50) { // Pressed
|
||||
// currentStepSize = notes[(RX_Message[1] - 1) * 12 + RX_Message[2]].stepSize;
|
||||
// } else { // Released
|
||||
// currentStepSize = 0;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
void keyChangedSendTXMessage(uint8_t octave, uint8_t key, bool pressed) {
|
||||
uint8_t TX_Message[8] = {0};
|
||||
if (pressed) {
|
||||
TX_Message[0] = 0x50; // "P"
|
||||
} else {
|
||||
TX_Message[0] = 0x52; // "R"
|
||||
}
|
||||
TX_Message[1] = octave;
|
||||
TX_Message[2] = key;
|
||||
CAN_TX(canID, TX_Message);
|
||||
}
|
||||
// void keyChangedSendTXMessage(uint8_t octave, uint8_t key, bool pressed) {
|
||||
// uint8_t TX_Message[8] = {0};
|
||||
// if (pressed) {
|
||||
// TX_Message[0] = 0x50; // "P"
|
||||
// } else {
|
||||
// TX_Message[0] = 0x52; // "R"
|
||||
// }
|
||||
// TX_Message[1] = octave;
|
||||
// TX_Message[2] = key;
|
||||
// CAN_TX(canID, TX_Message);
|
||||
// }
|
||||
|
||||
// Task to update keyArray values at a higher priority
|
||||
void scanKeysTask(void *pvParameters) {
|
||||
|
@ -217,7 +217,7 @@ void scanKeysTask(void *pvParameters) {
|
|||
keyArray[i] = newRow;
|
||||
for (uint8_t j = 0; j < 4; 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() {
|
||||
octave = 4;
|
||||
#pragma region Pin Setup
|
||||
pinMode(RA0_PIN, OUTPUT);
|
||||
pinMode(RA1_PIN, OUTPUT);
|
||||
|
@ -330,13 +331,13 @@ void setup() {
|
|||
Serial.begin(115200);
|
||||
Serial.println("Hello World");
|
||||
#pragma endregion
|
||||
#pragma region CAN Setup
|
||||
msgInQ = xQueueCreate(36, 8);
|
||||
CAN_Init(true);
|
||||
setCANFilter(0x123, 0x7ff);
|
||||
CAN_RegisterRX_ISR(CAN_RX_ISR);
|
||||
CAN_Start();
|
||||
#pragma endregion
|
||||
// #pragma region CAN Setup
|
||||
// msgInQ = xQueueCreate(36, 8);
|
||||
// CAN_Init(true);
|
||||
// setCANFilter(0x123, 0x7ff);
|
||||
// CAN_RegisterRX_ISR(CAN_RX_ISR);
|
||||
// CAN_Start();
|
||||
// #pragma endregion
|
||||
#pragma region Task Scheduler Setup
|
||||
TIM_TypeDef *Instance = TIM1;
|
||||
HardwareTimer *sampleTimer = new HardwareTimer(Instance);
|
||||
|
|
Loading…
Reference in a new issue