Open FFBoard
Open source force feedback firmware
Loading...
Searching...
No Matches
FFBHIDMain Class Referenceabstract

#include <FFBHIDMain.h>

Inheritance diagram for FFBHIDMain:
TimerHandler SelectableInputs ErrorHandler UsbHidHandler ExtiHandler PersistentStorage cpp_freertos::Thread FFBoardMain FFBHIDExt FFBJoystick FFBWheel

Classes

struct  FFB_update_rates
 

Public Member Functions

 FFBHIDMain (uint8_t axisCount, bool hidAxis32b=false)
 
virtual ~FFBHIDMain ()
 
void setFFBEffectsCalc (std::shared_ptr< EffectsControlItf > ffb, std::shared_ptr< EffectsCalculator > effects_calc)
 
const ClassIdentifier getInfo ()=0
 
CommandStatus command (const ParsedCommand &cmd, std::vector< CommandReply > &replies)
 
void registerCommands ()
 
virtual std::string getHelpstring ()
 
virtual void usbInit ()=0
 
void usbSuspend ()
 
void usbResume ()
 
void saveFlash ()
 
void restoreFlash ()
 
void Run ()
 
void updateControl ()
 
void emergencyStop (bool reset)
 
uint32_t getRate ()
 
bool getFfbActive ()
 
void exti (uint16_t GPIO_Pin)
 
void errorCallback (const Error &error, bool cleared)
 
void systick ()
 
void timerElapsed (TIM_HandleTypeDef *htim)
 
float getCurFFBFreq ()
 
- Public Member Functions inherited from FFBoardMain
const ClassType getClassType () override
 returns the used classchooser selection id of this instance
 
 FFBoardMain ()
 
virtual ~FFBoardMain ()
 
virtual void update ()
 
virtual void cdcRcv (char *Buf, uint32_t *Len)
 
virtual void cdcRcvReady (uint8_t itf)
 
- Public Member Functions inherited from ChoosableClass
virtual ~ChoosableClass ()
 
uint16_t getSelectionID ()
 
- Public Member Functions inherited from CommandHandler
 CommandHandler (const char *clsname, uint16_t clsid, uint8_t instance=0)
 
virtual ~CommandHandler ()
 
virtual bool hasCommands ()
 
virtual void setCommandsEnabled (bool enable)
 
void registerCommands ()
 
virtual CommandStatus internalCommand (const ParsedCommand &cmd, std::vector< CommandReply > &replies)
 
virtual std::string getCommandsHelpstring ()
 
virtual std::string getCsvHelpstring ()
 
virtual uint8_t getCommandHandlerInstance ()
 
void broadcastCommandReply (CommandReply reply, uint32_t cmdId, CMDtype type)
 
void sendCommandReplyAsync (CommandReply reply, uint32_t cmdId, CMDtype type, CommandInterface *interface=nullptr)
 
virtual uint16_t getCommandHandlerID ()
 
virtual CmdHandlerInfogetCommandHandlerInfo ()
 
virtual bool isValidCommandId (uint32_t cmdid, uint32_t ignoredFlags=0, uint32_t requiredFlag=0)
 
virtual CmdHandlerCommanddefgetCommandFromName (const std::string &cmd, uint32_t ignoredFlags=0)
 
virtual CmdHandlerCommanddefgetCommandFromId (const uint32_t id, uint32_t ignoredFlags=0)
 
template<typename ID>
void registerCommand (const char *cmd, const ID cmdid, const char *help=nullptr, uint32_t flags=0)
 
virtual void postCmdhandlerInit ()
 
template<typename ID>
void overrideCommandFlags (const ID cmdid, uint32_t flagmask=0)
 
- Public Member Functions inherited from cpp_freertos::Thread
 Thread (const std::string Name, uint16_t StackDepth, UBaseType_t Priority)
 
 Thread (const char *Name, uint16_t StackDepth, UBaseType_t Priority)
 
 Thread (uint16_t StackDepth, UBaseType_t Priority)
 
bool Start ()
 
