Hyelicht 2.0
Controller application for the Hyelicht shelf. Paint on the shelf with colors, turn on the fireplace mode, and more.
Loading...
Searching...
No Matches
displaycontroller.h
1/*
2 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
3 * SPDX-FileCopyrightText: 2021-2022 Eike Hein <sho@eikehein.com>
4 */
5
6#pragma once
7
8#include <QEasingCurve>
9#include <QObject>
10#include <QQmlParserStatus>
11#include <QVariantAnimation>
12
13#ifdef HYELICHT_BUILD_ONBOARD
14#include <QSerialPort>
15#endif
16
17#include <QTimer>
18
19class QSerialPort;
20
22
46class DisplayController : public QObject, public QQmlParserStatus
47{
48 Q_OBJECT
49 Q_INTERFACES(QQmlParserStatus)
50
51
60 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
61
63
71
73
80 Q_PROPERTY(qint32 baudRate READ baudRate WRITE setBaudRate NOTIFY baudRateChanged)
81
83
94 Q_PROPERTY(bool on READ on WRITE setOn NOTIFY onChanged)
95
97
108 Q_PROPERTY(qreal brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged)
109
111
121
123
136
138
145 Q_PROPERTY(QEasingCurve fadeEasing READ fadeEasing WRITE setFadeEasing NOTIFY fadeEasingChanged)
146
147 public:
149
152 explicit DisplayController(QObject *parent = nullptr);
153 ~DisplayController() override;
154
156
162 bool enabled() const;
163
165
170 void setEnabled(bool enabled);
171
173
180 QString serialPortName() const;
181
183
189 void setSerialPortName(const QString &serialPortName);
190
192
199 qint32 baudRate() const;
200
202
208 void setBaudRate(qint32 rate);
209
211
222 bool on() const;
223
225
235 void setOn(bool on);
236
238
247 qreal brightness() const;
248
250
256 void setBrightness(qreal brightness);
257
259
266 int idleTimeout() const;
267
269
277 void setIdleTimeout(int timeout);
278
280
288 Q_INVOKABLE void resetIdleTimeout();
289
291
298 int fadeDuration() const;
299
301
312
314
321 QEasingCurve fadeEasing() const;
322
324
330 void setFadeEasing(const QEasingCurve &fadeEasing);
331
333 void classBegin() override;
335 void componentComplete() override;
336
337 Q_SIGNALS:
339
343 void enabledChanged() const;
344
346
351
353
357 void baudRateChanged() const;
358
360
364 void onChanged() const;
365
367
371 void brightnessChanged() const;
372
374
378 void idleTimeoutChanged() const;
379
381
386
388
392 void fadeEasingChanged() const;
393
394 private:
395 void connectPwmGenerator();
396 void disconnectPwmGenerator();
397 void fade(qreal from, qreal to);
398 inline void writeBrightness(qreal brightness);
399
400 bool m_enabled;
401
402#ifdef HYELICHT_BUILD_ONBOARD
403 QSerialPort m_serialPort;
404#endif
405
406 bool m_on;
407
408 qreal m_brightness;
409 qreal m_pendingBrightness;
410
411 QTimer m_idleTimeoutTimer;
412
413 QVariantAnimation m_fadeAnimation;
414 int m_fadeDuration;
415
416 bool m_createdByQML;
417 bool m_complete;
418};
Provides PWM-based display backlight control with the help of an attached MCU.
Definition displaycontroller.h:47
void setIdleTimeout(int timeout)
Set the wait time in seconds after which the display is turned off.
Definition displaycontroller.cpp:232
qreal brightness
Display brightness level while on.
Definition displaycontroller.h:108
void componentComplete() override
Implements the QQmlParserStatus interface.
Definition displaycontroller.cpp:291
void setSerialPortName(const QString &serialPortName)
Set the serial port device filename used for communication with the PWM generator MCU.
Definition displaycontroller.cpp:121
void brightnessChanged() const
The display brightness level while on has changed.
void setEnabled(bool enabled)
Turn serial communication with the PWM generator MCU on or off.
Definition displaycontroller.cpp:95
int fadeDuration
Duration in milliseconds for an animated fade between the two ends of the brightness range.
Definition displaycontroller.h:135
QEasingCurve fadeEasing
Easing curve used when fading between display brightness levels.
Definition displaycontroller.h:145
void classBegin() override
Implements the QQmlParserStatus interface.
Definition displaycontroller.cpp:286
void baudRateChanged() const
The baud rate used for serial communication with the PWM generator MCU has changed.
QString serialPortName
Serial port device filename used for communication with the PWM generator MCU.
Definition displaycontroller.h:70
void serialPortNameChanged() const
The serial port device filename used for communication with the PWM generator MCU has changed.
void idleTimeoutChanged() const
The wait time in seconds after which the display is turned off has changed.
void fadeDurationChanged() const
The duration in milliseconds for an animated fade between the two ends of the brightness range has ch...
void setBrightness(qreal brightness)
Set the display brightness level while on.
Definition displaycontroller.cpp:212
void setOn(bool on)
Turn the display on or off.
Definition displaycontroller.cpp:173
void setFadeEasing(const QEasingCurve &fadeEasing)
Set the easing curve used when fading between display brightness levels.
Definition displaycontroller.cpp:278
void enabledChanged() const
Serial communication with the PWM generator MCU has turned on or off.
int idleTimeout
Wait time in seconds after which the display is turned off.
Definition displaycontroller.h:120
Q_INVOKABLE void resetIdleTimeout()
Reset the auto-turnoff timer.
Definition displaycontroller.cpp:250
void setFadeDuration(int fadeDuration)
Set the duration in milliseconds for an animated fade between the two ends of the brightness range.
Definition displaycontroller.cpp:264
void onChanged() const
The display has turned on or off.
bool enabled
Toggle serial communication with the PWM generator MCU.
Definition displaycontroller.h:60
qint32 baudRate
Baud rate used for serial communication with the PWM generator MCU.
Definition displaycontroller.h:80
bool on
Toggle the display on or off.
Definition displaycontroller.h:94
void fadeEasingChanged() const
The easing curve used when fading between display brightness levels has changed.
void setBaudRate(qint32 rate)
Set the baud rate used for serial communication with the PWM generator MCU.
Definition displaycontroller.cpp:149