@@ -0,0 +1,141 @@
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 <hardware/hardware.h>
24+#include <hardware/lights.h>
28+Lights::Lights(QObject* parent)
30+ m_state(Lights::Off),
39+ hw_device_t* device = (hw_device_t*) m_lightDevice;
40+ device->close(device);
44+void Lights::setState(Lights::State newState)
46+ if (m_state != newState) {
47+ if (newState == Lights::On) {
55+Lights::State Lights::state() const
69+ err = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
72+ err = module->methods->open(module, LIGHT_ID_NOTIFICATIONS, &device);
74+ m_lightDevice = (light_device_t*)device;
77+ qWarning() << "Failt to access notification lights";
80+ qWarning() << "Failt to initialize lights hardware.";
88+ qWarning() << "No lights device";
92+ if (m_state == Lights::On) {
98+ memset(&state, 0, sizeof(light_state_t));
99+ state.color = 0xff0000ff; // blue
100+ state.flashMode = LIGHT_FLASH_TIMED;
101+ state.flashOnMS = 1000;
102+ state.flashOffMS = 1000;
103+ state.brightnessMode = BRIGHTNESS_MODE_USER;
105+ if (m_lightDevice->set_light(m_lightDevice, &state) != 0) {
106+ qWarning() << "Fail to turn the light off";
108+ m_state = Lights::On;
109+ Q_EMIT stateChanged(m_state);
113+void Lights::turnOff()
116+ qWarning() << "No lights device";
120+ if (m_state == Lights::Off) {
124+ light_state_t state;
125+ memset(&state, 0, sizeof(light_state_t));
126+ state.color = 0x00000000;
127+ state.flashMode = LIGHT_FLASH_NONE;
128+ state.flashOnMS = 0;
129+ state.flashOffMS = 0;
130+ state.brightnessMode = 0;
132+ if (m_lightDevice->set_light(m_lightDevice, &state) != 0) {
133+ qWarning() << "Fail to turn the light off";
135+ m_state = Lights::Off;
136+ Q_EMIT stateChanged(m_state);