I2cdecoder refactor (#76)

* Use Qt5 type-safe connect on i2cDecoder

* Add destructor, fixing a memory leak in i2cDecoder

* Remove commented debug print

* formatting
This commit is contained in:
Sebastián Mestre 2019-03-31 18:31:52 -03:00 committed by Chris Esposito
parent e6f0e24a28
commit 3c0616a46f
2 changed files with 9 additions and 9 deletions

View File

@ -13,7 +13,14 @@ i2cDecoder::i2cDecoder(isoBuffer* sda_in, isoBuffer* scl_in, QPlainTextEdit* con
updateTimer = new QTimer();
updateTimer->setTimerType(Qt::PreciseTimer);
updateTimer->start(CONSOLE_UPDATE_TIMER_PERIOD);
connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateConsole()));
connect(updateTimer, &QTimer::timeout, this, &i2cDecoder::updateConsole);
}
i2cDecoder::~i2cDecoder()
{
// TODO: Is a lock needed here? Destructors should never be called more than once but...
delete updateTimer;
delete serialBuffer;
}
void i2cDecoder::reset()
@ -78,14 +85,6 @@ void i2cDecoder::runStateMachine()
edge sdaEdge = edgeDetection(currentSdaValue, previousSdaValue);
edge sclEdge = edgeDetection(currentSclValue, previousSclValue);
// if (sdaEdge == edge::rising || sdaEdge == edge::falling)
// qDebug() << "sdaEdge";
// if (sclEdge == edge::rising || sclEdge == edge::falling)
// qDebug() << "sclEdge";
// if (sclEdge != edge::held_low)
// qDebug() << "sdaEdge" << (uint8_t)sdaEdge << "sclEdge" << (uint8_t)sclEdge;
if ((sdaEdge == edge::rising) && (sclEdge == edge::falling)) // INVALID STATE TRANSITION
{
state = transmissionState::unknown;

View File

@ -36,6 +36,7 @@ class i2cDecoder : public QObject
Q_OBJECT
public:
explicit i2cDecoder(isoBuffer* sda_in, isoBuffer* scl_in, QPlainTextEdit* console_in);
~i2cDecoder();
// misc
isoBuffer* sda;
isoBuffer* scl;