LedDeviceTemplate.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "LedDeviceTemplate.h"
  2. LedDeviceTemplate::LedDeviceTemplate(const QJsonObject & /*deviceConfig*/)
  3. {
  4. }
  5. LedDevice* LedDeviceTemplate::construct(const QJsonObject &deviceConfig)
  6. {
  7. return new LedDeviceTemplate(deviceConfig);
  8. }
  9. bool LedDeviceTemplate::init(const QJsonObject &deviceConfig)
  10. {
  11. bool isInitOK = false;
  12. // Initialise sub-class
  13. if ( LedDevice::init(deviceConfig) )
  14. {
  15. // Initialise LedDevice configuration and execution environment
  16. // ...
  17. if ( false /*Error during init*/)
  18. {
  19. //Build an errortext, illustrative
  20. QString errortext = QString ("Error message: %1").arg("errno/text");
  21. this->setInError(errortext);
  22. isInitOK = false;
  23. }
  24. else
  25. {
  26. isInitOK = true;
  27. }
  28. }
  29. return isInitOK;
  30. }
  31. int LedDeviceTemplate::open()
  32. {
  33. int retval = -1;
  34. QString errortext;
  35. _isDeviceReady = false;
  36. // Try to open the LedDevice
  37. //...
  38. if ( false /*If opening failed*/ )
  39. {
  40. //Build an errortext, illustrative
  41. errortext = QString ("Failed to xxx. Error message: %1").arg("errno/text");
  42. }
  43. else
  44. {
  45. // Everything is OK, device is ready
  46. _isDeviceReady = true;
  47. retval = 0;
  48. }
  49. // On error/exceptions, set LedDevice in error
  50. if ( false /* retval < 0*/ )
  51. {
  52. this->setInError( errortext );
  53. }
  54. return retval;
  55. }
  56. int LedDeviceTemplate::close()
  57. {
  58. // LedDevice specific closing activities
  59. //...
  60. int retval = 0;
  61. _isDeviceReady = false;
  62. #if 0
  63. // Test, if device requires closing
  64. if ( true /*If device is still open*/ )
  65. {
  66. // Close device
  67. // Everything is OK -> device is closed
  68. }
  69. #endif
  70. return retval;
  71. }
  72. int LedDeviceTemplate::write(const std::vector<ColorRgb> & ledValues)
  73. {
  74. int retval = -1;
  75. //...
  76. return retval;
  77. }