Compare commits

..

3 Commits

5 changed files with 25 additions and 2 deletions

View File

@ -10,6 +10,8 @@
#include <physicalmonitorenumerationapi.h>
#include <windows.h>
#include <QString>
namespace detail {
extern BOOL enumMonitorsCallback(HMONITOR, HDC, LPRECT, LPARAM);
@ -26,6 +28,8 @@ class Monitor {
bool setBrightness(float percentage);
float getBrightness();
QString getName() const;
operator bool() const;
private:

View File

@ -24,6 +24,8 @@ Monitor::Monitor(Monitor&& other) noexcept
other.m_hMonitor = 0;
other.m_physicalMonitor.name.clear();
other.m_physicalMonitor.handle = 0;
other.m_brightnessRange.reset();
other.m_errorOccurred = false;
}
Monitor::~Monitor()
@ -111,6 +113,14 @@ float Monitor::getBrightness()
return std::clamp(utils::map(brightness, minBrightness, maxBrightness, 0.f, 1.f), 0.f, 1.f);
}
QString Monitor::getName() const
{
return QString("%1 (0x%2:0x%3)")
.arg(m_physicalMonitor.name)
.arg(reinterpret_cast<qulonglong>(m_hMonitor), 0, 16)
.arg(reinterpret_cast<qulonglong>(m_physicalMonitor.handle), 0, 16);
}
Monitor::operator bool() const
{
return !m_errorOccurred;

View File

@ -15,6 +15,13 @@ Sensor::~Sensor()
qDebug(ltr("Destroying sensor on serial port %1").arg(m_serialPortName));
}
Sensor::Sensor(Sensor&& other) noexcept : m_serialPortName(other.m_serialPortName), m_errorOccurred(other.m_errorOccurred), m_range(other.m_range)
{
other.m_serialPortName.clear();
other.m_errorOccurred = false;
other.m_range.reset();
}
std::vector<float> Sensor::readValues()
{
qDebug(ltr("Reading values of sensor on port %1").arg(m_serialPortName));

View File

@ -11,6 +11,8 @@
class Sensor {
public:
Sensor(const Sensor&) = delete;
Sensor(Sensor&& other) noexcept;
~Sensor();
std::vector<float> readValues();
@ -26,7 +28,7 @@ class Sensor {
static constexpr auto SUPPORTED_FIRMWARE = std::string_view{"AdaptiveBrightness v1.2"};
const QString m_serialPortName;
QString m_serialPortName;
bool m_errorOccurred = false;
std::optional<std::pair<int, int>> m_range;

View File

@ -21,7 +21,7 @@ std::vector<Sensor> enumerateSensors()
auto sensor = Sensor(portInfo.portName());
if(sensor.isValidSensor()) {
qInfo(ltr("Successfully enumerated sensor on port %1").arg(portInfo.portName()));
sensors.push_back(sensor);
sensors.push_back(std::move(sensor));
}
}