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)
48 qWarning() <<
"No lights device";
52 if (m_state != newState) {
53 if (newState == Lights::On) {
60 Q_EMIT stateChanged(m_state);
64 Lights::State Lights::state()
const
69 void Lights::setColor(
const QColor &color)
71 if (m_color != color) {
73 Q_EMIT colorChanged(m_color);
78 QColor Lights::color()
const
83 int Lights::onMillisec()
const
88 void Lights::setOnMillisec(
int onMs)
92 Q_EMIT onMillisecChanged(m_onMs);
97 int Lights::offMillisec()
const
102 void Lights::setOffMillisec(
int offMs)
104 if (m_offMs != offMs) {
106 Q_EMIT offMillisecChanged(m_offMs);
120 err = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, (hw_module_t
const**)&module);
123 err = module->methods->open(module, LIGHT_ID_NOTIFICATIONS, &device);
125 m_lightDevice = (light_device_t*)device;
129 qWarning() <<
"Failed to access notification lights";
132 qWarning() <<
"Failed to initialize lights hardware.";
137 void Lights::turnOn()
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";
153 void Lights::turnOff()
156 memset(&state, 0,
sizeof(light_state_t));
157 state.color = 0x00000000;
158 state.flashMode = LIGHT_FLASH_NONE;
160 state.flashOffMS = 0;
161 state.brightnessMode = 0;
163 if (m_lightDevice->set_light(m_lightDevice, &state) != 0) {
164 qWarning() <<
"Failed to turn the light off";