Open FFBoard
Open source force feedback firmware
EncoderBissC Class Reference

#include <EncoderBissC.h>

Inheritance diagram for EncoderBissC:
Encoder SPIDevice CommandHandler cpp_freertos::Thread PersistentStorage ChoosableClass

Public Types

enum class  EncoderBissC_commands {
  bits , cs , speed , errors ,
  direction
}
 

Public Member Functions

const ClassIdentifier getInfo ()
 Command handlers always have class infos. Works well with ChoosableClass. More...
 
 EncoderBissC ()
 
virtual ~EncoderBissC ()
 
EncoderType getEncoderType ()
 
bool updateFrame ()
 
int32_t getPos ()
 
int32_t getPosAbs ()
 
void setPos (int32_t pos)
 
uint32_t getCpr ()
 
void saveFlash ()
 
void restoreFlash ()
 
void Run ()
 
CommandStatus command (const ParsedCommand &cmd, std::vector< CommandReply > &replies)
 
void registerCommands ()
 
void configSPI ()
 
void acquirePosition ()
 
void spiRxCompleted (SPIPort *port) override
 
void beginSpiTransfer (SPIPort *port)
 
void endSpiTransfer (SPIPort *port)
 
- Public Member Functions inherited from Encoder
 Encoder ()
 
virtual ~Encoder ()
 
virtual float getPos_f ()
 
virtual float getPosAbs_f ()
 
virtual const ClassType getClassType () override
 returns the used classchooser selection id of this instance More...
 
- Public Member Functions inherited from ChoosableClass
virtual ~ChoosableClass ()
 
uint16_t getSelectionID ()
 
- Public Member Functions inherited from SPIDevice
 SPIDevice (SPIPort &port, OutputPin csPin)
 
 SPIDevice (SPIPort &port, SPIConfig &spiConfig)
 
virtual ~SPIDevice ()
 
void assertChipSelect ()
 
void clearChipSelect ()
 
virtual bool updateCSPin (OutputPin &csPin)
 
virtual void spiTxCompleted (SPIPort *port)
 
virtual void spiTxRxCompleted (SPIPort *port)
 
virtual void spiRequestError (SPIPort *port)
 
virtual SPIConfiggetSpiConfig ()
 
- 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 PersistentStorage
 PersistentStorage ()
 
virtual ~PersistentStorage ()
 
void restoreFlashDelayed ()
 

Static Public Member Functions

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 Attributes

static ClassIdentifier info
 
- Static Public Attributes inherited from Encoder
static ClassIdentifier info ={.name = "None" , .id=CLSID_ENCODER_NONE, .visibility = ClassVisibility::visible}
 
static const std::vector< class_entry< Encoder > > all_encoders
 
- Static Public Attributes inherited from ChoosableClass
static ClassIdentifier info
 
- Static Public Attributes inherited from CommandHandler
static bool logEnabled = true
 

Private Attributes

int lenghtDataBit = 22
 
int spiSpeed = 3
 
bool waitData = false
 
bool invertDirection = true
 
uint32_t lastUpdateTick = 0
 
int32_t pos = 0
 
int32_t posOffset = 0
 
int32_t lastPos = 0
 
int32_t newPos = 0
 
int32_t mtpos = 0
 
uint8_t spi_buf [bytes] = {0}
 
uint32_t decod_buf [bytes/4] = {0}
 
const uint8_t POLY = 0x43
 
int32_t numErrors = 0
 
cpp_freertos::BinarySemaphore requestNewDataSem = cpp_freertos::BinarySemaphore(false)
 
cpp_freertos::BinarySemaphore waitForUpdateSem = cpp_freertos::BinarySemaphore(false)
 

Static Private Attributes

static const bool useWaitSem = true
 
static const uint32_t waitThresh = 2
 
static const uint8_t bytes = 8
 
static std::array< uint8_t, 64 > tableCRC6n
 
static bool inUse = false
 

Additional Inherited Members

