2020-02-10 15:21:58 +01:00
|
|
|
#include "LedDeviceTemplate.h"
|
|
|
|
|
|
|
|
LedDeviceTemplate::LedDeviceTemplate(const QJsonObject &deviceConfig)
|
|
|
|
: LedDevice()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LedDevice* LedDeviceTemplate::construct(const QJsonObject &deviceConfig)
|
|
|
|
{
|
|
|
|
return new LedDeviceTemplate(deviceConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LedDeviceTemplate::init(const QJsonObject &deviceConfig)
|
|
|
|
{
|
2020-07-12 20:27:56 +02:00
|
|
|
bool isInitOK = false;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
// Initialise sub-class
|
|
|
|
if ( LedDevice::init(deviceConfig) )
|
2020-02-10 15:21:58 +01:00
|
|
|
{
|
2020-07-12 20:27:56 +02:00
|
|
|
// Initialise LedDevice configuration and execution environment
|
|
|
|
// ...
|
|
|
|
if ( 0 /*Error during init*/)
|
|
|
|
{
|
|
|
|
//Build an errortext, illustrative
|
|
|
|
QString errortext = QString ("Error message: %1").arg("errno/text");
|
|
|
|
this->setInError(errortext);
|
|
|
|
isInitOK = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isInitOK = true;
|
|
|
|
}
|
2020-02-10 15:21:58 +01:00
|
|
|
}
|
|
|
|
return isInitOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LedDeviceTemplate::open()
|
|
|
|
{
|
|
|
|
int retval = -1;
|
|
|
|
QString errortext;
|
2020-07-12 20:27:56 +02:00
|
|
|
_isDeviceReady = false;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
// Try to open the LedDevice
|
|
|
|
//...
|
2020-02-10 15:21:58 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
if ( false /*If opening failed*/ )
|
|
|
|
{
|
|
|
|
//Build an errortext, illustrative
|
|
|
|
errortext = QString ("Failed to xxx. Error message: %1").arg("errno/text");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Everything is OK, device is ready
|
|
|
|
_isDeviceReady = true;
|
|
|
|
retval = 0;
|
|
|
|
}
|
2020-02-10 15:21:58 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
// On error/exceptions, set LedDevice in error
|
|
|
|
if ( retval < 0 )
|
|
|
|
{
|
|
|
|
this->setInError( errortext );
|
2020-02-10 15:21:58 +01:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
int LedDeviceTemplate::close()
|
2020-02-10 15:21:58 +01:00
|
|
|
{
|
2020-07-12 20:27:56 +02:00
|
|
|
// LedDevice specific closing activities
|
2020-02-10 15:21:58 +01:00
|
|
|
//...
|
2020-07-12 20:27:56 +02:00
|
|
|
int retval = 0;
|
|
|
|
_isDeviceReady = false;
|
|
|
|
|
|
|
|
// Test, if device requires closing
|
|
|
|
if ( true /*If device is still open*/ )
|
|
|
|
{
|
|
|
|
// Close device
|
|
|
|
// Everything is OK -> device is closed
|
|
|
|
}
|
|
|
|
return retval;
|
2020-02-10 15:21:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int LedDeviceTemplate::write(const std::vector<ColorRgb> & ledValues)
|
|
|
|
{
|
|
|
|
int retval = -1;
|
|
|
|
|
|
|
|
//...
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|