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

Update BLE Joystick #2050

Merged
merged 4 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 12 additions & 33 deletions src/lib/BLE/devBLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,6 @@
#include <BleGamepad.h>
#include <NimBLEDevice.h>

#define numOfButtons 0
#define numOfHatSwitches 0
#define enableX true
#define enableY true
#define enableZ false
#define enableRZ false
#define enableRX true
#define enableRY true
#define enableSlider1 true
#define enableSlider2 true
#define enableRudder true
#define enableThrottle true
#define enableAccelerator false
#define enableBrake false
#define enableSteering false


class ELRSGamepad : public BleGamepad {
public:
ELRSGamepad() : BleGamepad("ExpressLRS Joystick", "ELRS", 100) {};
Expand All @@ -44,22 +27,25 @@ void BluetoothJoystickUpdateValues()
{
if (bleGamepad->isConnected())
{
// map first 8 channels to axis
int16_t data[8];

for (uint8_t i = 0; i < 8; i++)
{
data[i] = map(CRSF::ChannelData[i], CRSF_CHANNEL_VALUE_MIN, CRSF_CHANNEL_VALUE_MAX, 0, 32767);
}
bleGamepad->setAxes(data[0], data[1], data[4], data[5], data[2], data[3], data[6], data[7]);

bleGamepad->setX(data[0]);
bleGamepad->setY(data[1]);
bleGamepad->setRX(data[2]);
bleGamepad->setRY(data[3]);
bleGamepad->setRudder(data[4]);
bleGamepad->setThrottle(data[5]);
bleGamepad->setSlider1(data[6]);
bleGamepad->setSlider2(data[7]);
// map other 8 channels to buttons
for (uint8_t i = 8; i < 16; i++)
{
if (CRSF::ChannelData[i] >= CRSF_CHANNEL_VALUE_2000) {
bleGamepad->press(i - 7);
} else {
bleGamepad->release(i - 7);
}
}

// send BLE report
bleGamepad->sendReport();
}
}
Expand All @@ -73,19 +59,12 @@ void BluetoothJoystickBegin()
// construct the BLE immediately to prevent reentry from events/timeout
bleGamepad = new ELRSGamepad();

hwTimer::updateInterval(10000);
CRSF::setSyncParams(10000); // 100hz
// CRSF::disableOpentxSync();
POWERMGNT::setPower(MinPower);
Radio.End();
CRSF::RCdataCallback = BluetoothJoystickUpdateValues;

BleGamepadConfiguration *gamepadConfig = new BleGamepadConfiguration();
gamepadConfig->setAutoReport(false);
gamepadConfig->setButtonCount(0);
gamepadConfig->setHatSwitchCount(0);
gamepadConfig->setWhichAxes(enableX, enableY, enableZ, enableRX, enableRY, enableRZ, enableSlider1, enableSlider2);
gamepadConfig->setWhichSimulationControls(enableRudder, enableThrottle, enableAccelerator, enableBrake, enableSteering);

DBGLN("Starting BLE Joystick!");
bleGamepad->begin(gamepadConfig);
Expand Down
4 changes: 2 additions & 2 deletions src/targets/common.ini
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ build_src_filter = ${common_env_data.build_src_filter} -<ESP8266*.*> -<STM32*.*>
lib_deps =
makuna/NeoPixelBus @ 2.7.0
ottowinter/ESPAsyncWebServer-esphome @ 3.0.0
lemmingdev/ESP32-BLE-Gamepad @ 0.5.1
h2zero/NimBLE-Arduino @ 1.4.0
lemmingdev/ESP32-BLE-Gamepad @ 0.5.2
h2zero/NimBLE-Arduino @ 1.4.1
bblanchon/ArduinoJson @ 6.19.4
oled_lib_deps =
${env_common_esp32.lib_deps}
Expand Down