Open FFBoard
Open source force feedback firmware
FFBHIDMain_commmands.cpp
Go to the documentation of this file.
1/*
2 * FFBWheel_commands.cpp
3 *
4 * Created on: 28.01.2021
5 * Author: Yannick / Lidgard
6 */
7
8
9#include <FFBHIDMain.h>
10
12 //CommandHandler::registerCommands();
13
14 //registerCommand("axes", FFBWheel_commands::axes, "Number of axes (1-2)");
15 registerCommand("ffbactive", FFBWheel_commands::ffbactive, "FFB status",CMDFLAG_GET);
16
17 registerCommand("btntypes", FFBWheel_commands::btntypes, "Enabled button sources",CMDFLAG_GET|CMDFLAG_SET);
18 registerCommand("addbtn", FFBWheel_commands::addbtn, "Enable button source",CMDFLAG_SET);
19 registerCommand("lsbtn", FFBWheel_commands::lsbtn, "Get available button sources",CMDFLAG_GET|CMDFLAG_STR_ONLY);
20
21 registerCommand("aintypes", FFBWheel_commands::aintypes, "Enabled analog sources",CMDFLAG_GET|CMDFLAG_SET);
22 registerCommand("lsain", FFBWheel_commands::lsain, "Get available analog sources",CMDFLAG_GET|CMDFLAG_STR_ONLY);
23 registerCommand("addain", FFBWheel_commands::addain, "Enable analog source",CMDFLAG_SET);
24
25 registerCommand("hidrate", FFBWheel_commands::hidrate, "Get estimated effect update speed",CMDFLAG_GET);
26 registerCommand("cfrate", FFBWheel_commands::cfrate, "Get estimated const force rate",CMDFLAG_GET);
27 registerCommand("hidsendspd", FFBWheel_commands::hidsendspd, "Change HID gamepad update rate",CMDFLAG_GET|CMDFLAG_SET|CMDFLAG_INFOSTRING);
28
29 registerCommand("estop", FFBWheel_commands::estop, "Emergency stop",CMDFLAG_GET|CMDFLAG_SET);
30}
31
32CommandStatus FFBHIDMain::command(const ParsedCommand& cmd,std::vector<CommandReply>& replies){
33 switch(static_cast<FFBWheel_commands>(cmd.cmdId)){
35 if(cmd.type == CMDtype::get){
36 replies.emplace_back(this->control.emergency);
37 }else if(cmd.type == CMDtype::set){
38 this->emergencyStop(cmd.val == 0);
39 }
40
41 break;
43 {
44 if(cmd.type != CMDtype::get)
45 return CommandStatus::ERR;
46
47 int8_t flag = this->getFfbActive() ? 1 : 0;
48 if(this->control.emergency){
49 flag = -1;
50 }
51 replies.emplace_back(flag);
52 break;
53 }
54// case FFBWheel_commands::axes:
55// if(cmd.type == CMDtype::get){
56// replies.emplace_back(this->axes_manager->getAxisCount());
57// }else if(cmd.type == CMDtype::set){
58// this->axes_manager->setAxisCount(cmd.val);
59// }
60// break;
62 if(cmd.type == CMDtype::get){
63 replies.emplace_back(btnsources);
64 }else if(cmd.type == CMDtype::set){
65 setBtnTypes(cmd.val);
66 }
67 break;
69 btn_chooser.replyAvailableClasses(replies);
70 break;
72 if(cmd.type == CMDtype::set){
73 this->addBtnType(cmd.val);
74 }
75 break;
77 if(cmd.type == CMDtype::get){
78 replies.emplace_back(ainsources);
79 }else if(cmd.type == CMDtype::set){
80 setAinTypes(cmd.val);
81 }
82 break;
84 analog_chooser.replyAvailableClasses(replies);
85 break;
87 if(cmd.type == CMDtype::set){
88 this->addAinType(cmd.val);
89 }
90 break;
92 if(cmd.type == CMDtype::get){
93 replies.emplace_back(this->getRate());
94 }else{
95 return CommandStatus::ERR;
96 }
97 break;
99 if(cmd.type == CMDtype::get){
100 replies.emplace_back(this->ffb->getConstantForceRate());
101 }else{
102 return CommandStatus::ERR;
103 }
104 break;
106 if(cmd.type == CMDtype::get){
107 replies.emplace_back(usb_report_rate_idx);
108 }else if(cmd.type == CMDtype::set){
109 setReportRate(cmd.val);
110 }else if(cmd.type == CMDtype::info){
111 replies.emplace_back(usb_report_rates_names());
112 }
113 break;
114 case FFBWheel_commands::axes: // Dummy for compatibility. remove later
115 default:
117 }
118 return CommandStatus::OK;
119};
120
121
122
CommandStatus
void registerCommand(const char *cmd, const ID cmdid, const char *help=nullptr, uint32_t flags=0)
std::shared_ptr< EffectsControlItf > ffb
Definition: FFBHIDMain.h:86
uint32_t getRate()
Definition: FFBHIDMain.cpp:201
void setReportRate(uint8_t rateidx)
Definition: FFBHIDMain.cpp:277
std::string usb_report_rates_names()
Definition: FFBHIDMain.cpp:286
void setAinTypes(uint16_t aintypes)
Definition: FFBHIDMain.cpp:176
volatile Control_t control
Definition: FFBHIDMain.h:91
CommandStatus command(const ParsedCommand &cmd, std::vector< CommandReply > &replies)
uint16_t ainsources
Definition: FFBHIDMain.h:121
uint8_t usb_report_rate_idx
Definition: FFBHIDMain.h:102
ClassChooser< AnalogSource > analog_chooser
Definition: FFBHIDMain.h:125
uint16_t btnsources
Definition: FFBHIDMain.h:120
bool getFfbActive()
Definition: FFBHIDMain.cpp:205
void addBtnType(uint16_t id)
Definition: FFBHIDMain.cpp:158
void addAinType(uint16_t id)
Definition: FFBHIDMain.cpp:190
void setBtnTypes(uint16_t btntypes)
Definition: FFBHIDMain.cpp:143
ClassChooser< ButtonSource > btn_chooser
Definition: FFBHIDMain.h:124
void emergencyStop(bool reset)
Definition: FFBHIDMain.cpp:296
bool emergency
Definition: Axis.h:39
uint32_t cmdId