Compare commits
7
Commits
v1.0
...
eb18ab9f1e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb18ab9f1e | ||
|
|
2253a25011 | ||
|
|
d1d2d4ae0a | ||
|
|
19d73640c7 | ||
|
|
927c318f54 | ||
|
|
ab8b1bfbbe | ||
|
|
d3d80a2062 |
No files matched your search
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
#include <QCloseEvent>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QSlider>
|
#include <QSlider>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
@@ -52,7 +53,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
|||||||
m_visibility = !m_visibility;
|
m_visibility = !m_visibility;
|
||||||
});
|
});
|
||||||
m_trayIconMenu->addSeparator();
|
m_trayIconMenu->addSeparator();
|
||||||
m_trayIconMenu->addAction(tr("Quit"), this, &QWidget::close);
|
m_trayIconMenu->addAction(tr("Quit"), this, &QCoreApplication::quit);
|
||||||
|
|
||||||
qDebug(ltr("Tray icon context menu initialized"));
|
qDebug(ltr("Tray icon context menu initialized"));
|
||||||
|
|
||||||
@@ -64,9 +65,13 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
|||||||
qDebug(ltr("Tray icon initialized"));
|
qDebug(ltr("Tray icon initialized"));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_timer = new QTimer(this);
|
m_timerThread = new QThread(this);
|
||||||
connect(m_timer, &QTimer::timeout, this, &MainWindow::updateState);
|
m_timer = new QTimer(nullptr);
|
||||||
m_timer->start(1000);
|
m_timer->setInterval(1000);
|
||||||
|
m_timer->moveToThread(m_timerThread);
|
||||||
|
m_timerThread->connect(m_timer, &QTimer::timeout, this, &MainWindow::updateState, Qt::DirectConnection);
|
||||||
|
m_timer->connect(m_timerThread, SIGNAL(started()), SLOT(start()));
|
||||||
|
m_timerThread->start();
|
||||||
|
|
||||||
qDebug(ltr("Tray icon update timer started"));
|
qDebug(ltr("Tray icon update timer started"));
|
||||||
|
|
||||||
@@ -77,6 +82,17 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
|||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
qDebug(ltr("Destroying main window"));
|
qDebug(ltr("Destroying main window"));
|
||||||
|
|
||||||
|
m_timerThread->quit();
|
||||||
|
if(!m_timerThread->wait()) {
|
||||||
|
qCritical(ltr("Timer thread did not terminate cleanly"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::closeEvent(QCloseEvent* event)
|
||||||
|
{
|
||||||
|
m_showHideAction->activate(QAction::Trigger);
|
||||||
|
event->ignore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::loadIcons()
|
void MainWindow::loadIcons()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
|
#include <QThread>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include "monitor.hpp"
|
#include "monitor.hpp"
|
||||||
@@ -24,6 +25,8 @@ class MainWindow : public QMainWindow {
|
|||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void closeEvent(QCloseEvent* event) override;
|
||||||
|
|
||||||
void loadIcons();
|
void loadIcons();
|
||||||
|
|
||||||
void updateState();
|
void updateState();
|
||||||
@@ -39,6 +42,7 @@ class MainWindow : public QMainWindow {
|
|||||||
QMenu* m_trayIconMenu = nullptr;
|
QMenu* m_trayIconMenu = nullptr;
|
||||||
QSystemTrayIcon* m_trayIcon = nullptr;
|
QSystemTrayIcon* m_trayIcon = nullptr;
|
||||||
|
|
||||||
|
QThread* m_timerThread = nullptr;
|
||||||
QTimer* m_timer = nullptr;
|
QTimer* m_timer = nullptr;
|
||||||
|
|
||||||
float m_brightness = 0.5f;
|
float m_brightness = 0.5f;
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ extern BOOL enumMonitorsCallback(HMONITOR, HDC, LPRECT, LPARAM);
|
|||||||
class Monitor {
|
class Monitor {
|
||||||
public:
|
public:
|
||||||
Monitor() = delete;
|
Monitor() = delete;
|
||||||
|
Monitor(const Monitor&) = delete;
|
||||||
|
Monitor(Monitor&& other) noexcept;
|
||||||
~Monitor();
|
~Monitor();
|
||||||
|
|
||||||
bool setBrightness(float percentage);
|
bool setBrightness(float percentage);
|
||||||
@@ -36,8 +38,8 @@ class Monitor {
|
|||||||
|
|
||||||
friend BOOL detail::enumMonitorsCallback(HMONITOR, HDC, LPRECT, LPARAM);
|
friend BOOL detail::enumMonitorsCallback(HMONITOR, HDC, LPRECT, LPARAM);
|
||||||
|
|
||||||
const HMONITOR m_hMonitor;
|
HMONITOR m_hMonitor;
|
||||||
const PhysicalMonitor m_physicalMonitor;
|
PhysicalMonitor m_physicalMonitor;
|
||||||
|
|
||||||
std::optional<std::pair<DWORD, DWORD>> m_brightnessRange;
|
std::optional<std::pair<DWORD, DWORD>> m_brightnessRange;
|
||||||
bool m_errorOccurred = false;
|
bool m_errorOccurred = false;
|
||||||
|
|||||||
@@ -28,14 +28,14 @@ static BOOL enumMonitorsCallback(HMONITOR hMonitor, [[maybe_unused]] HDC hDC, [[
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(const auto& physicalMonitor: physicalMonitors) {
|
for(const auto& physicalMonitor: physicalMonitors) {
|
||||||
const auto monitor = Monitor(hMonitor, physicalMonitor);
|
auto monitor = Monitor(hMonitor, physicalMonitor);
|
||||||
|
|
||||||
if(monitor.hasBrightnessCapability()) {
|
if(monitor.hasBrightnessCapability()) {
|
||||||
qInfo(ltr("Found brightness capable monitor '%1' with handle '0x%2' and physical handle '0x%3'")
|
qInfo(ltr("Found brightness capable monitor '%1' with handle '0x%2' and physical handle '0x%3'")
|
||||||
.arg(monitor.m_physicalMonitor.name)
|
.arg(monitor.m_physicalMonitor.name)
|
||||||
.arg(reinterpret_cast<qulonglong>(monitor.m_hMonitor), 0, 16)
|
.arg(reinterpret_cast<qulonglong>(monitor.m_hMonitor), 0, 16)
|
||||||
.arg(reinterpret_cast<qulonglong>(monitor.m_physicalMonitor.handle), 0, 16));
|
.arg(reinterpret_cast<qulonglong>(monitor.m_physicalMonitor.handle), 0, 16));
|
||||||
monitors.push_back(monitor);
|
monitors.push_back(std::move(monitor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,14 +15,15 @@
|
|||||||
#include "log_tr.hpp"
|
#include "log_tr.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
|
||||||
Monitor::Monitor(HMONITOR hMonitor, PHYSICAL_MONITOR physicalMonitor)
|
Monitor::Monitor(Monitor&& other) noexcept
|
||||||
: m_hMonitor(hMonitor)
|
: m_hMonitor(other.m_hMonitor)
|
||||||
, m_physicalMonitor(physicalMonitor.hPhysicalMonitor, physicalMonitor.szPhysicalMonitorDescription)
|
, m_physicalMonitor(other.m_physicalMonitor)
|
||||||
|
, m_brightnessRange(other.m_brightnessRange)
|
||||||
|
, m_errorOccurred(other.m_errorOccurred)
|
||||||
{
|
{
|
||||||
qDebug(ltr("Creating monitor '%1' with handle '0x%2' and physical handle '0x%3'")
|
other.m_hMonitor = 0;
|
||||||
.arg(m_physicalMonitor.name)
|
other.m_physicalMonitor.name.clear();
|
||||||
.arg(reinterpret_cast<qulonglong>(m_hMonitor), 0, 16)
|
other.m_physicalMonitor.handle = 0;
|
||||||
.arg(reinterpret_cast<qulonglong>(m_physicalMonitor.handle), 0, 16));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Monitor::~Monitor()
|
Monitor::~Monitor()
|
||||||
@@ -31,6 +32,14 @@ Monitor::~Monitor()
|
|||||||
.arg(m_physicalMonitor.name)
|
.arg(m_physicalMonitor.name)
|
||||||
.arg(reinterpret_cast<qulonglong>(m_hMonitor), 0, 16)
|
.arg(reinterpret_cast<qulonglong>(m_hMonitor), 0, 16)
|
||||||
.arg(reinterpret_cast<qulonglong>(m_physicalMonitor.handle), 0, 16));
|
.arg(reinterpret_cast<qulonglong>(m_physicalMonitor.handle), 0, 16));
|
||||||
|
|
||||||
|
if(m_physicalMonitor.handle && !DestroyPhysicalMonitor(m_physicalMonitor.handle)) {
|
||||||
|
qCritical(ltr("Error occurred while destroying monitor '%1' with handle '0x%2' and physical handle '0x%3', error: %4")
|
||||||
|
.arg(m_physicalMonitor.name)
|
||||||
|
.arg(reinterpret_cast<qulonglong>(m_hMonitor), 0, 16)
|
||||||
|
.arg(reinterpret_cast<qulonglong>(m_physicalMonitor.handle), 0, 16)
|
||||||
|
.arg(getLastErrorString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Monitor::setBrightness(float percentage)
|
bool Monitor::setBrightness(float percentage)
|
||||||
@@ -107,6 +116,16 @@ Monitor::operator bool() const
|
|||||||
return !m_errorOccurred;
|
return !m_errorOccurred;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Monitor::Monitor(HMONITOR hMonitor, PHYSICAL_MONITOR physicalMonitor)
|
||||||
|
: m_hMonitor(hMonitor)
|
||||||
|
, m_physicalMonitor(physicalMonitor.hPhysicalMonitor, physicalMonitor.szPhysicalMonitorDescription)
|
||||||
|
{
|
||||||
|
qDebug(ltr("Creating monitor '%1' with handle '0x%2' and physical handle '0x%3'")
|
||||||
|
.arg(m_physicalMonitor.name)
|
||||||
|
.arg(reinterpret_cast<qulonglong>(m_hMonitor), 0, 16)
|
||||||
|
.arg(reinterpret_cast<qulonglong>(m_physicalMonitor.handle), 0, 16));
|
||||||
|
}
|
||||||
|
|
||||||
bool Monitor::hasBrightnessCapability() const
|
bool Monitor::hasBrightnessCapability() const
|
||||||
{
|
{
|
||||||
qDebug(ltr("Getting capabilities of monitor '%1' with handle '0x%2' and physical handle '0x%3'")
|
qDebug(ltr("Getting capabilities of monitor '%1' with handle '0x%2' and physical handle '0x%3'")
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class VirtualComPort {
|
|||||||
return hcdc->TxState != 0;
|
return hcdc->TxState != 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifdef INFO_LEDS
|
||||||
HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_SET);
|
||||||
HAL_GPIO_WritePin(BLUE_LED_GPIO_Port, BLUE_LED_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(BLUE_LED_GPIO_Port, BLUE_LED_Pin, GPIO_PIN_RESET);
|
||||||
#endif
|
#endif
|
||||||
@@ -98,7 +98,7 @@ class VirtualComPort {
|
|||||||
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, const_cast<uint8_t*>(m_usbAsyncTxBuffer.data), m_usbAsyncTxBuffer.size);
|
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, const_cast<uint8_t*>(m_usbAsyncTxBuffer.data), m_usbAsyncTxBuffer.size);
|
||||||
USBD_CDC_TransmitPacket(&hUsbDeviceFS);
|
USBD_CDC_TransmitPacket(&hUsbDeviceFS);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifdef INFO_LEDS
|
||||||
HAL_GPIO_WritePin(BLUE_LED_GPIO_Port, BLUE_LED_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(BLUE_LED_GPIO_Port, BLUE_LED_Pin, GPIO_PIN_SET);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ class VirtualComPort {
|
|||||||
|
|
||||||
static int8_t CdcInit()
|
static int8_t CdcInit()
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
#ifdef INFO_LEDS
|
||||||
HAL_GPIO_WritePin(RED_LED_GPIO_Port, RED_LED_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(RED_LED_GPIO_Port, RED_LED_Pin, GPIO_PIN_SET);
|
||||||
HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_RESET);
|
||||||
HAL_GPIO_WritePin(BLUE_LED_GPIO_Port, BLUE_LED_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(BLUE_LED_GPIO_Port, BLUE_LED_Pin, GPIO_PIN_SET);
|
||||||
@@ -129,7 +129,7 @@ class VirtualComPort {
|
|||||||
|
|
||||||
static int8_t CdcDeInit()
|
static int8_t CdcDeInit()
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
#ifdef INFO_LEDS
|
||||||
HAL_GPIO_WritePin(RED_LED_GPIO_Port, RED_LED_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(RED_LED_GPIO_Port, RED_LED_Pin, GPIO_PIN_RESET);
|
||||||
HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_SET);
|
||||||
HAL_GPIO_WritePin(BLUE_LED_GPIO_Port, BLUE_LED_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(BLUE_LED_GPIO_Port, BLUE_LED_Pin, GPIO_PIN_SET);
|
||||||
@@ -196,7 +196,7 @@ class VirtualComPort {
|
|||||||
|
|
||||||
static int8_t CdcReceive([[maybe_unused]] uint8_t* buf, uint32_t* length)
|
static int8_t CdcReceive([[maybe_unused]] uint8_t* buf, uint32_t* length)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
#ifdef INFO_LEDS
|
||||||
HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_SET);
|
||||||
HAL_GPIO_WritePin(RED_LED_GPIO_Port, RED_LED_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(RED_LED_GPIO_Port, RED_LED_Pin, GPIO_PIN_RESET);
|
||||||
#endif
|
#endif
|
||||||
@@ -208,7 +208,7 @@ class VirtualComPort {
|
|||||||
rxHandler(m_usbAsyncRxBuffer.data[i]);
|
rxHandler(m_usbAsyncRxBuffer.data[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifdef INFO_LEDS
|
||||||
HAL_GPIO_WritePin(RED_LED_GPIO_Port, RED_LED_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(RED_LED_GPIO_Port, RED_LED_Pin, GPIO_PIN_SET);
|
||||||
#endif
|
#endif
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ TARGET = AdaptiveBrightnessFirmware
|
|||||||
# building variables
|
# building variables
|
||||||
######################################
|
######################################
|
||||||
# debug build?
|
# debug build?
|
||||||
DEBUG = 1
|
DEBUG = 0
|
||||||
# optimization
|
# optimization
|
||||||
OPT = -Og
|
OPT = -Os
|
||||||
|
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
@@ -126,12 +126,14 @@ AS_DEFS =
|
|||||||
# C defines
|
# C defines
|
||||||
C_DEFS = \
|
C_DEFS = \
|
||||||
-DUSE_HAL_DRIVER \
|
-DUSE_HAL_DRIVER \
|
||||||
-DSTM32F042x6
|
-DSTM32F042x6 \
|
||||||
|
-DINFO_LEDS
|
||||||
|
|
||||||
# C++ defines
|
# C++ defines
|
||||||
CXX_DEFS = \
|
CXX_DEFS = \
|
||||||
-DUSE_HAL_DRIVER \
|
-DUSE_HAL_DRIVER \
|
||||||
-DSTM32F042x6
|
-DSTM32F042x6 \
|
||||||
|
-DINFO_LEDS
|
||||||
|
|
||||||
|
|
||||||
# AS includes
|
# AS includes
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user