2020-06-28 23:05:32 +02:00
|
|
|
#ifndef LEDEVICEFILE_H
|
|
|
|
#define LEDEVICEFILE_H
|
2013-08-15 21:11:02 +02:00
|
|
|
|
2020-06-28 23:05:32 +02:00
|
|
|
// LedDevice includes
|
2013-12-17 19:50:15 +01:00
|
|
|
#include <leddevice/LedDevice.h>
|
2013-08-15 21:11:02 +02:00
|
|
|
|
2020-06-28 23:05:32 +02:00
|
|
|
// Qt includes
|
|
|
|
#include <QFile>
|
|
|
|
#include <QDateTime>
|
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2020-06-28 23:05:32 +02:00
|
|
|
/// Implementation of the LedDevice that write the LED-colors to an
|
|
|
|
/// ASCII-textfile primarily for testing purposes
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2016-03-23 11:12:34 +01:00
|
|
|
class LedDeviceFile : public LedDevice
|
2013-08-15 21:11:02 +02:00
|
|
|
{
|
|
|
|
public:
|
2020-06-28 23:05:32 +02:00
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2020-06-28 23:05:32 +02:00
|
|
|
/// @brief Constructs a file output LED-device
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2020-06-28 23:05:32 +02:00
|
|
|
/// @param deviceConfig Device's configuration as JSON-Object
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
2020-02-10 15:21:58 +01:00
|
|
|
explicit LedDeviceFile(const QJsonObject &deviceConfig);
|
2013-09-09 04:54:13 +02:00
|
|
|
|
|
|
|
///
|
2020-06-28 23:05:32 +02:00
|
|
|
/// @brief Destructor of the LedDevice
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2020-02-10 15:21:58 +01:00
|
|
|
virtual ~LedDeviceFile() override;
|
2013-08-15 21:11:02 +02:00
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
2020-06-28 23:05:32 +02:00
|
|
|
/// @brief Constructs the LED-device
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
2020-06-28 23:05:32 +02:00
|
|
|
/// @param[in] deviceConfig Device's configuration as JSON-Object
|
|
|
|
/// @return LedDevice constructed
|
|
|
|
static LedDevice* construct(const QJsonObject &deviceConfig);
|
2020-02-10 15:21:58 +01:00
|
|
|
|
2020-06-28 23:05:32 +02:00
|
|
|
public slots:
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-06-28 23:05:32 +02:00
|
|
|
/// @brief Closes the output device.
|
|
|
|
///
|
|
|
|
/// @return Zero on success (i.e. device is closed), else negative
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
|
|
|
virtual void close() override;
|
2020-06-28 23:05:32 +02:00
|
|
|
|
2016-09-23 08:49:22 +02:00
|
|
|
protected:
|
2020-06-28 23:05:32 +02:00
|
|
|
|
2019-12-08 13:12:01 +01:00
|
|
|
///
|
2020-06-28 23:05:32 +02:00
|
|
|
/// @brief Initialise the device's configuration
|
2019-12-08 13:12:01 +01:00
|
|
|
///
|
2020-06-28 23:05:32 +02:00
|
|
|
/// @param[in] deviceConfig the JSON device configuration
|
|
|
|
/// @return True, if success
|
2019-12-08 13:12:01 +01:00
|
|
|
///
|
2020-06-28 23:05:32 +02:00
|
|
|
virtual bool init(const QJsonObject &deviceConfig) override;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2020-06-28 23:05:32 +02:00
|
|
|
/// @brief Opens the output device.
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2020-06-28 23:05:32 +02:00
|
|
|
/// @return Zero on success (i.e. device is ready), else negative
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2020-06-28 23:05:32 +02:00
|
|
|
virtual int open() override;
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Writes the RGB-Color values to the LEDs.
|
|
|
|
///
|
|
|
|
/// @param[in] ledValues The RGB-color per LED
|
|
|
|
/// @return Zero on success, else negative
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2020-02-10 15:21:58 +01:00
|
|
|
virtual int write(const std::vector<ColorRgb> & ledValues) override;
|
2013-08-15 21:11:02 +02:00
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
/// The outputstream
|
2020-06-28 23:05:32 +02:00
|
|
|
QFile* _file;
|
2019-12-08 13:12:01 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2020-06-28 23:05:32 +02:00
|
|
|
void initFile(const QString &filename);
|
|
|
|
|
2019-12-08 13:12:01 +01:00
|
|
|
QString _fileName;
|
|
|
|
/// Timestamp for the output record
|
|
|
|
bool _printTimeStamp;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
2013-08-15 21:11:02 +02:00
|
|
|
};
|
2020-06-28 23:05:32 +02:00
|
|
|
|
|
|
|
#endif // LEDEVICEFILE_H
|