Skip to content

Commit

Permalink
Merge pull request #122: Issue 117: Support potentiometer for setting…
Browse files Browse the repository at this point in the history
… the volume
  • Loading branch information
boerge1 authored Oct 13, 2023
2 parents 63678ad + 0ab6751 commit 3532b11
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Die DIY Musikbox (nicht nur) für Kinder

Dies ist die offizielle Software für die Musikbox, die [hier](https://www.tonuino.de/TNG) beschrieben ist.

Falls du Interesse daran hast, zur Weiterentwicklung des TonUINO-Projekts beizutragen, bist du herzlich eingeladen, dich zu beteiligen. Für Diskussionen verwende bitte das [Forum](https://discourse.voss.earth). Dort findest du auch weitere Anleitungen und bekommst Hilfe bei Problemen.

# Anleitung zum Compilieren

Allgemeine Anleitungen zum Einrichten der IDE findet man hier [www.tonuino.de/TNG](https://www.tonuino.de/TNG) und hier [www.leiterkartenpiraten.de](https://www.leiterkartenpiraten.de)
Expand Down Expand Up @@ -50,6 +52,7 @@ Die SD Karte (Ordner mp3 und advert) hat sich gegenüber der Version 3.1.2 geän
# Change Log

## Version 3.1.4 (13.10.2023)
- [Issue 117](https://github.com/tonuino/TonUINO-TNG/issues/117): Support potentiometer for setting the
- [Issue 120](https://github.com/tonuino/TonUINO-TNG/issues/120): Change to version 1.2.2 of the DFMiniMp3 library
- [Issue 118](https://github.com/tonuino/TonUINO-TNG/issues/118): In modus pause_if_card_removed no shortcut is played

Expand Down
2 changes: 1 addition & 1 deletion TonUINO-TNG.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void setup()
LOG(init_log, s_error, F("TonUINO Version 3.1 - refactored by Boerge1\n"));
LOG(init_log, s_error, F("created by Thorsten Voß and licensed under GNU/GPL."));
LOG(init_log, s_error, F("Information and contribution at https://tonuino.de.\n"));
LOG(init_log, s_error, F("V3.1.4 13.10.23 II\n"));
LOG(init_log, s_error, F("V3.1.4 13.10.23 III\n"));

Tonuino::getTonuino().setup();
}
Expand Down
6 changes: 6 additions & 0 deletions src/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
inline constexpr uint8_t rotaryEncoderClkPin = 31;
inline constexpr uint8_t rotaryEncoderDtPin = 32;

/* uncomment the below line to enable the poti for volume setting
* um den Poti zu unterstützen bitte in der nächste Zeile den Kommentar entfernen
*/
//#define POTI
//inline constexpr uint8_t potiPin = A14; // AiO+ PF4

/* uncomment the below line to enable the neo ring
* um den Neo Ring zu unterstützen bitte in der nächste Zeile den Kommentar entfernen
*/
Expand Down
7 changes: 7 additions & 0 deletions src/mp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ void Mp3::setVolume() {
logVolume();
}

void Mp3::setVolume(uint8_t v) {
volume = v;
LOG(mp3_log, s_debug, F("setVolume: "), volume);
Base::setVolume(volume);
logVolume();
}

void Mp3::logVolume() {
LOG(mp3_log, s_info, F("Volume: "), volume);
}
Expand Down
2 changes: 2 additions & 0 deletions src/mp3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ class Mp3: public DfMp3 {
void increaseVolume();
void decreaseVolume();
void setVolume ();
void setVolume (uint8_t);
uint8_t getVolume () const { return volume; }
void loop ();

private:
Expand Down
35 changes: 35 additions & 0 deletions src/poti.cpp
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
22 changes: 22 additions & 0 deletions src/poti.hpp
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_ */
7 changes: 7 additions & 0 deletions src/tonuino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "buttons.hpp"
#include "buttons3x3.hpp"
#include "rotary_encoder.hpp"
#include "poti.hpp"
#include "serial_input.hpp"
#include "mp3.hpp"
#include "modifier.hpp"
Expand Down Expand Up @@ -72,6 +73,9 @@ class Tonuino {
#endif
#ifdef ROTARY_ENCODER
RotaryEncoder rotaryEncoder {settings};
#endif
#ifdef POTI
Poti poti {settings, mp3};
#endif
Commands commands {
settings
Expand All @@ -84,6 +88,9 @@ class Tonuino {
#endif
#ifdef ROTARY_ENCODER
, &rotaryEncoder
#endif
#ifdef POTI
, &poti
#endif
};
Chip_card chip_card {mp3};
Expand Down

0 comments on commit 3532b11

Please sign in to comment.