Skip to content

Commit

Permalink
chore: controller output
Browse files Browse the repository at this point in the history
  • Loading branch information
MrUnzO committed Dec 25, 2023
1 parent 394e7c7 commit eafa96c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Arduino/Esp32/Main/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,40 @@ static const int16_t JOYSTICK_RANGE = JOYSTICK_MAX_VALUE - JOYSTICK_MIN_VALUE;
char ssid[23];
uint64_t chipid = ESP.getEfuseMac(); // The chip ID is essentially its MAC address(length: 6 bytes).
unsigned int chip = (unsigned int)(chipid >> 32);
std::string bluetoothName_lcl = "DiyActivePedal_" + std::to_string( chip );
std::string bluetoothName_lcl = "DiyFfbPedal_" + std::to_string( chip );
BleGamepad bleGamepad(bluetoothName_lcl, bluetoothName_lcl, 100);


void SetupController() {
BleGamepadConfiguration bleGamepadConfig;
bleGamepadConfig.setControllerType(CONTROLLER_TYPE_GAMEPAD); // CONTROLLER_TYPE_JOYSTICK, CONTROLLER_TYPE_GAMEPAD (DEFAULT), CONTROLLER_TYPE_MULTI_AXIS
bleGamepadConfig.setControllerType(CONTROLLER_TYPE_MULTI_AXIS); // CONTROLLER_TYPE_JOYSTICK, CONTROLLER_TYPE_GAMEPAD (DEFAULT), CONTROLLER_TYPE_MULTI_AXIS
bleGamepadConfig.setAxesMin(JOYSTICK_MIN_VALUE); // 0 --> int16_t - 16 bit signed integer - Can be in decimal or hexadecimal
bleGamepadConfig.setAxesMax(JOYSTICK_MAX_VALUE); // 32767 --> int16_t - 16 bit signed integer - Can be in decimal or hexadecimal
//bleGamepadConfig.setWhichSpecialButtons(false, false, false, false, false, false, false, false);
//bleGamepadConfig.setWhichAxes(false, false, false, false, false, false, false, false);
bleGamepadConfig.setWhichSimulationControls(false, false, false, true, false); // only brake active
bleGamepadConfig.setWhichAxes(true, true, true, true, true, true, true, true);
//bleGamepadConfig.setWhichSimulationControls(true, true, true, true, true); // only brake active
bleGamepadConfig.setButtonCount(0);
bleGamepadConfig.setHatSwitchCount(0);
bleGamepadConfig.setAutoReport(false);
bleGamepadConfig.setPid(chip); // product id

bleGamepad.begin(&bleGamepadConfig);

//bleGamepad.deviceManufacturer = "DiyFfbPedal";
//bleGamepad.deviceName = chip;
}

bool IsControllerReady() { return bleGamepad.isConnected(); }

void SetControllerOutputValue(int32_t value) {
//bleGamepad.setBrake(value);

if (bleGamepad.isConnected() )
{
// bleGamepad.setBrake(value);
bleGamepad.setAxes(0, 0, 0, 0, value, 0, 0, 0);
//bleGamepad.setAxes(value, 0, 0, 0, 0, 0, 0, 0);
bleGamepad.setX(value);
//bleGamepad.setSimulationControls(value, 0, 0, 0, 0);
//bleGamepad.setSliders(value,0);
bleGamepad.sendReport();
}
else
Expand All @@ -90,4 +96,4 @@ int32_t NormalizeControllerOutputValue(float value, float minVal, float maxVal,
float fractional = (value - minVal) / valRange;
int32_t controller = JOYSTICK_MIN_VALUE + (fractional * JOYSTICK_RANGE);
return constrain(controller, JOYSTICK_MIN_VALUE, (maxGameOutput/100.) * JOYSTICK_MAX_VALUE);
}
}

0 comments on commit eafa96c

Please sign in to comment.