Skip to content

Commit

Permalink
Moved Analog, Encoder and Button source lists into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
Ultrawipf committed Jul 6, 2024
1 parent cf9be52 commit 11c62b0
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Firmware/FFBoard/Inc/AnalogSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AnalogSource : public ChoosableClass, public PersistentStorage{
virtual std::vector<int32_t>* getAxes();
std::vector<int32_t> buf;


static const std::vector<class_entry<AnalogSource>> all_analogsources;

private:

Expand Down
4 changes: 3 additions & 1 deletion Firmware/FFBoard/Inc/ButtonSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "cppmain.h"
#include "ChoosableClass.h"
#include "PersistentStorage.h"

#include "vector"

/**
* A button source can return up to 64 buttons
Expand All @@ -32,6 +32,8 @@ class ButtonSource : public ChoosableClass,public PersistentStorage {
static bool isCreatable() {return true;};
virtual const ClassType getClassType() {return ClassType::Buttonsource;};

static const std::vector<class_entry<ButtonSource> > all_buttonsources;

protected:
uint16_t btnnum = 0; // Amount of active buttons (valid bitfield length) to report
};
Expand Down
24 changes: 0 additions & 24 deletions Firmware/FFBoard/Src/Encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,6 @@

#include "Encoder.h"
#include "ClassChooser.h"
#include "EncoderLocal.h"
#include "MtEncoderSPI.h"
#include "EncoderBissC.h"
#include "EncoderSSI.h"
// 0-63 valid ids
std::vector<class_entry<Encoder>> const Encoder::all_encoders =
{
add_class<Encoder, Encoder>(0),

#ifdef LOCALENCODER
add_class<EncoderLocal, Encoder>(2),
#endif

#ifdef MTENCODERSPI
add_class<MtEncoderSPI, Encoder>(4),
#endif
#ifdef BISSENCODER
add_class<EncoderBissC, Encoder>(5),
#endif
#ifdef SSIENCODER
add_class<EncoderSSI, Encoder>(6),
#endif

};

ClassIdentifier Encoder::info ={.name = "None" , .id=CLSID_ENCODER_NONE, .visibility = ClassVisibility::visible};

Expand Down
27 changes: 27 additions & 0 deletions Firmware/FFBoard/UserExtensions/Src/AnalogSources.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* AnalogSources.cpp
*
* Created on: Apr 18, 2024
* Author: Yannick
*/

#include "constants.h"
#include "LocalAnalog.h"
#include "CanAnalog.h"
#include "ADS111X.h"

// Register possible analog sources (id 0-15)
#ifndef ANALOGSOURCES_DEFAULT_OVERRIDE
const std::vector<class_entry<AnalogSource>> AnalogSource::all_analogsources =
{
#ifdef ANALOGAXES
add_class<LocalAnalog,AnalogSource>(0),
#endif
#ifdef CANANALOG
add_class<CanAnalog<8>,AnalogSource>(1),
#endif
#ifdef ADS111XANALOG
add_class<ADS111X_AnalogSource,AnalogSource>(2),
#endif
};
#endif
37 changes: 37 additions & 0 deletions Firmware/FFBoard/UserExtensions/Src/ButtonSources.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* ButtonSources.cpp
*
* Created on: Apr 18, 2024
* Author: Yannick
*/
#include "constants.h"
#include "SPIButtons.h"
#include "CanButtons.h"
#include "LocalButtons.h"
#include <ShifterAnalog.h>
#include "PCF8574.h"

#ifndef BUTTONSOURCES_DEFAULT_OVERRIDE
// Register possible button sources (id 0-15)
const std::vector<class_entry<ButtonSource>> ButtonSource::all_buttonsources =
{
#ifdef LOCALBUTTONS
add_class<LocalButtons,ButtonSource>(0),
#endif
#ifdef SPIBUTTONS
add_class<SPI_Buttons_1,ButtonSource>(1),
#endif
#ifdef SPIBUTTONS2
add_class<SPI_Buttons_2,ButtonSource>(2),
#endif
#ifdef SHIFTERBUTTONS
add_class<ShifterAnalog,ButtonSource>(3),
#endif
#ifdef PCF8574BUTTONS
add_class<PCF8574Buttons,ButtonSource>(4),
#endif
#ifdef CANBUTTONS
add_class<CanButtons,ButtonSource>(5),
#endif
};
#endif
33 changes: 33 additions & 0 deletions Firmware/FFBoard/UserExtensions/Src/EncoderSources.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* EncoderSources.cpp
*
* Created on: Apr 18, 2024
* Author: Yannick
*/

#include "constants.h"
#include "EncoderLocal.h"
#include "MtEncoderSPI.h"
#include "EncoderBissC.h"
#include "EncoderSSI.h"
// 0-63 valid ids
#ifndef ENCODERSOURCES_DEFAULT_OVERRIDE
std::vector<class_entry<Encoder>> const Encoder::all_encoders =
{
add_class<Encoder, Encoder>(0),

#ifdef LOCALENCODER
add_class<EncoderLocal, Encoder>(2),
#endif

#ifdef MTENCODERSPI
add_class<MtEncoderSPI, Encoder>(4),
#endif
#ifdef BISSENCODER
add_class<EncoderBissC, Encoder>(5),
#endif
#ifdef SSIENCODER
add_class<EncoderSSI, Encoder>(6),
#endif
};
#endif
51 changes: 2 additions & 49 deletions Firmware/FFBoard/UserExtensions/Src/FFBHIDMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,18 @@
#include "tusb.h"
#include "usb_hid_ffb_desc.h"

#include "SPIButtons.h"
#include "CanButtons.h"
#include "LocalButtons.h"
#include <ShifterAnalog.h>
#include "PCF8574.h"

#include "LocalAnalog.h"
#include "CanAnalog.h"
#include "ADS111X.h"

#include "cmsis_os.h"
extern osThreadId_t defaultTaskHandle;

//////////////////////////////////////////////
/*
* Sources for class choosers here
*/
// Register possible button sources (id 0-15)
const std::vector<class_entry<ButtonSource>> button_sources =
{
#ifdef LOCALBUTTONS
add_class<LocalButtons,ButtonSource>(0),
#endif
#ifdef SPIBUTTONS
add_class<SPI_Buttons_1,ButtonSource>(1),
#endif
#ifdef SPIBUTTONS2
add_class<SPI_Buttons_2,ButtonSource>(2),
#endif
#ifdef SHIFTERBUTTONS
add_class<ShifterAnalog,ButtonSource>(3),
#endif
#ifdef PCF8574BUTTONS
add_class<PCF8574Buttons,ButtonSource>(4),
#endif
#ifdef CANBUTTONS
add_class<CanButtons,ButtonSource>(5),
#endif
};

// Register possible analog sources (id 0-15)
const std::vector<class_entry<AnalogSource>> analog_sources =
{
#ifdef ANALOGAXES
add_class<LocalAnalog,AnalogSource>(0),
#endif
#ifdef CANANALOG
add_class<CanAnalog<8>,AnalogSource>(1),
#endif
#ifdef ADS111XANALOG
add_class<ADS111X_AnalogSource,AnalogSource>(2),
#endif
};

/**
* setFFBEffectsCalc must be called in constructor of derived class to finish the setup
*/
FFBHIDMain::FFBHIDMain(uint8_t axisCount) :
Thread("FFBMAIN", 256, 30),axisCount(axisCount),btn_chooser(button_sources),analog_chooser(analog_sources)
Thread("FFBMAIN", 256, 30),axisCount(axisCount),
btn_chooser(ButtonSource::all_buttonsources),analog_chooser(AnalogSource::all_analogsources)
{

restoreFlash(); // Load parameters
Expand Down
2 changes: 2 additions & 0 deletions Firmware/FFBoard/UserExtensions/Src/mainclass_chooser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#endif

// Add all classes here
#ifndef CLASSREGISTRY_OVERRIDE
const std::vector<class_entry<FFBoardMain>> class_registry =
{
add_class<FFBoardMain,FFBoardMain>(0),
Expand Down Expand Up @@ -60,5 +61,6 @@ const std::vector<class_entry<FFBoardMain>> class_registry =

add_class<CustomMain,FFBoardMain>()
};
#endif


0 comments on commit 11c62b0

Please sign in to comment.