-
Notifications
You must be signed in to change notification settings - Fork 0
/
QRetroLed.h
47 lines (39 loc) · 993 Bytes
/
QRetroLed.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef QRETRO_LED_H
#define QRETRO_LED_H
#include <QObject>
#include <map>
#define QRETRO_LED_DEFAULT_STATE 0
class QRetroLed : public QObject
{
Q_OBJECT
public:
/**
* @brief Get the state of the LED with the specified index.
* @param index The index of the LED.
* @return State of the LED. If not found, returns QRETRO_LED_DEFAULT_STATE.
*/
int state(int index)
{
auto led = m_Leds.find(index);
return led == m_Leds.end() ? QRETRO_LED_DEFAULT_STATE : led->second;
}
/**
* @brief Set the state of the LED with the specified index.
* @param index The index of the LED.
* @param state The new state to set for the LED.
* @note If an LED with the index does not exist, it will be created.
*/
void setState(int index, int state)
{
if (m_Leds[index] != state)
{
m_Leds[index] = state;
emit changed(index, state);
}
}
signals:
void changed(int index, int state);
private:
std::map<int, int> m_Leds;
};
#endif