Open FFBoard
Open source force feedback firmware
CANInputMain Class Reference

#include <CanInputMain.h>

Inheritance diagram for CANInputMain:
FFBoardMain PersistentStorage SelectableInputs cpp_freertos::Thread ChoosableClass CommandHandler

Public Member Functions

 CANInputMain ()
 
 CANInputMain (CANPort &canport)
 
virtual ~CANInputMain ()
 
const ClassIdentifier getInfo ()
 
CommandStatus command (const ParsedCommand &cmd, std::vector< CommandReply > &replies)
 
void registerCommands ()
 
virtual std::string getHelpstring ()
 
void usbInit () override
 
void saveFlash ()
 
void restoreFlash ()
 
void Run ()
 
void updateControl ()
 
void sendReport ()
 
void setReportRate (uint8_t rateidx)
 
std::string report_rates_names ()
 
- Public Member Functions inherited from FFBoardMain
const ClassType getClassType () override
 returns the used classchooser selection id of this instance More...
 
 FFBoardMain ()
 
virtual ~FFBoardMain ()
 
virtual void update ()
 
virtual void cdcRcv (char *Buf, uint32_t *Len)
 
virtual void cdcRcvReady (uint8_t itf)
 
virtual void usbSuspend ()
 
virtual void usbResume ()
 
- 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)
 
- Public Member Functions inherited from PersistentStorage
 PersistentStorage ()
 
virtual ~PersistentStorage ()
 
void restoreFlashDelayed ()
 
- Public 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 ()
 
- 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 ()
 

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. 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 Member Functions inherited from PersistentStorage
static std::vector< PersistentStorage * > & getFlashHandlers ()
 
static void restoreFlashStartupCb ()
 
- Static Public Member Functions inherited from cpp_freertos::Thread
static void Yield ()
 
static void StartScheduler ()
 
static void EndScheduler ()
 

Static Public Attributes

static ClassIdentifier info
 
- 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
 

Protected Attributes

uint32_t report_rate_cnt = 0
 
uint32_t report_rate = 1
 
std::vector< int32_t > analogBuffer
 
uint64_t digitalBuffer
 
CANPortcan
 
uint32_t buttons_id = 100
 
uint32_t analog_id = 110
 
uint8_t rate_idx = 0
 
const std::array< uint8_t, 7 > report_rates = {1,2,4,8,10,16,32}
 
- 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. More...
 
- Protected Attributes inherited from CommandHandler
bool commandsEnabled = true
 
std::vector< CmdHandlerCommanddefregisteredCommands
 
CmdHandlerInfo cmdHandlerInfo
 
- Protected Attributes inherited from PersistentStorage
bool restoreDelayedFlag = false
 
- Protected 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
 

Private Types

enum class  CANInput_commands : uint32_t {
  caniddigital , canidanalog , btntypes , lsbtn ,
  addbtn , aintypes , lsain , addain ,
  rate , dvals , avals
}
 

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. More...
 
std::unique_ptr< UART_CommandInterfaceuartCmdInterface = std::make_unique<UART_CommandInterface>(115200)
 
- Protected Member Functions inherited from CommandHandler
void setInstance (uint8_t instance)
 
virtual void addCommandHandler ()
 
virtual void removeCommandHandler ()
 
- 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 Protected Attributes inherited from PersistentStorage
static bool startupComplete = false
 

Detailed Description

Definition at line 21 of file CanInputMain.h.

Member Enumeration Documentation

◆ CANInput_commands

enum class CANInputMain::CANInput_commands : uint32_t
strongprivate
Enumerator
caniddigital 
canidanalog 
btntypes 
lsbtn 
addbtn 
aintypes 
lsain 
addain 
rate 
dvals 
avals 

Definition at line 22 of file CanInputMain.h.

Constructor & Destructor Documentation

◆ CANInputMain() [1/2]

CANInputMain::CANInputMain ( )

Definition at line 23 of file CanInputMain.cpp.

◆ CANInputMain() [2/2]

CANInputMain::CANInputMain ( CANPort canport)

Definition at line 27 of file CanInputMain.cpp.

◆ ~CANInputMain()

CANInputMain::~CANInputMain ( )
virtual

Definition at line 38 of file CanInputMain.cpp.

Member Function Documentation

◆ command()

CommandStatus CANInputMain::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 198 of file CanInputMain.cpp.

◆ getHelpstring()

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

Returns a description of this class

Reimplemented from FFBoardMain.

Definition at line 36 of file CanInputMain.h.

◆ getInfo()

const ClassIdentifier CANInputMain::getInfo ( )
virtual

Reimplemented from FFBoardMain.

Definition at line 18 of file CanInputMain.cpp.

◆ isCreatable()

static bool CANInputMain::isCreatable ( )
inlinestatic

Definition at line 32 of file CanInputMain.h.

◆ registerCommands()

void CANInputMain::registerCommands ( )

Definition at line 179 of file CanInputMain.cpp.

◆ report_rates_names()

std::string CANInputMain::report_rates_names ( )

Generates the speed strings to display to the user

Definition at line 168 of file CanInputMain.cpp.

◆ restoreFlash()

void CANInputMain::restoreFlash ( )
virtual

Read parameters from flash and restore settings

Reimplemented from PersistentStorage.

Definition at line 54 of file CanInputMain.cpp.

◆ Run()

void CANInputMain::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 91 of file CanInputMain.cpp.

◆ saveFlash()

void CANInputMain::saveFlash ( )
virtual

Save parameters to flash

Reimplemented from PersistentStorage.

Definition at line 76 of file CanInputMain.cpp.

◆ sendReport()

void CANInputMain::sendReport ( )

Definition at line 111 of file CanInputMain.cpp.

◆ setReportRate()

void CANInputMain::setReportRate ( uint8_t  rateidx)

Changes the report rate based on the index for report_rates

Definition at line 159 of file CanInputMain.cpp.

◆ updateControl()

void CANInputMain::updateControl ( )

Main update loop

Definition at line 103 of file CanInputMain.cpp.

◆ usbInit()

void CANInputMain::usbInit ( )
overridevirtual

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

Reimplemented from FFBoardMain.

Definition at line 44 of file CanInputMain.cpp.

Member Data Documentation

◆ analog_id

uint32_t CANInputMain::analog_id = 110
protected

Definition at line 64 of file CanInputMain.h.

◆ analogBuffer

std::vector<int32_t> CANInputMain::analogBuffer
protected

Definition at line 58 of file CanInputMain.h.

◆ buttons_id

uint32_t CANInputMain::buttons_id = 100
protected

Definition at line 63 of file CanInputMain.h.

◆ can

CANPort& CANInputMain::can
protected

Definition at line 61 of file CanInputMain.h.

◆ digitalBuffer

uint64_t CANInputMain::digitalBuffer
protected

Definition at line 59 of file CanInputMain.h.

◆ info

ClassIdentifier CANInputMain::info
static
Initial value:
= {
.name = "CAN remote Digital/Analog" ,
.id=CLSID_MAIN_CANINPUT,
}

Definition at line 30 of file CanInputMain.h.

◆ rate_idx

uint8_t CANInputMain::rate_idx = 0
protected

Definition at line 66 of file CanInputMain.h.

◆ report_rate

uint32_t CANInputMain::report_rate = 1
protected

Definition at line 56 of file CanInputMain.h.

◆ report_rate_cnt

uint32_t CANInputMain::report_rate_cnt = 0
protected

Definition at line 55 of file CanInputMain.h.

◆ report_rates

const std::array<uint8_t,7> CANInputMain::report_rates = {1,2,4,8,10,16,32}
protected

Definition at line 67 of file CanInputMain.h.


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