20 #include <QtCore/QDebug>
23 #include "android-hardware.h"
27 Lights::Lights(QObject* parent)
40 hw_device_t* device = (hw_device_t*) m_lightDevice;
41 device->close(device);
45 void Lights::setState(Lights::State newState)
47 if (m_state != newState) {
48 if (newState == Lights::On) {
56 Lights::State Lights::state()
const
61 void Lights::setColor(
const QColor &color)
63 if (m_color != color) {
65 Q_EMIT colorChanged(m_color);
70 QColor Lights::color()
const
75 int Lights::onMillisec()
const
80 void Lights::setOnMillisec(
int onMs)
84 Q_EMIT onMillisecChanged(m_onMs);
89 int Lights::offMillisec()
const
94 void Lights::setOffMillisec(
int offMs)
96 if (m_offMs != offMs) {
98 Q_EMIT offMillisecChanged(m_offMs);
112 err = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, (hw_module_t
const**)&module);
115 err = module->methods->open(module, LIGHT_ID_NOTIFICATIONS, &device);
117 m_lightDevice = (light_device_t*)device;
120 qWarning() <<
"Failed to access notification lights";
123 qWarning() <<
"Failed to initialize lights hardware.";
128 void Lights::turnOn()
131 qWarning() <<
"No lights device";
135 if (m_state == Lights::On) {
141 memset(&state, 0,
sizeof(light_state_t));
142 state.color = m_color.rgba();
143 state.flashMode = LIGHT_FLASH_TIMED;
144 state.flashOnMS = m_onMs;
145 state.flashOffMS = m_offMs;
146 state.brightnessMode = BRIGHTNESS_MODE_USER;
148 if (m_lightDevice->set_light(m_lightDevice, &state) != 0) {
149 qWarning() <<
"Failed to turn the light off";
151 m_state = Lights::On;
152 Q_EMIT stateChanged(m_state);
156 void Lights::turnOff()
159 qWarning() <<
"No lights device";
163 if (m_state == Lights::Off) {
168 memset(&state, 0,
sizeof(light_state_t));
169 state.color = 0x00000000;
170 state.flashMode = LIGHT_FLASH_NONE;
172 state.flashOffMS = 0;
173 state.brightnessMode = 0;
175 if (m_lightDevice->set_light(m_lightDevice, &state) != 0) {
176 qWarning() <<
"Failed to turn the light off";
178 m_state = Lights::Off;
179 Q_EMIT stateChanged(m_state);