Open FFBoard
Open source force feedback firmware
HidCommandInterface.h
Go to the documentation of this file.
1/*
2 * HidCommandInterface.h
3 *
4 * Created on: 10.12.2021
5 * Author: Yannick
6 */
7
8#ifndef INC_HIDCOMMANDINTERFACE_H_
9#define INC_HIDCOMMANDINTERFACE_H_
10#include "CommandInterface.h"
11#include "semaphore.hpp"
12#include "thread.hpp"
13#include "ffb_defs.h"
14#include "CommandHandler.h"
15
16enum class HidCmdType : uint8_t {write = 0, request = 1, info = 2, writeAddr = 3, requestAddr = 4,ACK = 10, notFound = 13, notification = 14, err = 15};
17
18
19
20// TODO: can only be 25B long. tinyusb will hang otherwise!
21typedef struct
22{
23 uint8_t reportId = HID_ID_HIDCMD; // Report ID = 0xA1
24 HidCmdType type = HidCmdType::err; // 0x01. Type of report. 0 = write, 1 = request
25 uint16_t clsid = 0; // 0x02 Class ID identifies the target class type
26 uint8_t instance = 0; // 0x03 Class instance number to target a specific instance (often 0). 0xff for broadcast to all instances
27 uint32_t cmd = 0; // 0x04 Use this as an identifier for the command. upper 16 bits for class type
28 uint64_t data = 0; // 0x05 Use this to transfer data or the primary value
29 uint64_t addr = 0; // 0x06 Use this to transfer an optional address or second value (CAN for example)
30
31} __attribute__((packed)) HID_CMD_Data_t;
32
33
34
36public:
38 virtual ~HID_CommandInterface();
39
40 static HID_CommandInterface* globalInterface; // Pointer used to access the main hid command interface
41
42 const std::string getHelpstring(){return "HID";}; // Not applicable here
43 bool getNewCommands(std::vector<ParsedCommand>& commands);
44 //bool hasNewCommands();
45 void sendReplies(const std::vector<CommandResult>& results,CommandInterface* originalInterface); // All commands from batch done
46 void hidCmdCallback(HID_CMD_Data_t* data);
47 bool sendHidCmd(HID_CMD_Data_t* data);
48 void queueReplyValues(const CommandReply& reply,const ParsedCommand& command);
49 void transferComplete(uint8_t itf, uint8_t const* report, uint8_t len);
50 bool readyToSend();
51 void Run();
52 bool waitingToSend();
53
54private:
55 std::vector<ParsedCommand> commands;
56 std::vector<HID_CMD_Data_t> outBuffer;
57 bool enableBroadcastFromOtherInterfaces = true; // TODO make configurable via command
58 //static cpp_freertos::BinarySemaphore threadSem;
59 const uint32_t maxQueuedReplies = 50;
60 const uint32_t maxQueuedRepliesBroadcast = 10; // Must be smaller than maxQueuedReplies
61
62};
63
64
65
66#endif /* INC_HIDCOMMANDINTERFACE_H_ */
void queueReplyValues(const CommandReply &reply, const ParsedCommand &command)
const uint32_t maxQueuedRepliesBroadcast
void transferComplete(uint8_t itf, uint8_t const *report, uint8_t len)
std::vector< ParsedCommand > commands
void sendReplies(const std::vector< CommandResult > &results, CommandInterface *originalInterface)
std::vector< HID_CMD_Data_t > outBuffer
const uint32_t maxQueuedReplies
bool sendHidCmd(HID_CMD_Data_t *data)
void hidCmdCallback(HID_CMD_Data_t *data)
static HID_CommandInterface * globalInterface
const std::string getHelpstring()
bool getNewCommands(std::vector< ParsedCommand > &commands)
static struct @612 data
struct __attribute__((__packed__)) reportHID_t
Definition: ffb_defs.h:102