Compare commits
5 Commits
5b6dd9e62c
...
17a4890fdc
Author | SHA1 | Date | |
---|---|---|---|
17a4890fdc | |||
e4f18911f9 | |||
17a1eab03d | |||
69b14243bc | |||
65b4fbc484 |
@ -17,7 +17,7 @@ static inline void rotateLog(const std::filesystem::path& logFileName, int numRo
|
|||||||
const auto generateRotateNames = [&]() {
|
const auto generateRotateNames = [&]() {
|
||||||
std::vector<QString> rotateFileNames = {QString().fromStdString(logFileName.string())};
|
std::vector<QString> rotateFileNames = {QString().fromStdString(logFileName.string())};
|
||||||
|
|
||||||
for(size_t i = 1; i < numRotatingLogs; ++i) {
|
for(int i = 1; i < numRotatingLogs; ++i) {
|
||||||
auto rotateName = logFileName.stem();
|
auto rotateName = logFileName.stem();
|
||||||
rotateName += std::string(".") + std::to_string(i);
|
rotateName += std::string(".") + std::to_string(i);
|
||||||
rotateName += logFileName.extension();
|
rotateName += logFileName.extension();
|
||||||
|
@ -123,8 +123,7 @@ void MainWindow::setupMonitorsTab()
|
|||||||
[this](int state) { m_ui.monitorOverallBrightnessSlider->setEnabled(state == Qt::CheckState::Checked); });
|
[this](int state) { m_ui.monitorOverallBrightnessSlider->setEnabled(state == Qt::CheckState::Checked); });
|
||||||
|
|
||||||
connect(m_ui.monitorBrightnessSlider, &QSlider::valueChanged, [this](int value) {
|
connect(m_ui.monitorBrightnessSlider, &QSlider::valueChanged, [this](int value) {
|
||||||
const auto mappedBrightness = utils::map(value, 0, 100, 0.f, 1.f);
|
const auto newBrightness = utils::map(value, 0, 100, 0.f, 1.f);
|
||||||
const auto newBrightness = std::clamp(mappedBrightness, 0.f, 1.f);
|
|
||||||
qDebug(ltr("Overriding brightness with %1").arg(newBrightness));
|
qDebug(ltr("Overriding brightness with %1").arg(newBrightness));
|
||||||
m_brightness = newBrightness;
|
m_brightness = newBrightness;
|
||||||
});
|
});
|
||||||
@ -183,9 +182,9 @@ void MainWindow::setupCallbackTimer()
|
|||||||
|
|
||||||
void MainWindow::updateCurrentMonitorGUI(int index)
|
void MainWindow::updateCurrentMonitorGUI(int index)
|
||||||
{
|
{
|
||||||
const auto brightness = std::clamp<int>(utils::map(m_monitors[index].brightness, 0.f, 1.f, 0, 100), 0, 100);
|
const auto brightness = utils::map(m_monitors[index].brightness, 0.f, 1.f, 0, 100);
|
||||||
const auto minimum = std::clamp<int>(utils::map(m_monitors[index].minBrightness, 0.f, 1.f, 0, 100), 0, 100);
|
const auto minimum = utils::map(m_monitors[index].minBrightness, 0.f, 1.f, 0, 100);
|
||||||
const auto maximum = std::clamp<int>(utils::map(m_monitors[index].maxBrightness, 0.f, 1.f, 0, 100), 0, 100);
|
const auto maximum = utils::map(m_monitors[index].maxBrightness, 0.f, 1.f, 0, 100);
|
||||||
|
|
||||||
m_ui.monitorMinBrightnessSlider->setValue(minimum);
|
m_ui.monitorMinBrightnessSlider->setValue(minimum);
|
||||||
m_ui.monitorMinBrightnessValueLabel->setText(QString("%1%").arg(minimum, 3, 10));
|
m_ui.monitorMinBrightnessValueLabel->setText(QString("%1%").arg(minimum, 3, 10));
|
||||||
@ -205,7 +204,6 @@ void MainWindow::updateState()
|
|||||||
|
|
||||||
bool sensorError = false;
|
bool sensorError = false;
|
||||||
bool monitorError = false;
|
bool monitorError = false;
|
||||||
size_t iconBrightness = 0;
|
|
||||||
|
|
||||||
const auto getAverageSensorValue = [this](float& brightness) {
|
const auto getAverageSensorValue = [this](float& brightness) {
|
||||||
if(m_sensors.empty()) {
|
if(m_sensors.empty()) {
|
||||||
@ -246,8 +244,7 @@ void MainWindow::updateState()
|
|||||||
sensorError = true;
|
sensorError = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto roundedBrightness = std::round(utils::map(m_brightness, 0.f, 1.f, 0, 8));
|
const auto iconBrightness = utils::map(m_brightness, 0.f, 1.f, size_t{0}, size_t{8});
|
||||||
iconBrightness = std::clamp<size_t>(roundedBrightness, 0, 8);
|
|
||||||
|
|
||||||
if(!setAllMonitorsBrightness(m_brightness)) {
|
if(!setAllMonitorsBrightness(m_brightness)) {
|
||||||
enumMonitors();
|
enumMonitors();
|
||||||
|
@ -57,6 +57,8 @@ class Monitor {
|
|||||||
|
|
||||||
#if defined(__clang__) || defined(__GNUC__)
|
#if defined(__clang__) || defined(__GNUC__)
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
class Monitor {
|
class Monitor {
|
||||||
public:
|
public:
|
||||||
Monitor();
|
Monitor();
|
||||||
@ -64,6 +66,8 @@ class Monitor {
|
|||||||
bool setBrightness(float);
|
bool setBrightness(float);
|
||||||
float getBrightness();
|
float getBrightness();
|
||||||
|
|
||||||
|
QString getName() const;
|
||||||
|
|
||||||
operator bool() const;
|
operator bool() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -26,6 +26,12 @@ float Monitor::getBrightness()
|
|||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Monitor::getName() const
|
||||||
|
{
|
||||||
|
qWarning(ltr("Getting monitor name not implemented"));
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
|
||||||
Monitor::operator bool() const
|
Monitor::operator bool() const
|
||||||
{
|
{
|
||||||
qWarning(ltr("Checking monitor validity not implemented"));
|
qWarning(ltr("Checking monitor validity not implemented"));
|
||||||
|
@ -64,8 +64,7 @@ bool Monitor::setBrightness(float percentage)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto mappedBrightness = utils::map(percentage, 0.f, 1.f, m_brightnessRange->first, m_brightnessRange->second);
|
const auto newBrightness = utils::map(percentage, 0.f, 1.f, m_brightnessRange->first, m_brightnessRange->second);
|
||||||
const auto newBrightness = std::clamp<DWORD>(std::round(mappedBrightness), m_brightnessRange->first, m_brightnessRange->second);
|
|
||||||
|
|
||||||
if(!SetMonitorBrightness(m_physicalMonitor.handle, newBrightness)) {
|
if(!SetMonitorBrightness(m_physicalMonitor.handle, newBrightness)) {
|
||||||
qCritical(ltr("Failed to set brightness of monitor '%1' with handle '0x%2' and physical handle '0x%3', error: %4")
|
qCritical(ltr("Failed to set brightness of monitor '%1' with handle '0x%2' and physical handle '0x%3', error: %4")
|
||||||
@ -110,7 +109,7 @@ float Monitor::getBrightness()
|
|||||||
m_brightnessRange = std::pair{minBrightness, maxBrightness};
|
m_brightnessRange = std::pair{minBrightness, maxBrightness};
|
||||||
m_errorOccurred = false;
|
m_errorOccurred = false;
|
||||||
|
|
||||||
return std::clamp(utils::map(brightness, minBrightness, maxBrightness, 0.f, 1.f), 0.f, 1.f);
|
return utils::map(brightness, minBrightness, maxBrightness, 0.f, 1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Monitor::getName() const
|
QString Monitor::getName() const
|
||||||
|
@ -47,8 +47,7 @@ std::vector<float> Sensor::readValues()
|
|||||||
std::vector<float> normalizedValues;
|
std::vector<float> normalizedValues;
|
||||||
|
|
||||||
for(const auto& value: values) {
|
for(const auto& value: values) {
|
||||||
const auto mappedValue = utils::map(value, m_range->first, m_range->second, 0.f, 1.f);
|
normalizedValues.push_back(utils::map(value, m_range->first, m_range->second, 0.f, 1.f));
|
||||||
normalizedValues.push_back(std::clamp(mappedValue, 0.f, 1.f));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return normalizedValues;
|
return normalizedValues;
|
||||||
|
@ -1,17 +1,30 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
|
|
||||||
template<typename InType, typename OutType>
|
template<typename InType, typename OutType>
|
||||||
auto map(InType value, InType inMin, InType inMax, OutType outMin, OutType outMax)
|
auto interpolate(InType value, InType inMin, InType inMax, OutType outMin, OutType outMax)
|
||||||
{
|
{
|
||||||
return (value - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
|
return (value - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename InType, typename OutType>
|
||||||
|
auto map(InType value, InType inMin, InType inMax, OutType outMin, OutType outMax)
|
||||||
|
{
|
||||||
|
if constexpr(std::is_integral_v<OutType>) {
|
||||||
|
return std::clamp(static_cast<OutType>(std::round(interpolate(value, inMin, inMax, outMin, outMax))), outMin, outMax);
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::clamp(static_cast<OutType>(interpolate(value, inMin, inMax, outMin, outMax)), outMin, outMax);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename>
|
template<typename>
|
||||||
struct array_size;
|
struct array_size;
|
||||||
|
|
||||||
|
@ -71,10 +71,16 @@ target_link_libraries(AdaptiveBrightness
|
|||||||
Qt5::SerialPort
|
Qt5::SerialPort
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
|
||||||
|
target_link_libraries(AdaptiveBrightness
|
||||||
|
stdc++fs
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
target_link_libraries(AdaptiveBrightness
|
target_link_libraries(AdaptiveBrightness
|
||||||
Dxva2.lib
|
Dxva2.lib
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
|
Loading…
Reference in New Issue
Block a user