- Protected Member Functions inherited from SPIDevice
virtual void setSpiConfig (SPIConfig config)
 
- 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 Encoder
uint32_t cpr = 0
 
- Protected Attributes inherited from ChoosableClass
uint16_t selectionId
 Should only be written by ClassChooser during creation. More...
 
- Protected Attributes inherited from SPIDevice
SPIPortspiPort
 
SPIConfig spiConfig
 
- Protected Attributes inherited from CommandHandler
bool commandsEnabled = true
 
std::vector< CmdHandlerCommanddefregisteredCommands
 
CmdHandlerInfo cmdHandlerInfo
 
- Protected Attributes inherited from PersistentStorage
bool restoreDelayedFlag = false
 
- Static Protected Attributes inherited from PersistentStorage
static bool startupComplete = false
 
- Private 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 ()
 
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 Private Member Functions inherited from cpp_freertos::Thread
static void Yield ()
 
static void StartScheduler ()
 
static void EndScheduler ()
 

Detailed Description

Definition at line 23 of file EncoderBissC.h.

Member Enumeration Documentation

◆ EncoderBissC_commands

Enumerator
bits 
cs 
speed 
errors 
direction 

Definition at line 45 of file EncoderBissC.h.

Constructor & Destructor Documentation

◆ EncoderBissC()

EncoderBissC::EncoderBissC ( )

Definition at line 26 of file EncoderBissC.cpp.

◆ ~EncoderBissC()

EncoderBissC::~EncoderBissC ( )
virtual

Definition at line 134 of file EncoderBissC.cpp.

Member Function Documentation

◆ acquirePosition()

void EncoderBissC::acquirePosition ( )

◆ beginSpiTransfer()

void EncoderBissC::beginSpiTransfer ( SPIPort port)
virtual

Reimplemented from SPIDevice.

Definition at line 146 of file EncoderBissC.cpp.

◆ command()

CommandStatus EncoderBissC::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 249 of file EncoderBissC.cpp.

◆ configSPI()

void EncoderBissC::configSPI ( )

Definition at line 99 of file EncoderBissC.cpp.

◆ endSpiTransfer()

void EncoderBissC::endSpiTransfer ( SPIPort port)
virtual

Reimplemented from SPIDevice.

Definition at line 151 of file EncoderBissC.cpp.

◆ getCpr()

uint32_t EncoderBissC::getCpr ( )
virtual

Gets the amount of counts per full rotation of the encoder

Reimplemented from Encoder.

Definition at line 237 of file EncoderBissC.cpp.

◆ getEncoderType()

EncoderType EncoderBissC::getEncoderType ( )
virtual

Returns the type of the encoder. Must override this and NOT return NONE in other classes

Reimplemented from Encoder.

Definition at line 158 of file EncoderBissC.cpp.

◆ getInfo()

const ClassIdentifier EncoderBissC::getInfo ( )
virtual

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

Implements CommandHandler.

Definition at line 20 of file EncoderBissC.cpp.

◆ getPos()

int32_t EncoderBissC::getPos ( )
virtual

Returns the encoder position as raw counts

Reimplemented from Encoder.

Definition at line 216 of file EncoderBissC.cpp.

◆ getPosAbs()

int32_t EncoderBissC::getPosAbs ( )
virtual

Returns absolute positions without offsets for absolute encoders. Otherwise it returns getPos

Reimplemented from Encoder.

Definition at line 206 of file EncoderBissC.cpp.

◆ isCreatable()

bool EncoderBissC::isCreatable ( )
static

Definition at line 130 of file EncoderBissC.cpp.

◆ registerCommands()

void EncoderBissC::registerCommands ( )

Definition at line 241 of file EncoderBissC.cpp.

◆ restoreFlash()

void EncoderBissC::restoreFlash ( )
virtual

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

Reimplemented from PersistentStorage.

Definition at line 79 of file EncoderBissC.cpp.

◆ Run()

void EncoderBissC::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 43 of file EncoderBissC.cpp.

