qt/LedOK/globaldefine.h

122 lines
3.3 KiB
C
Raw Normal View History

2023-05-25 10:00:00 +08:00
#ifndef GLOBALDEFINE_H
2023-04-18 14:14:46 +08:00
#define GLOBALDEFINE_H
2023-05-15 16:06:10 +08:00
2023-04-18 14:14:46 +08:00
#include <QJsonDocument>
2023-05-15 16:06:10 +08:00
#include <QNetworkReply>
class LedCard {
public:
QString id;
QString ip;
int mWidth{0};
int mHeight{0};
int bright{100};
int BrightnessLevel{255};
QString FirmwareVersion;
QString HardVersion = "0000";
QString ScreenResolution;
QString androidVersion;
QString alias;
2023-05-25 10:00:00 +08:00
QString IMEI;
2023-05-15 16:06:10 +08:00
bool hasPassword{false};
bool isLocked{true};
bool isScreenOn{true};
bool isOnline{true};
};
2023-04-18 14:14:46 +08:00
enum {
MainPage_DeviceManager = 0,
MainPage_ProgManager,
MainPage_Setting,
MainPage_LoraScreen,
MainPage_End,
};
2023-05-19 18:50:21 +08:00
2023-04-18 14:14:46 +08:00
struct ST_ANSY_PROGRAM_PACKET {
2023-05-19 18:50:21 +08:00
unsigned char SyncHead[3]{0x7e, 0x7e, 0x55};
2023-04-18 14:14:46 +08:00
unsigned char ucCommType;
int iBaoLiu;
unsigned int iLength;
unsigned char pDataBuffer[20];
};
2023-05-15 16:06:10 +08:00
class DevicePanel;
extern DevicePanel *gDevicePanel;
extern QList<LedCard> gSelCards;
2023-04-18 14:14:46 +08:00
extern bool gVideoCompress;
extern bool gVideoTranscoding;
extern bool gTextAntialiasing;
extern bool gShowLoraScreen;
extern bool gWidthSplit;
extern quint64 dirFileSize(const QString &path);
extern bool copyDir(const QString &source, const QString &destination, bool override);
extern unsigned char GetCheckCodeIn8(unsigned char * pBuffer,unsigned int uiSize);
enum _ENUM_CONTRL_WIDGET {
Setting_Bright=0,
Setting_PowerControl,
Setting_NetCfg,
Setting_VerifyClock,
Setting_Encrypt,
Setting_HDMI,
Setting_Volume,
Setting_Advanced,
Setting_Test,
Setting_End,
};
2023-05-15 16:06:10 +08:00
class DeviceItem;
extern DeviceItem *findItem(QString id);
2023-04-18 14:14:46 +08:00
2023-05-18 18:24:40 +08:00
inline int verCompare(const QString& a, const QString& b) {
auto aparts = a.split(".");
auto bparts = b.split(".");
int cnt = qMin(aparts.count(), bparts.count());
for(int i=0; i<cnt; ++i) {
int aaa = aparts[i].toInt();
int bbb = bparts[i].toInt();
if(aaa != bbb) return aaa - bbb;
}
2023-05-18 20:53:43 +08:00
if(aparts.count() == bparts.count()) return 0;
2023-05-18 18:24:40 +08:00
return aparts.count() > bparts.count() ? aparts[cnt].toInt() : bparts[cnt].toInt();
}
2023-04-18 14:14:46 +08:00
QString replyErr(QNetworkReply *);
QString checkReply(QNetworkReply *, QJsonDocument * = 0);
QString checkReplyForJson(QNetworkReply *, QJsonDocument * = 0, QByteArray * = 0);
#define Def_CtrlReqPre \
waitingDlg->show();\
2023-05-15 16:06:10 +08:00
auto card = gSelCards[0];\
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);\
2023-04-23 17:01:35 +08:00
waitingDlg->connAbort(reply);
2023-04-18 14:14:46 +08:00
#define Def_CtrlSetReqAfter \
QString err = checkReplyForJson(reply);\
if(! err.isEmpty()) {\
waitingDlg->close();\
2023-05-11 11:47:00 +08:00
QMessageBox::critical(this, tr("Error"), err);\
2023-04-18 14:14:46 +08:00
return;\
}\
waitingDlg->success();
#define Def_CtrlSingleGetReply \
QJsonDocument json;\
QString err = checkReplyForJson(reply, &json);\
if(! err.isEmpty()) {\
waitingDlg->close();\
2023-05-11 11:47:00 +08:00
QMessageBox::critical(this, tr("Error"), err);\
2023-04-18 14:14:46 +08:00
return;\
}
#define Def_CtrlSetMulti(tip) \
2023-05-15 16:06:10 +08:00
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);\
connect(reply, &QNetworkReply::finished, gFdResInfo, [=] {\
2023-04-18 14:14:46 +08:00
QString err = checkReplyForJson(reply);\
2023-05-15 16:06:10 +08:00
gFdResInfo->append(card.id+" "+tip+" "+(err.isEmpty()?QCoreApplication::translate("Def","Success"):err));\
2023-04-18 14:14:46 +08:00
});
#endif // GLOBALDEFINE_H