Browse Source

Add helper to ease development

mode-button
h-4nd-h 3 years ago
parent
commit
0b955aea6c
  1. 39
      logic/include/model/ButtonHelper.h
  2. 31
      logic/include/model/Console.h
  3. 134
      logic/include/model/FunctionCodes.h
  4. 19
      logic/include/model/Led.h
  5. 22
      logic/include/model/PushButton.h
  6. 20
      logic/include/model/Pushbutton.h
  7. 16
      logic/include/model/RotayButton.h
  8. 55
      logic/src/model/Console.cpp
  9. 13
      logic/src/model/Led.cpp
  10. 52
      logic/src/model/PushButton.cpp
  11. 58
      logic/src/model/Pushbutton.cpp
  12. 49
      logic/src/model/RotayButton.cpp
  13. 26
      logic/src/viewModel/MainViewModel.cpp
  14. 180
      test/tst_console.cpp

39
logic/include/model/ButtonHelper.h

@ -0,0 +1,39 @@
#ifndef BUTTONHELPER_H
#define BUTTONHELPER_H
#define PUSH_BUTTON(CAPITAL_NAME, SMALL_NAME, FUNC_CODE, LED_FUNC_CODE) \
private: \
PushButton _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \
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); \
} \
signals: \
void SMALL_NAME ## LedChanged(int value)
/*************************************************************************************************/
#define PUSH_BUTTON_NO_LED(CAPITAL_NAME, SMALL_NAME, FUNC_CODE) \
private: \
PushButton _ ## SMALL_NAME{FUNC_CODE}; \
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); \
} \
signals: \
void SMALL_NAME ## LedChanged(int value)
#endif //BUTTONHELPER_H

31
logic/include/model/Console.h

@ -3,31 +3,26 @@
#include <QObject> #include <QObject>
#include "Pushbutton.h" #include "ButtonHelper.h"
#include "FunctionCodes.h"
#include "PushButton.h"
#include "RotayButton.h" #include "RotayButton.h"
class DataSender; #include "DataSender.h"
class Console: public QObject class Console : public QObject
{ {
Q_OBJECT Q_OBJECT
PUSH_BUTTON(Dual, dual, DUAL_FC, static_cast<char>(DUAL_LED_FC));
PUSH_BUTTON(Quad, quad, QUAD_FC, static_cast<char>(QUAD_LED_FC));
private: private:
DataSender* _dataSender; DataSender* _dataSender;
PushButton _dual, _quad;
// RotayButton _Js1;
public: public:
Console(); Console();
void injectDataSender(DataSender* sender); void injectDataSender(DataSender* sender);
void test();
void pressDual();
void releaseDual();
void pressQuad();
void releaseQuad();
signals:
void dualLedChanged(int value);
}; };
#endif // CONSOLE_H #endif //CONSOLE_H

134
logic/include/model/FunctionCodes.h

@ -0,0 +1,134 @@
#ifndef FUNCTIONCODES_H
#define FUNCTIONCODES_H
//Buttons
#define DUAL_FC 0x1D
#define QUAD_FC 0x1C
#define SINGLE_FC 0x1B
#define P1_FC 0x21
#define P2_FC 0x22
#define P3_FC 0x23
#define P4_FC 0x24
#define EXIT_FC 0x0C
#define FREEZE_FC 0x15
#define POINTER_FC 0x0D
#define AUTOSET_FC 0x14
#define ABC_FC 0x0E
#define FOUR_D_FC 0x13
#define CLEAR_FC 0x10
#define THREE_D_FC 0x12
#define MEASURE_FC 0x11
#define BODY_MARK_FC 0x0F
#define PATIENT_FC 0x02
#define UTILS_FC 0x03
#define DVD_FC 0x04
#define REPORT_FC 0x05
#define PROBE_FC 0x06
#define ARCHIVE_FC 0x07
#define END_FC 0x08
#define XTD_FC 0x16
#define BF_FC 0x17
#define P5_FC 0x25
#define P6_FC 0x26
#define JOYSTICK1_TOP_FC 0x39
#define JOYSTICK2_TOP_FC 0x3C
#define JOYSTICK3_TOP_FC 0x3F
#define JOYSTICK4_TOP_FC 0x42
#define JOYSTICK5_TOP_FC 0x45
#define DEPTHTOP_FC 0x33
#define FOCUSTOP_FC 0x36
#define JOYSTICK1_CENTER_FC 0x38
#define JOYSTICK2_CENTER_FC 0x3B
#define JOYSTICK3_CENTER_FC 0x3E
#define JOYSTICK4_CENTER_FC 0x41
#define JOYSTICK5_CENTER_FC 0x44
#define DEPTH_CENTER_FC 0x32
#define FOCUS_CENTER_FC 0x35
#define MODE_PW_CENTER_FC 0x49
#define MODE_M_CENTER_FC 0x4A
#define MODE_PD_CENTER_FC 0x4B
#define MODE_C_CENTER_FC 0x4C
#define MODE_2D_CENTER_FC 0x4D
#define JOYSTICK1_BOTTOM_FC 0x37
#define JOYSTICK2_BOTTOM_FC 0x3A
#define JOYSTICK3_BOTTOM_FC 0x3D
#define JOYSTICK4_BOTTOM_FC 0x40
#define JOYSTICK5_BOTTOM_FC 0x43
#define DEPTH_BOTTOM_FC 0x31
#define FOCUS_BOTTOM_FC 0x34
//Trackball
#define TRACKBALL_TOP_FC 0x2A
#define TRACKBALL_BOTTOM_FC 0x2B
#define TRACKBALL_RIGHT_FC 0x2C
#define TRACKBALL_LEFT_FC 0x2D
#define TRACKBALL_TOP_RIGHT_FC 0x2E
#define TRACKBALL_BOTTOM_RIGHT_FC 0x28
#define TRACKBALL_TOP_LEFT_FC 0x2F
#define TRACKBALL_TOP_BOTTOM_FC 0x29
//Joystick
#define JOYSTICK1_FC 0x56
#define JOYSTICK2_FC 0x57
#define JOYSTICK3_FC 0x58
#define JOYSTICK4_FC 0x59
#define JOYSTICK5_FC 0x5A
#define DEPTH_FC 0x52
#define FOCUS_FC 0x51
#define MODE_PW_FC 0x5E
#define MODE_M_FC 0x5F
#define MODE_PD_FC 0x60
#define MODE_C_FC 0x61
#define MODE_2D_FC 0x62
//Leds
#define DUAL_LED_FC 0X82
#define QUAD_LED_FC 0X81
#define SINGLE_LED_FC 0X80
#define P1_LED_FC 0X86
#define P2_LED_FC 0X87
#define P3_LED_FC 0X88
#define P4_LED_FC 0X89
#define EXIT_LED_FC 0X71
#define FREEZE_LED_FC 0X7A
#define POINTER_LED_FC 0X72
#define AUTOSET_LED_FC 0X79
#define ABC_LED_FC 0X73
#define FOUR_D_LED_FC 0X78
#define CLEAR_LED_FC 0X75
#define THREE_D_LED_FC 0X77
#define MEASURE_LED_FC 0X76
#define BODY_MARK_LED_FC 0X74
#define POWER_LED_FC 0X66
#define PATIENT_LED_FC 0X67
#define UTILS_LED_FC 0X68
#define DVD_LED_FC 0X69
#define REPORT_LED_FC 0X6A
#define PROBE_LED_FC 0X6B
#define ARCHIVE_LED_FC 0X6C
#define END_LED_FC 0X6D
#define XTD_LED_FC 0X7B
#define BF_LED_FC 0X7C
#define P5_LED_FC 0X8A
#define P6_LED_FC 0X8B
#define MODE_PW_LED_FC 0X98
#define MODE_2D_LED_FC 0X9A
#define MODE_M_LED_FC 0X9C
#define MODE_C_LED_FC 0X9E
#define MODE_PD_LED_FC 0X9F
#define QUADRAT_LED_FC 0X9D
#define X_LED_FC 0X9B
#define Y_LED_FC 0X99
#define Z_LED_FC 0X97
#define ZOOM_LED_FC 0X8F
#define DEPTH_LED_FC 0X90
#define ANGLE_LED_FC 0X91
#define FOCUS_ZONE_LED_FC 0X92
#define FOCUS_DEPTH_LED_FC 0X93
#endif //FUNCTIONCODES_H

19
logic/include/model/Led.h

@ -5,20 +5,19 @@
class Led : public QObject class Led : public QObject
{ {
Q_OBJECT Q_OBJECT
private: private:
char _functionCode; char _functionCode;
bool _hasLed; bool _hasLed;
public: public:
Led(); Led();
Led(char functionCode); Led(char functionCode);
void newData(QByteArray data); void newData(QByteArray data);
signals: signals:
void ledChanged(char value); void ledChanged(char value);
}; };
#endif // LED_H #endif //LED_H

22
logic/include/model/PushButton.h

@ -0,0 +1,22 @@
#ifndef PUSHBUTTON_H
#define PUSHBUTTON_H
#include "Led.h"
class PushButton
{
private:
char _functionCode;
Led _led;
QByteArray generateCode(bool isPressed);
public:
PushButton(char functionCode);
PushButton(char functionCode, char ledFunctionCode);
QByteArray press();
QByteArray release();
Led* getLed();
};
#endif //PUSHBUTTON_H

20
logic/include/model/Pushbutton.h

@ -1,20 +0,0 @@
#ifndef PUSHBUTTON_H
#define PUSHBUTTON_H
#include "Led.h"
class PushButton
{
private:
char _functionCode;
Led _led ;
public:
PushButton(char functionCode);
PushButton(char functionCode, char ledFunctionCode);
QByteArray press();
QByteArray release();
Led* getLed();
};
#endif // PUSHBUTTON_H

16
logic/include/model/RotayButton.h

@ -6,14 +6,14 @@
class RotayButton class RotayButton
{ {
private: private:
char _functionCode; char _functionCode;
Led _led; Led _led;
public:
RotayButton(char functionCode); public:
RotayButton(char functionCode, char ledFunctionCode); RotayButton(char functionCode);
Led* getLed(); RotayButton(char functionCode, char ledFunctionCode);
QByteArray rotate(int value); Led* getLed();
QByteArray rotate(int value);
}; };
#endif // ROTAYBUTTON_H #endif //ROTAYBUTTON_H

55
logic/src/model/Console.cpp

@ -1,58 +1,13 @@
#include "model/Console.h" #include "model/Console.h"
#include <model/DataSender.h> #include "model/DataSender.h"
Console::Console() : Console::Console()
_dual(0x1D, static_cast<char>(0x82)),
_quad(0x1C, static_cast<char>(0x81))
{
}
//********************************************************************************
void Console::injectDataSender(DataSender *sender)
{ {
_dataSender = sender;
} }
//******************************************************************************** /*************************************************************************************************/
void Console::test() void Console::injectDataSender(DataSender* sender)
{ {
QByteArray arr; _dataSender = sender;
arr.append(0x01);
arr.append(0x03);
arr.append(0x05);
_dataSender->send(arr);
} }
//********************************************************************************
void Console::pressDual()
{
auto arr = _dual.press();
_dataSender->send(arr);
}
//********************************************************************************
void Console::releaseDual()
{
auto arr = _dual.release();
_dataSender->send(arr);
}
//********************************************************************************
void Console::pressQuad()
{
auto arr = _quad.press();
_dataSender->send(arr);
}
//********************************************************************************
void Console::releaseQuad()
{
auto arr = _quad.release();
_dataSender->send(arr);
}
//********************************************************************************

13
logic/src/model/Led.cpp

@ -1,16 +1,13 @@
#include "../../include/model/Led.h" #include "model/Led.h"
Led::Led() Led::Led()
{ {
_hasLed = false; _hasLed = false;
} }
//******************************************************************************** /*************************************************************************************************/
Led::Led(char functionCode) Led::Led(char functionCode)
{ {
_functionCode = functionCode; _functionCode = functionCode;
_hasLed = true; _hasLed = true;
} }
//********************************************************************************

52
logic/src/model/PushButton.cpp

@ -0,0 +1,52 @@
#include "model/PushButton.h"
/*************************************************************************************************/
QByteArray PushButton::generateCode(bool isPressed)
{
QByteArray arr;
arr.resize(8);
arr[0] = 0x00;
arr[1] = 0x01;
arr[2] = 0x04;
arr[3] = _functionCode;
arr[4] = isPressed ? 0x01 : 0x00;
arr[5] = 0x00;
arr[6] = 0x00;
arr[7] = 0x00;
return arr;
}
/*************************************************************************************************/
PushButton::PushButton(char functionCode)
{
_functionCode = functionCode;
}
/*************************************************************************************************/
PushButton::PushButton(char functionCode, char ledFunctionCode) :
_led(ledFunctionCode)
{
_functionCode = functionCode;
}
/*************************************************************************************************/
QByteArray PushButton::press()
{
return generateCode(true);
}
/*************************************************************************************************/
QByteArray PushButton::release()
{
return generateCode(false);
}
/*************************************************************************************************/
Led* PushButton::getLed()
{
return &_led;
}

58
logic/src/model/Pushbutton.cpp

@ -1,58 +0,0 @@
#include "../../include/model/Pushbutton.h"
//********************************************************************************
PushButton::PushButton(char functionCode)
{
_functionCode = functionCode;
}
//********************************************************************************
PushButton::PushButton(char functionCode, char ledFunctionCode) :
_led(ledFunctionCode)
{
_functionCode = functionCode;
}
//********************************************************************************
QByteArray PushButton::press()
{
QByteArray arr;
arr.resize(8);
arr[0] = 0x00;
arr[1] = 0x01;
arr[2] = 0x04;
arr[3] = _functionCode;
arr[4] = 0x01;
arr[5] = 0x00;
arr[6] = 0x00;
arr[7] = 0x00;
return arr;
}
//********************************************************************************
QByteArray PushButton::release()
{
QByteArray arr;
arr.resize(8);
arr[0] = 0x00;
arr[1] = 0x01;
arr[2] = 0x04;
arr[3] = _functionCode;
arr[4] = 0x00;
arr[5] = 0x00;
arr[6] = 0x00;
arr[7] = 0x00;
return arr;
}
//********************************************************************************
Led *PushButton::getLed()
{
return &_led;
}
//********************************************************************************

49
logic/src/model/RotayButton.cpp

@ -1,40 +1,37 @@
#include "../../include/model/RotayButton.h" #include "model/RotayButton.h"
RotayButton::RotayButton(char functionCode) RotayButton::RotayButton(char functionCode)
{ {
_functionCode = functionCode; _functionCode = functionCode;
} }
//******************************************************************************** /*************************************************************************************************/
RotayButton::RotayButton(char functionCode, char ledFunctionCode): RotayButton::RotayButton(char functionCode, char ledFunctionCode) :
_led(ledFunctionCode) _led(ledFunctionCode)
{ {
_functionCode = functionCode; _functionCode = functionCode;
} }
//******************************************************************************** /*************************************************************************************************/
Led *RotayButton::getLed() Led* RotayButton::getLed()
{ {
return &_led; return &_led;
} }
//******************************************************************************** /*************************************************************************************************/
QByteArray RotayButton::rotate(int value) QByteArray RotayButton::rotate(int value)
{ {
QByteArray arr; QByteArray arr;
arr.resize(8); arr.resize(8);
arr[0] = 0x00; arr[0] = 0x00;
arr[1] = 0X02; arr[1] = 0X02;
arr[2] = 0X05; arr[2] = 0X05;
arr[3] = _functionCode; arr[3] = _functionCode;
arr[4] = 0x01; arr[4] = 0x01;
arr[5] = 0x00; arr[5] = 0x00;
arr[6] = 0x00; arr[6] = 0x00;
arr[7] = 0x00; arr[7] = 0x00;
return arr;
return arr;
} }
//********************************************************************************

26
logic/src/viewModel/MainViewModel.cpp

@ -5,31 +5,29 @@
#include "model/Console.h" #include "model/Console.h"
#include "UdpDataSender.h" #include "UdpDataSender.h"
MainViewModel::MainViewModel(QObject *parent) : MainViewModel::MainViewModel(QObject* parent) :
ViewModel(parent), ViewModel(parent),
_text(QStringLiteral("hello world")) _text(QStringLiteral("hello world"))
{ {
Console c;
auto u = new UdpDataSender;
c.injectDataSender(u);
c.test();
} }
QString MainViewModel::text() const QString MainViewModel::text() const
{ {
return _text; return _text;
} }
void MainViewModel::showSettings() void MainViewModel::showSettings()
{ {
show<QtMvvm::SettingsViewModel>(); show<QtMvvm::SettingsViewModel>();
} }
void MainViewModel::setText(const QString &text) void MainViewModel::setText(const QString& text)
{ {
if (_text == text) if(_text == text)
return; {
return;
}
_text = text; _text = text;
emit textChanged(_text); emit textChanged(_text);
} }

180
test/tst_console.cpp

