99 lines
2.9 KiB
C++
99 lines
2.9 KiB
C++
#ifndef OLATHREAD_H
|
|
#define OLATHREAD_H
|
|
|
|
#include <QObject>
|
|
#include <QThread>
|
|
#include <QDebug>
|
|
|
|
#include <string>
|
|
|
|
#include <ola/DmxBuffer.h>
|
|
#include <ola/Logging.h>
|
|
#include <ola/OlaClientWrapper.h>
|
|
#include <ola/client/OlaClient.h>
|
|
#include <ola/DmxBuffer.h>
|
|
#include <ola/client/ClientTypes.h>
|
|
|
|
#include "defines.h"
|
|
#include "dmxPersonality.h"
|
|
|
|
class olaThread : public QThread
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
olaThread(QObject *parent = 0);
|
|
virtual ~olaThread();
|
|
|
|
/** Retorna el valor de un canal
|
|
*@param int layer the layer for we want the channel
|
|
*@param int channel the channel for the value wanted
|
|
*@return int the value
|
|
*/
|
|
|
|
inline int getValue(int layer, int channel) {
|
|
return m_dmx[layer][channel];
|
|
}
|
|
|
|
/**
|
|
* @brief resendDMX emite todo el buffer DMX
|
|
*/
|
|
|
|
void resendDmx();
|
|
|
|
private:
|
|
|
|
void run ();
|
|
ola::client::OlaClientWrapper *m_clientWrapper;
|
|
ola::client::OlaClient *m_client;
|
|
unsigned int m_counter;
|
|
struct timeval m_last_data; // Last DMX frame received
|
|
|
|
// DMX Conf
|
|
QList<int> *m_universe; // Registered universes.
|
|
int m_layersNumber; // Number of layers in wich divide the dmx frame. Each layer, one source.
|
|
int m_dmx[LAYERS_NUMBER][LAYER_CHANNELS]; // DMX Buffer. Habría que cambiarlo si queremos hacer las capas dinámicas
|
|
QList<dmxSetting> m_settings;
|
|
|
|
inline void registerUniverse(int universe) {
|
|
// void ola::client::OlaClient::RegisterUniverse(unsigned int universe,RegisterAction register_action,SetCallback * callback
|
|
m_client->RegisterUniverse(universe, ola::client::REGISTER,ola::NewSingleCallback(this, &olaThread::RegisterComplete));
|
|
}
|
|
|
|
/**
|
|
* Control de errores en el registro de Universos en OLA
|
|
*/
|
|
// typedef SingleUseCallback1<void, const Result&> ola::client::SetCallback
|
|
inline void RegisterComplete(const ola::client::Result &error) {
|
|
if (error.Success()) {
|
|
// qDebug("Register Universe success");
|
|
emit toTerminal("Register Universe success");
|
|
} else {
|
|
// qWarning("Register command failed: %s", error.Error().c_str());
|
|
emit toTerminal("olaThread| Register command failed " + QString::fromStdString(error.Error()));
|
|
}
|
|
}
|
|
|
|
bool CheckDataLoss();
|
|
|
|
// typedef Callback2<void, const DMXMetadata&, const DmxBuffer&> ola::client::RepeatableDMXCallback
|
|
void NewDmx(const ola::client::DMXMetadata &dmx_meta, const ola::DmxBuffer &buffer); // Callback from OlaCLient when there is new dmx info
|
|
|
|
public slots:
|
|
|
|
void stop(); // Close the connection with olad.
|
|
void setLayersNumber(int layersNumber);
|
|
void setDMXConf(dmxSetting set);
|
|
|
|
protected slots:
|
|
|
|
signals:
|
|
|
|
void finished(); // Signal for closing. Not used now.
|
|
void dmxOutput(int layer, int channel, int value); // Signal when a channel has changed
|
|
void toTerminal(QString message);
|
|
void layerReceived(int i);
|
|
};
|
|
|
|
#endif // OLATHREAD_H
|