Commit 54824e45 authored by Benjamin Gallois's avatar Benjamin Gallois

New Dual version 2

parent f75c01f4
Pipeline #14 canceled with stages
This diff is collapsed.
No preview for this file type
No preview for this file type
......@@ -132,56 +132,29 @@ void Dual::initialize() {
conn->setStopBits(QSerialPort::OneStop);
conn->setFlowControl(QSerialPort::NoFlowControl);
if (!conn->open(QIODevice::ReadWrite)) {
if (conn->open(QIODevice::ReadWrite)) {
for (int i=0 ; i<10 ; i++) {
conn->write("getId");
conn->flush();
QThread::msleep(100);
}
} else {
qWarning() << "Failed to open port" << conn->portName();
return;
}
OUT << "Init. serial connection";
// Connect serial read output
connect(conn, SIGNAL(readyRead()), this, SLOT(readSerial()));
qInfo() << TITLE_2 << "Setting pin modes";
// --- Backward compatibility ---------------
// Set valve pins to OUTPUT
send(QString("setMode:%1:OUTPUT").arg(ui->pinValve1->value()));
send(QString("setMode:%1:OUTPUT").arg(ui->pinValve2->value()));
send(QString("setMode:%1:OUTPUT").arg(ui->pinValve3->value()));
send(QString("setMode:%1:OUTPUT").arg(ui->pinValve4->value()));
send(QString("setMode:%1:OUTPUT").arg(ui->pinValve5->value()));
send(QString("setMode:%1:OUTPUT").arg(ui->pinValve6->value()));
// Set motor pins to OUTPUT,
send(QString("setMode:%1:OUTPUT").arg(ui->pinDir->value()));
send(QString("setMode:%1:OUTPUT").arg(ui->pinStep->value()));
send(QString("setMode:%1:OUTPUT").arg(ui->pinEnable->value()));
send(QString("setMode:%1:OUTPUT").arg(ui->pinMS1->value()));
send(QString("setMode:%1:OUTPUT").arg(ui->pinMS2->value()));
send(QString("setMode:%1:OUTPUT").arg(ui->pinMS3->value()));
// No microstepping
if (ui->pinMS1->isEnabled()) { send(QString("setVal:%1:").arg(ui->pinMS1->value()) + "OFF"); }
if (ui->pinMS1->isEnabled()) { send(QString("setVal:%1:").arg(ui->pinMS2->value()) + "OFF"); }
if (ui->pinMS1->isEnabled()) { send(QString("setVal:%1:").arg(ui->pinMS3->value()) + "OFF"); }
// Set Enable and Direction
send(QString("setVal:%1:OFF").arg(ui->pinEnable->value()));
send(QString("setVal:%1:ON").arg(ui->pinDir->value()));
// Set switch pins to INPUT (with internal pull-up)
send(QString("setMode:%1:INPUT_PULLUP").arg(ui->pTopSwitch->value()));
send(QString("setMode:%1:INPUT_PULLUP").arg(ui->pBottomSwitch->value()));
// Set LED
send(QString("setMode:%1:OUTPUT").arg(ui->pinVisLED->value()));
// --- Directories --------------------------
autoset();
// --- Initialization -----------------------
initialized = true;
}
......@@ -265,34 +238,6 @@ void Dual::GrabLoop() {
// --- Save image
/*
// Set EXIF metadata
if (comment.length()) {
// Save milestone
QFile fmiles(RunPath + filesep + "Milestones.txt");
if (fmiles.open(QIODevice::WriteOnly | QIODevice::Append)) {
QTextStream stream(&fmiles);
stream << nFrame << "\t" << TimeStamp << "\t" << comment << endl;
}
// Set EXIF metadata
ImgWriter->setText("Description", QString("Timestamp %1, %2").arg(TimeStamp).arg(comment));
// Update current state
currentState = comment;
// Reset comment
comment = QString();
} else {
ImgWriter->setText("Description", QString("Timestamp %1").arg(TimeStamp));
}
*/
// Save Image
ImgWriter->setFileName(QString(RunPath + filesep + "Frame_%1.pgm").arg(nFrame, 6, 10, QLatin1Char('0')));
ImgWriter->write(pixmap.toImage());
......@@ -493,6 +438,26 @@ void Dual::ProtoLoop() {
}
} else if (list.at(0)=="blink") {
// --- BLINK ----------------------------
send(QString("blink:%1").arg(list.at(1).toUpper()));
} else if (list.at(0)=="light") {
// --- LIGHT ----------------------------
if (list.at(1)=="VIS") {
send(QString("light:VIS:%1").arg(list.at(2).toUpper()));
}
if (list.at(1)=="IR") {
send(QString("light:IR:%1").arg(list.at(2).toUpper()));
}
} else if (list.at(0)=="camera") {
// --- CAMERA ---------------------------
......@@ -614,7 +579,7 @@ void Dual::ProtoLoop() {
void Dual::send(QString cmd) {
conn->write(cmd.toStdString().c_str());
conn->flush();
QThread::msleep(5);
QThread::msleep(10);
}
// === SLOTS ===============================================================
......@@ -644,7 +609,9 @@ void Dual::readSerial() {
}
// --- Display
OUT << res[i].toStdString().c_str();
if (res[i] != QString::number(this->guiid)) {
OUT << res[i].toStdString().c_str();
}
}
}
......@@ -762,14 +729,14 @@ void Dual::setCircuitRight(int i) {
void Dual::toggleIRLED(bool b) {
// Send command
send(QString("setVal:%1:").arg(ui->pinIRLED->value()) + (b?"ON":"OFF"));
send(QString("light:IR:") + (b?"ON":"OFF"));
}
void Dual::toggleVisLED(bool b) {
// Send command
send(QString("setVal:%1:").arg(ui->pinVisLED->value()) + (b?"ON":"OFF"));
send(QString("light:VIS:") + (b?"ON":"OFF"));
}
......@@ -789,7 +756,7 @@ void Dual::toggleDir(bool b) {
void Dual::setPeriod() {
send(QString("setPeriod:") + ui->MotorPeriod->text());
send(QString("stepPeriod:%1").arg(ui->MotorPeriod->text()));
}
......@@ -800,9 +767,24 @@ void Dual::toggleRun(bool b) {
}
// --- STATE ---------------------------------------------------------------
void Dual::setState(QString S) {
send(QString("state:%1").arg(S));
OUT << "State is " << S;
if (S=="Active") {
QThread::msleep(50);
send(QString("setVal:%1:%2").arg(ui->pinDir->value()).arg(ui->MotorDir->isChecked()?"ON":"OFF"));
}
}
// === Window closing ======================================================
void Dual::closeEvent(QCloseEvent *event) {
setState(QString("Idle"));
emit closed(guiid);
event->accept();
}
......
......@@ -40,11 +40,14 @@ public:
// Serial communication
QString portName;
bool initialized;
// --- Methods ------------------------------
explicit Dual(QVector<QRect> screens, QString path, int id, QWidget *parent = 0);
void initialize();
void setState(QString);
virtual void closeEvent(QCloseEvent*);
~Dual();
......@@ -96,15 +99,12 @@ private:
// --- Properties ---------------------------
bool initialized;
// UI
Ui::Dual *ui;
QVector<QRect> Screen;
// Identification
int guiid;
QString ID;
int NValves;
......@@ -136,7 +136,6 @@ private:
QString filesep;
void updatePath();
// Serial communication
void send(QString);
const char* str(QString);
......
No preview for this file type
This diff is collapsed.
No preview for this file type
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2018-02-22T14:09:50. -->
<!-- Written by QtCreator 3.5.1, 2019-04-30T15:20:13. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......
......@@ -9,20 +9,20 @@ print:Loading settings
# --- Dual 1
CamSN:1:CM3 16386575
ROI:1:25,200,1000,500
ROI:1:0,0,1280,1024
# --- Dual 2
CamSN:2:CM3 16369084
ROI:2:25,200,1000,500
ROI:2:0,0,1280,1024
# --- Dual 3
CamSN:3:CM3 16386609
ROI:3:25,200,1000,500
ROI:3:0,0,1280,1024
# --- Dual 4
CamSN:4:CM3 16386604
ROI:4:25,200,1000,500
ROI:4:0,0,1280,1024
No preview for this file type
......@@ -33,6 +33,18 @@ MainWindow::MainWindow(QWidget *parent) :
s_Settings = new QShortcut(QKeySequence("P"), this);
connect(s_Settings, SIGNAL(activated()), this, SLOT(loadSettings()));
// i: Set all Duals to Idle state
s_Idle = new QShortcut(QKeySequence("I"), this);
connect(s_Idle, SIGNAL(activated()), this, SLOT(setIdle()));
// x: Set all Duals to Xmas state
s_Xmas = new QShortcut(QKeySequence("X"), this);
connect(s_Xmas, SIGNAL(activated()), this, SLOT(setXmas()));
// k: Set all Duals to K2000 state
s_K2000 = new QShortcut(QKeySequence("K"), this);
connect(s_K2000, SIGNAL(activated()), this, SLOT(setK2000()));
// --- Messages -----------------------------
// Style
......@@ -235,7 +247,7 @@ void MainWindow::checkSerial() {
// --- Get available ports
const QList<QSerialPortInfo> infos = QSerialPortInfo::availablePorts();
// qInfo() << infos.length() << "connections detected";
qInfo() << infos.length() << "serial connections detected";
// --- Remove unused ports
......@@ -248,7 +260,7 @@ void MainWindow::checkSerial() {
// --- Checks
// Skip non-Arduino connections
if (infos[i].description().left(7)!="Arduino") { continue; }
if (infos[i].description().left(7).toLower()!="arduino") { continue; }
// Skip connections already attributed
bool att = false;
......@@ -277,7 +289,11 @@ void MainWindow::checkSerial() {
connect(conn, SIGNAL(readyRead()), this, SLOT(getSerialId()));
if (conn->open(QIODevice::ReadWrite)) {
conn->write("getId");
for (int i=0 ; i<10 ; i++) {
conn->write("getId");
conn->flush();
QThread::msleep(100);
}
} else {
qWarning() << "Failed to open port" << conn->portName();
}
......@@ -322,6 +338,26 @@ void MainWindow::getSerialId() {
}
// === Sates ===============================================================
void MainWindow::setIdle() {
for (int i=0; i<NDual; i++) {
if (Duals[i]->initialized) { Duals[i]->setState(QString("Idle")); }
}
}
void MainWindow::setXmas() {
for (int i=0; i<NDual; i++) {
if (Duals[i]->initialized) { Duals[i]->setState(QString("Xmas")); }
}
}
void MainWindow::setK2000() {
for (int i=0; i<NDual; i++) {
if (Duals[i]->initialized) { Duals[i]->setState(QString("K2000")); }
}
}
// === Window management ===================================================
void MainWindow::toggleWindow(bool b) {
......@@ -332,7 +368,11 @@ void MainWindow::toggleWindow(bool b) {
if (b) {
Duals[guiid-1]->initialize();
Duals[guiid-1]->show();
} else { Duals[guiid-1]->hide(); }
Duals[guiid-1]->setState(QString("Active"));
} else {
Duals[guiid-1]->hide();
Duals[guiid-1]->setState(QString("Idle"));
}
}
......@@ -347,7 +387,6 @@ void MainWindow::uncheckDual(int guiid) {
}
MainWindow::~MainWindow() {
delete ui;
}
......@@ -57,6 +57,9 @@ public slots:
void toggleWindow(bool);
void uncheckDual(int);
void setIdle();
void setXmas();
void setK2000();
private:
......@@ -70,6 +73,9 @@ private:
QShortcut *s_Close;
QShortcut *s_Settings;
QShortcut *s_Idle;
QShortcut *s_Xmas;
QShortcut *s_K2000;
// --- Dual windows -------------------------
......
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -19,8 +19,8 @@
QT_BEGIN_MOC_NAMESPACE
struct qt_meta_stringdata_MainWindow_t {
QByteArrayData data[9];
char stringdata0[103];
QByteArrayData data[12];
char stringdata0[128];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
......@@ -37,12 +37,16 @@ QT_MOC_LITERAL(4, 39, 14), // "refreshCameras"
QT_MOC_LITERAL(5, 54, 11), // "checkSerial"
QT_MOC_LITERAL(6, 66, 11), // "getSerialId"
QT_MOC_LITERAL(7, 78, 12), // "toggleWindow"
QT_MOC_LITERAL(8, 91, 11) // "uncheckDual"
QT_MOC_LITERAL(8, 91, 11), // "uncheckDual"
QT_MOC_LITERAL(9, 103, 7), // "setIdle"
QT_MOC_LITERAL(10, 111, 7), // "setXmas"
QT_MOC_LITERAL(11, 119, 8) // "setK2000"
},
"MainWindow\0UpdateMessage\0\0loadSettings\0"
"refreshCameras\0checkSerial\0getSerialId\0"
"toggleWindow\0uncheckDual"
"toggleWindow\0uncheckDual\0setIdle\0"
"setXmas\0setK2000"
};
#undef QT_MOC_LITERAL
......@@ -52,7 +56,7 @@ static const uint qt_meta_data_MainWindow[] = {
7, // revision
0, // classname
0, 0, // classinfo
7, 14, // methods
10, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
......@@ -60,13 +64,16 @@ static const uint qt_meta_data_MainWindow[] = {
0, // signalCount
// slots: name, argc, parameters, tag, flags
1, 0, 49, 2, 0x0a /* Public */,
3, 0, 50, 2, 0x0a /* Public */,
4, 0, 51, 2, 0x0a /* Public */,
5, 0, 52, 2, 0x0a /* Public */,
6, 0, 53, 2, 0x0a /* Public */,
7, 1, 54, 2, 0x0a /* Public */,
8, 1, 57, 2, 0x0a /* Public */,
1, 0, 64, 2, 0x0a /* Public */,
3, 0, 65, 2, 0x0a /* Public */,
4, 0, 66, 2, 0x0a /* Public */,
5, 0, 67, 2, 0x0a /* Public */,
6, 0, 68, 2, 0x0a /* Public */,
7, 1, 69, 2, 0x0a /* Public */,
8, 1, 72, 2, 0x0a /* Public */,
9, 0, 75, 2, 0x0a /* Public */,
10, 0, 76, 2, 0x0a /* Public */,
11, 0, 77, 2, 0x0a /* Public */,
// slots: parameters
QMetaType::Void,
......@@ -76,6 +83,9 @@ static const uint qt_meta_data_MainWindow[] = {
QMetaType::Void,
QMetaType::Void, QMetaType::Bool, 2,
QMetaType::Void, QMetaType::Int, 2,
QMetaType::Void,
QMetaType::Void,
QMetaType::Void,
0 // eod
};
......@@ -93,6 +103,9 @@ void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id,
case 4: _t->getSerialId(); break;
case 5: _t->toggleWindow((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 6: _t->uncheckDual((*reinterpret_cast< int(*)>(_a[1]))); break;
case 7: _t->setIdle(); break;
case 8: _t->setXmas(); break;
case 9: _t->setK2000(); break;
default: ;
}
}
......@@ -123,13 +136,13 @@ int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 7)
if (_id < 10)
qt_static_metacall(this, _c, _id, _a);
_id -= 7;
_id -= 10;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 7)
if (_id < 10)
*reinterpret_cast<int*>(_a[0]) = -1;
_id -= 7;
_id -= 10;
}
return _id;
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment