Unity 8
Lights.cpp
1 /*
2  * Copyright (C) 2014 Canonical, Ltd.
3  *
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.
7  *
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.
12  *
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/>.
15  *
16  * Author: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
17  */
18 
19 #include "Lights.h"
20 #include <QtCore/QDebug>
21 
22 extern "C" {
23 #include "android-hardware.h"
24 #include <string.h>
25 }
26 
27 Lights::Lights(QObject* parent)
28  : QObject(parent),
29  m_color("blue"),
30  m_state(Lights::Off),
31  m_onMs(1000),
32  m_offMs(3000)
33 {
34 
35 }
36 
37 void Lights::setState(Lights::State newState)
38 {
39  if (!init()) {
40  qWarning() << "No lights device";
41  return;
42  }
43 
44  if (m_state != newState) {
45  if (newState == Lights::On) {
46  turnOn();
47  } else {
48  turnOff();
49  }
50 
51  m_state = newState;
52  Q_EMIT stateChanged(m_state);
53  }
54 }
55 
56 Lights::State Lights::state() const
57 {
58  return m_state;
59 }
60 
61 void Lights::setColor(const QColor &color)
62 {
63  if (m_color != color) {
64  m_color = color;
65  Q_EMIT colorChanged(m_color);
66  // FIXME: update the color if the light is already on
67  }
68 }
69 
70 QColor Lights::color() const
71 {
72  return m_color;
73 }
74 
75 int Lights::onMillisec() const
76 {
77  return m_onMs;
78 }
79 
80 void Lights::setOnMillisec(int onMs)
81 {
82  if (m_onMs != onMs) {
83  m_onMs = onMs;
84  Q_EMIT onMillisecChanged(m_onMs);
85  // FIXME: update the property if the light is already on
86  }
87 }
88 
89 int Lights::offMillisec() const
90 {
91  return m_offMs;
92 }
93 
94 void Lights::setOffMillisec(int offMs)
95 {
96  if (m_offMs != offMs) {
97  m_offMs = offMs;
98  Q_EMIT offMillisecChanged(m_offMs);
99  // FIXME: update the property if the light is already on
100  }
101 }