virtual ~Thread ()
 
TaskHandle_t GetHandle ()
 
void Suspend ()
 
void Resume ()
 
void ResumeFromISR ()
 
void Notify ()
 
void NotifyFromISR ()
 
uint32_t WaitForNotification (TickType_t Timeout=portMAX_DELAY)
 
UBaseType_t GetPriority ()
 
UBaseType_t GetPriorityFromISR ()
 
void SetPriority (UBaseType_t NewPriority)
 
std::string GetName ()
 
char * GetName ()
 
- Public Member Functions inherited from UsbHidHandler
 UsbHidHandler ()
 
virtual ~UsbHidHandler ()
 
virtual void hidOut (uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize)
 
virtual uint16_t hidGet (uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen)
 
void registerHidCallback ()
 
void transferComplete (uint8_t itf, uint8_t const *report, uint8_t len)
 

Static Public Member Functions

static bool isCreatable ()
 
- Static Public Member Functions inherited from FFBoardMain
static bool isCreatable ()
 
- Static Public Member Functions inherited from ChoosableClass
static bool isCreatable ()
 
- Static Public Member Functions inherited from CommandHandler
static void logSerial (std::string string)
 Send a log formatted sequence.
 
static void logSerialDebug (std::string string)
 Send a log formatted sequence if debug is on.
 
static bool logsEnabled ()
 
static void setLogsEnabled (bool enabled)
 
static uint32_t getClassIdFromName (const char *name)
 
static const char * getClassNameFromId (const uint32_t id)
 
static CommandHandlergetHandlerFromHandlerId (const uint16_t cmdhandlerID)
 
static CommandHandlergetHandlerFromId (const uint16_t id, const uint8_t instance=0xFF)
 
static CommandHandlergetHandlerFromClassName (const char *name, const uint8_t instance=0xFF)
 
static std::vector< CommandHandler * > getHandlersFromClassName (const char *name)
 
static std::vector< CommandHandler * > getHandlersFromId (const uint16_t id)
 
static bool isInHandlerList (CommandHandler *handler)
 
static std::string getAllHelpstrings ()
 
static std::vector< CommandHandler * > & getCommandHandlers ()
 
template<typename TVal>
static CommandStatus handleGetSet (const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal &value)
 
template<typename TVal, class cls, class cls1>
static CommandStatus handleGetSetFunc (const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal &value, void(cls1::*setfunc)(TVal), cls *obj)
 
template<typename TVal, class cls, class cls1, class cls2>
static CommandStatus handleGetFuncSetFunc (const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal(cls1::*getfunc)(), void(cls2::*setfunc)(TVal), cls *obj)
 
template<typename TVal, class cls, class cls1>
static CommandStatus handleGetFuncSet (const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal &value, TVal(cls1::*getfunc)(), cls *obj)
 
- Static Public Member Functions inherited from cpp_freertos::Thread
static void Yield ()
 
static void StartScheduler ()
 
static void EndScheduler ()
 
- Static Public Member Functions inherited from UsbHidHandler
static void setHidDesc (const uint8_t *desc)
 
static const uint8_t * getHidDesc ()
 

Protected Attributes

std::shared_ptr< EffectsControlItfffb
 
std::shared_ptr< EffectsCalculatoreffects_calc
 
uint8_t axisCount =0
 
- Protected Attributes inherited from FFBoardMain
std::unique_ptr< USBdeviceusbdev
 
- Protected Attributes inherited from ChoosableClass
uint16_t selectionId
 Should only be written by ClassChooser during creation.
 
- Protected Attributes inherited from CommandHandler
bool commandsEnabled = true
 
std::vector< CmdHandlerCommanddefregisteredCommands
 
CmdHandlerInfo cmdHandlerInfo
 

Private Types

enum class  FFBWheel_commands : uint32_t {
  ffbactive , axes , btntypes , lsbtn ,
  addbtn , aintypes , lsain , addain ,
  hidrate , hidsendspd , estop , cfrate
}
 

Private Member Functions

void send_report ()
 
