mirror of
https://github.com/supleed2/ELEC60013-ES-CW2.git
synced 2024-11-10 02:45:47 +00:00
68 lines
1.7 KiB
C++
68 lines
1.7 KiB
C++
#include <knob>
|
|
|
|
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;
|
|
}; |