Browse Source

Change probe slot selection to push button

pull/1/head
miladS 1 year ago
parent
commit
da3dedef1c
  1. 38
      logic/include/model/ButtonHelper.h
  2. 16
      logic/include/model/Console.h
  3. 44
      logic/include/viewModel/MainViewModel.h
  4. 11
      logic/include/viewModel/utils/Property.h
  5. 3
      logic/logic.pro
  6. 65
      logic/src/viewModel/MainViewModel.cpp

38
logic/include/model/ButtonHelper.h

@ -24,9 +24,9 @@ public: \
Q_SIGNAL void SMALL_NAME ## LedChanged(char value) Q_SIGNAL void SMALL_NAME ## LedChanged(char value)
/*************************************************************************************************/ /*************************************************************************************************/
#define PUSH_BUTTON_NO_LED(CAPITAL_NAME, SMALL_NAME, FUNC_CODE) \ #define PUSH_BUTTON_PROBE_SLOT(CAPITAL_NAME, SMALL_NAME, SLOT_NUMBER) \
private: \ private: \
PushButton _ ## SMALL_NAME{FUNC_CODE}; \ PushButton _ ## SMALL_NAME{SLOT_NUMBER}; \
void init ## CAPITAL_NAME() \ void init ## CAPITAL_NAME() \
{ \ { \
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \ connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \
@ -37,19 +37,20 @@ public: \
void press ## CAPITAL_NAME() \ void press ## CAPITAL_NAME() \
{ \ { \
auto arr = _ ## SMALL_NAME.press(); \ auto arr = _ ## SMALL_NAME.press(); \
_dataSender->send(arr); \ arr[5] = static_cast<char>(this->selectedProbe ## SLOT_NUMBER); \
_dataSender->sendProbeSlots(arr); \
emit changeProbeSelectionEnable ## SLOT_NUMBER(); \
} \ } \
void release ## CAPITAL_NAME() \ void release ## CAPITAL_NAME() \
{ \ { \
auto arr = _ ## SMALL_NAME.release(); \
_dataSender->send(arr); \
} \ } \
Q_SIGNAL void SMALL_NAME ## LedChanged(char value) Q_SIGNAL void SMALL_NAME ## LedChanged(char value); \
Q_SIGNAL void changeProbeSelectionEnable ## SLOT_NUMBER()
/*************************************************************************************************/ /*************************************************************************************************/
#define ROTARY_BUTTON(CAPITAL_NAME, SMALL_NAME, FUNC_CODE, LED_FUNC_CODE) \ #define PUSH_BUTTON_NO_LED(CAPITAL_NAME, SMALL_NAME, FUNC_CODE) \
private: \ private: \
RotaryButton _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \ PushButton _ ## SMALL_NAME {FUNC_CODE}; \
void init ## CAPITAL_NAME() \ void init ## CAPITAL_NAME() \
{ \ { \
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \ connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \
@ -57,17 +58,22 @@ private: \
SIGNAL(SMALL_NAME ## LedChanged(char))); \ SIGNAL(SMALL_NAME ## LedChanged(char))); \
} \ } \
public: \ public: \
void rotate ## CAPITAL_NAME(int value) \ void press ## CAPITAL_NAME() \
{ \ { \
auto arr = _ ## SMALL_NAME.rotate(value); \ auto arr = _ ## SMALL_NAME.press(); \
_dataSender->send(arr); \
} \
void release ## CAPITAL_NAME() \
{ \
auto arr = _ ## SMALL_NAME.release(); \
_dataSender->send(arr); \ _dataSender->send(arr); \
} \ } \
Q_SIGNAL void SMALL_NAME ## LedChanged(char value) Q_SIGNAL void SMALL_NAME ## LedChanged(char value)
/*************************************************************************************************/ /*************************************************************************************************/
#define ROTARY_BUTTON_NO_LED(CAPITAL_NAME, SMALL_NAME, FUNC_CODE) \ #define ROTARY_BUTTON(CAPITAL_NAME, SMALL_NAME, FUNC_CODE, LED_FUNC_CODE) \
private: \ private: \
RotaryButton _ ## SMALL_NAME{FUNC_CODE}; \ RotaryButton _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \
void init ## CAPITAL_NAME() \ void init ## CAPITAL_NAME() \
{ \ { \
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \ connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \
@ -83,9 +89,9 @@ public: \
Q_SIGNAL void SMALL_NAME ## LedChanged(char value) Q_SIGNAL void SMALL_NAME ## LedChanged(char value)
/*************************************************************************************************/ /*************************************************************************************************/
#define DROP_DOWN(CAPITAL_NAME, SMALL_NAME, FUNC_CODE, LED_FUNC_CODE) \ #define ROTARY_BUTTON_NO_LED(CAPITAL_NAME, SMALL_NAME, FUNC_CODE) \
private: \ private: \
DropDown _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \ RotaryButton _ ## SMALL_NAME{FUNC_CODE}; \
void init ## CAPITAL_NAME() \ void init ## CAPITAL_NAME() \
{ \ { \
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \ connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \
@ -93,9 +99,9 @@ private: \
SIGNAL(SMALL_NAME ## LedChanged(char))); \ SIGNAL(SMALL_NAME ## LedChanged(char))); \
} \ } \
public: \ public: \
void select ## CAPITAL_NAME(int value) \ void rotate ## CAPITAL_NAME(int value) \
{ \ { \
auto arr = _ ## SMALL_NAME.select(value); \ auto arr = _ ## SMALL_NAME.rotate(value); \
_dataSender->send(arr); \ _dataSender->send(arr); \
} \ } \
Q_SIGNAL void SMALL_NAME ## LedChanged(char value) Q_SIGNAL void SMALL_NAME ## LedChanged(char value)

16
logic/include/model/Console.h

@ -14,7 +14,6 @@
#include "FunctionCodes.h" #include "FunctionCodes.h"
#include "PushButton.h" #include "PushButton.h"
#include "RotaryButton.h" #include "RotaryButton.h"
#include "DropDown.h"
#include "DataSender.h" #include "DataSender.h"
#include "Logger.h" #include "Logger.h"
@ -23,11 +22,11 @@ class Console : public QObject
{ {
Q_OBJECT Q_OBJECT
//Slotes //Probe slotes
DROP_DOWN(Slot1, slot1, SLOT1_FC, static_cast<char>(SLOT1_LED_FC)); PUSH_BUTTON_PROBE_SLOT(Slot1, slot1, 1);
DROP_DOWN(Slot2, slot2, SLOT2_FC, static_cast<char>(SLOT2_LED_FC)); PUSH_BUTTON_PROBE_SLOT(Slot2, slot2, 2);
DROP_DOWN(Slot3, slot3, SLOT3_FC, static_cast<char>(SLOT3_LED_FC)); PUSH_BUTTON_PROBE_SLOT(Slot3, slot3, 3);
DROP_DOWN(Slot4, slot4, SLOT4_FC, static_cast<char>(SLOT4_LED_FC)); PUSH_BUTTON_PROBE_SLOT(Slot4, slot4, 4);
//PushButton with LED //PushButton with LED
PUSH_BUTTON(Dual, dual, DUAL_FC, static_cast<char>(DUAL_LED_FC)); PUSH_BUTTON(Dual, dual, DUAL_FC, static_cast<char>(DUAL_LED_FC));
@ -118,6 +117,11 @@ private:
public: public:
Console(); Console();
int selectedProbe1 = 0;
int selectedProbe2 = 0;
int selectedProbe3 = 0;
int selectedProbe4 = 0;
void injectDataSender(DataSender* sender); void injectDataSender(DataSender* sender);
void injectLogger(Logger* logger); void injectLogger(Logger* logger);
void hasValidDataFormat(const QByteArray& data); void hasValidDataFormat(const QByteArray& data);

44
logic/include/viewModel/MainViewModel.h

@ -20,11 +20,23 @@ class MainViewModel : public QtMvvm::ViewModel
MVVM_PROPERTY(int, stepInc, 1) MVVM_PROPERTY(int, stepInc, 1)
MVVM_PROPERTY(int, stepDec, -1) MVVM_PROPERTY(int, stepDec, -1)
//Slots //Probes
DROP_DOWN_PROPERTY(slot1, Slot1, LED_OFF) BUTTON_LED_PROPERTY(slot1, Slot1, false, LED_COLOR_GREEN)
DROP_DOWN_PROPERTY(slot2, Slot2, LED_OFF) BUTTON_LED_PROPERTY(slot2, Slot2, false, LED_COLOR_WHITE)
DROP_DOWN_PROPERTY(slot3, Slot3, LED_OFF) BUTTON_LED_PROPERTY(slot3, Slot3, false, LED_COLOR_WHITE)
DROP_DOWN_PROPERTY(slot4, Slot4, LED_OFF) 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 //Top Left
BUTTON_LED_PROPERTY(patient, Patient, false, LED_OFF) BUTTON_LED_PROPERTY(patient, Patient, false, LED_OFF)
@ -141,19 +153,6 @@ class MainViewModel : public QtMvvm::ViewModel
JOYSTICK_PROPERTY(js4, Js4) JOYSTICK_PROPERTY(js4, Js4)
JOYSTICK_PROPERTY(js5, Js5) JOYSTICK_PROPERTY(js5, Js5)
//Probes
//BUTTON_LED_PROPERTY(probe1, Probe1, false, LED_OFF)
//BUTTON_LED_PROPERTY(probe2, Probe2, false, LED_OFF)
//BUTTON_LED_PROPERTY(probe3, Probe3, false, LED_OFF)
//BUTTON_LED_PROPERTY(probe4, Probe4, false, LED_OFF)
MVVM_PROPERTY(QList<QVariant>, probeList, QList<QVariant>({"Pouya", "Mamad"}))
MVVM_PROPERTY(int, currentSelectedProbe1, 0)
MVVM_PROPERTY(int, currentSelectedProbe2, 0)
MVVM_PROPERTY(int, currentSelectedProbe3, 0)
MVVM_PROPERTY(int, currentSelectedProbe4, 0)
public: public:
Q_INVOKABLE explicit MainViewModel(QObject* parent = nullptr); Q_INVOKABLE explicit MainViewModel(QObject* parent = nullptr);
@ -165,10 +164,10 @@ signals:
//uncrustify off //uncrustify off
public slots: public slots:
//Probes //Probes
// LED_SLOT(slot1) LED_SLOT(slot1)
// LED_SLOT(slot2) LED_SLOT(slot2)
// LED_SLOT(slot3) LED_SLOT(slot3)
// LED_SLOT(slot4) LED_SLOT(slot4)
//Top Left //Top Left
LED_SLOT(patient) LED_SLOT(patient)
@ -235,7 +234,6 @@ public slots:
LED_SLOT(focusCenter) LED_SLOT(focusCenter)
LED_SLOT(depthBottom) LED_SLOT(depthBottom)
LED_SLOT(focusBottom) LED_SLOT(focusBottom)
//uncrustify on //uncrustify on
}; };

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

@ -77,16 +77,5 @@
NAME ## Led(static_cast<int>(value)); \ NAME ## Led(static_cast<int>(value)); \
} \ } \
/**************************************************************************************************/
#define DROP_DOWN_PROPERTY(NAME, CAP_NAME, LED_DEF_VAL) \
MVVM_PROPERTY_CUSTOM(bool, NAME, false) \
void NAME ## Handle() { \
if(NAME()) \
{ \
panel->select ## CAP_NAME('stepDec()'); \
} \
} \
//uncrustify on
#endif //PROPERTY_H #endif //PROPERTY_H

3
logic/logic.pro

@ -12,8 +12,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += $$files(src/*.cpp, true) \ SOURCES += $$files(src/*.cpp, true) \
HEADERS += $$files(include/*.h, true) \ \ HEADERS += $$files(include/*.h, true) \
include/model/FakeHardwareProbesInfo.h
INCLUDEPATH += $$PWD/include/ INCLUDEPATH += $$PWD/include/

65
logic/src/viewModel/MainViewModel.cpp

@ -5,12 +5,12 @@
#include "model/Console.h" #include "model/Console.h"
#include "logger/ConsoleLogger.h" #include "logger/ConsoleLogger.h"
#include "network/UdpDataSender.h" #include "network/UdpDataSender.h"
#include "model/DatabaseManager.h"
#define CONNECT_LED(NAME) \ #define CONNECT_LED(NAME) \
connect(panel, SIGNAL(NAME ## LedChanged(char)), this, SLOT(NAME ## LedHandle(char))); connect(panel, SIGNAL(NAME ## LedChanged(char)), this, SLOT(NAME ## LedHandle(char)));
MainViewModel::MainViewModel(QObject* parent) : MainViewModel::MainViewModel(QObject* parent) : ViewModel(parent)
ViewModel(parent)
{ {
panel = new Console; panel = new Console;
auto network = new UdpDataSender; auto network = new UdpDataSender;
@ -19,12 +19,65 @@ MainViewModel::MainViewModel(QObject* parent) :
panel->injectLogger(logger); panel->injectLogger(logger);
connect(network, &UdpDataSender::dataReady, panel, &Console::newData); connect(network, &UdpDataSender::dataReady, panel, &Console::newData);
connect(network, &UdpDataSender::probeSlotsDataReady, panel, &Console::newData);
//Read probe ids from the database
QString databasePath = "../../../US_Home/database/ProbeProperties.db";
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();
});
//Enable and disable changes in probe selection box
connect(panel, &Console::changeProbeSelectionEnable1, [ = ]()
{
this->isProbeSelectionEnable1(!this->isProbeSelectionEnable1());
this->slot1Led(this->isProbeSelectionEnable1() ? LED_COLOR_WHITE : LED_COLOR_GREEN);
});
connect(panel, &Console::changeProbeSelectionEnable2, [ = ]()
{
this->isProbeSelectionEnable2(!this->isProbeSelectionEnable2());
this->slot2Led(this->isProbeSelectionEnable2() ? LED_COLOR_WHITE : LED_COLOR_GREEN);
});
connect(panel, &Console::changeProbeSelectionEnable3, [ = ]()
{
this->isProbeSelectionEnable3(!this->isProbeSelectionEnable3());
this->slot3Led(this->isProbeSelectionEnable3() ? LED_COLOR_WHITE : LED_COLOR_GREEN);
});
connect(panel, &Console::changeProbeSelectionEnable4, [ = ]()
{
this->isProbeSelectionEnable4(!this->isProbeSelectionEnable4());
this->slot4Led(this->isProbeSelectionEnable4() ? LED_COLOR_WHITE : LED_COLOR_GREEN);
});
//connect(this, );
//Add Probes in 4 Slots //Add Probes in 4 Slots
//CONNECT_LED(slot1) CONNECT_LED(slot1)
//CONNECT_LED(slot2) CONNECT_LED(slot2)
//CONNECT_LED(slot3) CONNECT_LED(slot3)
//CONNECT_LED(slot4) CONNECT_LED(slot4)
//Top Left //Top Left
CONNECT_LED(patient) CONNECT_LED(patient)

Loading…
Cancel
Save