void setReportRate (uint8_t rateidx)
 
std::string usb_report_rates_names ()
 
- Private Member Functions inherited from PersistentStorage
 PersistentStorage ()
 
virtual ~PersistentStorage ()
 
void restoreFlashDelayed ()
 
- Private Member Functions inherited from ExtiHandler
 ExtiHandler ()
 
virtual ~ExtiHandler ()
 
- Private Member Functions inherited from ErrorHandler
 ErrorHandler ()
 
virtual ~ErrorHandler ()
 
- Private Member Functions inherited from SelectableInputs
 SelectableInputs (const ClassChooser< ButtonSource > &btn_chooser, const ClassChooser< AnalogSource > &analog_chooser)
 
virtual ~SelectableInputs ()
 
virtual void setBtnTypes (uint16_t btntypes)
 
virtual void addBtnType (uint16_t id)
 
virtual void clearBtnTypes ()
 
virtual void setAinTypes (uint16_t aintypes)
 
virtual void addAinType (uint16_t id)
 
virtual void clearAinTypes ()
 
virtual uint8_t getButtonValues (uint64_t &values)
 
virtual std::vector< int32_t > * getAnalogValues ()
 
- Private Member Functions inherited from TimerHandler
 TimerHandler ()
 
virtual ~TimerHandler ()
 

Private Attributes

volatile Control_t control
 
const bool allowEstopReset = true
 
const Error estopError = Error(ErrorCode::emergencyStop, ErrorType::critical, "Emergency stop button triggered")
 
uint8_t usb_report_rate = HID_BINTERVAL
 
uint8_t usb_report_rate_idx = ffbrates.defaultmode
 
uint8_t ffb_rate_divider = 1
 
uint8_t ffb_rate_counter = 0
 
const bool hidAxis32b
 
uint8_t report_rate_cnt = 0
 
std::unique_ptr< AxesManageraxes_manager
 
std::vector< std::unique_ptr< ButtonSource > > btns
 
std::vector< std::unique_ptr< AnalogSource > > analog_inputs
 
std::unique_ptr< HID_GamepadReport_basereportHID
 
uint8_t reportSendCounter = 0
 
const uint8_t analogAxisCount = 8
 
std::unique_ptr< HID_CommandInterfacehidCommands = std::make_unique<HID_CommandInterface>()
 
uint32_t lastUsbReportTick = 0
 
volatile uint32_t lastEstop = 0
 
- Private Attributes inherited from PersistentStorage
bool restoreDelayedFlag = false
 
- Private Attributes inherited from SelectableInputs
std::vector< std::unique_ptr< ButtonSource > > btns
 
std::vector< std::unique_ptr< AnalogSource > > analog_inputs
 
cpp_freertos::BinarySemaphore sourcesSem = cpp_freertos::BinarySemaphore(true)
 
uint16_t btnsources = 0
 
uint16_t ainsources = 0
 
std::vector< int32_t > analogsources_buf
 
ClassChooser< ButtonSourcebtn_chooser
 
ClassChooser< AnalogSourceanalog_chooser
 

Static Private Attributes

static const FFB_update_rates ffbrates
 
- Static Private Attributes inherited from PersistentStorage
static bool startupComplete = false
 
- Static Private Attributes inherited from ExtiHandler
static std::vector< ExtiHandler * > extiHandlers
 
- Static Private Attributes inherited from ErrorHandler
static std::vector< ErrorHandler * > errorHandlers
 
static std::array< Error, ERRORHANDLER_MAXERRORS > errors
 
- Static Private Attributes inherited from TimerHandler
static std::vector< TimerHandler * > timerHandlers
 

Additional Inherited Members

- Public Attributes inherited from FFBoardMain
std::unique_ptr< FFBoardMainCommandThreadcommandThread
 
std::unique_ptr< CDC_CommandInterfacecdcCmdInterface = std::make_unique<CDC_CommandInterface>()
 
ErrorPrinter errorPrinter
 
SystemCommands systemCommands
 System command handler.
 
