serialPort = NULL;
}
-bool LivingDevice::sendCommand(char command)
+bool LivingDevice::sendCommand(char command) const
{
if (serialPort)
{
return false;
}
-bool LivingDevice::sendCommand(char command, int value)
+bool LivingDevice::sendCommand(char command, int value) const
{
if (serialPort)
{
return false;
}
-bool LivingDevice::sendCommand(char *command, int *value, int nb)
+bool LivingDevice::sendCommand(char *command, int *value, int nb) const
{
QString buffer;
if (serialPort)
return false;
}
-QString LivingDevice::readAnswer(int timeout)
+QString LivingDevice::readAnswer(int timeout) const
{
char buffer[128];
virtual void calibrate() = 0;
- QString readAnswer(int timeout);
+ QString readAnswer(int timeout) const;
protected:
Serial *serialPort;
void discover(QString name, int timeout=5000);
void closeSerialPort();
- bool sendCommand(char command);
- bool sendCommand(char command, int value);
- bool sendCommand(char *command, int *value, int nb);
+ bool sendCommand(char command) const;
+ bool sendCommand(char command, int value) const;
+ bool sendCommand(char *command, int *value, int nb) const;
};
#include "LivingScreen.h"
#include <QDebug>
+#include <QRegularExpression>
+#include <QRegularExpressionMatch>
+#include <QThread>
LivingScreen::LivingScreen()
: LivingDevice("LivingScreen", 5000)
sendCommand('T', dis);
}
+void LivingScreen::moveto(unsigned int pos)
+{
+ sendCommand('M', pos);
+}
+
+unsigned int LivingScreen::getPosition() const
+{
+ int tries = 0;
+ do
+ {
+ if (!sendCommand('P'))
+ {
+ qDebug() << "Cannot speak with port";
+ throw "Screen port unreachable";
+ }
+ QString answer = readAnswer(2000);
+ QRegularExpression reg("Position: (\\d+)");
+ QRegularExpressionMatch match = reg.match(answer);
+ if (match.hasMatch())
+ return match.captured(1).toUInt();
+ QThread::msleep(100);
+ } while (tries++ < 5);
+
+ return 0;
+}
+
+unsigned int LivingScreen::getWidth() const
+{
+ int tries = 0;
+ do
+ {
+ if (!sendCommand('W'))
+ {
+ qDebug() << "Cannot speak with port";
+ throw "Screen port unreachable";
+ }
+ QString answer = readAnswer(2000);
+ QRegularExpression reg("Width: (\\d+)");
+ QRegularExpressionMatch match = reg.match(answer);
+ if (match.hasMatch())
+ return match.captured(1).toUInt();
+ QThread::msleep(100);
+ } while (tries++ < 5);
+
+ return 0;
+}
+
void LivingScreen::calibrate()
{
sendCommand('C');
void rotation(direction t, unsigned int angle);
void translation(direction d, unsigned int distance);
+ void moveto(unsigned int pos);
+
+ //Get the current position
+ //may last 1s or so
+ unsigned int getPosition() const;
+ //Get the rack width
+ //may last 1s or so
+ unsigned int getWidth() const;
void calibrate();
};