Open FFBoard
Open source force feedback firmware
ShifterAnalog Class Reference

#include <ShifterAnalog.h>

Inheritance diagram for ShifterAnalog:
ButtonSource CommandHandler ChoosableClass PersistentStorage

Classes

class  G27ShifterButtonClient
 

Public Member Functions

 ShifterAnalog ()
 
virtual ~ShifterAnalog ()
 
const ClassIdentifier getInfo ()
 
uint8_t readButtons (uint64_t *buf) override
 
uint16_t getBtnNum ()
 
void saveFlash () override
 
void restoreFlash () override
 
std::string printModes ()
 
CommandStatus command (const ParsedCommand &cmd, std::vector< CommandReply > &replies) override
 
void registerCommands ()
 
virtual std::string getHelpstring ()
 
const ClassType getClassType () override
 returns the used classchooser selection id of this instance More...
 
- Public Member Functions inherited from ButtonSource
 ButtonSource ()
 
virtual ~ButtonSource ()
 
- Public Member Functions inherited from ChoosableClass
virtual ~ChoosableClass ()
 
uint16_t getSelectionID ()
 
- Public Member Functions inherited from PersistentStorage
 PersistentStorage ()
 
virtual ~PersistentStorage ()
 
void restoreFlashDelayed ()
 

Static Public Member Functions

static bool isCreatable ()
 
- Static Public Member Functions inherited from ButtonSource
static bool isCreatable ()
 
- Static Public Member Functions inherited from ChoosableClass
static bool isCreatable ()
 
- Static Public Member Functions inherited from PersistentStorage
static std::vector< PersistentStorage * > & getFlashHandlers ()
 
static void restoreFlashStartupCb ()
 

Public Attributes

const std::array< std::string, number_of_modesmode_names {"G29-H","G29 Sequential","G27-H","G27 Sequential"}
 

Static Public Attributes

static constexpr int number_of_modes {4}
 
static constexpr std::array< bool, number_of_modesmode_uses_spi {false, false, true, true}
 
static constexpr std::array< bool, number_of_modesmode_uses_local_reverse {true, true, false, false}
 
static ClassIdentifier info
 
- Static Public Attributes inherited from ButtonSource
static ClassIdentifier info
 
static const std::vector< class_entry< ButtonSource > > all_buttonsources
 
- Static Public Attributes inherited from ChoosableClass
static ClassIdentifier info
 

Private Types

enum class  ShifterMode : uint8_t { G29_H =0 , G29_seq =1 , G27_H =2 , G27_seq =3 }
 
enum class  ShifterAnalog_commands : uint32_t {
  mode , x12 , x56 , y135 ,
  y246 , revbtn , cspin , xchan ,
  ychan , vals , gear
}
 

Private Member Functions

void updateAdc ()
 
void setMode (ShifterMode newMode)
 
void setCSPin (uint8_t new_cs_pin_num)
 
void calculateGear ()
 
void updateReverseState ()
 
int getUserButtons (uint64_t *buf)
 
- Private 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)
 
void setInstance (uint8_t instance)
 
virtual void addCommandHandler ()
 
virtual void removeCommandHandler ()
 

Static Private Member Functions

static bool isG27Mode (ShifterMode m)
 
- Static Private 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 std::vector< uint16_t > & getCommandHandlerIds ()
 

Private Attributes

ShifterMode mode
 
uint8_t x_chan {6}
 
uint8_t y_chan {5}
 
uint8_t reverseButtonNum {1}
 
uint8_t cs_pin_num {1}
 
uint16_t X_12 {25600}
 
uint16_t X_56 {40000}
 
uint16_t Y_135 {51200}
 
uint16_t Y_246 {13600}
 
uint16_t x_val {0}
 
uint16_t y_val {0}
 
bool reverseButtonState {false}
 
uint8_t gear {0}
 
uint8_t bitshift = 0
 
std::unique_ptr< G27ShifterButtonClientg27ShifterButtonClient
 
- Private Attributes inherited from CommandHandler
bool commandsEnabled = true
 
std::vector< CmdHandlerCommanddefregisteredCommands
 
CmdHandlerInfo cmdHandlerInfo
 

Additional Inherited Members