std::unique_ptr< UART_CommandInterfaceuartCmdInterface = std::make_unique<UART_CommandInterface>(115200)
 
- Static Public Attributes inherited from FFBoardMain
static ClassIdentifier info ={.name = "Basic (Failsafe)" ,.id=0}
 
- Static Public Attributes inherited from ChoosableClass
static ClassIdentifier info
 
- Static Public Attributes inherited from CommandHandler
static bool logEnabled = true
 
- Static Public Attributes inherited from UsbHidHandler
static UsbHidHandlerglobalHidHandler = nullptr
 
static uint8_t * hid_desc = nullptr
 
- Protected Member Functions inherited from CommandHandler
void setInstance (uint8_t instance)
 
virtual void addCommandHandler ()
 
virtual void removeCommandHandler ()
 
void registerCommand_INT (const char *cmd, const uint32_t cmdid, const char *help=nullptr, uint32_t flags=0)
 
void overrideCommandFlags_INT (const uint32_t cmdid, uint32_t flagmask=CMDFLAG_GET|CMDFLAG_GETADR)
 
- Protected Member Functions inherited from cpp_freertos::Thread
virtual void Cleanup ()
 
void Delay (const TickType_t Delay)
 
void DelayUntil (const TickType_t Period)
 
void ResetDelayUntil ()
 
bool Wait (ConditionVariable &Cv, Mutex &CvLock, TickType_t Timeout=portMAX_DELAY)
 
- Static Protected Member Functions inherited from CommandHandler
static std::vector< uint16_t > & getCommandHandlerIds ()
 
- Static Protected Attributes inherited from FFBoardMain
static char cdcbuf []
 
- Static Private Member Functions inherited from PersistentStorage
static std::vector< PersistentStorage * > & getFlashHandlers ()
 
static void restoreFlashStartupCb ()
 
- Static Private Member Functions inherited from ErrorHandler
static void addError (const Error &error)
 
static void clearError (const Error &error)
 
static void clearError (ErrorCode errorcode)
 
static void clearTemp ()
 
static void clearAll ()
 
static std::span< ErrorgetErrors ()
 
static void sortErrors ()
 

Detailed Description

Definition at line 36 of file FFBHIDMain.h.

Member Enumeration Documentation

◆ FFBWheel_commands

enum class FFBHIDMain::FFBWheel_commands : uint32_t
strongprivate
Enumerator
ffbactive 
axes 
btntypes 
lsbtn 
addbtn 
aintypes 
lsain 
addain 
hidrate 
hidsendspd 
estop 
cfrate 

Definition at line 41 of file FFBHIDMain.h.

Constructor & Destructor Documentation

◆ FFBHIDMain()

FFBHIDMain::FFBHIDMain ( uint8_t axisCount,
bool hidAxis32b = false )

setFFBEffectsCalc must be called in constructor of derived class to finish the setup

Definition at line 31 of file FFBHIDMain.cpp.

◆ ~FFBHIDMain()

FFBHIDMain::~FFBHIDMain ( )
virtual

Definition at line 62 of file FFBHIDMain.cpp.

Member Function Documentation

◆ command()

CommandStatus FFBHIDMain::command ( const ParsedCommand & cmd,
std::vector< CommandReply > & replies )
virtual
Parameters
[in]cmdThe parsed command to be executed.
[out]repliesA vector to return one or multiple reply objects into. Replies to the interface will be generated based on the reply objects. A string reply may not contain start, end and separation markers: [,],| Other characters are allowed.

Reimplemented from FFBoardMain.

Definition at line 32 of file FFBHIDMain_commmands.cpp.

◆ emergencyStop()

void FFBHIDMain::emergencyStop ( bool reset)

Definition at line 297 of file FFBHIDMain.cpp.

◆ errorCallback()

void FFBHIDMain::errorCallback ( const Error & error,
bool cleared )
virtual

Reimplemented from ErrorHandler.

Definition at line 360 of file FFBHIDMain.cpp.

◆ exti()

void FFBHIDMain::exti ( uint16_t GPIO_Pin)
virtual

