Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
BlackMark | b7895d61c6 | |
BlackMark | 77d9a22419 | |
BlackMark | 392a03a23d |
|
@ -19,7 +19,7 @@
|
|||
#include "sensor_driver.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), m_mtx(QMutex::RecursionMode::Recursive)
|
||||
{
|
||||
qDebug(ltr("Creating main window"));
|
||||
|
||||
|
@ -54,6 +54,8 @@ void MainWindow::closeEvent(QCloseEvent* event)
|
|||
|
||||
void MainWindow::enumSensors()
|
||||
{
|
||||
m_sensors.clear();
|
||||
|
||||
auto sensors = enumerateSensors();
|
||||
|
||||
for(auto& sensor: sensors) {
|
||||
|
@ -357,6 +359,12 @@ void MainWindow::updateState()
|
|||
|
||||
bool MainWindow::setMonitorBrightness(float& brightness)
|
||||
{
|
||||
constexpr auto hysteresis = [](const auto& lowThreshold, const auto& highThreshold, const auto& currentValue, const auto& newValue) {
|
||||
if(newValue > highThreshold || newValue < lowThreshold)
|
||||
return newValue;
|
||||
return currentValue;
|
||||
};
|
||||
|
||||
if(m_monitors.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -365,6 +373,28 @@ bool MainWindow::setMonitorBrightness(float& brightness)
|
|||
bool allMonitorsSameBrightness = true;
|
||||
|
||||
for(size_t i = 0; i < m_monitors.size(); ++i) {
|
||||
const auto updateMonitorBrightness = [&] {
|
||||
const auto brightnessRange = m_monitors[i].maxBrightness - m_monitors[i].minBrightness;
|
||||
const auto hysteresisDelta = m_monitors[i].manualOverride ? 0.f : m_monitors[i].HYSTERESIS_THRESHOLD * brightnessRange;
|
||||
const auto lowThreshold = std::clamp(m_monitors[i].prevBrightness - hysteresisDelta, m_monitors[i].minBrightness, m_monitors[i].maxBrightness);
|
||||
const auto highThreshold = std::clamp(m_monitors[i].prevBrightness + hysteresisDelta, m_monitors[i].minBrightness, m_monitors[i].maxBrightness);
|
||||
if(hysteresis(lowThreshold, highThreshold, m_monitors[i].prevBrightness, m_monitors[i].brightness) != m_monitors[i].prevBrightness) {
|
||||
qDebug(ltr("Setting monitor %1 brightness from %2 to %3")
|
||||
.arg(i)
|
||||
.arg(m_monitors[i].prevBrightness, 0, 'f', 2)
|
||||
.arg(m_monitors[i].brightness, 0, 'f', 2));
|
||||
m_monitors[i].prevBrightness = m_monitors[i].brightness;
|
||||
return m_monitors[i].driver.setBrightness(m_monitors[i].brightness);
|
||||
}
|
||||
else {
|
||||
qDebug(ltr("Hysteresis prevented setting monitor %1 brightness from %2 to %3")
|
||||
.arg(i)
|
||||
.arg(m_monitors[i].prevBrightness, 0, 'f', 2)
|
||||
.arg(m_monitors[i].brightness, 0, 'f', 2));
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
if(!std::isnan(brightness) && !m_monitors[i].manualOverride) {
|
||||
m_monitors[i].brightness = brightness;
|
||||
}
|
||||
|
@ -375,7 +405,7 @@ bool MainWindow::setMonitorBrightness(float& brightness)
|
|||
allMonitorsSameBrightness = false;
|
||||
}
|
||||
|
||||
if(!m_monitors[i].driver.setBrightness(m_monitors[i].brightness)) {
|
||||
if(!updateMonitorBrightness()) {
|
||||
errorOccurred = true;
|
||||
}
|
||||
else if(m_ui.monitorDropdown->currentIndex() == static_cast<int>(i)) {
|
||||
|
|
|
@ -75,10 +75,13 @@ class MainWindow : public QMainWindow {
|
|||
};
|
||||
|
||||
struct MonitorData {
|
||||
static constexpr auto HYSTERESIS_THRESHOLD = 0.05f;
|
||||
|
||||
Monitor driver;
|
||||
float minBrightness;
|
||||
float maxBrightness;
|
||||
float brightness;
|
||||
float prevBrightness;
|
||||
bool manualOverride;
|
||||
};
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ Found DFU: [0483:df11] ver=2200, devnum=57, cfg=1, intf=0, path="2-13.2.2", alt=
|
|||
Found DFU: [0483:df11] ver=2200, devnum=57, cfg=1, intf=0, path="2-13.2.2", alt=0, name="@Internal Flash /0x08000000/032*0001Kg", serial="FFFFFFFEFFFF"
|
||||
```
|
||||
|
||||
The firmware can then be flashing using:
|
||||
The firmware can then be flashed using:
|
||||
|
||||
```console
|
||||
$ dfu-util -a 0 -s 0x08000000 -D AdaptiveBrightnessFirmware.bin
|
||||
|
|
Loading…
Reference in New Issue