diff options
Diffstat (limited to 'examples/sensors/grue/plugin')
-rw-r--r-- | examples/sensors/grue/plugin/CMakeLists.txt | 64 | ||||
-rw-r--r-- | examples/sensors/grue/plugin/gruesensor.cpp | 112 | ||||
-rw-r--r-- | examples/sensors/grue/plugin/gruesensor.h | 43 | ||||
-rw-r--r-- | examples/sensors/grue/plugin/gruesensor_p.h | 29 | ||||
-rw-r--r-- | examples/sensors/grue/plugin/gruesensorimpl.cpp | 103 | ||||
-rw-r--r-- | examples/sensors/grue/plugin/gruesensorimpl.h | 40 | ||||
-rw-r--r-- | examples/sensors/grue/plugin/main.cpp | 42 | ||||
-rw-r--r-- | examples/sensors/grue/plugin/plugin.json | 1 | ||||
-rw-r--r-- | examples/sensors/grue/plugin/plugin.pro | 27 |
9 files changed, 0 insertions, 461 deletions
diff --git a/examples/sensors/grue/plugin/CMakeLists.txt b/examples/sensors/grue/plugin/CMakeLists.txt deleted file mode 100644 index 11e8aee..0000000 --- a/examples/sensors/grue/plugin/CMakeLists.txt +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(qtsensors_grue LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/sensors/grue/sensors") - -find_package(Qt6 REQUIRED COMPONENTS Core Sensors) - -qt_add_plugin(qtsensors_grue - PLUGIN_TYPE sensors -) - -target_sources(qtsensors_grue PRIVATE - gruesensorimpl.cpp gruesensorimpl.h - gruesensor.cpp gruesensor.h gruesensor_p.h - main.cpp -) - -set_target_properties(qtsensors_grue PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -if(WIN32 OR (UNIX AND NOT APPLE)) - set_target_properties(qtsensors_grue PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../sensors - ) -endif() - -if(APPLE AND QT6_IS_SHARED_LIBS_BUILD) - set_target_properties(qtsensors_grue PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../grue_app.app/Contents/Plugins/sensors - ) -endif() - -target_link_libraries(qtsensors_grue PUBLIC - Qt::Core - Qt::Sensors -) - -if(ANDROID) - add_custom_target(gruesensorplugin_android_copy ALL - COMMAND "${CMAKE_COMMAND}" - -E copy_if_different - "$<TARGET_FILE:qtsensors_grue>" - "${CMAKE_CURRENT_BINARY_DIR}/../android-build/libs/${CMAKE_ANDROID_ARCH_ABI}/$<TARGET_FILE_NAME:qtsensors_grue>" - COMMENT "Copying sensor plugin lib to grue_app android libs folder.") - - add_dependencies(gruesensorplugin_android_copy qtsensors_grue) -endif() - -install(TARGETS qtsensors_grue - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/sensors/grue/plugin/gruesensor.cpp b/examples/sensors/grue/plugin/gruesensor.cpp deleted file mode 100644 index 9bc3784..0000000 --- a/examples/sensors/grue/plugin/gruesensor.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "gruesensor.h" -#include "gruesensor_p.h" - -IMPLEMENT_READING(GrueSensorReading) - -/* - \omit - \class GrueSensorReading - - \brief The GrueSensorReading class holds readings from the Grue sensor. - - The Grue Sensor informs you of your chance of being eaten by a Grue. - - Grues love the dark so as long as your surroundings are relatively light - you are safe. However the more time you spend in the dark, the higher - your chances are of being eaten by a Grue. -*/ - -/* - \property GrueSensorReading::chanceOfBeingEaten - \brief holds your chance of being eaten. - - The value is the probability (from 0 to 100) that a Grue will eat you. - A probability of 100 means you are currently being eaten. The darker - it is, the more likely you are to be eaten by a Grue. The longer you - stay in a dark area, the more likely you are to be eaten by a Grue. - If you are in a lit room, the probability will be 0 as Grues fear light. - \endomit -*/ - -int GrueSensorReading::chanceOfBeingEaten() const -{ - return d->chanceOfBeingEaten; -} - -void GrueSensorReading::setChanceOfBeingEaten(int chanceOfBeingEaten) -{ - d->chanceOfBeingEaten = chanceOfBeingEaten; -} - -// ===================================================================== - -// begin generated code - -/* - \omit - \class GrueFilter - - \brief The GrueFilter class is a convenience wrapper around QSensorFilter. - - The only difference is that the filter() method features a pointer to GrueSensorReading - instead of QSensorReading. - \endomit -*/ - -/* - \omit - \fn GrueFilter::filter(GrueSensorReading *reading) - - Called when \a reading changes. Returns false to prevent the reading from propagating. - - \sa QSensorFilter::filter() - \endomit -*/ - -char const * const GrueSensor::sensorType("GrueSensor"); - -/* - \omit - \class GrueSensor - - \brief The GrueSensor class is a convenience wrapper around QSensor. - - The only behavioural difference is that this class sets the type properly. - - This class also features a reading() function that returns a GrueSensorReading instead of a QSensorReading. - - For details about how the sensor works, see \l GrueSensorReading. - - \sa GrueSensorReading - \endomit -*/ - -/* - \omit - \fn GrueSensor::GrueSensor(QObject *parent) - - Construct the sensor as a child of \a parent. - \endomit -*/ - -/* - \fn GrueSensor::~GrueSensor() - - Destroy the sensor. Stops the sensor if it has not already been stopped. -*/ - -/* - \omit - \fn GrueSensor::reading() const - - Returns the reading class for this sensor. - - \sa QSensor::reading() - \endomit -*/ -// end generated code - -#include "moc_gruesensor.cpp" diff --git a/examples/sensors/grue/plugin/gruesensor.h b/examples/sensors/grue/plugin/gruesensor.h deleted file mode 100644 index 9677e62..0000000 --- a/examples/sensors/grue/plugin/gruesensor.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef GRUESENSOR_H -#define GRUESENSOR_H - -#include <qsensor.h> - -class GrueSensorReadingPrivate; - -class GrueSensorReading : public QSensorReading -{ - Q_OBJECT - Q_PROPERTY(int chanceOfBeingEaten READ chanceOfBeingEaten WRITE setChanceOfBeingEaten) - DECLARE_READING(GrueSensorReading) -public: - int chanceOfBeingEaten() const; - void setChanceOfBeingEaten(int chanceOfBeingEaten); -}; - -// begin generated code - -class GrueFilter : public QSensorFilter -{ -public: - virtual bool filter(GrueSensorReading *reading) = 0; -private: - bool filter(QSensorReading *reading) override { return filter(static_cast<GrueSensorReading*>(reading)); } -}; - -class GrueSensor : public QSensor -{ - Q_OBJECT - Q_PROPERTY(GrueSensorReading* reading READ reading) -public: - explicit GrueSensor(QObject *parent = 0) : QSensor(GrueSensor::sensorType, parent) {} - virtual ~GrueSensor() {} - GrueSensorReading *reading() const { return static_cast<GrueSensorReading*>(QSensor::reading()); } - static char const * const sensorType; -}; -// end generated code - -#endif diff --git a/examples/sensors/grue/plugin/gruesensor_p.h b/examples/sensors/grue/plugin/gruesensor_p.h deleted file mode 100644 index 4804f8c..0000000 --- a/examples/sensors/grue/plugin/gruesensor_p.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef GRUESENSOR_P_H -#define GRUESENSOR_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -class GrueSensorReadingPrivate -{ -public: - GrueSensorReadingPrivate() - : chanceOfBeingEaten(-1) - { - } - - int chanceOfBeingEaten; -}; - -#endif diff --git a/examples/sensors/grue/plugin/gruesensorimpl.cpp b/examples/sensors/grue/plugin/gruesensorimpl.cpp deleted file mode 100644 index 7bfdb09..0000000 --- a/examples/sensors/grue/plugin/gruesensorimpl.cpp +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "gruesensorimpl.h" -#include <QDebug> -#include <QTimer> - -char const * const gruesensorimpl::id("grue.gruesensor"); - -gruesensorimpl::gruesensorimpl(QSensor *sensor) - : QSensorBackend(sensor) - , lightLevel(QAmbientLightReading::Undefined) -{ - // We need a light sensor - lightSensor = new QAmbientLightSensor(this); - connect(lightSensor, SIGNAL(readingChanged()), this, SLOT(lightChanged())); - lightSensor->connectToBackend(); - - // We need a timer - darkTimer = new QTimer(this); - darkTimer->setInterval(1000); - connect(darkTimer, SIGNAL(timeout()), this, SLOT(increaseChance())); - - // We use this as our timestamp source - timer.start(); - -//! [setReading] - // Register our reading instance - setReading<GrueSensorReading>(&m_reading); -//! [setReading] - -//! [metadata] - // Supply metadata - // We can run as fast as the light sensor does - setDataRates(lightSensor); - // Only one output range, 0 to 1 in .1 increments - addOutputRange(0, 1, 0.1); - setDescription(QLatin1String("Grue Sensor")); -//! [metadata] -} - -void gruesensorimpl::start() -{ -//! [start] - lightSensor->setDataRate(sensor()->dataRate()); - lightSensor->start(); - // If the light sensor doesn't work we don't work either - if (!lightSensor->isActive()) - sensorStopped(); - if (lightSensor->isBusy()) - sensorBusy(); -//! [start] -} - -void gruesensorimpl::stop() -{ - lightSensor->stop(); -} - -void gruesensorimpl::lightChanged() -{ - if (lightLevel == lightSensor->reading()->lightLevel()) - return; - - lightLevel = lightSensor->reading()->lightLevel(); - - int chance = 0; - darkTimer->stop(); - - switch (lightSensor->reading()->lightLevel()) { - case QAmbientLightReading::Dark: - // It is dark. You are likely to be eaten by a grue. - chance = 10; - darkTimer->start(); - break; - default: - break; - } - - // Only send an update if the value has changed. - if (chance != m_reading.chanceOfBeingEaten() || m_reading.timestamp() == 0) { - m_reading.setTimestamp(timer.elapsed()); - m_reading.setChanceOfBeingEaten(chance); - newReadingAvailable(); - } -} - -void gruesensorimpl::increaseChance() -{ - // The longer you stay in the dark, the higher your chance of being eaten - int chance = m_reading.chanceOfBeingEaten() + 10; - - m_reading.setTimestamp(timer.elapsed()); - m_reading.setChanceOfBeingEaten(chance); - - newReadingAvailable(); - - // No point in using the timer anymore if we've hit 100... you can't get more - // likely to be eaten than 100% - if (chance >= 100) - darkTimer->stop(); -} - diff --git a/examples/sensors/grue/plugin/gruesensorimpl.h b/examples/sensors/grue/plugin/gruesensorimpl.h deleted file mode 100644 index 001af4d..0000000 --- a/examples/sensors/grue/plugin/gruesensorimpl.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef GRUESENSORIMPL_H -#define GRUESENSORIMPL_H - -#include <qsensorbackend.h> -#include "gruesensor.h" -#include <qambientlightsensor.h> -#include <QElapsedTimer> - -QT_BEGIN_NAMESPACE -class QTimer; -QT_END_NAMESPACE - -class gruesensorimpl : public QSensorBackend -{ - Q_OBJECT -public: - static char const * const id; - - gruesensorimpl(QSensor *sensor); - - void start() override; - void stop() override; - -private Q_SLOTS: - void lightChanged(); - void increaseChance(); - -private: - GrueSensorReading m_reading; - QAmbientLightSensor *lightSensor; - QTimer *darkTimer; - QElapsedTimer timer; - QAmbientLightReading::LightLevel lightLevel; -}; - -#endif - diff --git a/examples/sensors/grue/plugin/main.cpp b/examples/sensors/grue/plugin/main.cpp deleted file mode 100644 index 39b9a58..0000000 --- a/examples/sensors/grue/plugin/main.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "gruesensorimpl.h" -#include <qsensorplugin.h> -#include <qsensorbackend.h> -#include <qsensormanager.h> -#include <QFile> -#include <QDebug> - -class GrueSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorChangesInterface, public QSensorBackendFactory -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json") - Q_INTERFACES(QSensorPluginInterface QSensorChangesInterface) -public: - void registerSensors() override - { - } - - void sensorsChanged() override - { - if (!QSensor::defaultSensorForType(QAmbientLightSensor::sensorType).isEmpty()) { - // There is a light sensor available. Register the backend - if (!QSensorManager::isBackendRegistered(GrueSensor::sensorType, gruesensorimpl::id)) - QSensorManager::registerBackend(GrueSensor::sensorType, gruesensorimpl::id, this); - } else { - if (QSensorManager::isBackendRegistered(GrueSensor::sensorType, gruesensorimpl::id)) - QSensorManager::unregisterBackend(GrueSensor::sensorType, gruesensorimpl::id); - } - } - - QSensorBackend *createBackend(QSensor *sensor) override - { - if (sensor->identifier() == gruesensorimpl::id) - return new gruesensorimpl(sensor); - - return 0; - } -}; - -#include "main.moc" diff --git a/examples/sensors/grue/plugin/plugin.json b/examples/sensors/grue/plugin/plugin.json deleted file mode 100644 index ab37205..0000000 --- a/examples/sensors/grue/plugin/plugin.json +++ /dev/null @@ -1 +0,0 @@ -{ "Keys": [ "grue" ] } diff --git a/examples/sensors/grue/plugin/plugin.pro b/examples/sensors/grue/plugin/plugin.pro deleted file mode 100644 index aa03d6c..0000000 --- a/examples/sensors/grue/plugin/plugin.pro +++ /dev/null @@ -1,27 +0,0 @@ -TEMPLATE = lib -CONFIG += plugin -TARGET = $$qtLibraryTarget(plugins_sensors_qtsensors_grue) -PLUGIN_TYPE = sensors - -QT = core sensors - -macos:!qtConfig(static): DESTDIR = ../grue_app.app/Contents/MacOS/$$PLUGIN_TYPE -else: DESTDIR = ../$$PLUGIN_TYPE - -HEADERS += gruesensorimpl.h \ - gruesensor.h \ - gruesensor_p.h - -SOURCES += gruesensorimpl.cpp \ - main.cpp \ - gruesensor.cpp - - -# Install the plugin under Grue example directory -target.path=$$[QT_INSTALL_EXAMPLES]/sensors/grue/$$PLUGIN_TYPE -INSTALLS += target - -CONFIG += install_ok # Do not cargo-cult this! - -OTHER_FILES += \ - plugin.json |