Compare commits

...

23 Commits

Author SHA1 Message Date
mmtalaie 15998c6b25 Remove commneted codes 10 months ago
miladS ed46cbed6f Remove redundant macros 10 months ago
miladS 06228358f4 Check data received from fake relay board to sync with changes 10 months ago
miladS 2781bc5f13 Add rotary button to change fps in Sono 12 months ago
miladS 881a6e8986 Merge branch 'fix-not-button-fakehardware' into develop 1 year ago
miladS 7c3de270ee Add probe slot button that get the isEnables of the probe slot states. 1 year ago
miladS 208abc7138 Merge pull request 'add-probes' (#2) from add-probes into develop 1 year ago
miladS a3a411d325 Merge pull request 'Fix database address from relevant addressing to absolute by use environment variables' (#1) from fix-database-address into add-probes 1 year ago
mmtalaie ac8322f347 Fix database address from relevant addressing to absolute by use environment variables 1 year ago
miladS 28785c93fa Solve the error from test part 1 year ago
miladS 7a6190159b Do not use function codes for probe slot push button 1 year ago
miladS e0849692f4 Send probe datas on a new port 1 year ago
miladS da3dedef1c Change probe slot selection to push button 1 year ago
miladS 9023678656 Add get probe names to database manager 1 year ago
miladS f556b108f5 Add drop down with disable to the ui 1 year ago
miladS 55650dccbb Read probes from database 1 year ago
miladS c3ceb47b41 Change `slot` to `probe` in .qml file 1 year ago
miladS 6a7cb62011 Merge remote-tracking branch 'origin/Pouya-Azimi' into milad 1 year ago
miladS a7de368ccc Add database manager. 1 year ago
pouya 06cf192488 Add probe selection dropDown menue 1 year ago
miladS 4d6254ff05 Add probes 1 year ago
miladS ab9fcdd18b Probes added 1 year ago
pouya 091e380a82 Decrease size for convenience 2 years ago
  1. 0
      ConsoleEmulatorAddProbes.pro
  2. 127
      logic/include/model/ButtonHelper.h
  3. 15
      logic/include/model/Console.h
  4. 2
      logic/include/model/DataSender.h
  5. 20
      logic/include/model/DatabaseManager.h
  6. 29
      logic/include/model/DropDown.h
  7. 5
      logic/include/network/UdpDataSender.h
  8. 47
      logic/include/viewModel/MainViewModel.h
  9. 5
      logic/include/viewModel/utils/Property.h
  10. 9
      logic/logic.pro
  11. 37
      logic/src/model/Console.cpp
  12. 69
      logic/src/model/DatabaseManager.cpp
  13. 38
      logic/src/model/DropDown.cpp
  14. 36
      logic/src/network/UdpDataSender.cpp
  15. 69
      logic/src/viewModel/MainViewModel.cpp
  16. 6
      test/TestDataSender.h
  17. 2
      test/test.pro
  18. 6
      ui/App.qml
  19. 57
      ui/emulator/Emulator.qml
  20. 378
      ui/emulator/elements/ProbeButton.qml
  21. 46
      ui/emulator/items/DropDownWithDisable.qml
  22. 52
      ui/emulator/items/TopLeft.qml
  23. 94
      ui/emulator/items/TopLeftTop.qml
  24. 2
      ui/ui.pro
  25. 3
      ui/ui.qrc

0
consoleEmulator.pro → ConsoleEmulatorAddProbes.pro

127
logic/include/model/ButtonHelper.h

@ -2,79 +2,148 @@
#define BUTTONHELPER_H
#define PUSH_BUTTON(CAPITAL_NAME, SMALL_NAME, FUNC_CODE, LED_FUNC_CODE) \
private: \
private: \
PushButton _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \
void init ## CAPITAL_NAME() \
{ \
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData);\
connect(_ ## SMALL_NAME.getLed(), SIGNAL(ledChanged(char)), this, SIGNAL(SMALL_NAME ## LedChanged(char)));\
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \
connect(_ ## SMALL_NAME.getLed(), SIGNAL(ledChanged(char)), this, \
SIGNAL(SMALL_NAME ## LedChanged(char))); \
} \
public: \
public: \
void press ## CAPITAL_NAME() \
{ \
auto arr = _ ## SMALL_NAME.press(); \
_dataSender->send(arr); \
auto arr = _ ## SMALL_NAME.press(); \
_dataSender->send(arr); \
} \
void release ## CAPITAL_NAME() \
{ \
auto arr = _ ## SMALL_NAME.release(); \
_dataSender->send(arr); \
auto arr = _ ## SMALL_NAME.release(); \
_dataSender->send(arr); \
} \
Q_SIGNAL void SMALL_NAME ## LedChanged(char value)
/*************************************************************************************************/
#define PUSH_BUTTON_FPS(CAPITAL_NAME, SMALL_NAME) \
private: \
PushButton _ ## SMALL_NAME{0x00}; \
void init ## CAPITAL_NAME() \
{ \
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \
connect(_ ## SMALL_NAME.getLed(), SIGNAL(ledChanged(char)), this, \
SIGNAL(SMALL_NAME ## LedChanged(char))); \
} \
public: \
void press ## CAPITAL_NAME() \
{ \
auto arr = _ ## SMALL_NAME.press(); \
_dataSender->send(arr); \
} \
void release ## CAPITAL_NAME() \
{ \
auto arr = _ ## SMALL_NAME.release(); \
_dataSender->send(arr); \
} \
Q_SIGNAL void SMALL_NAME ## LedChanged(char value)
/*************************************************************************************************/
#define PUSH_BUTTON_PROBE_SLOT(CAPITAL_NAME, SMALL_NAME, SLOT_NUMBER) \
private: \
PushButton _ ## SMALL_NAME{SLOT_NUMBER, SLOT_NUMBER}; \
void init ## CAPITAL_NAME() \
{ \
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \
connect(_ ## SMALL_NAME.getLed(), SIGNAL(ledChanged(char)), this, \
SIGNAL(SMALL_NAME ## LedChanged(char))); \
} \
public: \
void press ## CAPITAL_NAME() \
{ \
auto arr = _ ## SMALL_NAME.press(); \
arr[5] = static_cast<char>(this->selectedProbe ## SLOT_NUMBER); \
_dataSender->sendProbeSlots(arr); \
} \
void release ## CAPITAL_NAME() \
{ \
} \
Q_SIGNAL void SMALL_NAME ## LedChanged(char value); \
Q_SIGNAL void changeProbeSelectionEnable ## SLOT_NUMBER(bool value)
/*************************************************************************************************/
#define PUSH_BUTTON_NO_LED(CAPITAL_NAME, SMALL_NAME, FUNC_CODE) \
private: \
PushButton _ ## SMALL_NAME{FUNC_CODE}; \
private: \
PushButton _ ## SMALL_NAME {FUNC_CODE}; \
void init ## CAPITAL_NAME() \
{ \
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData);\
connect(_ ## SMALL_NAME.getLed(), SIGNAL(ledChanged(char)), this, SIGNAL(SMALL_NAME ## LedChanged(char)));\
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \
connect(_ ## SMALL_NAME.getLed(), SIGNAL(ledChanged(char)), this, \
SIGNAL(SMALL_NAME ## LedChanged(char))); \
} \
public: \
public: \
void press ## CAPITAL_NAME() \
{ \
auto arr = _ ## SMALL_NAME.press(); \
_dataSender->send(arr); \
auto arr = _ ## SMALL_NAME.press(); \
_dataSender->send(arr); \
} \
void release ## CAPITAL_NAME() \
{ \
auto arr = _ ## SMALL_NAME.release(); \
_dataSender->send(arr); \
auto arr = _ ## SMALL_NAME.release(); \
_dataSender->send(arr); \
} \
Q_SIGNAL void SMALL_NAME ## LedChanged(char value)
/*************************************************************************************************/
#define ROTARY_BUTTON(CAPITAL_NAME, SMALL_NAME, FUNC_CODE, LED_FUNC_CODE) \
private: \
private: \
RotaryButton _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \
void init ## CAPITAL_NAME() \
{ \
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData);\
connect(_ ## SMALL_NAME.getLed(), SIGNAL(ledChanged(char)), this, SIGNAL(SMALL_NAME ## LedChanged(char)));\
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \
connect(_ ## SMALL_NAME.getLed(), SIGNAL(ledChanged(char)), this, \
SIGNAL(SMALL_NAME ## LedChanged(char))); \
} \
public: \
public: \
void rotate ## CAPITAL_NAME(int value) \
{ \
auto arr = _ ## SMALL_NAME.rotate(value); \
_dataSender->send(arr); \
auto arr = _ ## SMALL_NAME.rotate(value); \
_dataSender->send(arr); \
} \
Q_SIGNAL void SMALL_NAME ## LedChanged(char value)
/*************************************************************************************************/
#define ROTARY_BUTTON_NO_LED(CAPITAL_NAME, SMALL_NAME, FUNC_CODE) \
private: \
private: \
RotaryButton _ ## SMALL_NAME{FUNC_CODE}; \
void init ## CAPITAL_NAME() \
{ \
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData);\
connect(_ ## SMALL_NAME.getLed(), SIGNAL(ledChanged(char)), this, SIGNAL(SMALL_NAME ## LedChanged(char)));\
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \
connect(_ ## SMALL_NAME.getLed(), SIGNAL(ledChanged(char)), this, \
SIGNAL(SMALL_NAME ## LedChanged(char))); \
} \
public: \
void rotate ## CAPITAL_NAME(int value) \
{ \
auto arr = _ ## SMALL_NAME.rotate(value); \
_dataSender->send(arr); \
} \
Q_SIGNAL void SMALL_NAME ## LedChanged(char value)
/*************************************************************************************************/
#define ROTARY_BUTTON_FPS(CAPITAL_NAME, SMALL_NAME) \
private: \
RotaryButton _ ## SMALL_NAME{0x00}; \
void init ## CAPITAL_NAME() \
{ \
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \
connect(_ ## SMALL_NAME.getLed(), SIGNAL(ledChanged(char)), this, \
SIGNAL(SMALL_NAME ## LedChanged(char))); \
} \
public: \
public: \
void rotate ## CAPITAL_NAME(int value) \
{ \
auto arr = _ ## SMALL_NAME.rotate(value); \
_dataSender->send(arr); \
auto arr = _ ## SMALL_NAME.rotate(value); \
arr[7] = 0x01; \
_dataSender->sendProbeSlots(arr); \
} \
Q_SIGNAL void SMALL_NAME ## LedChanged(char value)

15
logic/include/model/Console.h

@ -22,6 +22,12 @@ class Console : public QObject
{
Q_OBJECT
//Probe slotes
PUSH_BUTTON_PROBE_SLOT(Slot1, slot1, 1);
PUSH_BUTTON_PROBE_SLOT(Slot2, slot2, 2);
PUSH_BUTTON_PROBE_SLOT(Slot3, slot3, 3);
PUSH_BUTTON_PROBE_SLOT(Slot4, slot4, 4);
//PushButton with LED
PUSH_BUTTON(Dual, dual, DUAL_FC, static_cast<char>(DUAL_LED_FC));
PUSH_BUTTON(Quad, quad, QUAD_FC, static_cast<char>(QUAD_LED_FC));
@ -59,7 +65,8 @@ class Console : public QObject
PUSH_BUTTON(ModeCCenter, modeCCenter, MODE_C_CENTER_FC, static_cast<char>(MODE_C_LED_FC));
PUSH_BUTTON(ModeBCenter, modeBCenter, MODE_2D_CENTER_FC, static_cast<char>(MODE_2D_LED_FC));
PUSH_BUTTON(DepthBottom, depthBottom, DEPTH_BOTTOM_FC, static_cast<char>(DEPTH_LED_FC));
PUSH_BUTTON(FocusBottom, focusBottom, FOCUS_BOTTOM_FC, static_cast<char>(FOCUS_DEPTH_LED_FC));
PUSH_BUTTON(FocusBottom, focusBottom, FOCUS_BOTTOM_FC, static_cast<char>(FOCUS_DEPTH_LED_FC));
PUSH_BUTTON_FPS(FrameRateCenter, frameRateCenter);
//PushButton with No LED
PUSH_BUTTON_NO_LED(Js1Top, js1Top, JOYSTICK1_TOP_FC);
@ -103,6 +110,7 @@ class Console : public QObject
ROTARY_BUTTON_NO_LED(Js5, js5, JOYSTICK5_FC);
ROTARY_BUTTON_NO_LED(Depth, depth, DEPTH_FC);
ROTARY_BUTTON_NO_LED(ModePw, modePw, MODE_PW_FC);
ROTARY_BUTTON_FPS(FrameRate, frameRate);
private:
DataSender* _dataSender;
@ -111,6 +119,11 @@ private:
public:
Console();
int selectedProbe1 = 0;
int selectedProbe2 = 0;
int selectedProbe3 = 0;
int selectedProbe4 = 0;
void injectDataSender(DataSender* sender);
void injectLogger(Logger* logger);
void hasValidDataFormat(const QByteArray& data);

2
logic/include/model/DataSender.h

@ -10,12 +10,14 @@ class DataSender : public QObject
public:
virtual void send(const QByteArray& data) = 0;
virtual void sendProbeSlots(const QByteArray& data) = 0;
virtual ~DataSender()
{
}
signals:
void dataReady(const QByteArray& data);
void probeSlotsDataReady(const QByteArray& data);
};
#endif //DATASENDER_H

20
logic/include/model/DatabaseManager.h

@ -0,0 +1,20 @@
#ifndef DATABASEMANAGER_H
#define DATABASEMANAGER_H
#include <QSqlDatabase>
#include <QDebug>
class DatabaseManager
{
private:
QSqlDatabase _db;
public:
DatabaseManager(const QString& databasePath);
~DatabaseManager();
QList<QVariant> getProbeIds();
QList<QVariant> getProbeNames();
};
#endif //DATABASEMANAGER_H

29
logic/include/model/DropDown.h

@ -0,0 +1,29 @@
#ifndef DropDown_H
#define DropDown_H
#define PROTOCOL_LENGTH 8
#define MESSAGE_DIRECTION 0x00
#define DropDownDataLength 0x02
#define DropDownType 0x03
#define ProbA 0x00
#define ProbB 0x01
#define ProbNC 0x02
#define TIME_TAG 0x00
#include "Led.h"
class DropDown
{
private:
char _functionCode;
Led _led;
public:
DropDown(char functionCode);
DropDown(char functionCode, char ledFunctionCode);
Led* getLed();
QByteArray select(int value);
};
#endif //DropDown_H

5
logic/include/network/UdpDataSender.h

@ -10,18 +10,21 @@ class UdpDataSender : public DataSender
Q_OBJECT
private:
QUdpSocket* _socket;
QUdpSocket* _socketDashboard;
QUdpSocket* _socketProbeSlots;
public:
UdpDataSender();
~UdpDataSender() override;
void send(const QByteArray& data) override;
void sendProbeSlots(const QByteArray& data) override;
//uncrustify off
public slots:
//uncrustify on
void read();
void readProbeSlots();
};
#endif //UDPDATASENDER_H

47
logic/include/viewModel/MainViewModel.h

@ -4,6 +4,7 @@
#include <QtMvvmCore/ViewModel>
#include "utils/Property.h"
#include "model/Console.h"
#include <QList>
#define LED_OFF 0x00
#define LED_COLOR_WHITE 0x01
@ -19,6 +20,23 @@ class MainViewModel : public QtMvvm::ViewModel
MVVM_PROPERTY(int, stepInc, 1)
MVVM_PROPERTY(int, stepDec, -1)
BUTTON_LED_PROPERTY(slot1, Slot1, false, LED_COLOR_GREEN)
BUTTON_LED_PROPERTY(slot2, Slot2, false, LED_COLOR_WHITE)
BUTTON_LED_PROPERTY(slot3, Slot3, false, LED_COLOR_WHITE)
BUTTON_LED_PROPERTY(slot4, Slot4, false, LED_COLOR_WHITE)
MVVM_PROPERTY(QList<QVariant>, probeList, {})
MVVM_PROPERTY(int, currentSelectedProbe1, 0)
MVVM_PROPERTY(int, currentSelectedProbe2, 0)
MVVM_PROPERTY(int, currentSelectedProbe3, 0)
MVVM_PROPERTY(int, currentSelectedProbe4, 0)
MVVM_PROPERTY(bool, isProbeSelectionEnable1, false)
MVVM_PROPERTY(bool, isProbeSelectionEnable2, true)
MVVM_PROPERTY(bool, isProbeSelectionEnable3, true)
MVVM_PROPERTY(bool, isProbeSelectionEnable4, true)
//Top Left
BUTTON_LED_PROPERTY(patient, Patient, false, LED_OFF)
BUTTON_LED_PROPERTY(utils, Utils, false, LED_COLOR_WHITE)
@ -90,6 +108,10 @@ class MainViewModel : public QtMvvm::ViewModel
JOYSTICK_PROPERTY(modeM, ModeM)
JOYSTICK_PROPERTY(modeB, ModeB)
LED_PROPERTY(frameRateCenter, LED_OFF) //modeB -> modeBCenterLed
BUTTON_PROPERTY(frameRateCenter, FrameRateCenter, false)
JOYSTICK_PROPERTY(frameRate, FrameRate)
//JoystickCouple
LED_PROPERTY(depthCenter, LED_OFF) //zoom -> depthCenterLed
LED_PROPERTY(depthBottom, LED_OFF) //depth -> depthBottomLed
@ -128,22 +150,35 @@ class MainViewModel : public QtMvvm::ViewModel
BUTTON_PROPERTY(js4Bottom, Js4Bottom, false)
BUTTON_PROPERTY(js5Bottom, Js5Bottom, false)
JOYSTICK_PROPERTY(js1, Js1)
JOYSTICK_PROPERTY(js2, Js2)
JOYSTICK_PROPERTY(js3, Js3)
JOYSTICK_PROPERTY(js4, Js4)
JOYSTICK_PROPERTY(js5, Js5)
JOYSTICK_PROPERTY(js1, Js1)
JOYSTICK_PROPERTY(js2, Js2)
JOYSTICK_PROPERTY(js3, Js3)
JOYSTICK_PROPERTY(js4, Js4)
JOYSTICK_PROPERTY(js5, Js5)
public:
Q_INVOKABLE explicit MainViewModel(QObject* parent = nullptr);
private:
const QString _dbPath = "database/ProbeProperties.db";
signals:
void ledChanged(char value);
//uncrustify off
private slots:
void setProbeSelectionEnable1(bool value);
void setProbeSelectionEnable2(bool value);
void setProbeSelectionEnable3(bool value);
void setProbeSelectionEnable4(bool value);
public slots:
//Probes
LED_SLOT(slot1)
LED_SLOT(slot2)
LED_SLOT(slot3)
LED_SLOT(slot4)
//Top Left
LED_SLOT(patient)
LED_SLOT(utils)
@ -210,6 +245,8 @@ public slots:
LED_SLOT(depthBottom)
LED_SLOT(focusBottom)
LED_SLOT(frameRateCenter)
//uncrustify on
};

5
logic/include/viewModel/utils/Property.h

@ -8,8 +8,8 @@
#define MVVM_PROPERTY(TYPE, NAME, DEFAULT_VALUE) \
Q_PROPERTY(TYPE NAME READ NAME WRITE NAME NOTIFY NAME ## Changed ) \
public: \
TYPE NAME() const { return _ ## NAME ; } \
void NAME(TYPE value) { \
TYPE NAME() const { return _ ## NAME ; } \
void NAME(TYPE value) { \
if (_ ## NAME == value) return; \
_ ## NAME = value; \
emit NAME ## Changed(value); \
@ -77,6 +77,5 @@
NAME ## Led(static_cast<int>(value)); \
} \
//uncrustify on
#endif //PROPERTY_H

9
logic/logic.pro

@ -1,6 +1,7 @@
TEMPLATE = lib
QT += mvvmcore network
QT += mvvmcore network sql
# Creating a static library is typically more efficient. You can still create a shared library if you want to
CONFIG += c++14 static
@ -8,9 +9,11 @@ TARGET = logic
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += $$files(src/*.cpp, true)
SOURCES += $$files(src/*.cpp, true) \
HEADERS += $$files(include/*.h, true) \
HEADERS += $$files(include/*.h, true)
INCLUDEPATH += $$PWD/include/

37
logic/src/model/Console.cpp

@ -34,6 +34,36 @@ void Console::newData(QByteArray data)
{
emit dataReady(data, _logger);
}
switch(data[FUNCTION_CODE])
{
case 1:
{
emit changeProbeSelectionEnable1(!data[1]);
}
break;
case 2:
{
emit changeProbeSelectionEnable2(!data[1]);
}
break;
case 3:
{
emit changeProbeSelectionEnable3(!data[1]);
}
break;
case 4:
{
emit changeProbeSelectionEnable4(!data[1]);
}
break;
default:
break;
}
}
catch(const std::exception& e)
{
@ -84,6 +114,11 @@ bool Console::isEchoPacket(const QByteArray& data)
/*************************************************************************************************/
void Console::initializeButtons()
{
initSlot1();
initSlot2();
initSlot3();
initSlot4();
initDual();
initQuad();
initSingle();
@ -158,4 +193,6 @@ void Console::initializeButtons()
initModePd();
initModeC();
initModeB();
initFrameRate();
}

69
logic/src/model/DatabaseManager.cpp

@ -0,0 +1,69 @@
#include "model/DatabaseManager.h"
#include <QDebug>
#include <QSqlQuery>
#include <QSqlError>
DatabaseManager::DatabaseManager(const QString& databasePath)
{
_db = QSqlDatabase::addDatabase("QSQLITE");
_db.setDatabaseName(databasePath);
if(!_db.open())
{
qDebug() << "Error: " << _db.lastError().text();
}
}
/*************************************************************************************************/
DatabaseManager::~DatabaseManager()
{
if(_db.isOpen())
{
_db.close();
}
}
/*************************************************************************************************/
QList<QVariant> DatabaseManager::getProbeIds()
{
QList<QVariant> globalIds;
QSqlQuery query;
if(query.exec("SELECT globalId FROM Probe"))
{
while(query.next())
{
QString globalId = query.value(0).toString();
globalIds.append(QVariant(globalId));
}
}
else
{
qDebug() << "Error executing query: " << query.lastError().text();
}
return globalIds;
}
/*************************************************************************************************/
QList<QVariant> DatabaseManager::getProbeNames()
{
QList<QVariant> names;
QSqlQuery query;
if(query.exec("SELECT name FROM Probe"))
{
while(query.next())
{
QString name = query.value(0).toString();
names.append(QVariant(name));
}
}
else
{
qDebug() << "Error executing query: " << query.lastError().text();
}
return names;
}

38
logic/src/model/DropDown.cpp

@ -0,0 +1,38 @@
#include "model/DropDown.h"
/*************************************************************************************************/
DropDown::DropDown(char functionCode)
{
_functionCode = functionCode;
}
/*************************************************************************************************/
DropDown::DropDown(char functionCode, char ledFunctionCode) :
_led(ledFunctionCode)
{
_functionCode = functionCode;
}
/*************************************************************************************************/
Led* DropDown::getLed()
{
return &_led;
}
/*************************************************************************************************/
QByteArray DropDown::select(int value)
{
QByteArray arr;
arr.resize(PROTOCOL_LENGTH);
arr[0] = MESSAGE_DIRECTION;
arr[1] = DropDownDataLength;
arr[2] = DropDownType;
arr[3] = _functionCode;
arr[4] = static_cast<char>(value >> PROTOCOL_LENGTH);
arr[5] = static_cast<char>(value);
arr[6] = TIME_TAG;
arr[7] = TIME_TAG;
return arr;
}

36
logic/src/network/UdpDataSender.cpp

@ -4,31 +4,51 @@
void UdpDataSender::send(const QByteArray& data)
{
_socket->writeDatagram(data, QHostAddress::LocalHost, 5446);
_socketDashboard->writeDatagram(data, QHostAddress::LocalHost, 5446);
}
/*************************************************************************************************/
void UdpDataSender::sendProbeSlots(const QByteArray& data)
{
_socketProbeSlots->writeDatagram(data, QHostAddress::LocalHost, 5450);
}
/*************************************************************************************************/
void UdpDataSender::read()
{
char data[DATAGRAM_SIZE];
int cnt = _socket->readDatagram(data, DATAGRAM_SIZE);
int cnt = _socketDashboard->readDatagram(data, DATAGRAM_SIZE);
QByteArray a(data, cnt);
emit dataReady(a);
}
/*************************************************************************************************/
UdpDataSender::UdpDataSender()
void UdpDataSender::readProbeSlots()
{
_socket = new QUdpSocket();
char data[DATAGRAM_SIZE];
int cnt = _socketProbeSlots->readDatagram(data, DATAGRAM_SIZE);
QByteArray a(data, cnt);
emit probeSlotsDataReady(a);
}
_socket->bind(QHostAddress::Any, 5445);
/*************************************************************************************************/
UdpDataSender::UdpDataSender()
{
_socketDashboard = new QUdpSocket();
_socketDashboard->bind(QHostAddress::Any, 5445);
connect(_socketDashboard, SIGNAL(readyRead()), this, SLOT(read()));
connect(_socket, SIGNAL(readyRead()), this, SLOT(read()));
_socketProbeSlots = new QUdpSocket();
_socketProbeSlots->bind(QHostAddress::Any, 5449);
connect(_socketProbeSlots, SIGNAL(readyRead()), this, SLOT(readProbeSlots()));
}
/*************************************************************************************************/
UdpDataSender::~UdpDataSender()
{
_socket->close();
delete _socket;
_socketDashboard->close();
delete _socketDashboard;
_socketProbeSlots->close();
delete _socketProbeSlots;
}

69
logic/src/viewModel/MainViewModel.cpp

@ -5,12 +5,18 @@
#include "model/Console.h"
#include "logger/ConsoleLogger.h"
#include "network/UdpDataSender.h"
#include "model/DatabaseManager.h"
#define US_HOME_PATH "US_HOME"
#define CONNECT_LED(NAME) \
connect(panel, SIGNAL(NAME ## LedChanged(char)), this, SLOT(NAME ## LedHandle(char)));
#define CONNECT_PROBE_SELECTION(NAME) \
connect(panel, \
&Console::changeProbeSelectionEnable ## NAME, \
this, \
&MainViewModel::setProbeSelectionEnable ## NAME);
MainViewModel::MainViewModel(QObject* parent) :
ViewModel(parent)
MainViewModel::MainViewModel(QObject* parent) : ViewModel(parent)
{
panel = new Console;
auto network = new UdpDataSender;
@ -19,6 +25,43 @@ MainViewModel::MainViewModel(QObject* parent) :
panel->injectLogger(logger);
connect(network, &UdpDataSender::dataReady, panel, &Console::newData);
connect(network, &UdpDataSender::probeSlotsDataReady, panel, &Console::newData);
QString databasePath = QString("%1/%2").arg(qgetenv(US_HOME_PATH), _dbPath);
DatabaseManager manager(databasePath);
QList<QVariant> globalNames = manager.getProbeNames();
//probeList(QList<QVariant>({"prb A fromcpp", "prb B fromcpp"}));
probeList(QList<QVariant>(globalNames));
//Current Selected Probes
connect(this, &MainViewModel::currentSelectedProbe1Changed, [ = ]()
{
panel->selectedProbe1 = currentSelectedProbe1();
});
connect(this, &MainViewModel::currentSelectedProbe2Changed, [ = ]()
{
panel->selectedProbe2 = currentSelectedProbe2();
});
connect(this, &MainViewModel::currentSelectedProbe3Changed, [ = ]()
{
panel->selectedProbe3 = currentSelectedProbe3();
});
connect(this, &MainViewModel::currentSelectedProbe4Changed, [ = ]()
{
panel->selectedProbe4 = currentSelectedProbe4();
});
CONNECT_PROBE_SELECTION(1)
CONNECT_PROBE_SELECTION(2)
CONNECT_PROBE_SELECTION(3)
CONNECT_PROBE_SELECTION(4)
//Add Probes in 4 Slots
CONNECT_LED(slot1)
CONNECT_LED(slot2)
CONNECT_LED(slot3)
CONNECT_LED(slot4)
//Top Left
CONNECT_LED(patient)
@ -84,5 +127,25 @@ MainViewModel::MainViewModel(QObject* parent) :
CONNECT_LED(depthCenter)
CONNECT_LED(focusCenter)
CONNECT_LED(depthBottom)
CONNECT_LED(focusBottom)
CONNECT_LED(focusBottom)
}
void MainViewModel::setProbeSelectionEnable1(bool value)
{
isProbeSelectionEnable1(value);
}
void MainViewModel::setProbeSelectionEnable2(bool value)
{
isProbeSelectionEnable2(value);
}
void MainViewModel::setProbeSelectionEnable3(bool value)
{
isProbeSelectionEnable3(value);
}
void MainViewModel::setProbeSelectionEnable4(bool value)
{
isProbeSelectionEnable4(value);
}

6
test/TestDataSender.h

@ -7,11 +7,17 @@ class TestDataSender : public DataSender
{
public:
QByteArray consoleData;
QByteArray slotData;
void send(const QByteArray& data) override
{
consoleData = data;
}
void sendProbeSlots(const QByteArray& data) override
{
slotData = data;
}
};
#endif //TESTDATASENDER_H

2
test/test.pro

@ -1,5 +1,5 @@
QT += testlib
QT -= gui
QT -= gui mvvmcore network sql
CONFIG += qt console warn_on depend_includepath testcase
CONFIG -= app_bundle

6
ui/App.qml

@ -12,9 +12,9 @@ QtMvvmApp {
onHeightChanged: Const.heightRatio = mvvmApp.height / Const.windowHeight
Component.onCompleted: {
width = Const.windowWidth
height = Const.windowHeight
width = Const.windowWidth / 1.3
height = Const.windowHeight / 1.3
x = (Screen.width - width) / 2
y = (Screen.height - height)
y = (Screen.height - height)
}
}

57
ui/emulator/Emulator.qml

@ -4,33 +4,56 @@ import QtGraphicalEffects 1.13
import "qrc:/emulator/items"
import "qrc:/theme"
import "qrc:/const"
import "qrc:/emulator/elements"
Item {
width: Const.windowWidth
height: Const.windowHeight
width: Const.windowWidth
height: Const.windowHeight
Setting {
anchors.horizontalCenter: topLeft.horizontalCenter
anchors.top: topLeft.bottom
anchors.topMargin: 120
}
TopLeftTop {
}
TopLeft {
id: topLeft
}
Setting {
anchors.horizontalCenter: topLeft.horizontalCenter
anchors.top: topLeft.bottom
anchors.topMargin: 120
}
TopRight {}
TopLeft {
id: topLeft
}
BottomRight {}
TopRight {}
CurveButtons {}
BottomRight {}
Joysticks {}
CurveButtons {}
Encoders {}
Joysticks {}
JoystickCouple {}
Encoders {}
TrackballGroup {}
JoystickCouple {}
TrackballGroup {}
ModeButtonBind {
id: frameRate
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.bottomMargin: 20
anchors.rightMargin: 30
name: "frameRate"
nameLed: "frameRateLed"
nameIncrease: "frameRateRight"
nameDecrease: "frameRateLeft"
image: ""
Text {
anchors.centerIn: parent
text: "FPS"
}
}
}

378
ui/emulator/elements/ProbeButton.qml

@ -0,0 +1,378 @@
import QtQuick 2.0
import QtQuick.Controls 2.13
import QtGraphicalEffects 1.13
import "qrc:/theme"
import "qrc:/const"
import "qrc:/emulator/components"
import de.skycoder42.QtMvvm.Core 1.0
import de.skycoder42.QtMvvm.Quick 1.0
import com.example.consoleemulator 1.0
Button {
id: button
width: Const.macroButton
height: Const.macroButton * 2
implicitWidth: width
implicitHeight: height
//=========================================
property var name
property var nameLed: name + "Led"
MvvmBinding {
viewModel: mainView.viewModel
viewProperty: "down"
viewModelProperty: name
type: MvvmBinding.OneWayToViewModel
}
MvvmBinding {
viewModel: mainView.viewModel
viewProperty: "colorMode"
viewModelProperty: nameLed
}
//=========================================
property var image: ""
property var radius: Math.min(width / 2, height / 2)
property var timeToPress: 100
property var border: 6
property var colorMode: 0 // 0->None; 1->White; 2->Green; 3->Yellow
property color lightColor: getColor()
property color lightGlow: getColorGlow()
signal pressed
signal released
onPressed: {
button.down = true
}
onReleased: {
button.down = false
}
function getColor() {
switch (colorMode) {
case (0):
return Theme.current.none
case (1):
return Theme.current.white
case (2):
return Theme.current.green
case (3):
return Theme.current.yellow
}
}
function getColorGlow() {
switch (colorMode) {
case (0):
return Theme.current.noneGlow
case (1):
return Theme.current.whiteGlow
case (2):
return Theme.current.greenGlow
case (3):
return Theme.current.yellowGlow
}
}
contentItem: Item {
id: content
anchors.fill: parent
z: 1
Item {
property var factor: button.state
== "Pressed" ? Const.imageScalePressed : Const.imageScale
property var elevator: button.state == "Pressed" ? 3 : 0
anchors.horizontalCenter: parent.horizontalCenter
y: (parent.height * (1 - factor)) / 2 + elevator
width: parent.width * factor
height: parent.height * factor
Behavior on y {
NumberAnimation {
duration: timeToPress
easing.type: Easing.InOutQuad
}
}
Behavior on width {
NumberAnimation {
duration: timeToPress
easing.type: Easing.InOutQuad
}
}
Behavior on height {
NumberAnimation {
duration: timeToPress
easing.type: Easing.InOutQuad
}
}
Image {
id: img
anchors.fill: parent
source: image
fillMode: Image.PreserveAspectFit
antialiasing: true
smooth: true
}
ColorOverlay {
anchors.fill: img
source: img
color: button.state == "Pressed" ? Theme.current.textSelected : Theme.current.text
antialiasing: true
smooth: true
}
}
}
background: Item {
width: parent.width
height: parent.height
Rectangle {
id: backLightGlow
property var diffusion: Theme.current.glowRaduis
width: backLight.width + diffusion
height: backLight.height + diffusion
radius: width / 2
anchors.horizontalCenter: backLight.horizontalCenter
y: -diffusion / 4
color: Theme.current.background
border {
width: diffusion / 2
color: Theme.current.background
}
}
Rectangle {
anchors.fill: backLightGlow
color: "transparent"
layer.enabled: true
layer.effect: OpacityMask {
maskSource: backLightGlow
}
Rectangle {
width: parent.width
height: parent.height
radius: parent.radius
color: "transparent"
RadialGradient {
anchors.fill: parent
gradient: Gradient {
GradientStop {
position: 0.0
color: lightGlow
}
GradientStop {
position: 0.5 * (backLight.width - backLightGlow.diffusion
/ backLightGlow.width)
color: lightGlow
}
GradientStop {
position: 0.5
color: "transparent"
}
GradientStop {
position: 1.0
color: "transparent"
}
}
}
}
}
Rectangle {
id: backLight
width: parent.width + 4
height: parent.height + 4
radius: width / 2
color: lightColor
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
}
Rectangle {
id: background
anchors.fill: parent
radius: button.radius
color: Theme.current.button
Behavior on color {
ColorAnimation {
duration: timeToPress
easing.type: Easing.InOutQuad
}
}
}
Item {
id: coloredRing
width: parent.width
height: parent.height
Rectangle {
id: lightRing
width: parent.width
height: parent.height
radius: width / 2
color: "transparent"
border {
color: background.color
width: button.border
}
}
Item {
id: borderGrad
implicitWidth: parent.width
implicitHeight: parent.height
anchors.fill: parent
layer.enabled: true
layer.effect: OpacityMask {
maskSource: lightRing
}
Rectangle {
width: parent.width
height: parent.height
color: background.color
LinearGradient {
id: linGrad
anchors.fill: parent
start: Qt.point(0, parent.height)
end: Qt.point(0, 0)
gradient: Gradient {
GradientStop {
id: buttonDown
position: 0
color: Theme.current.shadow
Behavior on color {
ColorAnimation {
duration: timeToPress
easing.type: Easing.InOutQuad
}
}
}
GradientStop {
id: buttonUp
position: 1
color: Theme.current.light
Behavior on color {
ColorAnimation {
duration: timeToPress
easing.type: Easing.InOutQuad
}
}
}
}
}
}
}
}
MouseArea {
hoverEnabled: true
anchors.fill: background
onEntered: {
button.state = "Hovering"
}
onExited: {
button.state = ""
}
onPressed: {
button.state = "Pressed"
button.pressed()
}
onReleased: {
button.released()
if (containsMouse)
button.state = "Hovering"
else
button.state = ""
}
}
}
Item {
id: hoverLight
implicitWidth: parent.width
implicitHeight: parent.height
anchors.fill: parent
layer.enabled: true
layer.effect: OpacityMask {
maskSource: background
}
Rectangle {
id: hoverGlow
width: 2 * parent.width
height: parent.height
x: -2 * parent.width
color: "transparent"
HoverGlow {}
}
}
states: [
State {
name: "Hovering"
PropertyChanges {
target: hoverGlow
x: 0
}
},
State {
name: "Pressed"
PropertyChanges {
target: background
color: Theme.current.buttonSelected
}
PropertyChanges {
target: buttonUp
color: Theme.current.shadow
}
PropertyChanges {
target: buttonDown
color: Theme.current.light
}
}
]
transitions: [
Transition {
from: ""
to: "Hovering"
NumberAnimation {
properties: "x"
duration: 500
easing.type: Easing.OutQuad
}
}
]
}

46
ui/emulator/items/DropDownWithDisable.qml

@ -0,0 +1,46 @@
import QtQuick 2.0
import QtQuick.Layouts 1.13
import QtQuick.Controls 2.12
import de.skycoder42.QtMvvm.Core 1.0
import de.skycoder42.QtMvvm.Quick 1.0
import com.example.consoleemulator 1.0
import "qrc:/emulator/elements"
import "qrc:/emulator/components"
import "qrc:/const"
import "qrc:/qtmvvm/views"
Item {
id: root
implicitWidth: width
implicitHeight: 25
property var isDisable: false
property var viewModelProperty
property var isProbeEnableProperty
property alias model: idComobBox.model
ComboBox {
id: idComobBox
visible: isDisable
model: probeList
width: parent.width
implicitWidth: width
implicitHeight: parent.height
MvvmBinding {
viewModel: mainView.viewModel
viewProperty: "currentIndex"
viewModelProperty: root.viewModelProperty
}
}
Text {
visible: !isDisable
text: idComobBox.currentText
anchors.fill: parent
horizontalAlignment: Text.AlignHCenter
}
MvvmBinding {
viewModel: mainView.viewModel
viewProperty: "isDisable"
viewModelProperty: isProbeEnableProperty
}
}

52
ui/emulator/items/TopLeft.qml

@ -5,33 +5,33 @@ import "qrc:/emulator/components"
import "qrc:/const"
GridLayout {
id: topLeft
x: 70
y: 120
rows: 3
columns: 4
rowSpacing: 36
columnSpacing: 36
NeuLight {
image: "qrc:/icons/topLeft/power.png"
Layout.column: 3
colorMode: 3
id: topLeft
x: 70
y: 270
rows: 3
columns: 4
rowSpacing: 36
columnSpacing: 36
NeuLight {
image: "qrc:/icons/topLeft/power.png"
Layout.column: 3
colorMode: 3
// enabled: false
// name: "power"
}
KnobLightBind { name: "patient" ; image: "qrc:/icons/topLeft/patient.png" }
KnobLightBind { name: "utils" ; image: "qrc:/icons/topLeft/utils.png" }
KnobLightBind { name: "dvd" ; image: "qrc:/icons/topLeft/dvd.png" }
KnobLightBind { name: "report" ; image: "qrc:/icons/topLeft/report.png" }
KnobLightBind { name: "probe" ; image: "qrc:/icons/topLeft/probe.png"
Layout.column: 1
Layout.row: 2
}
KnobLightBind { name: "archive" ; image: "qrc:/icons/topLeft/archive.png" }
KnobLightBind { name: "end" ; image: "qrc:/icons/topLeft/end.png" }
// name: "power"
}
KnobLightBind { name: "patient" ; image: "qrc:/icons/topLeft/patient.png" }
KnobLightBind { name: "utils" ; image: "qrc:/icons/topLeft/utils.png" }
KnobLightBind { name: "dvd" ; image: "qrc:/icons/topLeft/dvd.png" }
KnobLightBind { name: "report" ; image: "qrc:/icons/topLeft/report.png" }
KnobLightBind { name: "probe" ; image: "qrc:/icons/topLeft/probe.png"
Layout.column: 1
Layout.row: 2
}
KnobLightBind { name: "archive" ; image: "qrc:/icons/topLeft/archive.png" }
KnobLightBind { name: "end" ; image: "qrc:/icons/topLeft/end.png" }
}

94
ui/emulator/items/TopLeftTop.qml

@ -0,0 +1,94 @@
import QtQuick 2.0
import QtQuick.Layouts 1.13
import QtQuick.Controls 2.12
import de.skycoder42.QtMvvm.Core 1.0
import de.skycoder42.QtMvvm.Quick 1.0
import com.example.consoleemulator 1.0
import "qrc:/emulator/elements"
import "qrc:/emulator/components"
import "qrc:/const"
import "qrc:/qtmvvm/views"
GridLayout {
x: 20
y: 50
rowSpacing: 30
columns: 4
property var widthOfBtns: 130
property var probeList: []
Item {
Layout.fillWidth: true
implicitHeight: Const.macroButton * 2
ProbeButton {
anchors.centerIn: parent
implicitWidth: width * 1.25
name: "slot4"
image: "qrc:/icons/topLeft/probe.png"
}
}
Item {
Layout.fillWidth: true
implicitHeight: Const.macroButton * 2
ProbeButton {
anchors.centerIn: parent
implicitWidth: width * 1.25
name: "slot3"
image: "qrc:/icons/topLeft/probe.png"
}
}
Item {
Layout.fillWidth: true
implicitHeight: Const.macroButton * 2
ProbeButton {
anchors.centerIn: parent
implicitWidth: width * 1.25
name: "slot2"
image: "qrc:/icons/topLeft/probe.png"
}
}
Item {
Layout.fillWidth: true
implicitHeight: Const.macroButton * 2
ProbeButton {
anchors.centerIn: parent
implicitWidth: width * 1.25
name: "slot1"
image: "qrc:/icons/topLeft/probe.png"
}
}
MvvmBinding {
viewModel: mainView.viewModel
viewProperty: "probeList"
viewModelProperty: "probeList"
}
DropDownWithDisable {
viewModelProperty: "currentSelectedProbe4"
model: probeList
width: widthOfBtns
isProbeEnableProperty: "isProbeSelectionEnable4"
}
DropDownWithDisable {
viewModelProperty: "currentSelectedProbe3"
model: probeList
width: widthOfBtns
isProbeEnableProperty: "isProbeSelectionEnable3"
}
DropDownWithDisable {
viewModelProperty: "currentSelectedProbe2"
model: probeList
width: widthOfBtns
isProbeEnableProperty: "isProbeSelectionEnable2"
}
DropDownWithDisable {
viewModelProperty: "currentSelectedProbe1"
model: probeList
width: widthOfBtns
isProbeEnableProperty: "isProbeSelectionEnable1"
}
}

2
ui/ui.pro

@ -1,6 +1,6 @@
TEMPLATE = app
QT += quick mvvmquick
QT += quick mvvmquick network sql
CONFIG += c++14
TARGET = ConsoleEmulator

3
ui/ui.qrc

@ -95,6 +95,9 @@
<file>emulator/components/SliderBar.qml</file>
<file>emulator/elements/SliderBarBind.qml</file>
<file>emulator/items/Setting.qml</file>
<file>emulator/items/TopLeftTop.qml</file>
<file>emulator/elements/ProbeButton.qml</file>
<file>emulator/items/DropDownWithDisable.qml</file>
</qresource>
<qresource prefix="/qtmvvm/views">
<file>MainView.qml</file>

Loading…
Cancel
Save