From b83b0118f5145f4f1a53da9b791e04a125476869 Mon Sep 17 00:00:00 2001 From: Mjolnir Date: Thu, 20 Aug 2015 18:06:17 +0200 Subject: [PATCH] debug keyboard, fied communication pb on XBee --- ArduinoKeyboard/ArduinoKeyboard.ino | 2 +- Library/LivingKeyboard.cpp | 6 +- Library/LivingKeyboard.h | 2 +- Test/mainwindow.cpp | 50 +++++++- Test/mainwindow.h | 4 + Test/mainwindow.ui | 169 +++++++++++++++++++++------- 6 files changed, 185 insertions(+), 48 deletions(-) diff --git a/ArduinoKeyboard/ArduinoKeyboard.ino b/ArduinoKeyboard/ArduinoKeyboard.ino index 3c6fc3d..b720004 100644 --- a/ArduinoKeyboard/ArduinoKeyboard.ino +++ b/ArduinoKeyboard/ArduinoKeyboard.ino @@ -48,7 +48,7 @@ void setup() init_motors(); //Communication - Serial.begin(115200); + Serial.begin(9600); } void loop() diff --git a/Library/LivingKeyboard.cpp b/Library/LivingKeyboard.cpp index 06be01d..a401f81 100644 --- a/Library/LivingKeyboard.cpp +++ b/Library/LivingKeyboard.cpp @@ -1,11 +1,11 @@ #include "LivingKeyboard.h" -LivingKeyboard::LivingKeyboard() -: serialPort(new QSerialPort(port)), connected(false), posX(0), posY(0), toolUp(false) +LivingKeyboard::LivingKeyboard(QString port) +: serialPort(new QSerialPort(port)), connected(false) { if(serialPort->open(QIODevice::ReadWrite)) { - serialPort->setBaudRate(QSerialPort::Baud115200,QSerialPort::AllDirections); + serialPort->setBaudRate(QSerialPort::Baud9600,QSerialPort::AllDirections); serialPort->setDataBits(QSerialPort::Data8); serialPort->setParity(QSerialPort::NoParity); serialPort->setStopBits(QSerialPort::TwoStop); diff --git a/Library/LivingKeyboard.h b/Library/LivingKeyboard.h index 681034b..43db051 100644 --- a/Library/LivingKeyboard.h +++ b/Library/LivingKeyboard.h @@ -8,7 +8,7 @@ class LivingKeyboard { public: - LivingKeyboard(); + LivingKeyboard(QString port); ~LivingKeyboard(); diff --git a/Test/mainwindow.cpp b/Test/mainwindow.cpp index a46af7e..e111210 100644 --- a/Test/mainwindow.cpp +++ b/Test/mainwindow.cpp @@ -7,17 +7,30 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); - qDebug("Start test"); + qDebug("Connect mouse"); try { - mouse = new XYPlotter("ttyUSB1"); - connect(ui->movebutton, SIGNAL(clicked()), this, SLOT(moveMouse())); - ui->movebutton->setEnabled(true); + mouse = new XYPlotter("ttyUSB3"); + connect(ui->mousebutton, SIGNAL(clicked()), this, SLOT(moveMouse())); + ui->mousebutton->setEnabled(true); } catch (ErrorMessage e) { mouse = NULL; - qDebug(e.what()); + qDebug() << QString(e.what()); + } + qDebug() << "Connect keyboard"; + try + { + keyboard = new LivingKeyboard("ttyUSB2"); + connect(ui->keyboardbutton, SIGNAL(clicked()), this, SLOT(translateKeyboard())); + connect(ui->rotation, SIGNAL(valueChanged(int)), this, SLOT(rotateKeyboard(int))); + ui->keyboardbutton->setEnabled(true); + } + catch (ErrorMessage e) + { + keyboard = NULL; + qDebug() << QString(e.what()); } } @@ -28,6 +41,8 @@ MainWindow::~MainWindow() mouse->moveTo(0, 0, false); delete mouse; } + if (keyboard) + delete keyboard; delete ui; } @@ -39,3 +54,28 @@ void MainWindow::moveMouse() if (mouse) mouse->moveTo(x, y, toolup); } + +void MainWindow::translateKeyboard() +{ + unsigned int distance = ui->translation->value(); + if (keyboard) + { + qDebug() << "translate keyboard " << QString::number(distance); + if (distance > 0) + keyboard->translation(LivingKeyboard::FORWARD, distance); + else + keyboard->translation(LivingKeyboard::BACKWARD, distance); + } +} + +void MainWindow::rotateKeyboard(int angle) +{ + if (keyboard) + { + qDebug() << "rotate keyboard " << QString::number(angle); + if (angle > 0) + keyboard->rotation(LivingKeyboard::RIGHT, angle); + else + keyboard->rotation(LivingKeyboard::LEFT, angle); + } +} diff --git a/Test/mainwindow.h b/Test/mainwindow.h index a180b49..e9d82e9 100644 --- a/Test/mainwindow.h +++ b/Test/mainwindow.h @@ -4,6 +4,7 @@ #include #include +#include #include namespace Ui { @@ -20,10 +21,13 @@ class MainWindow : public QMainWindow public slots: void moveMouse(); + void translateKeyboard(); + void rotateKeyboard(int angle); private: Ui::MainWindow *ui; XYPlotter *mouse; + LivingKeyboard *keyboard; }; #endif // MAINWINDOW_H diff --git a/Test/mainwindow.ui b/Test/mainwindow.ui index 61aa35e..e1b32a7 100644 --- a/Test/mainwindow.ui +++ b/Test/mainwindow.ui @@ -7,33 +7,73 @@ 0 0 400 - 300 + 388 MainWindow - - - - - X + + + + + Mouse + + + + + X + + + + + + + 2000 + + + 100 + + + + + + + Y + + + + + + + 2000 + + + 100 + + + + + + + Tool Up + + + + + + + Z + + + + - - - - 2000 - - - 100 - - - - - + + false @@ -42,34 +82,78 @@ - - - - 2000 + + + + Qt::Vertical - - 100 + + + 20 + 40 + - + - - - - Y + + + + Keyboard + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Tilt + + + + + + + -180 + + + 180 + + + Qt::Horizontal + + + + + + + Translation$ + + + + + + + -100 + + + 100 + + + 10 + + + + - - - - Z + + + + false - - - - - Tool Up + Move @@ -77,6 +161,15 @@ + + xvalue + yvalue + toolupvalue + mousebutton + rotation + translation + keyboardbutton + -- 2.30.2