Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use consistent code formatting in src cpp files #1214

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,30 @@ end_of_line = lf

[*.{js,jsx,ts,tsx}]
quote_type = single

[src/**.cpp]
indent_style = space
indent_size = 4

[{src/addons/keyboard_host_listener.cpp,src/addons/keyboard_host.cpp}]
indent_style = space
indent_size = 2

[{src/gamepad.cpp,src/gp2040.cpp,src/gp2040aux.cpp,src/main.cpp,src/storagemanager.cpp,src/system.cpp,src/usbdriver.cpp,src/gamepad/GamepadState.cpp,src/interfaces/i2c/ssd1306/obd_ssd1306.cpp}]
indent_style = tab
indent_size = 2

# Use tabs for these files in the src/addons directory
[{src/addons/bootsel_button.cpp,src/addons/buzzerspeaker.cpp,src/addons/drv8833_rumble.cpp,src/addons/focus_mode.cpp,src/addons/neopicoleds.cpp,src/addons/playerleds.cpp,src/addons/tilt.cpp}]
indent_style = tab
indent_size = 2

# Use tabs for these files in the src/drivers directory
[{src/drivers/astro/AstroDriver.cpp,src/drivers/egret/EgretDriver.cpp,src/drivers/hid/HIDDriver.cpp,src/drivers/keyboard/KeyboardDriver.cpp,src/drivers/mdmini/MDMiniDriver.cpp}]
indent_style = tab
indent_size = 2

# Use tabs for these files in the src/drivers directory
[{src/drivers/neogeo/NeoGeoDriver.cpp,src/drivers/pcengine/PCEngineDriver.cpp,src/drivers/psclassic/PSClassicDriver.cpp,src/drivers/switch/SwitchDriver.cpp,src/drivers/xinput/XInputDriver.cpp}]
indent_style = tab
indent_size = 2
2 changes: 1 addition & 1 deletion src/addonmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bool AddonManager::LoadAddon(GPAddon* addon, ADDON_PROCESS processAt) {
addons.push_back(block);
return true;
} else {
delete addon; // Don't use the memory if we don't have to
delete addon; // Don't use the memory if we don't have to
}

return false;
Expand Down
10 changes: 5 additions & 5 deletions src/addons/analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bool AnalogInput::available() {

void AnalogInput::setup() {
const AnalogOptions& analogOptions = Storage::getInstance().getAddonOptions().analogOptions;

// Setup our ADC Pair of Sticks
adc_pairs[0].x_pin = analogOptions.analogAdc1PinX;
adc_pairs[0].y_pin = analogOptions.analogAdc1PinY;
Expand Down Expand Up @@ -74,7 +74,7 @@ void AnalogInput::setup() {

void AnalogInput::process() {
Gamepad * gamepad = Storage::getInstance().GetGamepad();

uint16_t joystickMid = GAMEPAD_JOYSTICK_MID;
if ( DriverManager::getInstance().getDriver() != nullptr ) {
joystickMid = DriverManager::getInstance().getDriver()->GetJoystickMidValue();
Expand All @@ -84,7 +84,7 @@ void AnalogInput::process() {
// Read X-Axis
if (isValidPin(adc_pairs[i].x_pin)) {
adc_pairs[i].x_value = readPin(adc_pairs[i].x_pin_adc, adc_pairs[i].x_center);
if (adc_pairs[i].analog_invert == InvertMode::INVERT_X ||
if (adc_pairs[i].analog_invert == InvertMode::INVERT_X ||
adc_pairs[i].analog_invert == InvertMode::INVERT_XY) {
adc_pairs[i].x_value = ANALOG_MAX - adc_pairs[i].x_value;
}
Expand All @@ -96,7 +96,7 @@ void AnalogInput::process() {
// Read Y-Axis
if (isValidPin(adc_pairs[i].y_pin)) {
adc_pairs[i].y_value = readPin(adc_pairs[i].y_pin_adc, adc_pairs[i].y_center);
if (adc_pairs[i].analog_invert == InvertMode::INVERT_Y ||
if (adc_pairs[i].analog_invert == InvertMode::INVERT_Y ||
adc_pairs[i].analog_invert == InvertMode::INVERT_XY) {
adc_pairs[i].y_value = ANALOG_MAX - adc_pairs[i].y_value;
}
Expand Down Expand Up @@ -172,4 +172,4 @@ void AnalogInput::radialDeadzone(adc_instance & adc_inst) {
adc_inst.y_value = ((adc_inst.y_magnitude / adc_inst.xy_magnitude) * scaling_factor) + ANALOG_CENTER;
adc_inst.x_value = std::clamp(adc_inst.x_value, ANALOG_MINIMUM, ANALOG_MAX);
adc_inst.y_value = std::clamp(adc_inst.y_value, ANALOG_MINIMUM, ANALOG_MAX);
}
}
6 changes: 3 additions & 3 deletions src/addons/bootsel_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ bool __no_inline_not_in_flash_func(BootselButtonAddon::isBootselPressed)() {
}

bool BootselButtonAddon::available() {
const BootselButtonOptions& options = Storage::getInstance().getAddonOptions().bootselButtonOptions;
const BootselButtonOptions& options = Storage::getInstance().getAddonOptions().bootselButtonOptions;
return options.enabled && options.buttonMap != 0;
}

void BootselButtonAddon::setup() {
const BootselButtonOptions& options = Storage::getInstance().getAddonOptions().bootselButtonOptions;
const BootselButtonOptions& options = Storage::getInstance().getAddonOptions().bootselButtonOptions;
bootselButtonMap = options.buttonMap;
}

Expand All @@ -66,4 +66,4 @@ void BootselButtonAddon::preprocess() {
default: gamepad->state.buttons |= bootselButtonMap;
}
}
}
}
18 changes: 9 additions & 9 deletions src/addons/buzzerspeaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "config.pb.h"

bool BuzzerSpeakerAddon::available() {
const BuzzerOptions& options = Storage::getInstance().getAddonOptions().buzzerOptions;
const BuzzerOptions& options = Storage::getInstance().getAddonOptions().buzzerOptions;
return options.enabled && isValidPin(options.pin);
}

Expand All @@ -19,14 +19,14 @@ void BuzzerSpeakerAddon::setup() {
buzzerPinSlice = pwm_gpio_to_slice_num (buzzerPin);
buzzerPinChannel = pwm_gpio_to_channel (buzzerPin);

// enable pin is optional so not required to toggle addon
if (isValidPin(options.pin)) {
isSpeakerOn = true;
buzzerEnablePin = options.enablePin;
gpio_init(buzzerEnablePin);
gpio_set_dir(buzzerEnablePin, GPIO_OUT);
gpio_put(buzzerEnablePin, isSpeakerOn);
}
// enable pin is optional so not required to toggle addon
if (isValidPin(options.pin)) {
isSpeakerOn = true;
buzzerEnablePin = options.enablePin;
gpio_init(buzzerEnablePin);
gpio_set_dir(buzzerEnablePin, GPIO_OUT);
gpio_put(buzzerEnablePin, isSpeakerOn);
}

buzzerVolume = options.volume;
introPlayed = false;
Expand Down
8 changes: 4 additions & 4 deletions src/addons/drv8833_rumble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bool DRV8833RumbleAddon::available() {

void DRV8833RumbleAddon::setup() {
const DRV8833RumbleOptions& options = Storage::getInstance().getAddonOptions().drv8833RumbleOptions;
Gamepad * gamepad = Storage::getInstance().GetProcessedGamepad();
Gamepad * gamepad = Storage::getInstance().GetProcessedGamepad();

leftMotorPin = options.leftMotorPin;
rightMotorPin = options.rightMotorPin;
Expand Down Expand Up @@ -61,9 +61,9 @@ void DRV8833RumbleAddon::setup() {
}

bool DRV8833RumbleAddon::compareRumbleState(Gamepad * gamepad) {
if (currentRumbleState.leftActuator.active == gamepad->auxState.haptics.leftActuator.active &&
currentRumbleState.leftActuator.intensity == gamepad->auxState.haptics.leftActuator.intensity &&
currentRumbleState.rightActuator.active == gamepad->auxState.haptics.rightActuator.active &&
if (currentRumbleState.leftActuator.active == gamepad->auxState.haptics.leftActuator.active &&
currentRumbleState.leftActuator.intensity == gamepad->auxState.haptics.leftActuator.intensity &&
currentRumbleState.rightActuator.active == gamepad->auxState.haptics.rightActuator.active &&
currentRumbleState.rightActuator.intensity == gamepad->auxState.haptics.rightActuator.intensity)
return true;

Expand Down
64 changes: 32 additions & 32 deletions src/addons/dualdirectional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,32 @@ void DualDirectionalInput::reinit()

uint8_t DualDirectionalInput::updateDpadDDI(uint8_t dpad, DpadDirection direction)
{
static bool inList[] = {false, false, false, false, false}; // correspond to DpadDirection: none, up, down, left, right
static list<DpadDirection> dpadList;

if(dpad & getMaskFromDirection(direction))
{
if(!inList[direction])
{
dpadList.push_back(direction);
inList[direction] = true;
}
}
else
{
if(inList[direction])
{
dpadList.remove(direction);
inList[direction] = false;
}
}

if(dpadList.empty()) {
return 0;
}
else {
return getMaskFromDirection(dpadList.back());
}
static bool inList[] = {false, false, false, false, false}; // correspond to DpadDirection: none, up, down, left, right
static list<DpadDirection> dpadList;

if(dpad & getMaskFromDirection(direction))
{
if(!inList[direction])
{
dpadList.push_back(direction);
inList[direction] = true;
}
}
else
{
if(inList[direction])
{
dpadList.remove(direction);
inList[direction] = false;
}
}

if(dpadList.empty()) {
return 0;
}
else {
return getMaskFromDirection(dpadList.back());
}
}

/**
Expand All @@ -90,10 +90,10 @@ uint8_t DualDirectionalInput::updateDpadDDI(uint8_t dpad, DpadDirection directio
*/
uint8_t DualDirectionalInput::filterToFourWayModeDDI(uint8_t dpad)
{
updateDpadDDI(dpad, DIRECTION_UP);
updateDpadDDI(dpad, DIRECTION_DOWN);
updateDpadDDI(dpad, DIRECTION_LEFT);
return updateDpadDDI(dpad, DIRECTION_RIGHT);
updateDpadDDI(dpad, DIRECTION_UP);
updateDpadDDI(dpad, DIRECTION_DOWN);
updateDpadDDI(dpad, DIRECTION_LEFT);
return updateDpadDDI(dpad, DIRECTION_RIGHT);
}


Expand Down Expand Up @@ -133,7 +133,7 @@ void DualDirectionalInput::process()
// output is, in practice, the same behavior as mixed mode, so it also is addressed here
if (options.combineMode == DualDirectionalCombinationMode::MIXED_MODE ||
(options.combineMode == DualDirectionalCombinationMode::NONE_MODE &&
gamepad->getActiveDpadMode() == options.dpadMode)) {
gamepad->getActiveDpadMode() == options.dpadMode)) {
if ( socdMode == SOCD_MODE_UP_PRIORITY || socdMode == SOCD_MODE_NEUTRAL ) {
// neutral/up priority SOCD cleaning are pretty simple, they just need to be re-neutralized
dualOut = SOCDCombine(socdMode, gamepadDpad);
Expand Down Expand Up @@ -246,7 +246,7 @@ uint8_t DualDirectionalInput::SOCDCombine(SOCDMode mode, uint8_t gamepadState) {
return outState;
}

void DualDirectionalInput::SOCDDualClean(SOCDMode socdMode) {
void DualDirectionalInput::SOCDDualClean(SOCDMode socdMode) {
if (socdMode == SOCD_MODE_BYPASS) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/addons/focus_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ void FocusModeAddon::process() {
}
gamepad->state.buttons &= ~buttonLockMask;
}
}
}
2 changes: 1 addition & 1 deletion src/addons/input_macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void InputMacro::runCurrentMacro() {
if ((currentMicros - macroStartTime) >= macroInputHoldTime) {
macroStartTime = currentMicros;
macroInputPosition++;

if (macroInputPosition >= (macro.macroInputs_count)) {
if ( macro.macroType == ON_PRESS ) {
reset(); // On press = no more macro
Expand Down
2 changes: 1 addition & 1 deletion src/addons/keyboard_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

bool KeyboardHostAddon::available() {
const KeyboardHostOptions& keyboardHostOptions = Storage::getInstance().getAddonOptions().keyboardHostOptions;
return keyboardHostOptions.enabled && PeripheralManager::getInstance().isUSBEnabled(0);
return keyboardHostOptions.enabled && PeripheralManager::getInstance().isUSBEnabled(0);
}

void KeyboardHostAddon::setup() {
Expand Down
26 changes: 13 additions & 13 deletions src/addons/keyboard_host_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void KeyboardHostListener::setup() {
_keyboard_host_mounted = false;
_keyboard_dev_addr = DEV_ADDR_NONE;
_keyboard_instance = 0;

_mouse_host_mounted = false;
_mouse_dev_addr = DEV_ADDR_NONE;
_mouse_instance = 0;
Expand Down Expand Up @@ -139,18 +139,18 @@ if ( _keyboard_host_mounted == false && _mouse_host_mounted == false )
}

uint8_t KeyboardHostListener::getKeycodeFromModifier(uint8_t modifier) {
switch (modifier) {
case KEYBOARD_MODIFIER_LEFTCTRL : return HID_KEY_CONTROL_LEFT ;
case KEYBOARD_MODIFIER_LEFTSHIFT : return HID_KEY_SHIFT_LEFT ;
case KEYBOARD_MODIFIER_LEFTALT : return HID_KEY_ALT_LEFT ;
case KEYBOARD_MODIFIER_LEFTGUI : return HID_KEY_GUI_LEFT ;
case KEYBOARD_MODIFIER_RIGHTCTRL : return HID_KEY_CONTROL_RIGHT;
case KEYBOARD_MODIFIER_RIGHTSHIFT : return HID_KEY_SHIFT_RIGHT ;
case KEYBOARD_MODIFIER_RIGHTALT : return HID_KEY_ALT_RIGHT ;
case KEYBOARD_MODIFIER_RIGHTGUI : return HID_KEY_GUI_RIGHT ;
}

return 0;
switch (modifier) {
case KEYBOARD_MODIFIER_LEFTCTRL : return HID_KEY_CONTROL_LEFT ;
case KEYBOARD_MODIFIER_LEFTSHIFT : return HID_KEY_SHIFT_LEFT ;
case KEYBOARD_MODIFIER_LEFTALT : return HID_KEY_ALT_LEFT ;
case KEYBOARD_MODIFIER_LEFTGUI : return HID_KEY_GUI_LEFT ;
case KEYBOARD_MODIFIER_RIGHTCTRL : return HID_KEY_CONTROL_RIGHT;
case KEYBOARD_MODIFIER_RIGHTSHIFT : return HID_KEY_SHIFT_RIGHT ;
case KEYBOARD_MODIFIER_RIGHTALT : return HID_KEY_ALT_RIGHT ;
case KEYBOARD_MODIFIER_RIGHTGUI : return HID_KEY_GUI_RIGHT ;
}

return 0;
}

void KeyboardHostListener::preprocess_report()
Expand Down
2 changes: 1 addition & 1 deletion src/addons/neopicoleds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ PLEDAnimationState getXBoneAnimationNEOPICO(Gamepad * gamepad)
.animation = PLED_ANIM_OFF
};

if ( gamepad->auxState.playerID.ledValue == 1 ) {
if ( gamepad->auxState.playerID.ledValue == 1 ) {
animationState.animation = PLED_ANIM_SOLID;
}

Expand Down
2 changes: 1 addition & 1 deletion src/addons/playerleds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void PlayerLEDAddon::setup() {

Gamepad * gamepad = Storage::getInstance().GetProcessedGamepad();
gamepad->auxState.playerID.enabled = true;
gamepad->auxState.sensors.statusLight.enabled = true;
gamepad->auxState.sensors.statusLight.enabled = true;

switch (ledOptions.pledType)
{
Expand Down
28 changes: 14 additions & 14 deletions src/addons/playernum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
// Move to Proto Enums
typedef enum
{
XINPUT_PLED_OFF = 0x00, // All off
XINPUT_PLED_BLINKALL = 0x01, // All blinking
XINPUT_PLED_FLASH1 = 0x02, // 1 flashes, then on
XINPUT_PLED_FLASH2 = 0x03, // 2 flashes, then on
XINPUT_PLED_FLASH3 = 0x04, // 3 flashes, then on
XINPUT_PLED_FLASH4 = 0x05, // 4 flashes, then on
XINPUT_PLED_ON1 = 0x06, // 1 on
XINPUT_PLED_ON2 = 0x07, // 2 on
XINPUT_PLED_ON3 = 0x08, // 3 on
XINPUT_PLED_ON4 = 0x09, // 4 on
XINPUT_PLED_ROTATE = 0x0A, // Rotating (e.g. 1-2-4-3)
XINPUT_PLED_BLINK = 0x0B, // Blinking*
XINPUT_PLED_SLOWBLINK = 0x0C, // Slow blinking*
XINPUT_PLED_ALTERNATE = 0x0D, // Alternating (e.g. 1+4-2+3), then back to previous*
XINPUT_PLED_OFF = 0x00, // All off
XINPUT_PLED_BLINKALL = 0x01, // All blinking
XINPUT_PLED_FLASH1 = 0x02, // 1 flashes, then on
XINPUT_PLED_FLASH2 = 0x03, // 2 flashes, then on
XINPUT_PLED_FLASH3 = 0x04, // 3 flashes, then on
XINPUT_PLED_FLASH4 = 0x05, // 4 flashes, then on
XINPUT_PLED_ON1 = 0x06, // 1 on
XINPUT_PLED_ON2 = 0x07, // 2 on
XINPUT_PLED_ON3 = 0x08, // 3 on
XINPUT_PLED_ON4 = 0x09, // 4 on
XINPUT_PLED_ROTATE = 0x0A, // Rotating (e.g. 1-2-4-3)
XINPUT_PLED_BLINK = 0x0B, // Blinking*
XINPUT_PLED_SLOWBLINK = 0x0C, // Slow blinking*
XINPUT_PLED_ALTERNATE = 0x0D, // Alternating (e.g. 1+4-2+3), then back to previous*
} XInputPLEDPattern;

bool PlayerNumAddon::available() {
Expand Down
10 changes: 5 additions & 5 deletions src/addons/reverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
bool ReverseInput::available() {
const ReverseOptions& options = Storage::getInstance().getAddonOptions().reverseOptions;
pinButtonReverse = options.buttonPin;
return options.enabled && isValidPin(options.buttonPin);
return options.enabled && isValidPin(options.buttonPin);
}

void ReverseInput::setup()
Expand All @@ -33,10 +33,10 @@ void ReverseInput::setup()
actionRight = options.actionRight;

Gamepad * gamepad = Storage::getInstance().GetGamepad();
mapDpadUp = gamepad->mapDpadUp;
mapDpadDown = gamepad->mapDpadDown;
mapDpadLeft = gamepad->mapDpadLeft;
mapDpadRight = gamepad->mapDpadRight;
mapDpadUp = gamepad->mapDpadUp;
mapDpadDown = gamepad->mapDpadDown;
mapDpadLeft = gamepad->mapDpadLeft;
mapDpadRight = gamepad->mapDpadRight;

invertXAxis = gamepad->getOptions().invertXAxis;
invertYAxis = gamepad->getOptions().invertYAxis;
Expand Down
Loading