// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \example grue
    \title Qt Sensors - Grue Sensor Example
    \brief The Qt Sensors - Grue sensor example demonstrates all the steps from
    creating a new sensor to using it.
    \ingroup qtsensors-examples

    \image qtsensors-examples-grue.png

    The sensor definition and implementation are in a new sensor plugin that client
    apps can use for detecting Grues (imaginary monsters that live in the dark).

    \list
    \li \l{Grue Sensor Plugin}
    \endlist

    The sensor plugin can be used by C++ applications as shown in the console
    application example.

    \list
    \li \l{Grue Sensor Console Application}
    \endlist

    QML applications can use the new sensor by importing the QMLGrueSensor class.

    \list
    \li \l{Grue Sensor QML Application}
    \endlist

    \section1 Grue Sensor Plugin

    The Grue sensor is defined in a new sensor plugin that applications can use.

    The plugin provides the sensor reading property that describes your chance of
    being eaten. This chance is increasing in the dark until it is 100% when
    you are eaten by the Grue and at that point the plugin stops further processing.
    In case of the plugin receiving light again before that happens the chance of
    being eaten resets to 0%.

    This example was created using the make_sensor.pl script which can be found in
    src/sensors. As such, it contains some generated code that defines the convenience
    classes GrueFilter and GrueSensor.

    \section1 Grue Sensor Implementation

    The Grue sensor implementation lives in the plugin that is loaded by the Qt
    Sensors library. The source code is available in the \c{grue/plugin} subdirectory.

    The Grue sensor needs a backend before it can be used. The backend provided
    is rather basic and it relies on some kind of light sensor to work but it
    gets the job done. If new hardware that can detect the actual presence of Grues
    becomes available a backend could be created that supports this hardware and
    applications using the Grue sensor would be able to use it without any changes.

    There are a few mandatory parts to a backend. They are the start and stop methods
    and the setReading call. The start and stop methods are used to start and stop
    any underlying hardware. In the case of this backend they start and stop a
    light sensor. In the start method, the backend should call the \c{sensorStopped()}
    or \c{sensorBusy()} methods if it cannot start.

    \snippet grue/plugin/gruesensorimpl.cpp start

    The setReading method is needed so that the sensors library knows where the
    readings are coming from. This backend has a local copy of the reading so
    it passes a pointer to the function.

    \snippet grue/plugin/gruesensorimpl.cpp setReading

    However it is also possible to pass null to the setReading method in which
    case the sensors library will create an instance and return a pointer.

    \code
    // Create a reading instance for us to use
    m_reading = setReading<GrueSensorReading>(0);
    \endcode

    The Grue sensor backend also supplies some metadata.

    The backend checks 2 things, how dark it is and how long you have been in the dark.
    It uses the \c{readingChanged()} signal to know when to check the light sensor's
    value. Once it is dark, it uses a timer to increase your chance of being eaten.

    The Grue sensor backend is delivered as a plugin. The plugin has a factory object
    that registers the types available and does the actual instantiation of the backend.

    \section1 Grue Sensor Console Application

    The Grue sensor console application demonstrates use of the Grue sensor.
    The source code is available in the \c{grue/console_app} subdirectory.

    This is a simple commandline application. It demonstrates how to use the generic
    access feature of Qt Sensors to avoid a link-time dependency on a library.

    \section1 Grue Sensor C++ Class Registration for QML

    The QMLGrueSensor class is registered for QML, so the class name can be used
    as an import and the class properties can be accessed from QML.

    \section1 Grue Sensor QML Application

    The Grue sensor QML application demonstrates the use of QMLGrueSensor QML type.

    The application consists of a single QML file and an image. It is built as an
    executable with C++ code that runs the QML, but it can also be launched directly
    using the \c qmlscene tool.

    \code
    qmlscene -I . grue.qml
    \endcode
*/
