Browse Source

add rare class

mode-button
nasi 3 years ago
parent
commit
0f9dbd4d6d
  1. 16
      logic/include/model/Console.h
  2. 24
      logic/include/model/Led.h
  3. 20
      logic/include/model/Pushbutton.h
  4. 19
      logic/include/model/RotayButton.h
  5. 40
      logic/logic.pro
  6. 20
      logic/src/model/Console.cpp
  7. 16
      logic/src/model/Led.cpp
  8. 58
      logic/src/model/Pushbutton.cpp
  9. 29
      logic/src/model/RotayButton.cpp
  10. 6
      test/tst_console.cpp

16
logic/include/model/Console.h

@ -1,20 +1,30 @@
#ifndef CONSOLE_H
#define CONSOLE_H
#include <QObject>
#include "Pushbutton.h"
class DataSender;
class Console
class Console: public QObject
{
Q_OBJECT
private:
DataSender* _dataSender;
PushButton _dual;
public:
Console();
void injectDataSender(DataSender* sender);
void test();
void dualPress();
void dualRelease();
void pressDual();
void releaseDual();
signals:
void dualLedChanged(int value);
};
#endif // CONSOLE_H

24
logic/include/model/Led.h

@ -0,0 +1,24 @@
#ifndef LED_H
#define LED_H
#include <QObject>
class Led : public QObject
{
Q_OBJECT
private:
char _functionCode;
bool _hasLed;
public:
Led();
Led(char functionCode);
void newData(QByteArray data);
signals:
void ledChanged(char value);
};
#endif // LED_H

20
logic/include/model/Pushbutton.h

@ -0,0 +1,20 @@
#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

19
logic/include/model/RotayButton.h

@ -0,0 +1,19 @@
#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

40
logic/logic.pro

@ -1,20 +1,20 @@
TEMPLATE = lib
QT += mvvmcore
# Creating a static library is typically more efficient. You can still create a shared library if you want to
CONFIG += c++14 static
TARGET = logic
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += $$files(src/*.cpp, true)
HEADERS += $$files(include/*.h, true)
INCLUDEPATH += $$PWD/include/
INCLUDEPATH += $$PWD/../network/
_never_true_condition: SOURCES += $$files($$PWD/.ts-dummy/*)
# Uncomment the following line to automatically generated and update settings translations when building
#PRE_TARGETDEPS += qtmvvm-tsgen
TEMPLATE = lib
QT += mvvmcore
# Creating a static library is typically more efficient. You can still create a shared library if you want to
CONFIG += c++14 static
TARGET = logic
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += $$files(src/*.cpp, true)
HEADERS += $$files(include/*.h, true)
INCLUDEPATH += $$PWD/include/
INCLUDEPATH += $$PWD/../network/
_never_true_condition: SOURCES += $$files($$PWD/.ts-dummy/*)
# Uncomment the following line to automatically generated and update settings translations when building
#PRE_TARGETDEPS += qtmvvm-tsgen

20
logic/src/model/Console.cpp

@ -2,7 +2,9 @@
#include <model/DataSender.h>
Console::Console()
Console::Console() :
_dual(0x1D, static_cast<char>(0x82))
{
}
@ -24,24 +26,14 @@ void Console::test()
}
//********************************************************************************
void Console::dualPress()
void Console::pressDual()
{
QByteArray arr;
arr.resize(8);
arr[0] = 0x00;
arr[1] = 0x01;
arr[2] = 0x04;
arr[3] = 0x1D;
arr[4] = 0x00;
arr[5] = 0x00;
arr[6] = 0x00;
arr[7] = 0x00;
auto arr = _dual.press();
_dataSender->send(arr);
}
//********************************************************************************
void Console::dualRelease()
void Console::releaseDual()
{
}

16
logic/src/model/Led.cpp

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

58
logic/src/model/Pushbutton.cpp

@ -0,0 +1,58 @@
#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;
}
//********************************************************************************

29
logic/src/model/RotayButton.cpp

@ -0,0 +1,29 @@
#include "../../include/model/RotayButton.h"
RotayButton::RotayButton(char functionCode)
{
_functionCode = functionCode;
}
//********************************************************************************
RotayButton::RotayButton(char functionCode, char ledFunctionCode):
_led(ledFunctionCode)
{
_functionCode = functionCode;
}
//********************************************************************************
Led *RotayButton::getLed()
{
return &_led;
}
//********************************************************************************
QByteArray RotayButton::rotate(int value)
{
}
//********************************************************************************

6
test/tst_console.cpp

@ -50,19 +50,19 @@ void ConsoleTest::dualPress_test_case()
Console c;
auto t = new TestDataSender;
c.injectDataSender(t);
c.dualPress();
c.pressDual();
QByteArray arr;
arr.resize(8);
arr[0] = 0x00;
arr[1] = 0x01;
arr[2] = 0x04;
arr[3] = 0x1D;
arr[4] = 0x00;
arr[4] = 0x01;
arr[5] = 0x00;
arr[6] = 0x00;
arr[7] = 0x00;
QCOMPARE(t->consoleData, arr);

Loading…
Cancel
Save