Skip to content

Commit

Permalink
refactored soundcard for alsa api, improved main loop render polling …
Browse files Browse the repository at this point in the history
…logic
  • Loading branch information
podulator committed Jan 11, 2020
1 parent ad7949a commit f192d44
Show file tree
Hide file tree
Showing 18 changed files with 347 additions and 95 deletions.
2 changes: 1 addition & 1 deletion Makefile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CFLAGS = -ggdb \
-Wno-narrowing

CXXFLAGS := $(CFLAGS)
LDFLAGS := $(SDL_LIBS) -lSDL_image -lSDL_ttf -lSDL_gfx -lSDL_mixer -lfreetype -lpthread -lpng -L/usr/local/lib -lopk
LDFLAGS := $(SDL_LIBS) -lSDL_image -lSDL_ttf -lSDL_gfx -lSDL_mixer -lfreetype -lpthread -lpng -L/usr/local/lib -lopk -lasound

OBJDIR = objs/$(TARGET)
DISTDIR = dist/$(TARGET)/esoteric
Expand Down
2 changes: 1 addition & 1 deletion Makefile.rg-350
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ CFLAGS = \
-fomit-frame-pointer

CXXFLAGS = $(CFLAGS)
LDFLAGS = $(SDL_LIBS) -lfreetype -lSDL_image -lSDL_ttf -lSDL_gfx -lSDL_mixer -lSDL -lpthread -lopk -lpng
LDFLAGS = $(SDL_LIBS) -lfreetype -lSDL_image -lSDL_ttf -lSDL_gfx -lSDL_mixer -lSDL -lpthread -lopk -lpng -lasound

