2 * Copyright (C) 2014 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 * Author: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
20#include <QtCore/QDebug>
23#include "android-hardware.h"
27Lights::Lights(QObject* parent)
40 hw_device_t* device = (hw_device_t*) m_lightDevice;
41 device->close(device);
45void 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);
64Lights::State Lights::state() const
69void Lights::setColor(const QColor &color)
71 if (m_color != color) {
73 Q_EMIT colorChanged(m_color);
74 // FIXME: update the color if the light is already on
78QColor Lights::color() const
83int Lights::onMillisec() const
88void Lights::setOnMillisec(int onMs)
92 Q_EMIT onMillisecChanged(m_onMs);
93 // FIXME: update the property if the light is already on
97int Lights::offMillisec() const
102void Lights::setOffMillisec(int offMs)
104 if (m_offMs != offMs) {
106 Q_EMIT offMillisecChanged(m_offMs);
107 // FIXME: update the property if the light is already on
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.";
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";
153void 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";
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list