- Protected Attributes inherited from ButtonSource
uint16_t btnnum = 0
 
- Protected Attributes inherited from ChoosableClass
uint16_t selectionId
 Should only be written by ClassChooser during creation. More...
 
- Protected Attributes inherited from PersistentStorage
bool restoreDelayedFlag = false
 
- Static Protected Attributes inherited from PersistentStorage
static bool startupComplete = false
 
- Static Private Attributes inherited from CommandHandler
static bool logEnabled = true
 

Detailed Description

Button mapper for analog (Logitech G2x) shifters (6 gears + reverse) optionally SPI buttons on G27.

Connection: X-Axis: mappable analog Y-Axis: mappable analog Reverse Button: mappable digital for G29, SPI button for G27.

Definition at line 27 of file ShifterAnalog.h.

Member Enumeration Documentation

◆ ShifterAnalog_commands

enum class ShifterAnalog::ShifterAnalog_commands : uint32_t
strongprivate
Enumerator
mode 
x12 
x56 
y135 
y246 
revbtn 
cspin 
xchan 
ychan 
vals 
gear 

Definition at line 31 of file ShifterAnalog.h.

◆ ShifterMode

enum class ShifterAnalog::ShifterMode : uint8_t
strongprivate
Enumerator
G29_H 
G29_seq 
G27_H 
G27_seq 

Definition at line 29 of file ShifterAnalog.h.

Constructor & Destructor Documentation

◆ ShifterAnalog()

ShifterAnalog::ShifterAnalog ( )

Definition at line 24 of file ShifterAnalog.cpp.

◆ ~ShifterAnalog()

ShifterAnalog::~ShifterAnalog ( )
virtual

Definition at line 32 of file ShifterAnalog.cpp.

Member Function Documentation

◆ calculateGear()

void ShifterAnalog::calculateGear ( )
private

Definition at line 59 of file ShifterAnalog.cpp.

◆ command()

CommandStatus ShifterAnalog::command ( const ParsedCommand cmd,
std::vector< CommandReply > &  replies 
)
overridevirtual
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 218 of file ShifterAnalog.cpp.

◆ getBtnNum()

uint16_t ShifterAnalog::getBtnNum ( )
virtual

Reimplemented from ButtonSource.

Definition at line 139 of file ShifterAnalog.cpp.

◆ getClassType()

const ClassType ShifterAnalog::getClassType ( )
inlineoverridevirtual

returns the used classchooser selection id of this instance

Type of this class. Mainclass, motordriver... Should be implemented by the parent class so it is not in the info struct

Reimplemented from ButtonSource.

Definition at line 59 of file ShifterAnalog.h.

◆ getHelpstring()

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

Returns a description of this class

Reimplemented from CommandHandler.

Definition at line 58 of file ShifterAnalog.h.

◆ getInfo()

const ClassIdentifier ShifterAnalog::getInfo ( )
virtual

Implements ButtonSource.

Definition at line 20 of file ShifterAnalog.cpp.

◆ getUserButtons()

int ShifterAnalog::getUserButtons ( uint64_t *  buf)
private

Definition at line 112 of file ShifterAnalog.cpp.

◆ isCreatable()

static bool ShifterAnalog::isCreatable ( )
inlinestatic

Definition at line 46 of file ShifterAnalog.h.

◆ isG27Mode()

bool ShifterAnalog::isG27Mode ( ShifterMode  m)
staticprivate

Definition at line 188 of file ShifterAnalog.cpp.

◆ printModes()

std::string ShifterAnalog::printModes ( )

Definition at line 180 of file ShifterAnalog.cpp.

◆ readButtons()

uint8_t ShifterAnalog::readButtons ( uint64_t *  buf)
overridevirtual

Return a bit field without offset of pressed buttons in the supplied buffer. Returns amount of button read.

Implements ButtonSource.

Definition at line 121 of file ShifterAnalog.cpp.

◆ registerCommands()

void ShifterAnalog::registerCommands ( )

Definition at line 36 of file ShifterAnalog.cpp.

◆ restoreFlash()

void ShifterAnalog::restoreFlash ( )
overridevirtual

Should be implemented to restore settings. This is not automatically called and should be called when appropriate.

Reimplemented from PersistentStorage.

