diff --git a/logic/include/model/ButtonHelper.h b/logic/include/model/ButtonHelper.h index a85ade7..d497a89 100644 --- a/logic/include/model/ButtonHelper.h +++ b/logic/include/model/ButtonHelper.h @@ -24,9 +24,9 @@ public: \ 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: \ - PushButton _ ## SMALL_NAME{FUNC_CODE}; \ + PushButton _ ## SMALL_NAME{SLOT_NUMBER}; \ void init ## CAPITAL_NAME() \ { \ connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \ @@ -37,19 +37,20 @@ public: \ void press ## CAPITAL_NAME() \ { \ auto arr = _ ## SMALL_NAME.press(); \ - _dataSender->send(arr); \ + arr[5] = static_cast(this->selectedProbe ## SLOT_NUMBER); \ + _dataSender->sendProbeSlots(arr); \ + emit changeProbeSelectionEnable ## SLOT_NUMBER(); \ } \ 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: \ - RotaryButton _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \ + PushButton _ ## SMALL_NAME {FUNC_CODE}; \ void init ## CAPITAL_NAME() \ { \ connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \ @@ -57,17 +58,22 @@ private: \ SIGNAL(SMALL_NAME ## LedChanged(char))); \ } \ 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); \ } \ 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: \ - RotaryButton _ ## SMALL_NAME{FUNC_CODE}; \ + RotaryButton _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \ void init ## CAPITAL_NAME() \ { \ connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \ @@ -83,9 +89,9 @@ public: \ 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: \ - DropDown _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \ + RotaryButton _ ## SMALL_NAME{FUNC_CODE}; \ void init ## CAPITAL_NAME() \ { \ connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \ @@ -93,9 +99,9 @@ private: \ SIGNAL(SMALL_NAME ## LedChanged(char))); \ } \ 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); \ } \ Q_SIGNAL void SMALL_NAME ## LedChanged(char value) diff --git a/logic/include/model/Console.h b/logic/include/model/Console.h index 4846fc0..200906b 100644 --- a/logic/include/model/Console.h +++ b/logic/include/model/Console.h @@ -14,7 +14,6 @@ #include "FunctionCodes.h" #include "PushButton.h" #include "RotaryButton.h" -#include "DropDown.h" #include "DataSender.h" #include "Logger.h" @@ -23,11 +22,11 @@ class Console : public QObject { Q_OBJECT - //Slotes - DROP_DOWN(Slot1, slot1, SLOT1_FC, static_cast(SLOT1_LED_FC)); - DROP_DOWN(Slot2, slot2, SLOT2_FC, static_cast(SLOT2_LED_FC)); - DROP_DOWN(Slot3, slot3, SLOT3_FC, static_cast(SLOT3_LED_FC)); - DROP_DOWN(Slot4, slot4, SLOT4_FC, static_cast(SLOT4_LED_FC)); + //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(DUAL_LED_FC)); @@ -118,6 +117,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); diff --git a/logic/include/viewModel/MainViewModel.h b/logic/include/viewModel/MainViewModel.h index 8204ccc..039769a 100644 --- a/logic/include/viewModel/MainViewModel.h +++ b/logic/include/viewModel/MainViewModel.h @@ -20,11 +20,23 @@ class MainViewModel : public QtMvvm::ViewModel MVVM_PROPERTY(int, stepInc, 1) MVVM_PROPERTY(int, stepDec, -1) - //Slots - DROP_DOWN_PROPERTY(slot1, Slot1, LED_OFF) - DROP_DOWN_PROPERTY(slot2, Slot2, LED_OFF) - DROP_DOWN_PROPERTY(slot3, Slot3, LED_OFF) - DROP_DOWN_PROPERTY(slot4, Slot4, LED_OFF) + //Probes + 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, 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) @@ -135,24 +147,11 @@ 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) - - //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, probeList, QList({"Pouya", "Mamad"})) - - MVVM_PROPERTY(int, currentSelectedProbe1, 0) - MVVM_PROPERTY(int, currentSelectedProbe2, 0) - MVVM_PROPERTY(int, currentSelectedProbe3, 0) - MVVM_PROPERTY(int, currentSelectedProbe4, 0) + 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); @@ -165,10 +164,10 @@ signals: //uncrustify off public slots: //Probes -// LED_SLOT(slot1) -// LED_SLOT(slot2) -// LED_SLOT(slot3) -// LED_SLOT(slot4) + LED_SLOT(slot1) + LED_SLOT(slot2) + LED_SLOT(slot3) + LED_SLOT(slot4) //Top Left LED_SLOT(patient) @@ -235,7 +234,6 @@ public slots: LED_SLOT(focusCenter) LED_SLOT(depthBottom) LED_SLOT(focusBottom) - //uncrustify on }; diff --git a/logic/include/viewModel/utils/Property.h b/logic/include/viewModel/utils/Property.h index 459de35..db5ea7d 100644 --- a/logic/include/viewModel/utils/Property.h +++ b/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,16 +77,5 @@ NAME ## Led(static_cast(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 diff --git a/logic/logic.pro b/logic/logic.pro index e7c8368..c49c991 100644 --- a/logic/logic.pro +++ b/logic/logic.pro @@ -12,8 +12,7 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += $$files(src/*.cpp, true) \ -HEADERS += $$files(include/*.h, true) \ \ - include/model/FakeHardwareProbesInfo.h +HEADERS += $$files(include/*.h, true) \ INCLUDEPATH += $$PWD/include/ diff --git a/logic/src/viewModel/MainViewModel.cpp b/logic/src/viewModel/MainViewModel.cpp index 0e7232f..b3b1fa4 100644 --- a/logic/src/viewModel/MainViewModel.cpp +++ b/logic/src/viewModel/MainViewModel.cpp @@ -5,12 +5,12 @@ #include "model/Console.h" #include "logger/ConsoleLogger.h" #include "network/UdpDataSender.h" +#include "model/DatabaseManager.h" #define CONNECT_LED(NAME) \ connect(panel, SIGNAL(NAME ## LedChanged(char)), this, SLOT(NAME ## LedHandle(char))); -MainViewModel::MainViewModel(QObject* parent) : - ViewModel(parent) +MainViewModel::MainViewModel(QObject* parent) : ViewModel(parent) { panel = new Console; auto network = new UdpDataSender; @@ -19,12 +19,65 @@ MainViewModel::MainViewModel(QObject* parent) : panel->injectLogger(logger); 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 globalNames = manager.getProbeNames(); + + //probeList(QList({"prb A fromcpp", "prb B fromcpp"})); + probeList(QList(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 -//CONNECT_LED(slot1) -//CONNECT_LED(slot2) -//CONNECT_LED(slot3) -//CONNECT_LED(slot4) + CONNECT_LED(slot1) + CONNECT_LED(slot2) + CONNECT_LED(slot3) + CONNECT_LED(slot4) //Top Left CONNECT_LED(patient)