on xenial help sign in
Expose color, onMillisec and offMillisec properties to QML.
7cd27f2Renato Araujo Oliveira Filho
plugins/Lights/CMakeLists.txt+1−1
@@ -12,7 +12,7 @@ add_library(Lights-qml MODULE
12 Lights.cpp
12 Lights.cpp
13 )
13 )
14
14
15−qt5_use_modules(Lights-qml Qml)
15+qt5_use_modules(Lights-qml Qml Gui)
16target_link_libraries(Lights-qml ${ANDROID_HARDWARE_LIBRARIES})
16target_link_libraries(Lights-qml ${ANDROID_HARDWARE_LIBRARIES})
17
17
18add_unity8_plugin(Lights 0.1 Lights TARGETS Lights-qml)
18add_unity8_plugin(Lights 0.1 Lights TARGETS Lights-qml)
plugins/Lights/Lights.cpp+49−5
@@ -27,12 +27,14 @@ extern "C" {
27
27
28Lights::Lights(QObject* parent)
28Lights::Lights(QObject* parent)
29 : QObject(parent),
29 : QObject(parent),
30+ m_lightDevice(0),
31+ m_color("blue"),
30 m_state(Lights::Off),
32 m_state(Lights::Off),
31− m_lightDevice(0)
33+ m_onMs(1000),
34+ m_offMs(3000)
32{
35{
33}
36}
34
37
35−
36Lights::~Lights()
38Lights::~Lights()
37{
39{
38 if (m_lightDevice) {
40 if (m_lightDevice) {
@@ -57,6 +59,48 @@ Lights::State Lights::state() const
57 return m_state;
59 return m_state;
58}
60}
59
61
62+void Lights::setColor(const QColor &color)
63+{
64+ if (m_color != color) {
65+ m_color = color;
66+ Q_EMIT colorChanged(m_color);
67+ // FIXME: update the collor if the light is already on
68+ }
69+}
70+
71+QColor Lights::color() const
72+{
73+ return m_color;
74+}
75+
76+int Lights::onMillisec() const
77+{
78+ return m_onMs;
79+}
80+
81+void Lights::setOnMillisec(int onMs)
82+{
83+ if (m_onMs != onMs) {
84+ m_onMs = onMs;
85+ Q_EMIT onMillisecChanged(m_onMs);
86+ // FIXME: update the property if the light is already on
87+ }
88+}
89+
90+int Lights::offMillisec() const
91+{
92+ return m_offMs;
93+}
94+
95+void Lights::setOffMillisec(int offMs)
96+{
97+ if (m_offMs != offMs) {
98+ m_offMs = offMs;
99+ Q_EMIT offMillisecChanged(m_offMs);
100+ // FIXME: update the property if the light is already on
101+ }
102+}
103+
60bool Lights::init()
104bool Lights::init()
61{
105{
62 if (m_lightDevice) {
106 if (m_lightDevice) {
@@ -96,10 +140,10 @@ void Lights::turnOn()
96 // pulse
140 // pulse
97 light_state_t state;
141 light_state_t state;
98 memset(&state, 0, sizeof(light_state_t));
142 memset(&state, 0, sizeof(light_state_t));
99− state.color = 0xff0000ff; // blue
143+ state.color = m_color.rgba();
100 state.flashMode = LIGHT_FLASH_TIMED;
144 state.flashMode = LIGHT_FLASH_TIMED;
101− state.flashOnMS = 1000;
145+ state.flashOnMS = m_onMs;
102− state.flashOffMS = 1000;
146+ state.flashOffMS = m_offMs;
103 state.brightnessMode = BRIGHTNESS_MODE_USER;
147 state.brightnessMode = BRIGHTNESS_MODE_USER;
104
148
105 if (m_lightDevice->set_light(m_lightDevice, &state) != 0) {
149 if (m_lightDevice->set_light(m_lightDevice, &state) != 0) {
plugins/Lights/Lights.h+20−1
@@ -20,6 +20,7 @@
20#define UNITY_LIGHTS_H
20#define UNITY_LIGHTS_H
21
21
22#include <QtCore/QObject>
22#include <QtCore/QObject>
23+#include <QtGui/QColor>
23
24
24struct light_device_t;
25struct light_device_t;
25
26
@@ -28,6 +29,9 @@ class Lights: public QObject
28 Q_OBJECT
29 Q_OBJECT
29 Q_ENUMS(State)
30 Q_ENUMS(State)
30 Q_PROPERTY(State state READ state WRITE setState NOTIFY stateChanged)
31 Q_PROPERTY(State state READ state WRITE setState NOTIFY stateChanged)
32+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
33+ Q_PROPERTY(int onMillisec READ onMillisec WRITE setOnMillisec NOTIFY onMillisecChanged)
34+ Q_PROPERTY(int offMillisec READ offMillisec WRITE setOffMillisec NOTIFY offMillisecChanged)
31
35
32public:
36public:
33 enum State {
37 enum State {
@@ -41,12 +45,27 @@ public:
41 void setState(State newState);
45 void setState(State newState);
42 State state() const;
46 State state() const;
43
47
48+ void setColor(const QColor &color);
49+ QColor color() const;
50+
51+ int onMillisec() const;
52+ void setOnMillisec(int onMs);
53+
54+ int offMillisec() const;
55+ void setOffMillisec(int offMs);
56+
44Q_SIGNALS:
57Q_SIGNALS:
45 void stateChanged(State newState);
58 void stateChanged(State newState);
59+ void colorChanged(const QColor &color);
60+ void onMillisecChanged(int onMs);
61+ void offMillisecChanged(int offMs);
46
62
47private:
63private:
48− State m_state;
49 light_device_t* m_lightDevice;
64 light_device_t* m_lightDevice;
65+ QColor m_color;
66+ State m_state;
67+ int m_onMs;
68+ int m_offMs;
50
69
51 bool init();
70 bool init();
52 void turnOff();
71 void turnOff();