OBJDIR = objs/$(TARGET)
DISTDIR = dist/$(TARGET)/esoteric
Expand Down
41 changes: 27 additions & 14 deletions src/esoteric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Esoteric::Esoteric() {
if (this->config->setHwLevelsOnBoot() && Loader::isFirstRun()) {
TRACE("backlight, volume, aspect ratio and performance mode");
this->hw->setBacklightLevel(config->backlightLevel());
this->hw->setVolumeLevel(this->config->globalVolume());
this->hw->Soundcard()->setVolume(this->config->globalVolume());
this->hw->setKeepAspectRatio(this->config->aspectRatio());
this->hw->setPerformanceMode(this->config->performance());
}
Expand Down Expand Up @@ -449,13 +449,13 @@ void Esoteric::main() {
this->menu->setLinkIndex(this->config->link());
}

renderer->startPolling();
this->screenManager->resetTimer();
this->powerManager->resetTimer();
bool uiControlledQuit= false;
renderer->startPolling();
while (!this->quitApp) {
try {
TRACE("loop");
//TRACE("loop");
renderer->render();

if (showGreeting) {
Expand All @@ -482,17 +482,23 @@ void Esoteric::main() {

bool inputAction = this->inputManager->update(true);
if (inputAction) {
if ((*this->inputManager)[QUIT] ) {

if ((*this->inputManager)[NOOP]) {
continue;
} else if ((*this->inputManager)[QUIT] ) {
INFO("We got a quit request");
this->quitApp = true;
uiControlledQuit = true;
continue;
} else if ((*this->inputManager)[POWER] && this->inputManager->isOnlyActive(POWER)) {
this->poweroffDialog();
continue;
} else if ((*this->inputManager)[NOOP]) {
continue;
} else if ((*this->inputManager)[CONFIRM] && this->menu->selLink() != NULL) {
}

// if we get here then we can block the renderer while we act on the command
renderer->stopPolling();

if ((*this->inputManager)[CONFIRM] && this->menu->selLink() != NULL) {
TRACE("******************RUNNING THIS*******************");
if (menu->selLinkApp() != NULL && menu->selLinkApp()->getSelectorDir().empty()) {
MessageBox mb(this, tr["Launching "] + menu->selLink()->getTitle().c_str(), menu->selLink()->getIconPath());
Expand Down Expand Up @@ -534,6 +540,8 @@ void Esoteric::main() {
} else if ((*this->inputManager)[MANUAL] && this->menu->selLinkApp() != NULL) {
showManual();
}
// and start polling again now we're done
renderer->startPolling();
}
}

Expand Down Expand Up @@ -846,7 +854,7 @@ void Esoteric::deviceMenu() {
int selected = 0;

int backlightLevel = this->hw->getBacklightLevel();
int volumeLevel = this->hw->getVolumeLevel();
int volumeLevel = this->hw->Soundcard()->getVolume();
int backlightTimeout = config->backlightTimeout();
bool keepAspectRatio = this->hw->getKeepAspectRatio();
int buttonRepeatRate = this->config->buttonRepeatRate();
Expand Down Expand Up @@ -993,9 +1001,9 @@ void Esoteric::deviceMenu() {
}
}

if (volumeLevel != this->hw->getVolumeLevel()) {
if (volumeLevel != this->hw->Soundcard()->getVolume()) {
this->config->globalVolume(volumeLevel);
this->hw->setVolumeLevel(volumeLevel);
this->hw->Soundcard()->setVolume(volumeLevel);
}
if (backlightLevel != this->hw->getBacklightLevel()) {
this->config->backlightLevel(backlightLevel);
Expand Down Expand Up @@ -1523,8 +1531,6 @@ void Esoteric::skinColors() {

void Esoteric::about() {
TRACE("enter");
std::vector<std::string> text;
std::string temp;

std::string uptime = this->hw->uptime();
int battLevel = this->hw->getBatteryLevel();
Expand Down Expand Up @@ -1559,15 +1565,22 @@ void Esoteric::about() {
cpuFreq += " mhz";
}

temp = "\n";
std::string volume;
std::stringstream ss;
ss << this->hw->Soundcard()->getVolume();
ss >> volume;
volume += "%";

std::string temp = "\n";
temp += tr["Build date: "] + __BUILDTIME__ + "\n";
temp += tr["App: "] + appPath + "\n";
temp += tr["Config: "] + this->config->configFile() + "\n";
temp += tr["Skin: "] + this->skin->name + "\n";
temp += tr["Device: "] + this->hw->getDeviceType() + "\n";
temp += tr["Uptime: "] + uptime + "\n";
temp += tr["Battery: "] + ((battLevel == IHardware::BATTERY_CHARGING) ? tr["Charging"] : batt) + "\n";
temp += tr["CPU: "] + cpuFreq + " \n";
temp += tr["CPU: "] + cpuFreq + "\n";
temp += tr["Volume: "] + volume + "\n";
temp += tr["Internal storage size: "] + this->hw->getDiskSize(this->hw->getInternalMountDevice()) + "\n";
temp += tr["Internal storage free: "] + this->hw->getDiskFree("/media/data") + "\n";

Expand Down
37 changes: 24 additions & 13 deletions src/hw-generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,25 @@ HwGeneric::HwGeneric() : IHardware() {
this->performanceModes_.insert({"performance", "Performance"});

this->clock_ = new SysClock();
this->soundcard_ = new DummySoundcard();
TRACE(
"brightness: %i, volume : %i",
this->getBacklightLevel(),
this->soundcard_->getVolume());
}
HwGeneric::~HwGeneric() {
delete this->clock_;
delete this->soundcard_;
}

IClock *HwGeneric::Clock() { return (IClock *)this->clock_; };
IClock *HwGeneric::Clock() {
return (IClock *)this->clock_;
}
ISoundcard *HwGeneric::Soundcard() {
return (ISoundcard *)this->soundcard_;
}

bool HwGeneric::getTVOutStatus() { return 0; };
bool HwGeneric::getTVOutStatus() { return 0; }
std::string HwGeneric::getTVOutMode() { return "OFF"; }
void HwGeneric::setTVOutMode(std::string mode) {
std::string val = mode;
Expand Down Expand Up @@ -77,22 +88,22 @@ std::vector<std::string> HwGeneric::getPerformanceModes() {
}

bool HwGeneric::supportsOverClocking() { return false; }
uint32_t HwGeneric::getCPUSpeed() { return 0; };
bool HwGeneric::setCPUSpeed(uint32_t mhz) { return true; };
uint32_t HwGeneric::getCPUSpeed() { return 0; }
bool HwGeneric::setCPUSpeed(uint32_t mhz) { return true; }

uint32_t HwGeneric::getCpuDefaultSpeed() { return 0; };
uint32_t HwGeneric::getCpuDefaultSpeed() { return 0; }

void HwGeneric::ledOn(int flashSpeed) { return; };
void HwGeneric::ledOff() { return; };
void HwGeneric::ledOn(int flashSpeed) { return; }
void HwGeneric::ledOff() { return; }

int HwGeneric::getBatteryLevel() { return IHardware::BATTERY_CHARGING; };
int HwGeneric::getBatteryLevel() { return IHardware::BATTERY_CHARGING; }

int HwGeneric::getBacklightLevel() { return 100; };
int HwGeneric::setBacklightLevel(int val) { return val; };
int HwGeneric::getBacklightLevel() { return 100; }
int HwGeneric::setBacklightLevel(int val) { return val; }

bool HwGeneric::getKeepAspectRatio() { return true; };
bool HwGeneric::setKeepAspectRatio(bool val) { return val; };
bool HwGeneric::getKeepAspectRatio() { return true; }
bool HwGeneric::setKeepAspectRatio(bool val) { return val; }

std::string HwGeneric::getDeviceType() { return "Generic"; }

bool HwGeneric::setScreenState(const bool &enable) { return true; };
bool HwGeneric::setScreenState(const bool &enable) { return true; }
2 changes: 2 additions & 0 deletions src/hw-generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ class HwGeneric : IHardware {
std::string performanceMode_ = "ondemand";
const std::string defaultPerformanceMode = "ondemand";
SysClock * clock_;
DummySoundcard * soundcard_;

public:
HwGeneric();
~HwGeneric();

IClock * Clock();
ISoundcard * Soundcard();

bool getTVOutStatus();
std::string getTVOutMode();
Expand Down
22 changes: 15 additions & 7 deletions src/hw-gkd350h.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,32 @@ HwGkd350h::HwGkd350h() : IHardware() {
this->EXTERNAL_MOUNT_POINT = EXTERNAL_CARD_PATH;

this->clock_ = new RTC();
this->soundcard_ = new AlsaSoundcard("default", "Master");
this->pollBatteries = fileExists(BATTERY_CHARGING_PATH) && fileExists(BATTERY_LEVEL_PATH);
this->pollBacklight = fileExists(BACKLIGHT_PATH);

this->getBacklightLevel();
this->getVolumeLevel();
this->getKeepAspectRatio();
this->resetKeymap();

TRACE(
"brightness - current : %i, volume : %i",
this->backlightLevel_,
this->volumeLevel_);
"brightness: %i, volume : %i",
this->getBacklightLevel(),
this->soundcard_->getVolume());
TRACE("exit");
}

HwGkd350h::~HwGkd350h() {
delete this->clock_;
delete this->soundcard_;
}

IClock *HwGkd350h::Clock() { return (IClock *)this->clock_; };
IClock *HwGkd350h::Clock() {
return (IClock *)this->clock_;
}
ISoundcard *HwGkd350h::Soundcard() {
return (ISoundcard *)this->soundcard_;
}

bool HwGkd350h::getTVOutStatus() { return false; }

Expand All @@ -56,11 +62,13 @@ std::vector<std::string> HwGkd350h::getPerformanceModes() {

bool HwGkd350h::supportsOverClocking() { return true; }

uint32_t HwGkd350h::getCPUSpeed() { return 0; };
uint32_t HwGkd350h::getCPUSpeed() {
return this->getCpuDefaultSpeed();
}

bool HwGkd350h::setCPUSpeed(uint32_t mhz) { return true; }

uint32_t HwGkd350h::getCpuDefaultSpeed() { return 0; }
uint32_t HwGkd350h::getCpuDefaultSpeed() { return 1500; }

void HwGkd350h::ledOn(int flashSpeed) { return; }

Expand Down
2 changes: 2 additions & 0 deletions src/hw-gkd350h.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class HwGkd350h : IHardware {
void resetKeymap();

RTC * clock_;
AlsaSoundcard * soundcard_;

int backlightLevel_ = 0;

Expand All @@ -34,6 +35,7 @@ class HwGkd350h : IHardware {
HwGkd350h();
~HwGkd350h();
IClock * Clock();
ISoundcard * Soundcard();

bool getTVOutStatus();
void setTVOutMode(std::string mode);
Expand Down
15 changes: 11 additions & 4 deletions src/hw-ihardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <sys/stat.h>
#include <fcntl.h>

#include <sys/soundcard.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
Expand All @@ -25,6 +24,7 @@
#include "debug.h"
#include "utilities.h"
#include "iclock.h"
#include "hw-soundcard.h"

class IHardware {

Expand All @@ -33,12 +33,12 @@ class IHardware {
std::string kernelVersion_;

protected:

/*
int volumeLevel_ = 0;

bool pollVolume = true;
const std::string GET_VOLUME_PATH = "/dev/mixer";
const std::string SET_VOLUME_PATH = "/dev/mixer";
*/

std::vector<uint32_t> cpuSpeeds_;
int16_t curMMCStatus;
Expand Down Expand Up @@ -73,10 +73,14 @@ class IHardware {
};

IHardware() {
/*
this->volumeLevel_ = 0;
this->pollVolume = fileExists(GET_VOLUME_PATH);
*/
}

virtual IClock * Clock() = 0;
virtual ISoundcard * Soundcard() = 0;

virtual bool getTVOutStatus() = 0;
virtual void setTVOutMode(std::string mode) = 0;
Expand Down Expand Up @@ -119,6 +123,7 @@ class IHardware {
/*!
Gets or sets the devices volume level, scale 0 - 100
*/
/*
virtual int getVolumeLevel() {
TRACE("enter");
Expand All @@ -135,6 +140,8 @@ class IHardware {
} else {
TRACE("couldn't read value");
}
} else {
TRACE("couldn't open : '%s' for read only access", GET_VOLUME_PATH.c_str());
}
}
Expand Down Expand Up @@ -162,7 +169,7 @@ class IHardware {
TRACE("exit : %i", this->volumeLevel_);
return this->volumeLevel_;
};

*/
/*!
Gets or sets the devices backlight level, scale 0 - 100
*/
Expand Down
Loading

0 comments on commit f192d44

Please sign in to comment.