diff --git a/RetroFE/Source/Graphics/Component/Battery.cpp b/RetroFE/Source/Graphics/Component/Battery.cpp index 4efb3c0..e053112 100644 --- a/RetroFE/Source/Graphics/Component/Battery.cpp +++ b/RetroFE/Source/Graphics/Component/Battery.cpp @@ -2,6 +2,7 @@ #include "../ViewInfo.h" #include "../../SDL.h" #include "../../Utility/Log.h" +#include "../../Database/Configuration.h" #include @@ -75,14 +76,10 @@ static uint32_t noBatIcon [NOBAT_ICON_HEIGHT][NOBAT_ICON_WIDTH] = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; -/* TODO: this should be in config */ -static std::string fileUsbConnected = "/sys/class/power_supply/axp20x-usb/present"; -static std::string fileBatConnected = "/sys/class/power_supply/axp20x-battery/present"; -static std::string fileBatCapacity = "/sys/class/power_supply/axp20x-battery/capacity"; - -/*static std::string fileUsbConnected = "/home/vincent/Workspace/axp20x-usb_present"; -static std::string fileBatConnected = "/home/vincent/Workspace/axp20x-battery_present"; -static std::string fileBatCapacity = "/home/vincent/Workspace/axp20x-battery_capacity";*/ +/*Default value, reset with config*/ +std::string Battery::fileUsbConnected_ = "/sys/class/power_supply/axp20x-usb/present"; +std::string Battery::fileBatConnected_ = "/sys/class/power_supply/axp20x-battery/present"; +std::string Battery::fileBatCapacity_ = "/sys/class/power_supply/axp20x-battery/capacity"; int Battery::percentage_ = 0; int Battery::prevPercentage_ = 0; @@ -94,8 +91,9 @@ float Battery::currentWaitTime_ = 0.0f; bool Battery::mustRender_ = false; -Battery::Battery(Page &p, float scaleX, float scaleY, float reloadPeriod, SDL_Color fontColor) +Battery::Battery(Page &p, Configuration &config, float reloadPeriod, SDL_Color fontColor, float scaleX, float scaleY) : Component(p) + , config_(config) , texture_(NULL) , texture_prescaled_(NULL) , reloadPeriod_(reloadPeriod) @@ -104,6 +102,16 @@ Battery::Battery(Page &p, float scaleX, float scaleY, float reloadPeriod, SDL_Co , fontColor_(0xff000000 | ((uint32_t)fontColor.b) << 16 | ((uint32_t)fontColor.g) << 8 | ((uint32_t)fontColor.r)) { allocateGraphicsMemory(); + + if( config_.propertyExists( "fileUsbConnected" ) ){ + config_.getProperty( "fileUsbConnected", fileUsbConnected_ ); + } + if( config_.propertyExists( "fileBatConnected" ) ){ + config_.getProperty( "fileBatConnected", fileBatConnected_ ); + } + if( config_.propertyExists( "fileBatCapacity" ) ){ + config_.getProperty( "fileBatCapacity", fileBatCapacity_ ); + } } Battery::~Battery() @@ -295,7 +303,7 @@ int Battery::readFileValue(std::string file){ bool Battery::isBatConnected(){ - int res = readFileValue(fileBatConnected); + int res = readFileValue(fileBatConnected_); //printf("%s: %d \n", __func__, res); return (res==1)?true:false; @@ -303,7 +311,7 @@ bool Battery::isBatConnected(){ bool Battery::isUsbConnected(){ - int res = readFileValue(fileUsbConnected); + int res = readFileValue(fileUsbConnected_); //printf("%s: %d \n", __func__, res); return (res==1)?true:false; @@ -311,7 +319,7 @@ bool Battery::isUsbConnected(){ int Battery::getBatPercent(){ - int res = readFileValue(fileBatCapacity); + int res = readFileValue(fileBatCapacity_); //printf("%s: %d \n", __func__, res); return res; diff --git a/RetroFE/Source/Graphics/Component/Battery.h b/RetroFE/Source/Graphics/Component/Battery.h index 7c1713b..729ab8e 100644 --- a/RetroFE/Source/Graphics/Component/Battery.h +++ b/RetroFE/Source/Graphics/Component/Battery.h @@ -7,7 +7,7 @@ class Battery : public Component { public: - Battery(Page &p, float scaleX, float scaleY, float reloadPeriod, SDL_Color fontColor); + Battery(Page &p, Configuration &config, float reloadPeriod, SDL_Color fontColor, float scaleX, float scaleY); virtual ~Battery(); void freeGraphicsMemory(); void allocateGraphicsMemory(); @@ -24,6 +24,7 @@ protected: void drawNoBattery(); int readFileValue(std::string file); + Configuration &config_; SDL_Surface *texture_; SDL_Surface *texture_prescaled_; uint32_t fontColor_; @@ -31,6 +32,10 @@ protected: float scaleY_; float reloadPeriod_; + static std::string fileUsbConnected_; + static std::string fileBatConnected_; + static std::string fileBatCapacity_; + static float currentWaitTime_; static bool mustRender_; static int percentage_; diff --git a/RetroFE/Source/Graphics/PageBuilder.cpp b/RetroFE/Source/Graphics/PageBuilder.cpp index 53ca31e..ead0335 100644 --- a/RetroFE/Source/Graphics/PageBuilder.cpp +++ b/RetroFE/Source/Graphics/PageBuilder.cpp @@ -418,7 +418,7 @@ bool PageBuilder::buildComponents(xml_node<> *layout, Page *page) fontColor.r = intColor & 0xFF; } - Battery *c = new Battery(*page, scaleX_, scaleY_, reloadPeriod, fontColor); + Battery *c = new Battery(*page, config_, reloadPeriod, fontColor, scaleX_, scaleY_); buildViewInfo(componentXml, c->baseViewInfo); loadTweens(c, componentXml); page->addComponent(c);