Definition at line 168 of file ShifterAnalog.cpp.

◆ saveFlash()

void ShifterAnalog::saveFlash ( )
overridevirtual

Called when the user uses the "save" command and presses the save button in the configurator Automatically called by the command parser thread for every class that inherits from PersistentStorage

Reimplemented from PersistentStorage.

Definition at line 157 of file ShifterAnalog.cpp.

◆ setCSPin()

void ShifterAnalog::setCSPin ( uint8_t  new_cs_pin_num)
private

Definition at line 204 of file ShifterAnalog.cpp.

◆ setMode()

void ShifterAnalog::setMode ( ShifterMode  newMode)
private

Definition at line 192 of file ShifterAnalog.cpp.

◆ updateAdc()

void ShifterAnalog::updateAdc ( )
private

Definition at line 52 of file ShifterAnalog.cpp.

◆ updateReverseState()

void ShifterAnalog::updateReverseState ( )
private

Definition at line 104 of file ShifterAnalog.cpp.

Member Data Documentation

◆ bitshift

uint8_t ShifterAnalog::bitshift = 0
private

Definition at line 92 of file ShifterAnalog.h.

◆ cs_pin_num

uint8_t ShifterAnalog::cs_pin_num {1}
private

Definition at line 79 of file ShifterAnalog.h.

◆ g27ShifterButtonClient

std::unique_ptr<G27ShifterButtonClient> ShifterAnalog::g27ShifterButtonClient
private

Definition at line 94 of file ShifterAnalog.h.

◆ gear

uint8_t ShifterAnalog::gear {0}
private

Definition at line 90 of file ShifterAnalog.h.

◆ info

ClassIdentifier ShifterAnalog::info
static
Initial value:
= {
.name = "Shifter Analog" ,
.id=CLSID_BTN_SHIFTER,
}

Definition at line 45 of file ShifterAnalog.h.

◆ mode

ShifterMode ShifterAnalog::mode
private

Definition at line 74 of file ShifterAnalog.h.

◆ mode_names

const std::array<std::string, number_of_modes> ShifterAnalog::mode_names {"G29-H","G29 Sequential","G27-H","G27 Sequential"}

Definition at line 37 of file ShifterAnalog.h.

◆ mode_uses_local_reverse

constexpr std::array<bool, number_of_modes> ShifterAnalog::mode_uses_local_reverse {true, true, false, false}
staticconstexpr

Definition at line 39 of file ShifterAnalog.h.

◆ mode_uses_spi

constexpr std::array<bool, number_of_modes> ShifterAnalog::mode_uses_spi {false, false, true, true}
staticconstexpr

Definition at line 38 of file ShifterAnalog.h.

◆ number_of_modes

constexpr int ShifterAnalog::number_of_modes {4}
staticconstexpr

Definition at line 36 of file ShifterAnalog.h.

◆ reverseButtonNum

uint8_t ShifterAnalog::reverseButtonNum {1}
private

Definition at line 78 of file ShifterAnalog.h.

◆ reverseButtonState

bool ShifterAnalog::reverseButtonState {false}
private

Definition at line 89 of file ShifterAnalog.h.

◆ X_12

uint16_t ShifterAnalog::X_12 {25600}
private

Definition at line 82 of file ShifterAnalog.h.

◆ X_56

uint16_t ShifterAnalog::X_56 {40000}
private

Definition at line 83 of file ShifterAnalog.h.

◆ x_chan

uint8_t ShifterAnalog::x_chan {6}
private

Definition at line 76 of file ShifterAnalog.h.

◆ x_val

uint16_t ShifterAnalog::x_val {0}
private

Definition at line 87 of file ShifterAnalog.h.

◆ Y_135

uint16_t ShifterAnalog::Y_135 {51200}
private

Definition at line 84 of file ShifterAnalog.h.

◆ Y_246

uint16_t ShifterAnalog::Y_246 {13600}
private

Definition at line 85 of file ShifterAnalog.h.

◆ y_chan

uint8_t ShifterAnalog::y_chan {5}
private

Definition at line 77 of file ShifterAnalog.h.

◆ y_val

uint16_t ShifterAnalog::y_val {0}
private

Definition at line 88 of file ShifterAnalog.h.


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