Skip to content

Commit 2878328

Browse files
committed
Added debug printouts with debug compiler flag
1 parent ef51247 commit 2878328

7 files changed

Lines changed: 43 additions & 15 deletions

File tree

Firmware/FFBoard/Inc/ClassChooser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class ClassChooser {
129129
*/
130130
void replyAvailableClasses(std::vector<CommandReply>& replies,int16_t ignoredCreatableId = 255){
131131
for(class_entry<T> cls : class_registry){
132-
if(cls.info.visibility == ClassVisibility::hidden || (cls.info.visibility == ClassVisibility::debug && !SystemCommands::allowDebugCommands)){
132+
if(cls.info.visibility == ClassVisibility::hidden || (cls.info.visibility == ClassVisibility::debug && !SystemCommands::debugMode)){
133133
if(ignoredCreatableId != cls.selectionId)
134134
continue;
135135
}

Firmware/FFBoard/Inc/CommandHandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class CommandHandler {
143143
virtual std::string getCsvHelpstring(); // Returns a list of the commands helpstrings formatted for csv
144144

145145
static void logSerial(std::string string); //!< Send a log formatted sequence
146+
static void logSerialDebug(std::string string); //!< Send a log formatted sequence if debug is on
146147

147148
void broadcastCommandReply(CommandReply reply, uint32_t cmdId,CMDtype type);
148149
void sendCommandReplyAsync(CommandReply reply, uint32_t cmdId,CMDtype type,CommandInterface* interface = nullptr);

Firmware/FFBoard/Inc/SystemCommands.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SystemCommands : public CommandHandler {
3131
static void replyFlashDump(std::vector<CommandReply>& replies);
3232
static void replyErrors(std::vector<CommandReply>& replies);
3333

34-
static bool allowDebugCommands; // Global flag that controls the debug mode
34+
static bool debugMode; // Global flag that controls the debug mode
3535

3636
static bool errorPrintingEnabled;
3737
static SystemCommands* systemCommandsInstance;

Firmware/FFBoard/Inc/constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ static const uint8_t SW_VERSION_INT[3] = {1,8,7}; // Version as array. 8 bit eac
1515

1616
#define MAX_AXIS 2 // ONLY USE 2 for now else screws HID Reports
1717

18+
//#define DEBUGLOG // Uncomment to enable some debug printouts
1819

1920
#ifndef CANBUS
2021
#undef ODRIVE

Firmware/FFBoard/Src/CommandHandler.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void CommandHandler::registerCommands(){
186186
*/
187187
CmdHandlerCommanddef* CommandHandler::getCommandFromName(const std::string& cmd,uint32_t ignoredFlags){
188188
for(CmdHandlerCommanddef& cmdItem : registeredCommands){
189-
if(cmdItem.cmd == cmd && !(cmdItem.flags & ignoredFlags) && (SystemCommands::allowDebugCommands || !(cmdItem.flags & CMDFLAG_DEBUG))){
189+
if(cmdItem.cmd == cmd && !(cmdItem.flags & ignoredFlags) && (SystemCommands::debugMode || !(cmdItem.flags & CMDFLAG_DEBUG))){
190190
return &cmdItem;
191191
}
192192
}
@@ -199,7 +199,7 @@ CmdHandlerCommanddef* CommandHandler::getCommandFromName(const std::string& cmd,
199199
*/
200200
CmdHandlerCommanddef* CommandHandler::getCommandFromId(const uint32_t id,uint32_t ignoredFlags){
201201
for(CmdHandlerCommanddef& cmdItem : registeredCommands){
202-
if(cmdItem.cmdId == id && !(cmdItem.flags & ignoredFlags) && (SystemCommands::allowDebugCommands || !(cmdItem.flags & CMDFLAG_DEBUG))){
202+
if(cmdItem.cmdId == id && !(cmdItem.flags & ignoredFlags) && (SystemCommands::debugMode || !(cmdItem.flags & CMDFLAG_DEBUG))){
203203
return &cmdItem;
204204
}
205205
}
@@ -383,7 +383,7 @@ bool CommandHandler::isInHandlerList(CommandHandler* handler){
383383
*/
384384
bool CommandHandler::isValidCommandId(uint32_t cmdid,uint32_t ignoredFlags,uint32_t requiredFlags){
385385
for(CmdHandlerCommanddef& cmd : registeredCommands){
386-
if(cmd.cmdId == cmdid && !(cmd.flags & ignoredFlags) && ((cmd.flags & requiredFlags) == requiredFlags) && (SystemCommands::allowDebugCommands || !(cmd.flags & CMDFLAG_DEBUG))){
386+
if(cmd.cmdId == cmdid && !(cmd.flags & ignoredFlags) && ((cmd.flags & requiredFlags) == requiredFlags) && (SystemCommands::debugMode || !(cmd.flags & CMDFLAG_DEBUG))){
387387
return true;
388388
}
389389
}
@@ -445,6 +445,16 @@ void CommandHandler::logSerial(std::string string){
445445

446446
}
447447

448+
/**
449+
* Sends log info back via cdc if debug mode is on
450+
*/
451+
void CommandHandler::logSerialDebug(std::string string)
452+
{
453+
if(SystemCommands::debugMode){
454+
logSerial(string);
455+
}
456+
}
457+
448458
/**
449459
* Returns a description of this class
450460
*/

Firmware/FFBoard/Src/HidFFB.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ void HidFFB::hidOut(uint8_t report_id, hid_report_type_t report_type, uint8_t co
9292
const uint8_t* report = buffer;
9393
uint8_t event_idx = report_id - FFB_ID_OFFSET;
9494

95-
9695
// -------- Out Reports --------
9796
switch(event_idx)
9897
{
@@ -196,10 +195,16 @@ uint16_t HidFFB::hidGet(uint8_t report_id, hid_report_type_t report_type,uint8_t
196195
}
197196

198197
void HidFFB::start_FFB(){
198+
#ifdef DEBUGLOG
199+
CommandHandler::logSerialDebug("FFB on");
200+
#endif
199201
this->set_FFB(true);
200202
}
201203

202204
void HidFFB::stop_FFB(){
205+
#ifdef DEBUGLOG
206+
CommandHandler::logSerialDebug("FFB off");
207+
#endif
203208
this->set_FFB(false);
204209
}
205210

@@ -221,7 +226,7 @@ void HidFFB::set_filters(FFB_Effect *effect){
221226
}
222227

223228
void HidFFB::ffb_control(uint8_t cmd){
224-
//printf("Got Control signal: %d\n",cmd);
229+
225230
if(cmd & 0x01){ //enable
226231
start_FFB();
227232
}if(cmd & 0x02){ //disable
@@ -260,12 +265,17 @@ void HidFFB::new_effect(FFB_CreateNewEffect_Feature_Data_t* effect){
260265
uint8_t index = find_free_effect(effect->effectType); // next effect
261266
if(index == 0){
262267
blockLoad_report.loadStatus = 2;
263-
//CommandHandler::logSerial("Can't allocate a new effect");
268+
#ifdef DEBUGLOG
269+
CommandHandler::logSerialDebug("Can't allocate a new effect");
270+
#endif
264271
return;
265272
}
266273
FFB_Effect new_effect;
267274
new_effect.type = effect->effectType;
268275
this->effects_calc->logEffectType(effect->effectType);
276+
#ifdef DEBUGLOG
277+
CommandHandler::logSerialDebug("New effect type:" + std::to_string(effect->effectType) + " idx: " + std::to_string(index-1));
278+
#endif
269279

270280
set_filters(&new_effect);
271281

@@ -311,7 +321,7 @@ void HidFFB::set_effect(FFB_SetEffect_t* effect){
311321
if(!ffb_active)
312322
start_FFB();
313323
sendStatusReport(effect->effectBlockIndex); // TODO required?
314-
//CommandHandler::logSerial("Setting Effect: " + std::to_string(effect->effectType) + " at " + std::to_string(index) + "\n");
324+
//CommandHandler::logSerialDebug("Setting Effect: " + std::to_string(effect->effectType) + " at " + std::to_string(index) + "\n");
315325
}
316326

317327
void HidFFB::set_condition(FFB_SetCondition_Data_t *cond){
@@ -346,21 +356,27 @@ void HidFFB::set_effect_operation(FFB_EffOp_Data_t* report){
346356
uint8_t id = report->effectBlockIndex-1;
347357
if(report->state == 3){
348358
effects[id].state = 0; //Stop
349-
//CommandHandler::logSerial("Stop" + std::to_string(id));
359+
#ifdef DEBUGLOG
360+
CommandHandler::logSerialDebug("Stop effect: " + std::to_string(id));
361+
#endif
362+
350363
}else{
351364

352365
// 1 = start, 2 = start solo
353366
if(report->state == 2){
354-
//CommandHandler::logSerial("Start solo" + std::to_string(id));
367+
#ifdef DEBUGLOG
368+
CommandHandler::logSerialDebug("Start solo: " + std::to_string(id));
369+
#endif
355370
for(FFB_Effect& effect : effects){
356371
effect.state = 0; // Stop all other effects
357372
}
358373
}
359374
if(effects[id].state != 1){
360375
set_filters(&effects[id]);
361376
}
362-
363-
//CommandHandler::logSerial("Start" + std::to_string(id));
377+
#ifdef DEBUGLOG
378+
CommandHandler::logSerialDebug("Start effect: " + std::to_string(id));
379+
#endif
364380
effects[id].startTime = HAL_GetTick() + effects[id].startDelay; // + effects[id].startDelay;
365381
effects[id].state = 1; //Start
366382

Firmware/FFBoard/Src/SystemCommands.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extern ClassChooser<FFBoardMain> mainchooser;
1717
extern FFBoardMain* mainclass;
1818
//extern static const uint8_t SW_VERSION_INT[3];
1919

20-
bool SystemCommands::allowDebugCommands = false;
20+
bool SystemCommands::debugMode = false;
2121
bool SystemCommands::errorPrintingEnabled = true;
2222
SystemCommands* SystemCommands::systemCommandsInstance = nullptr;
2323

@@ -121,7 +121,7 @@ CommandStatus SystemCommands::internalCommand(const ParsedCommand& cmd,std::vect
121121
}
122122

123123
case FFBoardMain_commands::debug:
124-
return handleGetSet(cmd, replies, SystemCommands::allowDebugCommands);
124+
return handleGetSet(cmd, replies, SystemCommands::debugMode);
125125

126126
case FFBoardMain_commands::vext:
127127
{

0 commit comments

Comments
 (0)