Reimplemented from ExtiHandler.

Definition at line 332 of file FFBHIDMain.cpp.

◆ getCurFFBFreq()

float FFBHIDMain::getCurFFBFreq ( )

Returns current FFB update loop frequency in Hz

Definition at line 237 of file FFBHIDMain.cpp.

◆ getFfbActive()

bool FFBHIDMain::getFfbActive ( )

Definition at line 167 of file FFBHIDMain.cpp.

◆ getHelpstring()

virtual std::string FFBHIDMain::getHelpstring ( )
inlinevirtual

Returns a description of this class

Reimplemented from FFBoardMain.

Definition at line 56 of file FFBHIDMain.h.

◆ getInfo()

const ClassIdentifier FFBHIDMain::getInfo ( )
pure virtual

Reimplemented from FFBoardMain.

Implemented in FFBHIDExt, FFBJoystick, and FFBWheel.

◆ getRate()

uint32_t FFBHIDMain::getRate ( )

Definition at line 163 of file FFBHIDMain.cpp.

◆ isCreatable()

static bool FFBHIDMain::isCreatable ( )
inlinestatic

Definition at line 52 of file FFBHIDMain.h.

◆ registerCommands()

void FFBHIDMain::registerCommands ( )

Definition at line 11 of file FFBHIDMain_commmands.cpp.

◆ restoreFlash()

void FFBHIDMain::restoreFlash ( )
virtual

Read parameters from flash and restore settings

Reimplemented from PersistentStorage.

Definition at line 69 of file FFBHIDMain.cpp.

◆ Run()

void FFBHIDMain::Run ( )
virtual

Implementation of your actual thread code. You must override this function.

Note
If INCLUDE_vTaskDelete is defined, then you may return from your Run method. This will cause the task to be deleted from FreeRTOS, however you are still responsible to delete the task object. If this is not defined, then retuning from your Run() method will result in an assert.

Implements cpp_freertos::Thread.

Definition at line 101 of file FFBHIDMain.cpp.

◆ saveFlash()

void FFBHIDMain::saveFlash ( )
virtual

Save parameters to flash

Reimplemented from PersistentStorage.

Definition at line 89 of file FFBHIDMain.cpp.

◆ send_report()

void FFBHIDMain::send_report ( )
private

Sends periodic gamepad reports of buttons and analog axes

Definition at line 174 of file FFBHIDMain.cpp.

◆ setFFBEffectsCalc()

void FFBHIDMain::setFFBEffectsCalc ( std::shared_ptr< EffectsControlItf > ffb,
std::shared_ptr< EffectsCalculator > effects_calc )

MUST be called in the constructor of the derived class. This finishes the construction because the constructor of this class will be called before the ffb and effects calc objects are created in the derived class.

Definition at line 53 of file FFBHIDMain.cpp.

◆ setReportRate()

void FFBHIDMain::setReportRate ( uint8_t rateidx)
private

Changes the hid report rate based on the index for usb_report_rates

Definition at line 244 of file FFBHIDMain.cpp.

◆ systick()

void FFBHIDMain::systick ( )

◆ timerElapsed()

void FFBHIDMain::timerElapsed ( TIM_HandleTypeDef * htim)
virtual

Reimplemented from TimerHandler.

Definition at line 375 of file FFBHIDMain.cpp.

◆ updateControl()

void FFBHIDMain::updateControl ( )

Main update loop

Definition at line 129 of file FFBHIDMain.cpp.

◆ usb_report_rates_names()

std::string FFBHIDMain::usb_report_rates_names ( )
private

Generates the speed strings to display to the user

Definition at line 277 of file FFBHIDMain.cpp.

◆ usbInit()

virtual void FFBHIDMain::usbInit ( )
pure virtual

Called during the startup Should initialize a USBdevice and call registerUsb()

Reimplemented from FFBoardMain.

Implemented in FFBHIDExt, FFBJoystick, and FFBWheel.

◆ usbResume()

void FFBHIDMain::usbResume ( )
virtual

