Skip to content

Commit

Permalink
Dynamic brightness control path, and range adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
breakingspell committed May 10, 2024
1 parent 3ef459e commit dfbed87
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
11 changes: 10 additions & 1 deletion plugins/brightness/official_rpi/official_rpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@

OfficialRPi::OfficialRPi() : brightness_attribute(this->PATH)
{
this->brightness_attribute.open(QIODevice::WriteOnly);
QString fkms_path = "/sys/class/backlight/rpi_backlight/brightness";
QString kms_path = "/sys/class/backlight/10-0045/brightness";

if (QFileInfo(kms_path).exists()) {
PATH = kms_path;
} else {
PATH = fkms_path;
}
brightness_attribute.setFileName(PATH);
brightness_attribute.open(QIODevice::WriteOnly);
}

OfficialRPi::~OfficialRPi()
Expand Down
2 changes: 1 addition & 1 deletion plugins/brightness/official_rpi/official_rpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class OfficialRPi : public QObject, BrightnessPlugin {
void set(int brightness) override;

private:
const QString PATH = "/sys/class/backlight/rpi_backlight/brightness";
QString PATH;

QFile brightness_attribute;
};
4 changes: 2 additions & 2 deletions src/app/arbiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ void Arbiter::set_brightness(uint8_t brightness)

void Arbiter::decrease_brightness(uint8_t val)
{
this->set_brightness(std::min(std::max(76, this->system().brightness.value - val), 255));
this->set_brightness(std::min(std::max(20, this->system().brightness.value - val), 180));
}

void Arbiter::increase_brightness(uint8_t val)
{
this->set_brightness(std::min(std::max(76, this->system().brightness.value + val), 255));
this->set_brightness(std::min(std::max(20, this->system().brightness.value + val), 180));
}

void Arbiter::set_volume(uint8_t volume)
Expand Down
10 changes: 5 additions & 5 deletions src/app/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const char *Session::System::Brightness::AUTO_PLUGIN = "auto";

Session::System::Brightness::Brightness(QSettings &settings)
: plugin(settings.value("System/Brightness/plugin", Session::System::Brightness::AUTO_PLUGIN).toString())
, value(settings.value("System/Brightness/value", 255).toUInt())
, value(settings.value("System/Brightness/value", 180).toUInt())
, loader_()
{
for (const auto file : Session::plugin_dir("brightness").entryInfoList(QDir::Files)) {
Expand Down Expand Up @@ -206,7 +206,7 @@ void Session::System::Brightness::set()
void Session::System::Brightness::reset()
{
if (auto plugin = qobject_cast<BrightnessPlugin *>(this->loader_.instance()))
plugin->set(255);
plugin->set(180);
}

const QList<QString> &Session::System::Brightness::plugins() const
Expand Down Expand Up @@ -313,7 +313,7 @@ QWidget *Session::Forge::brightness_slider(bool buttons) const

auto slider = new QSlider(Qt::Orientation::Horizontal);
slider->setTracking(false);
slider->setRange(76, 255);
slider->setRange(20, 180);
slider->setValue(this->arbiter_.system().brightness.value);
QObject::connect(slider, &QSlider::sliderReleased, [this, slider]{
this->arbiter_.set_brightness(slider->sliderPosition());
Expand All @@ -324,12 +324,12 @@ QWidget *Session::Forge::brightness_slider(bool buttons) const
auto dim_button = new QPushButton();
dim_button->setFlat(true);
this->iconize("brightness_low", dim_button, 26);
QObject::connect(dim_button, &QPushButton::clicked, [this]{ this->arbiter_.decrease_brightness(18); });
QObject::connect(dim_button, &QPushButton::clicked, [this]{ this->arbiter_.decrease_brightness(20); });

auto brighten_button = new QPushButton();
brighten_button->setFlat(true);
this->iconize("brightness_high", brighten_button, 26);
QObject::connect(brighten_button, &QPushButton::clicked, [this]{ this->arbiter_.increase_brightness(18); });
QObject::connect(brighten_button, &QPushButton::clicked, [this]{ this->arbiter_.increase_brightness(20); });

layout->addWidget(dim_button);
layout->addWidget(brighten_button);
Expand Down

0 comments on commit dfbed87

Please sign in to comment.