You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.5 KiB
76 lines
2.5 KiB
#pragma once
|
|
#include "apphardware/apphardware.hpp"
|
|
#include "uappbase/base.hpp"
|
|
#include "config/config.hpp"
|
|
namespace iflytop {
|
|
using namespace std;
|
|
#define RCTRL RemoteControlerUpper::ins()
|
|
typedef struct {
|
|
uint8_t data[255];
|
|
uint16_t datalen;
|
|
} RemoteControlerReportPacket_t;
|
|
class RemoteControlerUpper {
|
|
public:
|
|
typedef std::function<void(uint8_t* rx, int32_t len)> on_report_cb_t;
|
|
|
|
private:
|
|
on_report_cb_t m_cb[50];
|
|
int32_t m_ncb = 0;
|
|
|
|
zmutex m_cmdlock = {"RemoteControlerUpperLock"};
|
|
|
|
uint8_t txbuf[255];
|
|
RemoteControlerReportPacket_t ackcache;
|
|
zble_proto_packet_t* txpacket = (zble_proto_packet_t*)txbuf;
|
|
zble_proto_packet_t* rxpacket = (zble_proto_packet_t*)ackcache.data;
|
|
|
|
uint8_t m_index = 0;
|
|
|
|
|
|
public:
|
|
RemoteControlerUpper() {};
|
|
~RemoteControlerUpper() {};
|
|
|
|
static RemoteControlerUpper* ins() {
|
|
static RemoteControlerUpper instance;
|
|
return &instance;
|
|
}
|
|
|
|
void initialize();
|
|
void regOnReport(on_report_cb_t on_report);
|
|
void startSchedule();
|
|
|
|
bool isConnected();
|
|
|
|
private:
|
|
bool txcmd(uint8_t* data, uint32_t len);
|
|
void preProcessrxpacket(RemoteControlerReportPacket_t* packet);
|
|
void processRxEventPacket(RemoteControlerReportPacket_t* packet);
|
|
void callOnReport(uint8_t* rx, int32_t len);
|
|
|
|
public:
|
|
/***********************************************************************************************************************
|
|
* COMMON_API *
|
|
***********************************************************************************************************************/
|
|
bool resetMasterBoard();
|
|
bool resetClientBoard();
|
|
|
|
bool readMasterBoardVersion(zble_read_version_t* version);
|
|
bool readClientBoardVersion(zble_read_version_t* version);
|
|
|
|
bool clearMasterResetFlag();
|
|
bool clearSlaveResetFlag();
|
|
|
|
bool setMasterInDfuMode();
|
|
bool setSlaveInDfuMode();
|
|
|
|
bool startScan(const char* slaveName, bool autoConnect);
|
|
bool stopScan();
|
|
|
|
/***********************************************************************************************************************
|
|
* app *
|
|
***********************************************************************************************************************/
|
|
bool setRemoterState(hand_acid_mode_t mode, bool state);
|
|
};
|
|
|
|
} // namespace iflytop
|