20 #include <QtCore/QDebug>
23 #include <hardware/hardware.h>
24 #include <hardware/lights.h>
28 Lights::Lights(QObject* parent)
41 hw_device_t* device = (hw_device_t*) m_lightDevice;
42 device->close(device);
46 void Lights::setState(Lights::State newState)
48 if (m_state != newState) {
49 if (newState == Lights::On) {
57 Lights::State Lights::state()
const
62 void Lights::setColor(
const QColor &color)
64 if (m_color != color) {
66 Q_EMIT colorChanged(m_color);
71 QColor Lights::color()
const
76 int Lights::onMillisec()
const
81 void Lights::setOnMillisec(
int onMs)
85 Q_EMIT onMillisecChanged(m_onMs);
90 int Lights::offMillisec()
const
95 void Lights::setOffMillisec(
int offMs)
97 if (m_offMs != offMs) {
99 Q_EMIT offMillisecChanged(m_offMs);
113 err = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, (hw_module_t
const**)&module);
116 err = module->methods->open(module, LIGHT_ID_NOTIFICATIONS, &device);
118 m_lightDevice = (light_device_t*)device;
121 qWarning() <<
"Failed to access notification lights";
124 qWarning() <<
"Failed to initialize lights hardware.";
129 void Lights::turnOn()
132 qWarning() <<
"No lights device";
136 if (m_state == Lights::On) {
142 memset(&state, 0,
sizeof(light_state_t));
143 state.color = m_color.rgba();
144 state.flashMode = LIGHT_FLASH_TIMED;
145 state.flashOnMS = m_onMs;
146 state.flashOffMS = m_offMs;
147 state.brightnessMode = BRIGHTNESS_MODE_USER;
149 if (m_lightDevice->set_light(m_lightDevice, &state) != 0) {
150 qWarning() <<
"Failed to turn the light off";
152 m_state = Lights::On;
153 Q_EMIT stateChanged(m_state);
157 void Lights::turnOff()
160 qWarning() <<
"No lights device";
164 if (m_state == Lights::Off) {
169 memset(&state, 0,
sizeof(light_state_t));
170 state.color = 0x00000000;
171 state.flashMode = LIGHT_FLASH_NONE;
173 state.flashOffMS = 0;
174 state.brightnessMode = 0;
176 if (m_lightDevice->set_light(m_lightDevice, &state) != 0) {
177 qWarning() <<
"Failed to turn the light off";
179 m_state = Lights::Off;
180 Q_EMIT stateChanged(m_state);