-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122: Issue 117: Support potentiometer for setting…
… the volume
- Loading branch information
Showing
8 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "poti.hpp" | ||
|
||
#include "constants.hpp" | ||
|
||
#ifdef POTI | ||
#include "logger.hpp" | ||
#include "mp3.hpp" | ||
|
||
#ifdef ALLinONE | ||
static constexpr int16_t maxLevel = 4064; | ||
#else | ||
static constexpr int16_t maxLevel = 1023; | ||
#endif | ||
|
||
|
||
Poti::Poti(const Settings& settings, Mp3& mp3) | ||
: CommandSource() | ||
, settings(settings) | ||
, mp3(mp3) | ||
{ | ||
pinMode(potiPin, INPUT); | ||
} | ||
|
||
commandRaw Poti::getCommandRaw() { | ||
const uint8_t volume = map( analogRead(potiPin), 0, maxLevel, settings.minVolume, settings.maxVolume); | ||
|
||
if (volume != mp3.getVolume()) { | ||
LOG(button_log, s_debug, F("poti volume: "), volume); | ||
mp3.setVolume(volume); | ||
} | ||
|
||
return commandRaw::none; | ||
} | ||
|
||
#endif // POTI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef SRC_POTI_HPP_ | ||
#define SRC_POTI_HPP_ | ||
|
||
#include <Arduino.h> | ||
|
||
#include "commands.hpp" | ||
|
||
class Mp3; | ||
|
||
class Poti: public CommandSource { | ||
public: | ||
|
||
Poti(const Settings& settings, Mp3& mp3); | ||
virtual ~Poti() {} | ||
commandRaw getCommandRaw() override; | ||
|
||
private: | ||
const Settings& settings; | ||
Mp3& mp3; | ||
}; | ||
|
||
#endif /* SRC_POTI_HPP_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters