Browse Source

add other interface to console and macro of buttons

mode-button
nasi 3 years ago
parent
commit
b474e88776
  1. 26
      logic/include/model/ButtonHelper.h
  2. 103
      logic/include/model/Console.h
  3. 12
      logic/include/model/Logger.h
  4. 1
      logic/include/model/PushButton.h
  5. 20
      logic/include/model/RotaryButton.h
  6. 19
      logic/include/model/RotayButton.h
  7. 3
      logic/logic.pro
  8. 78
      logic/src/model/Console.cpp
  9. 7
      logic/src/model/Led.cpp
  10. 27
      logic/src/model/PushButton.cpp
  11. 14
      logic/src/model/RotaryButton.cpp
  12. 48
      test/tst_console.cpp

26
logic/include/model/ButtonHelper.h

@ -36,4 +36,30 @@ public: \
signals: \
void SMALL_NAME ## LedChanged(int value)
/*************************************************************************************************/
#define ROTARY_BUTTON(CAPITAL_NAME, SMALL_NAME, FUNC_CODE, LED_FUNC_CODE) \
private: \
RotaryButton _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \
public: \
void rotate ## CAPITAL_NAME(int value) \
{ \
auto arr = _ ## SMALL_NAME.rotate(value); \
_dataSender->send(arr); \
} \
signals: \
void SMALL_NAME ## LedChanged(int value)
/*************************************************************************************************/
#define ROTARY_BUTTON_NO_LED(CAPITAL_NAME, SMALL_NAME, FUNC_CODE) \
private: \
RotaryButton _ ## SMALL_NAME{FUNC_CODE}; \
public: \
void rotate ## CAPITAL_NAME(int value) \
{ \
auto arr = _ ## SMALL_NAME.rotate(value); \
_dataSender->send(arr); \
} \
signals: \
void SMALL_NAME ## LedChanged(int value)
#endif //BUTTONHELPER_H

103
logic/include/model/Console.h

@ -6,23 +6,112 @@
#include "ButtonHelper.h"
#include "FunctionCodes.h"
#include "PushButton.h"
#include "RotayButton.h"
#include "RotaryButton.h"
#include "DataSender.h"
#include "Logger.h"
class Console : public QObject
{
Q_OBJECT
Q_OBJECT
// 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));
PUSH_BUTTON(Single, single, SINGLE_FC, static_cast<char>(SINGLE_LED_FC));
PUSH_BUTTON(P1, p1, P1_FC, static_cast<char>(P1_LED_FC));
PUSH_BUTTON(P2, p2, P2_FC, static_cast<char>(P2_LED_FC));
PUSH_BUTTON(P3, p3, P3_FC, static_cast<char>(P3_LED_FC));
PUSH_BUTTON(P4, p4, P4_FC, static_cast<char>(P4_LED_FC));
PUSH_BUTTON(P5, p5, P5_FC, static_cast<char>(P5_LED_FC));
PUSH_BUTTON(P6, p6, P6_FC, static_cast<char>(P6_LED_FC));
PUSH_BUTTON(Exit, exit, EXIT_FC, static_cast<char>(EXIT_LED_FC));
PUSH_BUTTON(Freeze, freeze, FREEZE_FC, static_cast<char>(FREEZE_LED_FC));
PUSH_BUTTON(Pointer, pointer, POINTER_FC, static_cast<char>(POINTER_LED_FC));
PUSH_BUTTON(Auto, auto, AUTOSET_FC, static_cast<char>(AUTOSET_LED_FC));
PUSH_BUTTON(Abc, abc, ABC_FC, static_cast<char>(ABC_LED_FC));
PUSH_BUTTON(FourD, fourD, FOUR_D_FC, static_cast<char>(FOUR_D_LED_FC));
PUSH_BUTTON(Clear, clear, CLEAR_FC, static_cast<char>(CLEAR_LED_FC));
PUSH_BUTTON(ThreeD, threeD, THREE_D_FC, static_cast<char>(THREE_D_LED_FC));
PUSH_BUTTON(Measure, measure, MEASURE_FC, static_cast<char>(MEASURE_LED_FC));
PUSH_BUTTON(BodyMark, bodyMark, BODY_MARK_FC, static_cast<char>(BODY_MARK_LED_FC));
PUSH_BUTTON(Patient, patient, PATIENT_FC, static_cast<char>(PATIENT_LED_FC));
PUSH_BUTTON(Utils, utils, UTILS_FC, static_cast<char>(UTILS_LED_FC));
PUSH_BUTTON(Dvd, dvd, DVD_FC, static_cast<char>(DVD_LED_FC));
PUSH_BUTTON(Report, report, REPORT_FC, static_cast<char>(REPORT_LED_FC));
PUSH_BUTTON(Probe, probe, PROBE_FC, static_cast<char>(PROBE_LED_FC));
PUSH_BUTTON(Archive, archive, ARCHIVE_FC, static_cast<char>(ARCHIVE_LED_FC));
PUSH_BUTTON(End, end, END_FC, static_cast<char>(END_LED_FC));
PUSH_BUTTON(Xtd, xtd, XTD_FC, static_cast<char>(XTD_LED_FC));
PUSH_BUTTON(Bf, bf, BF_FC, static_cast<char>(BF_LED_FC));
PUSH_BUTTON(DepthCenter, depthCenter, DEPTH_CENTER_FC, static_cast<char>(ZOOM_LED_FC));
PUSH_BUTTON(FocusCenter, focusCenter, FOCUS_CENTER_FC, static_cast<char>(FOCUS_ZONE_LED_FC));
PUSH_BUTTON(ModePwCenter, modePwCenter, MODE_PW_CENTER_FC, static_cast<char>(MODE_PW_LED_FC));
PUSH_BUTTON(ModeMCenter, modeMCenter, MODE_M_CENTER_FC, static_cast<char>(MODE_M_LED_FC));
PUSH_BUTTON(ModePdCenter, modePdCenter, MODE_PD_CENTER_FC, static_cast<char>(MODE_PD_LED_FC));
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));
// PushButton with No LED
PUSH_BUTTON_NO_LED(Js1Top, js1Top, JOYSTICK1_TOP_FC);
PUSH_BUTTON_NO_LED(Js2Top, js2Top, JOYSTICK2_TOP_FC);
PUSH_BUTTON_NO_LED(Js3Top, js3Top, JOYSTICK3_TOP_FC);
PUSH_BUTTON_NO_LED( Js4Top, Js4Top, JOYSTICK4_TOP_FC);
PUSH_BUTTON_NO_LED(Js5Top, js5Top, JOYSTICK5_TOP_FC);
PUSH_BUTTON_NO_LED(DepthTop, depthTop, DEPTHTOP_FC);
PUSH_BUTTON_NO_LED(FocusTop, focusTop, FOCUSTOP_FC);
PUSH_BUTTON_NO_LED(Js1Center, js1Center, JOYSTICK1_CENTER_FC);
PUSH_BUTTON_NO_LED(Js2Center, js2Center, JOYSTICK2_CENTER_FC);
PUSH_BUTTON_NO_LED(Js3Center, js3Center, JOYSTICK3_CENTER_FC);
PUSH_BUTTON_NO_LED(Js4Center, js4Center, JOYSTICK4_CENTER_FC);
PUSH_BUTTON_NO_LED(Js5Center, js5Center, JOYSTICK5_CENTER_FC);
PUSH_BUTTON_NO_LED(Js1Bottom, js1Bottom, JOYSTICK1_BOTTOM_FC);
PUSH_BUTTON_NO_LED(Js2Bottom, js2Bottom, JOYSTICK2_BOTTOM_FC);
PUSH_BUTTON_NO_LED(Js3Bottom, js3Bottom, JOYSTICK3_BOTTOM_FC);
PUSH_BUTTON_NO_LED(Js4Bottom, js4Bottom, JOYSTICK4_BOTTOM_FC);
PUSH_BUTTON_NO_LED(Js5Bottom, js5Bottom, JOYSTICK5_BOTTOM_FC);
PUSH_BUTTON_NO_LED(TrackballTop, trackballTop, TRACKBALL_TOP_FC);
PUSH_BUTTON_NO_LED(TrackballTopRight, trackballTopRight, TRACKBALL_TOP_RIGHT_FC);
PUSH_BUTTON_NO_LED(TrackballRight, trackballRight, TRACKBALL_RIGHT_FC);
PUSH_BUTTON_NO_LED(TrackballBottomRight, trackballBottomRight, TRACKBALL_BOTTOM_RIGHT_FC);
PUSH_BUTTON_NO_LED(TrackballBottom, trackballBottom, TRACKBALL_BOTTOM_FC);
PUSH_BUTTON_NO_LED(TrackballBottomLeft, trackballBottomLeft, TRACKBALL_TOP_BOTTOM_FC);
PUSH_BUTTON_NO_LED(TrackballLeft, trackballLeft, TRACKBALL_LEFT_FC);
PUSH_BUTTON_NO_LED(TrackballTopLeft, trackballTopLeft, TRACKBALL_TOP_LEFT_FC);
// ROTAY_BUTTON with LED
ROTARY_BUTTON(Focus, focus, FOCUS_FC, static_cast<char>(ANGLE_LED_FC));
ROTARY_BUTTON(ModeM, modeM, MODE_M_FC, static_cast<char>(QUADRAT_LED_FC));
ROTARY_BUTTON(ModePd, modePd, MODE_PD_FC, static_cast<char>(Z_LED_FC));
ROTARY_BUTTON(ModeC, modeC, MODE_C_FC, static_cast<char>(Y_LED_FC));
ROTARY_BUTTON(ModeB, modeB, MODE_2D_FC, static_cast<char>(X_LED_FC));
// ROTAY_BUTTON with No LED
ROTARY_BUTTON_NO_LED(Js1, js1, JOYSTICK1_FC);
ROTARY_BUTTON_NO_LED(Js2, js2, JOYSTICK2_FC);
ROTARY_BUTTON_NO_LED(Js3, js3, JOYSTICK3_FC);
ROTARY_BUTTON_NO_LED(Js4, js4, JOYSTICK4_FC);
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);
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:
DataSender* _dataSender;
DataSender* _dataSender;
Logger* _logger;
QString _message;
QByteArray _newData;
public:
Console();
void injectDataSender(DataSender* sender);
Console();
void injectDataSender(DataSender* sender);
void injectLogger(Logger* logger);
void newData(QByteArray data);
bool hasValidDataFormat();
bool isEchoPacket();
};
#endif //CONSOLE_H

12
logic/include/model/Logger.h

@ -0,0 +1,12 @@
#ifndef LOGGER_H
#define LOGGER_H
#include "QString"
class Logger
{
public:
virtual void log(QString message) = 0;
virtual ~Logger(){}
};
#endif // LOGGER_H

1
logic/include/model/PushButton.h

@ -14,6 +14,7 @@ private:
public:
PushButton(char functionCode);
PushButton(char functionCode, char ledFunctionCode);
QByteArray press();
QByteArray release();
Led* getLed();

20
logic/include/model/RotaryButton.h

@ -0,0 +1,20 @@
#ifndef RotaryButton_H
#define RotaryButton_H
#include "Led.h"
class RotaryButton
{
private:
char _functionCode;
Led _led;
public:
RotaryButton(char functionCode);
RotaryButton(char functionCode, char ledFunctionCode);
Led* getLed();
QByteArray rotate(int value);
};
#endif //RotaryButton_H

19
logic/include/model/RotayButton.h

@ -1,19 +0,0 @@
#ifndef ROTAYBUTTON_H
#define ROTAYBUTTON_H
#include "Led.h"
class RotayButton
{
private:
char _functionCode;
Led _led;
public:
RotayButton(char functionCode);
RotayButton(char functionCode, char ledFunctionCode);
Led* getLed();
QByteArray rotate(int value);
};
#endif //ROTAYBUTTON_H

3
logic/logic.pro

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

78
logic/src/model/Console.cpp

@ -1,6 +1,7 @@
#include "model/Console.h"
#include "model/DataSender.h"
#include "QByteArray"
Console::Console()
{
@ -9,5 +10,80 @@ Console::Console()
/*************************************************************************************************/
void Console::injectDataSender(DataSender* sender)
{
_dataSender = sender;
_dataSender = sender;
}
/*************************************************************************************************/
void Console::newData(QByteArray data)
{
_newData = data;
if(hasValidDataFormat())
{
if(isEchoPacket())
{
//send echo response
_dataSender->send(_newData);
}
else
{
// call all buttons newData
}
}
else
{
_logger->log(_message);
}
}
/*************************************************************************************************/
bool Console::hasValidDataFormat()
{
if(_newData.isNull() | _newData.isEmpty() | _newData.size() !=8)
{
_message = "Data is not Correct";
return false;
}
if(_newData[0] != static_cast<char>(0X00))
{
_message = "Data direction is not From App";
return false;
}
if(!(_newData[1] == static_cast<char>(0X01) || _newData[1] == static_cast<char>(0X02)))
{
_message = "data length is not correct";
return false;
}
/* if(!(data[2] == static_cast<char>(0X04) || data[2] == static_cast<char>(0X05) || data[2] == static_cast<char>(0X06)))
{
_logger->log("Data type is not : pushButton:4, Rotary:5, Special: 6");
return false;
}*/
return true;
}
/*************************************************************************************************/
bool Console::isEchoPacket()
{
QByteArray echoPacket;
echoPacket.resize(8);
echoPacket[0] = 0x01;
echoPacket[1] = 0x02;
echoPacket[2] = 0x06;
echoPacket[3] = static_cast<char>(0xA4);
echoPacket[4] = 0x00;
echoPacket[5] = 0x00;
echoPacket[6] = 0x00;
echoPacket[7] = 0x00;
for(int i=0 ; i<_newData.length() ; i++)
{
if (_newData[i] != echoPacket[i])
{
return false;
}
}
return true;
}

7
logic/src/model/Led.cpp

@ -9,5 +9,10 @@ Led::Led()
Led::Led(char functionCode)
{
_functionCode = functionCode;
_hasLed = true;
_hasLed = true;
}
void Led::newData(QByteArray data)
{
}

27
logic/src/model/PushButton.cpp

@ -3,19 +3,19 @@
/*************************************************************************************************/
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;
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;
}
/*************************************************************************************************/
@ -38,7 +38,6 @@ QByteArray PushButton::press()
}
/*************************************************************************************************/
QByteArray PushButton::release()
{
return generateCode(false);

14
logic/src/model/RotayButton.cpp → logic/src/model/RotaryButton.cpp

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

48
test/tst_console.cpp

@ -18,6 +18,9 @@ private slots:
void releaseDual_test_case();
void pressQuad_test_case();
void releaseQuad_test_case();
void rotateJs1NoLed_test_case();
void rotatFocusWithLed_test_case();
};
/*************************************************************************************************/
@ -113,7 +116,50 @@ void ConsoleTest::releaseQuad_test_case()
arr[6] = 0x00;
arr[7] = 0x00;
QCOMPARE(t->consoleData, arr);
QCOMPARE(t->consoleData, arr);
}
void ConsoleTest::rotateJs1NoLed_test_case()
{
Console c;
auto t = new TestDataSender;
c.injectDataSender(t);
c.rotateJs1(0);
QByteArray arr;
arr.resize(8);
arr[0] = 0x00;
arr[1] = 0x02;
arr[2] = 0x05;
arr[3] = 0x56;
arr[4] = static_cast<char>(0 >> 8);
arr[5] = static_cast<char>(0);
arr[6] = 0x00;
arr[7] = 0x00;
QCOMPARE(t->consoleData, arr);
}
void ConsoleTest::rotatFocusWithLed_test_case()
{
Console c;
auto t = new TestDataSender;
c.injectDataSender(t);
c.rotateFocus(4000);
QByteArray arr;
arr.resize(8);
arr[0] = 0x00;
arr[1] = 0x02;
arr[2] = 0x05;
arr[3] = 0x51;
arr[4] = static_cast<char>(4000 >> 8);
arr[5] = static_cast<char>(4000);
arr[6] = 0x00;
arr[7] = 0x00;
QCOMPARE(t->consoleData, arr);
}
QTEST_APPLESS_MAIN(ConsoleTest)

Loading…
Cancel
Save