Skip to content

Commit

Permalink
changes: * volume; bigger range, smaller steps, compact widget (displ…
Browse files Browse the repository at this point in the history
…ay is button at same time)

           ! alternatively do not use boxes but shadows in a darker color with exact same dimension as bar itself
         * enhanced GUI; add playback position selction on progress bar
           ! may be later also add fast forward/reverse (seek), e.g. using more buttons or IMU
           ! may be for progress bar use M5.Lcd.progressBar instead of M5.Lcd.drawRoundRect and M5.Lcd.fillRoundRect
         * option to enable force mono playback during build
  • Loading branch information
drtrigon committed Dec 7, 2023
1 parent bd02f4a commit d1b5459
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 17 deletions.
Binary file removed lib/ESP32-audioI2S-master-c612a07.zip
Binary file not shown.
Binary file removed lib/M5Core2-0.1.6-cb65d23.zip
Binary file not shown.
Empty file added lib/see v3
Empty file.
46 changes: 35 additions & 11 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ void CPlayer::begin()
// initialize Player (should be put into own method)
// hacky as int has size of 4 - should be using struct or json
// also store additional info to identify the SD and check whether its the same as last time
// also consider (re)storing state of volume and playback position within current file
File status = SPIFFS.open("/status", FILE_READ);
if (status) {
m_activeSongIdx = int(status.read()); // hacky as int has size 4, works up to 255 only!

m_audio.connecttoSD(m_songFiles[m_activeSongIdx].c_str());
}
status.close();
Serial.printf("SD Card Size: %lluMB\n", SD.cardSize() / (1024 * 1024)); // FUTURE: use to generate unique SD ID
Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024)); // FUTURE: use to generate unique SD ID
Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024)); // FUTURE: use to generate unique SD ID
}

void CPlayer::loop()
Expand Down Expand Up @@ -57,6 +61,10 @@ void CPlayer::initializeHardware()

m_audio.setPinout(12, 0, 2);
m_audio.setVolume(m_currentVolume);
#ifdef FORCE_MONO
m_audio.forceMono(true);
Serial.println("FORCE_MONO set");
#endif

populateMusicFileList();

Expand All @@ -76,9 +84,7 @@ void CPlayer::initializeGui()
m_prevSongWidget.draw(false);
m_pauseSongWidget.draw(false);
m_progressWidget.draw(false);
m_volumeDisplayWidget.draw(false);
m_volumeDownWidget.draw(false);
m_volumeUpWidget.draw(false);
m_volumeWidget.draw(false);
}

void CPlayer::appendSDDirectory(File dir)
Expand Down Expand Up @@ -171,16 +177,20 @@ void CPlayer::handleTouchEvents()
pauseSong();
}

if (m_volumeDownWidget.isTouched(touchPoint))
if (m_volumeWidget.isTouched(touchPoint))
{
vibrate();
decreaseVolume();
if (m_volumeWidget.getButton(touchPoint)) {
decreaseVolume();
} else {
increaseVolume();
}
}

if (m_volumeUpWidget.isTouched(touchPoint))
if (m_progressWidget.isTouched(touchPoint))
{
vibrate();
increaseVolume();
setPosSong(m_progressWidget.getPosition(touchPoint));
}
}

Expand Down Expand Up @@ -233,6 +243,20 @@ void CPlayer::pauseSong()
m_isRunning = m_audio.isRunning();
}

void CPlayer::setPosSong(float f_relPos)
{
if (!m_audio.isRunning())
{
return;
}

m_audio.pauseResume();

m_audio.setAudioPlayPosition(f_relPos * m_audio.getAudioFileDuration());

m_audio.pauseResume();
}

void CPlayer::updateGui()
{
m_batteryWidget.update();
Expand All @@ -247,13 +271,13 @@ void CPlayer::updateGui()

m_fileSelectionWidget.update(m_songFiles.size(), m_activeSongIdx);

m_volumeDisplayWidget.update(m_currentVolume);
m_volumeWidget.update(m_currentVolume);
}

