Unify paths...
This commit is contained in:
@ -9,6 +9,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
namespace C
|
namespace C
|
||||||
{
|
{
|
||||||
@ -21,7 +22,10 @@ namespace C
|
|||||||
const double updateTimeout= 0.1;
|
const double updateTimeout= 0.1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string conservePath= "/sys/devices/pci0000:00/0000:00:1f.0/PNP0C09:00/VPC2004:00/conservation_mode";
|
const std::filesystem::path conservePath= "/sys/devices/pci0000:00/0000:00:1f.0/PNP0C09:00/VPC2004:00/conservation_mode";
|
||||||
|
const std::filesystem::path powerPath= "/sys/class/power_supply/ADP0";
|
||||||
|
const std::filesystem::path batteryPath= "/sys/class/power_supply/BAT0";
|
||||||
|
const std::filesystem::path backlightPath= "/sys/class/backlight/intel_backlight";
|
||||||
|
|
||||||
const std::map< int, Fl_Color > levelColors=
|
const std::map< int, Fl_Color > levelColors=
|
||||||
{
|
{
|
||||||
@ -50,7 +54,7 @@ scheduledUpdate( void * )
|
|||||||
Fl::repeat_timeout( C::updateTimeout, scheduledUpdate, nullptr );
|
Fl::repeat_timeout( C::updateTimeout, scheduledUpdate, nullptr );
|
||||||
|
|
||||||
if( C::debugUpdateCalled ) std::cerr << "Update!" << std::endl;
|
if( C::debugUpdateCalled ) std::cerr << "Update!" << std::endl;
|
||||||
std::ifstream batt{ "/sys/class/power_supply/BAT0/capacity" };
|
std::ifstream batt{ batteryPath / "capacity" };
|
||||||
batt >> battLevelString;
|
batt >> battLevelString;
|
||||||
std::istringstream iss{ battLevelString };
|
std::istringstream iss{ battLevelString };
|
||||||
int battlevel= 2;
|
int battlevel= 2;
|
||||||
@ -72,20 +76,20 @@ scheduledUpdate( void * )
|
|||||||
}
|
}
|
||||||
if( C::debugUpdate ) std::cerr << "Conservation state read as: " << cons << std::endl;
|
if( C::debugUpdate ) std::cerr << "Conservation state read as: " << cons << std::endl;
|
||||||
|
|
||||||
std::ifstream acCheck{ "/sys/class/power_supply/ADP0/online" };
|
std::ifstream acCheck{ powerPath / "online" };
|
||||||
int ac= -1;
|
int ac= -1;
|
||||||
acCheck >> ac;
|
acCheck >> ac;
|
||||||
acButton->value( ac );
|
acButton->value( ac );
|
||||||
if( C::debugUpdate ) std::cerr << "AC state read as: " << ac << std::endl;
|
if( C::debugUpdate ) std::cerr << "AC state read as: " << ac << std::endl;
|
||||||
|
|
||||||
|
|
||||||
std::ifstream i_max{ "/sys/class/backlight/intel_backlight/max_brightness" };
|
std::ifstream i_max{ backlightPath / "max_brightness" };
|
||||||
|
|
||||||
int max;
|
int max;
|
||||||
i_max >> max;
|
i_max >> max;
|
||||||
|
|
||||||
|
|
||||||
std::ifstream inf{ "/sys/class/backlight/intel_backlight/brightness" };
|
std::ifstream inf{ backlightPath / "brightness" };
|
||||||
int in;
|
int in;
|
||||||
inf >> in;
|
inf >> in;
|
||||||
|
|
||||||
@ -178,7 +182,7 @@ namespace
|
|||||||
void
|
void
|
||||||
changeBrightness( int pct )
|
changeBrightness( int pct )
|
||||||
{
|
{
|
||||||
std::ifstream i_max{ "/sys/class/backlight/intel_backlight/max_brightness" };
|
std::ifstream i_max{ backlightPath / "max_brightness" };
|
||||||
|
|
||||||
int max;
|
int max;
|
||||||
i_max >> max;
|
i_max >> max;
|
||||||
@ -186,7 +190,7 @@ namespace
|
|||||||
int adj= max * pct / 100;
|
int adj= max * pct / 100;
|
||||||
std::cerr << "Adjustment computed: " << adj << std::endl;
|
std::cerr << "Adjustment computed: " << adj << std::endl;
|
||||||
|
|
||||||
std::ofstream out{ "/sys/class/backlight/intel_backlight/brightness" };
|
std::ofstream out{ backlightPath / "brightness" };
|
||||||
out << adj;
|
out << adj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user