hyperion.ng/libsrc/leddevice/dev_other/LedDeviceFile.cpp
LordGrey efc2046ab5
Various Cleanups (#1075)
* LedDevice - Address clang findings

* Fix Windows Warnings

* Ensure newInput is initialised

* Clean-up unused elements for Plaform Capture

* Fix initialization problem and spellings

* Address clang findings and spelling corrections

* LedDevice clean-ups

* Cleanups

* Align that getLedCount is int

* Have "display" as default for Grabbers

* Fix config during start-up for missing elements

* Framegrabber Clean-up - Remove non supported grabbers from selection, filter valid options

* Typo

* Framegrabber.json - Fix property numbering

* Preselect active Grabbertype

* Sort Grabbernames

* Align options with selected element

* Fix deletion of pointer to incomplete type 'BonjourBrowserWrapper'

* Address macOS compile warnings

* Have default layout = 1 LED only to avoid errors as in #673

* Address lgtm findings

* Address finding that params passed to LedDevice discovery were not considered

* Cleanups after merging with latest master

* Update Changelog

* Address lgtm findings

* Fix comment

* Test Fix

* Fix Python Warning

* Handle Dummy Device assignment correctly

* Address delete called on non-final 'commandline::Option' that has virtual functions but non-virtual destructor

* Correct that QTimer.start accepts only int

* Have Release Python GIL & reset threat state chnage downward compatible

* Correct format specifier

* LedDevice - add assertions

* Readonly DB - Fix merge issue

* Smoothing - Fix wrong defaults

* LedDevice - correct assertion

* Show smoothing config set# in debug and related values.

* Suppress error on windows, if default file is "/dev/null"

* CMAKE - Allow to define QT_BASE_DIR dynamically via environment-variable

* Ignore Visual Studio specific files

Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
2020-11-14 17:58:56 +01:00

124 lines
2.3 KiB
C++

#include "LedDeviceFile.h"
// Qt includes
#include <Qt>
#include <QTextStream>
LedDeviceFile::LedDeviceFile(const QJsonObject &deviceConfig)
: LedDevice(deviceConfig)
, _file (nullptr)
{
_printTimeStamp = false;
}
LedDeviceFile::~LedDeviceFile()
{
delete _file;
}
LedDevice* LedDeviceFile::construct(const QJsonObject &deviceConfig)
{
return new LedDeviceFile(deviceConfig);
}
bool LedDeviceFile::init(const QJsonObject &deviceConfig)
{
bool initOK = LedDevice::init(deviceConfig);
_fileName = deviceConfig["output"].toString("/dev/null");
#if _WIN32
if (_fileName == "/dev/null" )
{
_fileName = "NULL";
}
#endif
_printTimeStamp = deviceConfig["printTimeStamp"].toBool(false);
initFile(_fileName);
return initOK;
}
void LedDeviceFile::initFile(const QString &fileName)
{
if ( _file == nullptr )
{
_file = new QFile(fileName, this);
}
}
int LedDeviceFile::open()
{
int retval = -1;
_isDeviceReady = false;
if ( ! _file->isOpen() )
{
Debug(_log, "QIODevice::WriteOnly, %s", QSTRING_CSTR(_fileName));
if ( !_file->open(QIODevice::WriteOnly | QIODevice::Text) )
{
QString errortext = QString ("(%1) %2, file: (%3)").arg(_file->error()).arg(_file->errorString(),_fileName);
this->setInError( errortext );
}
else
{
_isDeviceReady = true;
retval = 0;
}
}
return retval;
}
int LedDeviceFile::close()
{
int retval = 0;
_isDeviceReady = false;
if ( _file != nullptr)
{
// Test, if device requires closing
if ( _file->isOpen() )
{
// close device physically
Debug(_log,"File: %s", QSTRING_CSTR(_fileName) );
_file->close();
}
}
return retval;
}
int LedDeviceFile::write(const std::vector<ColorRgb> & ledValues)
{
QTextStream out(_file);
//printLedValues (ledValues);
if ( _printTimeStamp )
{
QDateTime now = QDateTime::currentDateTime();
qint64 elapsedTimeMs = _lastWriteTime.msecsTo(now);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
out << now.toString(Qt::ISODateWithMs) << " | +" << QString("%1").arg( elapsedTimeMs,4);
#else
out << now.toString(Qt::ISODate) << now.toString(".zzz") << " | +" << QString("%1").arg( elapsedTimeMs,4);
#endif
}
out << " [";
for (const ColorRgb& color : ledValues)
{
out << color;
}
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
out << "]" << Qt::endl;
#else
out << "]" << endl;
#endif
return 0;
}