mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Stop LedDevice:write for disabled devices + Nanoleaf Fixes (#629)
* Handle Exceptions in main & Pythoninit * Have SSDPDiscover generic again * Have SSDPDiscover generic again * Change Info- to Debug logs as technical service messages * Nanoleaf - When switched on, ensure UDP mode * Include SQL Database in Cross-Compile instructions * Fix Clazy (QT code checker) and clang Warnings * Stop LedDevice:write for disabled device * Nanoleaf: Fix uint printfs * NanoLeaf: Fix indents to tabs * NanoLeaf - Add debug verbosity switches * Device switchability support, FileDevice with timestamp support * Nanoleaf Light Panels now support External Control V2 * Enhance LedDeviceFile by Timestamp + fix readyness * Stop color stream, if LedDevice disabled * Nanoleaf - remove switchability
This commit is contained in:
committed by
Paulchen Panther
parent
f917f0fceb
commit
ce7c99d2cd
@@ -1,9 +1,13 @@
|
||||
#include "LedDeviceFile.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
LedDeviceFile::LedDeviceFile(const QJsonObject &deviceConfig)
|
||||
: LedDevice()
|
||||
{
|
||||
init(deviceConfig);
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
LedDeviceFile::~LedDeviceFile()
|
||||
@@ -17,23 +21,40 @@ LedDevice* LedDeviceFile::construct(const QJsonObject &deviceConfig)
|
||||
|
||||
bool LedDeviceFile::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
if ( _ofs.is_open() )
|
||||
{
|
||||
_ofs.close();
|
||||
}
|
||||
|
||||
_refresh_timer_interval = 0;
|
||||
LedDevice::init(deviceConfig);
|
||||
|
||||
QString fileName = deviceConfig["output"].toString("/dev/null");
|
||||
_ofs.open( QSTRING_CSTR(fileName) );
|
||||
_refresh_timer_interval = 0;
|
||||
_fileName = deviceConfig["output"].toString("/dev/null");
|
||||
_printTimeStamp = deviceConfig["printTimeStamp"].toBool(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int LedDeviceFile::open()
|
||||
{
|
||||
if ( _ofs.is_open() )
|
||||
{
|
||||
_ofs.close();
|
||||
}
|
||||
_ofs.open( QSTRING_CSTR(_fileName) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LedDeviceFile::write(const std::vector<ColorRgb> & ledValues)
|
||||
{
|
||||
_ofs << "[";
|
||||
if ( _printTimeStamp )
|
||||
{
|
||||
// get a precise timestamp as a string
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
const auto nowAsTimeT = std::chrono::system_clock::to_time_t(now);
|
||||
const auto nowMs = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
now.time_since_epoch()) % 1000;
|
||||
|
||||
_ofs
|
||||
<< std::put_time(std::localtime(&nowAsTimeT), "%Y-%m-%d %T")
|
||||
<< '.' << std::setfill('0') << std::setw(3) << nowMs.count();
|
||||
|
||||
}
|
||||
_ofs << " [";
|
||||
for (const ColorRgb& color : ledValues)
|
||||
{
|
||||
_ofs << color;
|
||||
|
@@ -36,6 +36,13 @@ public:
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
protected:
|
||||
///
|
||||
/// Opens and configures the output file
|
||||
///
|
||||
/// @return Zero on succes else negative
|
||||
///
|
||||
///
|
||||
virtual int open();
|
||||
///
|
||||
/// Writes the given led-color values to the output stream
|
||||
///
|
||||
@@ -47,4 +54,10 @@ protected:
|
||||
|
||||
/// The outputstream
|
||||
std::ofstream _ofs;
|
||||
|
||||
private:
|
||||
|
||||
QString _fileName;
|
||||
/// Timestamp for the output record
|
||||
bool _printTimeStamp;
|
||||
};
|
||||
|
Reference in New Issue
Block a user