void CPlayer::updateVolume(int f_deltaVolume)
{
constexpr int minVolume = 0;
constexpr int maxVolume = 16;
constexpr int maxVolume = 20;

int newVolume = m_currentVolume + f_deltaVolume;

Expand All @@ -272,12 +296,12 @@ void CPlayer::updateVolume(int f_deltaVolume)

void CPlayer::increaseVolume()
{
updateVolume(+4);
updateVolume(+2);
}

void CPlayer::decreaseVolume()
{
updateVolume(-4);
updateVolume(-2);
}

void CPlayer::vibrate()
Expand Down
12 changes: 6 additions & 6 deletions src/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#include "prev_song_widget.hpp"
#include "pause_song_widget.hpp"
#include "progress_widget.hpp"
#include "volume_display_widget.hpp"
#include "volume_down_widget.hpp"
#include "volume_up_widget.hpp"
#include "volume_widget.hpp"

//#define FORCE_MONO

namespace singsang
{
Expand All @@ -39,6 +39,8 @@ class CPlayer

void pauseSong();

void setPosSong(float f_relPos);

void updateVolume(int f_deltaVolume);

void increaseVolume();
Expand Down Expand Up @@ -70,9 +72,7 @@ class CPlayer
CPrevSongWidget m_prevSongWidget;
CPauseSongWidget m_pauseSongWidget;
CProgressWidget m_progressWidget;
CVolumeDisplayWidget m_volumeDisplayWidget;
CVolumeDownWidget m_volumeDownWidget;
CVolumeUpWidget m_volumeUpWidget;
CVolumeWidget m_volumeWidget;
};

} // namespace singsang
Expand Down
9 changes: 9 additions & 0 deletions src/progress_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ class CProgressWidget : public CBaseWidget
}
}

float getPosition(TouchPoint_t f_point)
{
/* if (!isTouched(f_point))
{
return ...;
}*/
return float(f_point.x - m_positionX) / m_sizeX;
}

void draw(const bool updateOnly)
{
const uint16_t color = M5.Lcd.color565(100, 100, 100);
Expand Down
62 changes: 62 additions & 0 deletions src/volume_widget.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifndef SINGSANG_VOLUME_WIDGET_HPP
#define SINGSANG_VOLUME_WIDGET_HPP

#include "base_widget.hpp"

#define sizeYMax 4 // height of bar, multiple of 2
#define volumeIdxMax 10 // number of bars, <= 20 = (height=80)/(sizeYMax=4)

namespace singsang
{
class CVolumeWidget : public CBaseWidget
{
public:
CVolumeWidget() : CBaseWidget(10, 0, 40, 80) {}

void update(const int f_newAudioVolume)
{
if (f_newAudioVolume != m_audioVolume)
{
m_audioVolume = f_newAudioVolume;
draw(true);
}
}

int getButton(TouchPoint_t f_point)
{
/* if (!isTouched(f_point))
{
return ...;
}*/
return int(float(f_point.y - m_positionY) / m_sizeY * 2);
}

void draw(const bool updateOnly)
{
const uint16_t color = M5.Lcd.color565(100, 100, 100);

for (int volumeIdx = 0; volumeIdx < volumeIdxMax; volumeIdx++)
{
const int pointX = m_positionX;
const int pointY = m_positionY + m_sizeY - (m_sizeY/volumeIdxMax) * (volumeIdx + 1);
const int sizeX = (m_sizeX/volumeIdxMax) * (volumeIdx + 1);// + 12;
const int sizeY = sizeYMax;

if (!updateOnly)
{
M5.Lcd.fillRoundRect(pointX, pointY, sizeX, sizeY, sizeYMax/2, color);
}

const int barIsActive = (m_audioVolume > 2 * volumeIdx);
const int pickColor = barIsActive ? color : TFT_BLACK;
M5.Lcd.fillRoundRect(pointX+1, pointY+1, sizeX-2, sizeY-2, (sizeYMax/2)-1, pickColor);
}
}

private:
int m_audioVolume;
};

} // namespace singsang

#endif // SINGSANG_VOLUME_WIDGET_HPP

0 comments on commit d1b5459

Please sign in to comment.