Removed reader class
All checks were successful
Generate Documentation / build (push) Successful in 15s

This commit is contained in:
2025-11-02 14:10:50 +01:00
parent 4a4a66f0d4
commit 02a9c782c2
3 changed files with 31 additions and 38 deletions

View File

@@ -1,31 +1,19 @@
#pragma once #pragma once
class Reader /**
{
private:
unsigned long lastDebounceTime = 0;
bool lastButtonStateNO = LOW;
bool buttonStateNO = HIGH;
bool lastButtonStateNC = HIGH;
bool buttonStateNC = LOW;
int lastPin;
public:
/**
* @brief Function used to read state of a normally open(LOW) button * @brief Function used to read state of a normally open(LOW) button
* *
* @param buttonPin The pin of the button * @param buttonPin The pin of the button
* @return true * @return true
* @return false * @return false
*/ */
bool debounceReadNO(int buttonPin); bool debounceReadNO(int buttonPin);
/** /**
* @brief Function used to read state of a normally closed(HIGH) button * @brief Function used to read state of a normally closed(HIGH) button
* *
* @param buttonPin The pin of the button * @param buttonPin The pin of the button
* @return true * @return true
* @return false * @return false
*/ */
bool debounceReadNC(int buttonPin); bool debounceReadNC(int buttonPin);
};

View File

@@ -13,6 +13,13 @@
#include <commonFunctions.h> #include <commonFunctions.h>
#include <constants.h> #include <constants.h>
unsigned long lastDebounceTime = 0;
bool lastButtonStateNO = LOW;
bool buttonStateNO = HIGH;
bool lastButtonStateNC = HIGH;
bool buttonStateNC = LOW;
int lastPin;
/** /**
* @brief Function used to read state of a normally open(LOW) button * @brief Function used to read state of a normally open(LOW) button
* *
@@ -20,7 +27,7 @@
* @return true * @return true
* @return false * @return false
*/ */
bool Reader::debounceReadNO(int buttonPin) bool debounceReadNO(int buttonPin)
{ {
bool reading = digitalRead(buttonPin); bool reading = digitalRead(buttonPin);
@@ -60,7 +67,7 @@ bool Reader::debounceReadNO(int buttonPin)
* @return true * @return true
* @return false * @return false
*/ */
bool Reader::debounceReadNC(int buttonPin) bool debounceReadNC(int buttonPin)
{ {
bool reading = digitalRead(buttonPin); bool reading = digitalRead(buttonPin);

View File

@@ -10,8 +10,6 @@ int maxVolume = 64;
int userVolume = 64; int userVolume = 64;
int oldUserVolume = userVolume; int oldUserVolume = userVolume;
Reader reader;
void setup() void setup()
{ {
pinMode(LED_HIGH, OUTPUT); // Green pinMode(LED_HIGH, OUTPUT); // Green
@@ -45,39 +43,39 @@ void loop()
updateLeds(maxVolume); updateLeds(maxVolume);
// SW1 - Staff Volume Up // SW1 - Staff Volume Up
if (reader.debounceReadNC(BTN_STAFF_UP)) if (debounceReadNC(BTN_STAFF_UP))
{ {
staffVolumeUp(&maxVolume); staffVolumeUp(&maxVolume);
} }
// SW2 - Staff Volume Down // SW2 - Staff Volume Down
if (reader.debounceReadNC(BTN_STAFF_DWN)) if (debounceReadNC(BTN_STAFF_DWN))
{ {
staffVolumeDown(&maxVolume, &userVolume, &oldUserVolume); staffVolumeDown(&maxVolume, &userVolume, &oldUserVolume);
} }
// Remote D - Mute // Remote D - Mute
if (reader.debounceReadNO(REMOTE_D)) if (debounceReadNO(REMOTE_D))
{ {
mute(&userVolume, &oldUserVolume, maxVolume); mute(&userVolume, &oldUserVolume, maxVolume);
} }
// Remote A - Significantly Lower Volume // Remote A - Significantly Lower Volume
if (reader.debounceReadNO(REMOTE_A)) if (debounceReadNO(REMOTE_A))
{ {
lowerVolume(&userVolume, &oldUserVolume, maxVolume); lowerVolume(&userVolume, &oldUserVolume, maxVolume);
} }
// Remote B - Volume Up // Remote B - Volume Up
// Make sure we are not is a state of mute or lowered // Make sure we are not is a state of mute or lowered
if (reader.debounceReadNO(REMOTE_B) && !(oldUserVolume > userVolume)) if (debounceReadNO(REMOTE_B) && !(oldUserVolume > userVolume))
{ {
volumeUp(&userVolume, &oldUserVolume, maxVolume); volumeUp(&userVolume, &oldUserVolume, maxVolume);
} }
// Remote C - Volume Down // Remote C - Volume Down
// Make sure we are not is a state of mute or lowered // Make sure we are not is a state of mute or lowered
if (reader.debounceReadNO(REMOTE_C) && !(oldUserVolume > userVolume)) if (debounceReadNO(REMOTE_C) && !(oldUserVolume > userVolume))
{ {
volumeDown(&userVolume, &oldUserVolume); volumeDown(&userVolume, &oldUserVolume);
} }