USB plugged in

Reimplemented from FFBoardMain.

Definition at line 319 of file FFBHIDMain.cpp.

◆ usbSuspend()

void FFBHIDMain::usbSuspend ( )
virtual

USB unplugged Deactivates FFB

Reimplemented from FFBoardMain.

Definition at line 307 of file FFBHIDMain.cpp.

Member Data Documentation

◆ allowEstopReset

const bool FFBHIDMain::allowEstopReset = true
private

Definition at line 95 of file FFBHIDMain.h.

◆ analog_inputs

std::vector<std::unique_ptr<AnalogSource> > FFBHIDMain::analog_inputs
private

Definition at line 139 of file FFBHIDMain.h.

◆ analogAxisCount

const uint8_t FFBHIDMain::analogAxisCount = 8
private

Definition at line 145 of file FFBHIDMain.h.

◆ axes_manager

std::unique_ptr<AxesManager> FFBHIDMain::axes_manager
private

Definition at line 135 of file FFBHIDMain.h.

◆ axisCount

uint8_t FFBHIDMain::axisCount =0
protected

Definition at line 90 of file FFBHIDMain.h.

◆ btns

std::vector<std::unique_ptr<ButtonSource> > FFBHIDMain::btns
private

Definition at line 138 of file FFBHIDMain.h.

◆ control

volatile Control_t FFBHIDMain::control
private

Definition at line 93 of file FFBHIDMain.h.

◆ effects_calc

std::shared_ptr<EffectsCalculator> FFBHIDMain::effects_calc
protected

Definition at line 89 of file FFBHIDMain.h.

◆ estopError

const Error FFBHIDMain::estopError = Error(ErrorCode::emergencyStop, ErrorType::critical, "Emergency stop button triggered")
private

Definition at line 97 of file FFBHIDMain.h.

◆ ffb

std::shared_ptr<EffectsControlItf> FFBHIDMain::ffb
protected

Definition at line 88 of file FFBHIDMain.h.

◆ ffb_rate_counter

uint8_t FFBHIDMain::ffb_rate_counter = 0
private

Definition at line 107 of file FFBHIDMain.h.

◆ ffb_rate_divider

uint8_t FFBHIDMain::ffb_rate_divider = 1
private

Definition at line 106 of file FFBHIDMain.h.

◆ ffbrates

const FFBHIDMain::FFB_update_rates FFBHIDMain::ffbrates
staticprivate

Definition at line 127 of file FFBHIDMain.h.

◆ hidAxis32b

const bool FFBHIDMain::hidAxis32b
private

Definition at line 129 of file FFBHIDMain.h.

◆ hidCommands

std::unique_ptr<HID_CommandInterface> FFBHIDMain::hidCommands = std::make_unique<HID_CommandInterface>()
private

Definition at line 147 of file FFBHIDMain.h.

◆ lastEstop

volatile uint32_t FFBHIDMain::lastEstop = 0
private

Definition at line 151 of file FFBHIDMain.h.

◆ lastUsbReportTick

uint32_t FFBHIDMain::lastUsbReportTick = 0
private

Definition at line 149 of file FFBHIDMain.h.

◆ report_rate_cnt

uint8_t FFBHIDMain::report_rate_cnt = 0
private

Definition at line 133 of file FFBHIDMain.h.

◆ reportHID

std::unique_ptr<HID_GamepadReport_base> FFBHIDMain::reportHID
private

Definition at line 141 of file FFBHIDMain.h.

◆ reportSendCounter

uint8_t FFBHIDMain::reportSendCounter = 0
private

Definition at line 143 of file FFBHIDMain.h.

◆ usb_report_rate

uint8_t FFBHIDMain::usb_report_rate = HID_BINTERVAL
private

Definition at line 103 of file FFBHIDMain.h.

◆ usb_report_rate_idx

uint8_t FFBHIDMain::usb_report_rate_idx = ffbrates.defaultmode
private

Definition at line 104 of file FFBHIDMain.h.


The documentation for this class was generated from the following files: