From d98f03ccdd6eb550ffe978731aa430d9bf157dac Mon Sep 17 00:00:00 2001 From: Lyubomir Penev Date: Wed, 22 Oct 2025 14:52:17 +0200 Subject: [PATCH] Extracted mute to seperate file --- include/userFunctions.h | 1 + src/main.cpp | 39 +-------------------------------------- src/userFunctions.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 38 deletions(-) diff --git a/include/userFunctions.h b/include/userFunctions.h index 30b4526..392db24 100644 --- a/include/userFunctions.h +++ b/include/userFunctions.h @@ -1,5 +1,6 @@ #pragma once +void mute(int *userVolume, int *oldUserVolume, int maxVolume); void lowerVolume(int *userVolume, int *oldUserVolume, int maxVolume); void volumeUp(int *userVolume, int *oldUserVolume, int maxVolume); void volumeDown(int *userVolume, int *oldUserVolume); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 90dc927..33edca7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,44 +82,7 @@ void loop() // Remote D - Mute if (debounceRead(REMOTE_D)) { - - // Check if we are in a muted state - if (oldUserVolume > userVolume) - { - // This is if the user is muted and is asking to be unmuted - // Check if max volume has been lowered since mute - if (oldUserVolume > maxVolume) - { - // If the max volume has been lowered since mute, then set the user volume to the new max volume - userVolume = maxVolume; - - for (int i = 0; i < maxVolume; i++) - { - potIncrement(); - } - } - else - { - // If the max volume hasn't changed then, or the old user volume is lower than the new max - restore it to where it was - userVolume = oldUserVolume; - - for (int i = 0; i < oldUserVolume; i++) - { - potIncrement(); - } - } - } - else - { - // This is if the user is unmuted and is aksing to be muted - for (int i = 0; i < 64; i++) - { - potDecrement(); - } - - oldUserVolume = userVolume; - userVolume = 0; - } + mute(&userVolume, &oldUserVolume, maxVolume); } // Remote A - Significantly Lower Volume diff --git a/src/userFunctions.cpp b/src/userFunctions.cpp index a14f4ab..5f3fe46 100644 --- a/src/userFunctions.cpp +++ b/src/userFunctions.cpp @@ -2,6 +2,47 @@ #include #include +void mute(int *userVolume, int *oldUserVolume, int maxVolume) +{ + // Check if we are in a muted state + if (*oldUserVolume > *userVolume) + { + // This is if the user is muted and is asking to be unmuted + // Check if max volume has been lowered since mute + if (*oldUserVolume > maxVolume) + { + // If the max volume has been lowered since mute, then set the user volume to the new max volume + *userVolume = maxVolume; + + for (int i = 0; i < maxVolume; i++) + { + potIncrement(); + } + } + else + { + // If the max volume hasn't changed then, or the old user volume is lower than the new max - restore it to where it was + *userVolume = *oldUserVolume; + + for (int i = 0; i < *oldUserVolume; i++) + { + potIncrement(); + } + } + } + else + { + // This is if the user is unmuted and is aksing to be muted + for (int i = 0; i < 64; i++) + { + potDecrement(); + } + + *oldUserVolume = *userVolume; + *userVolume = 0; + } +} + void lowerVolume(int *userVolume, int *oldUserVolume, int maxVolume) { // Check if we volume is already lowered