Open FFBoard
Open source force feedback firmware
SerialFFB Class Reference

#include <SerialFFB.h>

Inheritance diagram for SerialFFB:
CommandHandler EffectsControlItf

Public Member Functions

 SerialFFB (std::shared_ptr< EffectsCalculator > ec, uint8_t instance=0)
 
virtual ~SerialFFB ()
 
CommandStatus command (const ParsedCommand &cmd, std::vector< CommandReply > &replies)
 
const ClassIdentifier getInfo ()
 Command handlers always have class infos. Works well with ChoosableClass. More...
 
bool getFfbActive ()
 
void reset_ffb ()
 
void set_FFB (bool state)
 
void set_gain (uint8_t gain)
 
int32_t newEffect (uint8_t effectType)
 
void setMagnitude (uint8_t idx, int16_t magnitude)
 
void setEffectState (uint8_t id, bool state)
 
- Public Member Functions inherited from CommandHandler
virtual const ClassType getClassType ()
 
 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 getHelpstring ()
 
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)
 
- Public Member Functions inherited from EffectsControlItf
virtual void stop_FFB ()
 
virtual void start_FFB ()
 
virtual uint32_t getConstantForceRate ()
 
virtual uint32_t getRate ()
 
virtual void cfUpdateEvent ()
 
virtual void fxUpdateEvent ()
 

Private Types

enum class  SerialEffects_commands : uint32_t {
  ffbstate , ffbreset , newEffect , fxtype ,
  fxmagnitude , fxstate , fxperiod , fxduration ,
  fxoffset , fxdeadzone , fxsat , fxcoeff ,
  fxaxisgain
}
 

Private Attributes

std::shared_ptr< EffectsCalculatoreffects_calc
 
std::array< FFB_Effect, EffectsCalculator::max_effects > & effects
 

Static Private Attributes

static ClassIdentifier info
 
static constexpr FFB_Effect_Condition defaultCond
 

Additional Inherited Members

- Static Public Member Functions inherited from CommandHandler
static void logSerial (std::string string)
 Send a log formatted sequence. More...
 
static void logSerialDebug (std::string string)
 Send a log formatted sequence if debug is on. More...
 
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 Attributes inherited from CommandHandler
static bool logEnabled = true
 
- Protected Member Functions inherited from CommandHandler
void setInstance (uint8_t instance)
 
virtual void addCommandHandler ()
 
virtual void removeCommandHandler ()
 
- Static Protected Member Functions inherited from CommandHandler
static std::vector< uint16_t > & getCommandHandlerIds ()
 
- Protected Attributes inherited from CommandHandler
bool commandsEnabled = true
 
std::vector< CmdHandlerCommanddefregisteredCommands
 
CmdHandlerInfo cmdHandlerInfo
 

Detailed Description

Helper class to manage the effectscalculator effects via commands directly

Definition at line 17 of file SerialFFB.h.

Member Enumeration Documentation

◆ SerialEffects_commands

enum class SerialFFB::SerialEffects_commands : uint32_t
strongprivate
Enumerator
ffbstate 
ffbreset 
newEffect 
fxtype 
fxmagnitude 
fxstate 
fxperiod 
fxduration 
fxoffset 
fxdeadzone 
fxsat 
fxcoeff 
fxaxisgain 

Definition at line 19 of file SerialFFB.h.

Constructor & Destructor Documentation

◆ SerialFFB()

SerialFFB::SerialFFB ( std::shared_ptr< EffectsCalculator ec,
uint8_t  instance = 0 
)

Creates an interface to control standard PID effects via commands

Definition at line 22 of file SerialFFB.cpp.

◆ ~SerialFFB()

SerialFFB::~SerialFFB ( )
virtual

Definition at line 40 of file SerialFFB.cpp.

Member Function Documentation

◆ command()

CommandStatus SerialFFB::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 CommandHandler.

Definition at line 124 of file SerialFFB.cpp.

◆ getFfbActive()

bool SerialFFB::getFfbActive ( )
virtual

Implements EffectsControlItf.

Definition at line 45 of file SerialFFB.cpp.

◆ getInfo()

const ClassIdentifier SerialFFB::getInfo ( )
virtual

Command handlers always have class infos. Works well with ChoosableClass.

Implements CommandHandler.

Definition at line 15 of file SerialFFB.cpp.

◆ newEffect()

int32_t SerialFFB::newEffect ( uint8_t  effectType)

Takes an effect type and allocates it in the effects array Returns the index where the effect was created or -1 if it can not be created

Definition at line 76 of file SerialFFB.cpp.

◆ reset_ffb()

void SerialFFB::reset_ffb ( )
virtual

Resets all effects and disables ffb

Implements EffectsControlItf.

Definition at line 52 of file SerialFFB.cpp.

◆ set_FFB()

void SerialFFB::set_FFB ( bool  state)
virtual

Enables or disables FFB actuator

Implements EffectsControlItf.

Definition at line 62 of file SerialFFB.cpp.

◆ set_gain()

void SerialFFB::set_gain ( uint8_t  gain)
virtual

Changes the global gain scaler

Implements EffectsControlItf.

Definition at line 68 of file SerialFFB.cpp.

◆ setEffectState()

void SerialFFB::setEffectState ( uint8_t  id,
bool  state 
)

Enables or disables an effect

Definition at line 114 of file SerialFFB.cpp.

◆ setMagnitude()

void SerialFFB::setMagnitude ( uint8_t  idx,
int16_t  magnitude 
)

Changes magnitude of non conditional effects (Constant, ramp, square, triangle, sawtooth)

Definition at line 95 of file SerialFFB.cpp.

Member Data Documentation

◆ defaultCond

constexpr FFB_Effect_Condition SerialFFB::defaultCond
staticconstexprprivate
Initial value:
= {
.cpOffset = 0,
.positiveCoefficient = 0x7fff,
.negativeCoefficient = 0x7fff,
.positiveSaturation = 0x7fff,
.negativeSaturation = 0x7fff,
.deadBand = 0
}

Definition at line 46 of file SerialFFB.h.

◆ effects

std::array<FFB_Effect,EffectsCalculator::max_effects>& SerialFFB::effects
private

Definition at line 44 of file SerialFFB.h.

◆ effects_calc

std::shared_ptr<EffectsCalculator> SerialFFB::effects_calc
private

Definition at line 43 of file SerialFFB.h.

◆ info

ClassIdentifier SerialFFB::info
staticprivate
Initial value:
= {
.name = "Effects manager" ,
.id = CLSID_EFFECTSMGR,
}

Definition at line 42 of file SerialFFB.h.


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