|
| 1 | +/**************************************************************************** |
| 2 | +** |
| 3 | +** Copyright (c) 2025 Jollyboys Ltd. |
| 4 | +** |
| 5 | +** $QT_BEGIN_LICENSE:LGPL$ |
| 6 | +** |
| 7 | +** GNU Lesser General Public License Usage |
| 8 | +** Alternatively, this file may be used under the terms of the GNU Lesser |
| 9 | +** General Public License version 2.1 as published by the Free Software |
| 10 | +** Foundation and appearing in the file LICENSE.LGPL included in the |
| 11 | +** packaging of this file. Please review the following information to |
| 12 | +** ensure the GNU Lesser General Public License version 2.1 requirements |
| 13 | +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 14 | +** |
| 15 | +** $QT_END_LICENSE$ |
| 16 | +** |
| 17 | +****************************************************************************/ |
| 18 | + |
| 19 | +#include <QFile> |
| 20 | +#include <QTextStream> |
| 21 | + |
| 22 | +#include "hybriswakeupadaptor.h" |
| 23 | +#include "logging.h" |
| 24 | +#include "datatypes/utils.h" |
| 25 | +#include "config.h" |
| 26 | + |
| 27 | +namespace { |
| 28 | +int wakeupSensorType() |
| 29 | +{ |
| 30 | + QVariant setting(SensorFrameworkConfig::configuration()->value("wakeup/sensor_type")); |
| 31 | + bool ok = false; |
| 32 | + int sensorType = setting.toInt(&ok); |
| 33 | + if (!ok) |
| 34 | + sensorType = SENSOR_TYPE_WAKE_GESTURE; |
| 35 | + qCInfo(lcSensorFw) << "wakeupSensorType:" << sensorType; |
| 36 | + return sensorType; |
| 37 | +} |
| 38 | +} |
| 39 | + |
| 40 | +HybrisWakeupAdaptor::HybrisWakeupAdaptor(const QString &id) |
| 41 | + : HybrisAdaptor(id, wakeupSensorType()) |
| 42 | +{ |
| 43 | + m_buffer = new DeviceAdaptorRingBuffer<TimedUnsigned>(1); |
| 44 | + setAdaptedSensor("wakeup", "Wakeup sensor events", m_buffer); |
| 45 | + setDescription("Hybris wakeup"); |
| 46 | + m_powerStatePath = SensorFrameworkConfig::configuration()->value("wakeup/powerstate_path").toByteArray(); |
| 47 | + if (!m_powerStatePath.isEmpty() && !QFile::exists(m_powerStatePath)) { |
| 48 | + qCWarning(lcSensorFw) << NodeBase::id() << "Path does not exists: " << m_powerStatePath; |
| 49 | + m_powerStatePath.clear(); |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +HybrisWakeupAdaptor::~HybrisWakeupAdaptor() |
| 54 | +{ |
| 55 | + delete m_buffer; |
| 56 | +} |
| 57 | + |
| 58 | +bool HybrisWakeupAdaptor::startSensor() |
| 59 | +{ |
| 60 | + if (!(HybrisAdaptor::startSensor())) |
| 61 | + return false; |
| 62 | + if (isRunning() && !m_powerStatePath.isEmpty()) |
| 63 | + writeToFile(m_powerStatePath, "1"); |
| 64 | + qCInfo(lcSensorFw) << id() << "HybrisWakeupAdaptor start"; |
| 65 | + return true; |
| 66 | +} |
| 67 | + |
| 68 | +void HybrisWakeupAdaptor::stopSensor() |
| 69 | +{ |
| 70 | + HybrisAdaptor::stopSensor(); |
| 71 | + if (!isRunning() && !m_powerStatePath.isEmpty()) |
| 72 | + writeToFile(m_powerStatePath, "0"); |
| 73 | + qCInfo(lcSensorFw) << id() << "HybrisWakeupAdaptor stop"; |
| 74 | +} |
| 75 | + |
| 76 | +void HybrisWakeupAdaptor::processSample(const sensors_event_t &data) |
| 77 | +{ |
| 78 | + TimedUnsigned *d = m_buffer->nextSlot(); |
| 79 | + d->timestamp_ = quint64(data.timestamp * 0.001); |
| 80 | + |
| 81 | +#ifdef USE_BINDER |
| 82 | + d->value_ = unsigned(data.u.scalar); |
| 83 | +#else |
| 84 | + d->value_ = unsigned(data.data[0]); |
| 85 | +#endif |
| 86 | + |
| 87 | + qCInfo(lcSensorFw) << id() << "HybrisWakeupAdaptor event" << d->timestamp_ << d->value_; |
| 88 | + |
| 89 | + m_buffer->commit(); |
| 90 | + m_buffer->wakeUpReaders(); |
| 91 | +} |
0 commit comments