◆ saveFlash()

void EncoderBissC::saveFlash ( )
virtual

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 90 of file EncoderBissC.cpp.

◆ setPos()

void EncoderBissC::setPos ( int32_t  pos)
virtual

Change the position of the encoder Can be used to reset the center

Reimplemented from Encoder.

Definition at line 225 of file EncoderBissC.cpp.

◆ spiRxCompleted()

void EncoderBissC::spiRxCompleted ( SPIPort port)
overridevirtual

Reimplemented from SPIDevice.

Definition at line 140 of file EncoderBissC.cpp.

◆ updateFrame()

bool EncoderBissC::updateFrame ( )

Member Data Documentation

◆ bytes

const uint8_t EncoderBissC::bytes = 8
staticprivate

Definition at line 69 of file EncoderBissC.h.

◆ decod_buf

uint32_t EncoderBissC::decod_buf[bytes/4] = {0}
private

Definition at line 71 of file EncoderBissC.h.

◆ info

ClassIdentifier EncoderBissC::info
static
Initial value:
= {
.name = "BISS-C" ,
.id=CLSID_ENCODER_BISS
}

Definition at line 26 of file EncoderBissC.h.

◆ inUse

bool EncoderBissC::inUse = false
staticprivate

Definition at line 77 of file EncoderBissC.h.

◆ invertDirection

bool EncoderBissC::invertDirection = true
private

Definition at line 62 of file EncoderBissC.h.

◆ lastPos

int32_t EncoderBissC::lastPos = 0
private

Definition at line 66 of file EncoderBissC.h.

◆ lastUpdateTick

uint32_t EncoderBissC::lastUpdateTick = 0
private

Definition at line 64 of file EncoderBissC.h.

◆ lenghtDataBit

int EncoderBissC::lenghtDataBit = 22
private

Definition at line 59 of file EncoderBissC.h.

◆ mtpos

int32_t EncoderBissC::mtpos = 0
private

Definition at line 67 of file EncoderBissC.h.

◆ newPos

int32_t EncoderBissC::newPos = 0
private

Definition at line 66 of file EncoderBissC.h.

◆ numErrors

int32_t EncoderBissC::numErrors = 0
private

Definition at line 76 of file EncoderBissC.h.

◆ POLY

const uint8_t EncoderBissC::POLY = 0x43
private

Definition at line 74 of file EncoderBissC.h.

◆ pos

int32_t EncoderBissC::pos = 0
private

Definition at line 66 of file EncoderBissC.h.

◆ posOffset

int32_t EncoderBissC::posOffset = 0
private

Definition at line 66 of file EncoderBissC.h.

◆ requestNewDataSem

cpp_freertos::BinarySemaphore EncoderBissC::requestNewDataSem = cpp_freertos::BinarySemaphore(false)
private

Definition at line 78 of file EncoderBissC.h.

◆ spi_buf

uint8_t EncoderBissC::spi_buf[bytes] = {0}
private

Definition at line 70 of file EncoderBissC.h.

◆ spiSpeed

int EncoderBissC::spiSpeed = 3
private

Definition at line 60 of file EncoderBissC.h.

◆ tableCRC6n

std::array<uint8_t,64> EncoderBissC::tableCRC6n
staticprivate

Definition at line 75 of file EncoderBissC.h.

◆ useWaitSem

const bool EncoderBissC::useWaitSem = true
staticprivate

Definition at line 57 of file EncoderBissC.h.

◆ waitData

bool EncoderBissC::waitData = false
private

Definition at line 61 of file EncoderBissC.h.

◆ waitForUpdateSem

cpp_freertos::BinarySemaphore EncoderBissC::waitForUpdateSem = cpp_freertos::BinarySemaphore(false)
private

Definition at line 79 of file EncoderBissC.h.

◆ waitThresh

const uint32_t EncoderBissC::waitThresh = 2
staticprivate

Definition at line 58 of file EncoderBissC.h.


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