@ -5,133 +5,115 @@
class ConsoleTest : public QObject class ConsoleTest : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
ConsoleTest(); ConsoleTest();
~ConsoleTest(); ~ConsoleTest();
//uncrustify off
private slots: private slots:
void test_case1(); //uncrustify on
void pressDual_test_case(); void pressDual_test_case();
void releaseDual_test_case(); void releaseDual_test_case();
void pressQuad_test_case(); void pressQuad_test_case();
void releaseQuad_test_case(); void releaseQuad_test_case();
}; };
//******************************************************************************** /*************************************************************************************************/
ConsoleTest::ConsoleTest() ConsoleTest::ConsoleTest()
{ {
} }
//******************************************************************************** /*************************************************************************************************/
ConsoleTest::~ConsoleTest() ConsoleTest::~ConsoleTest()
{ {
} }
//******************************************************************************** /*************************************************************************************************/
void ConsoleTest::test_case1()
{
Console c;
auto t = new TestDataSender;
c.injectDataSender(t);
c.test();
QByteArray arr;
arr.append(0x01);
arr.append(0x04);
arr.append(0x05);
QCOMPARE(t->consoleData, arr);
}
//********************************************************************************
void ConsoleTest::pressDual_test_case() void ConsoleTest::pressDual_test_case()
{ {
Console c; Console c;
auto t = new TestDataSender; auto t = new TestDataSender;
c.injectDataSender(t); c.injectDataSender(t);
c.pressDual(); c.pressDual();
QByteArray arr; QByteArray arr;
arr.resize(8); arr.resize(8);
arr[0] = 0x00; arr[0] = 0x00;
arr[1] = 0x01; arr[1] = 0x01;
arr[2] = 0x04; arr[2] = 0x04;
arr[3] = 0x1D; arr[3] = 0x1D;
arr[4] = 0x01; arr[4] = 0x01;
arr[5] = 0x00; arr[5] = 0x00;
arr[6] = 0x00; arr[6] = 0x00;
arr[7] = 0x00; arr[7] = 0x00;
QCOMPARE(t->consoleData, arr); QCOMPARE(t->consoleData, arr);
} }
//******************************************************************************** /*************************************************************************************************/
void ConsoleTest::releaseDual_test_case() void ConsoleTest::releaseDual_test_case()
{ {
Console c; Console c;
auto t = new TestDataSender; auto t = new TestDataSender;
c.injectDataSender(t); c.injectDataSender(t);
c.releaseDual(); c.releaseDual();
QByteArray arr; QByteArray arr;
arr.resize(8); arr.resize(8);
arr[0] = 0x00; arr[0] = 0x00;
arr[1] = 0x01; arr[1] = 0x01;
arr[2] = 0x04; arr[2] = 0x04;
arr[3] = 0x1D; arr[3] = 0x1D;
arr[4] = 0x00; arr[4] = 0x00;
arr[5] = 0x00; arr[5] = 0x00;
arr[6] = 0x00; arr[6] = 0x00;
arr[7] = 0x00; arr[7] = 0x00;
QCOMPARE(t->consoleData, arr); QCOMPARE(t->consoleData, arr);
} }
//******************************************************************************** /*************************************************************************************************/
void ConsoleTest::pressQuad_test_case() void ConsoleTest::pressQuad_test_case()
{ {
Console c; Console c;
auto t = new TestDataSender; auto t = new TestDataSender;
c.injectDataSender(t); c.injectDataSender(t);
c.pressQuad(); c.pressQuad();
QByteArray arr; QByteArray arr;
arr.resize(8); arr.resize(8);
arr[0] = 0x00; arr[0] = 0x00;
arr[1] = 0x01; arr[1] = 0x01;
arr[2] = 0x04; arr[2] = 0x04;
arr[3] = 0x1C; arr[3] = 0x1C;
arr[4] = 0x01; arr[4] = 0x01;
arr[5] = 0x00; arr[5] = 0x00;
arr[6] = 0x00; arr[6] = 0x00;
arr[7] = 0x00; arr[7] = 0x00;
QCOMPARE(t->consoleData, arr); QCOMPARE(t->consoleData, arr);
} }
//******************************************************************************** /*************************************************************************************************/
void ConsoleTest::releaseQuad_test_case() void ConsoleTest::releaseQuad_test_case()
{ {
Console c; Console c;
auto t = new TestDataSender; auto t = new TestDataSender;
c.injectDataSender(t); c.injectDataSender(t);
c.releaseQuad(); c.releaseQuad();
QByteArray arr; QByteArray arr;
arr.resize(8); arr.resize(8);
arr[0] = 0x00; arr[0] = 0x00;
arr[1] = 0x01; arr[1] = 0x01;
arr[2] = 0x04; arr[2] = 0x04;
arr[3] = 0x1C; arr[3] = 0x1C;
arr[4] = 0x00; arr[4] = 0x00;
arr[5] = 0x00; arr[5] = 0x00;
arr[6] = 0x00; arr[6] = 0x00;
arr[7] = 0x00; arr[7] = 0x00;
QCOMPARE(t->consoleData, arr); QCOMPARE(t->consoleData, arr);
} }
QTEST_APPLESS_MAIN(ConsoleTest) QTEST_APPLESS_MAIN(ConsoleTest)

Loading…
Cancel
Save