Unity 8
HfdLights.cpp
1 /*
2  * Copyright (C) 2021 UBports Foundation.
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: Florian Leeber <florian@ubports.com>
17  */
18 
19 #include "HfdLights.h"
20 #include <QtCore/QDebug>
21 #include <QDBusArgument>
22 #include <QDBusConnection>
23 #include <iostream>
24 
25 #define HFD_SERVICE_NAME "com.lomiri.hfd"
26 #define HFD_SERVICE_PATH "/com/lomiri/hfd"
27 #define HFD_SERVICE_INTERFACE "com.lomiri.hfd.Leds"
28 
29 HfdLights::HfdLights(QObject* parent)
30  : Lights(parent)
31 {
32  m_hfdInterface = new QDBusInterface(
33  QStringLiteral(HFD_SERVICE_NAME),
34  QStringLiteral(HFD_SERVICE_PATH),
35  QStringLiteral(HFD_SERVICE_INTERFACE),
36  QDBusConnection::systemBus(),
37  this
38  );
39 }
40 
41 bool HfdLights::init()
42 {
43  // hfd does not need any initalization to be used
44  return true;
45 }
46 
47 void HfdLights::turnOn()
48 {
49  m_hfdInterface->call(QStringLiteral("setState"), 0);
50  m_hfdInterface->call(QStringLiteral("setColor"), (quint32)m_color.rgba());
51  m_hfdInterface->call(QStringLiteral("setOnMs"), m_onMs);
52  m_hfdInterface->call(QStringLiteral("setOffMs"), m_offMs);
53  m_hfdInterface->call(QStringLiteral("setState"), 1);
54 }
55 
56 void HfdLights::turnOff()
57 {
58  m_hfdInterface->call(QStringLiteral("setState"), 0);
59  m_hfdInterface->call(QStringLiteral("setColor"), (quint32)0);
60  m_hfdInterface->call(QStringLiteral("setOnMs"), 0);
61  m_hfdInterface->call(QStringLiteral("setOffMs"), 0);
62 }