Torc  0.1
torcnetworkbuttonoutput.cpp
Go to the documentation of this file.
1 /* Class TorcNetworkButtonOutput
2 *
3 * This file is part of the Torc project.
4 *
5 * Copyright (C) Mark Kendall 2016-18
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
21 */
22 
23 // Torc
25 
40 TorcNetworkButtonOutput::TorcNetworkButtonOutput(double Default, const QVariantMap &Details)
41  : TorcNetworkSwitchOutput(Default, Details),
42  m_pulseTimer()
43 {
44  // timers cannot be started from other threads, so use some signalling
45  connect(this, &TorcNetworkButtonOutput::Pushed, this, &TorcNetworkButtonOutput::StartTimer);
46 
47  // setup the timer
48  m_pulseTimer.setSingleShot(true);
49  m_pulseTimer.setInterval(5);
50  connect(&m_pulseTimer, &QTimer::timeout, this, &TorcNetworkButtonOutput::EndPulse);
51 }
52 
54 {
55  return QStringList() << tr("Network button");
56 }
57 
59 {
60  return TorcOutput::Button;
61 }
62 
70 {
71  (void)Value;
72  QMutexLocker locker(&lock);
73 
74  if (m_pulseTimer.isActive())
75  return;
76 
77  TorcSwitchOutput::SetValue(value < 1.0 ? 1.0 : 0.0);
78  emit Pushed();
79 }
80 
81 void TorcNetworkButtonOutput::StartTimer(void)
82 {
83  if (!m_pulseTimer.isActive())
84  m_pulseTimer.start();
85 }
86 
87 void TorcNetworkButtonOutput::EndPulse(void)
88 {
89  QMutexLocker locker(&lock);
90 
91  TorcSwitchOutput::SetValue(value < 1.0 ? 1.0 : 0.0);
92 }
93 
94 
virtual void SetValue(double Value) override
TorcOutput::Type GetType(void) override
QMutex lock
Definition: torcdevice.h:66
double value
Definition: torcdevice.h:60
QStringList GetDescription(void) override
void SetValue(double Value) override
Toggle the value of the button.
TorcNetworkButtonOutput(double Default, const QVariantMap &Details)