Browse Source

Speed up BLE to 120++ packets per second. Also removed some unwanted process

master
Englebert 3 years ago
parent
commit
ede5ec968e
  1. 11
      src/BLE.cpp
  2. 3
      src/BLE.h
  3. 17
      src/BLEGamepad.cpp
  4. 2
      src/main.cpp

11
src/BLE.cpp

@ -33,7 +33,7 @@ void BLE::update(void) {
if(bleGamepad.isConnected()) {
if((uint32_t)(millis() - last_updated) > 30) {
if((uint32_t)(millis() - last_updated) > 1) {
int16_t throttle = map(inputs.throttle, 0, 4096, -32767, 32767); // Throttle
int16_t yaw = map(inputs.yaw, 0, 4096, -32767, 32767); // Yaw
int16_t pitch = map(inputs.pitch, 0, 4096, -32767, 32767); // Pitch
@ -41,11 +41,20 @@ void BLE::update(void) {
bleGamepad.setAxes(yaw, throttle, roll, pitch, 0, 0, DPAD_CENTERED);
sent_counter_raw++;
last_updated = millis();
// Serial.printf("Sent\n");
}
}
}
// Reset the profiler when hits 1 second mark
if((uint32_t)(millis() - last_seconds) > 1000) {
sent_counter = sent_counter_raw;
sent_counter_raw = 0;
last_seconds = millis();
}
}
BLE ble;

3
src/BLE.h

@ -11,6 +11,8 @@ class BLE {
bool ble_begin = false;
bool updated = false;
bool ble_started = false;
int16_t sent_counter_raw = 0;
int16_t sent_counter = 0;
BLE(void);
void begin(void);
@ -19,6 +21,7 @@ class BLE {
private:
uint32_t last_updated = 0;
uint32_t last_seconds = 0;
};
extern BLE ble;

17
src/BLEGamepad.cpp

@ -24,13 +24,16 @@ void BLEGamepad::show(TFT_eSprite *m) {
m->setTextColor(WHITE, BLACK);
m->setTextSize(2);
m->setCursor(0,0);
m->print(String(inputs.throttle));
m->setCursor(0,16);
m->print(String(inputs.yaw));
m->setCursor(0,32);
m->print(String(inputs.pitch));
m->setCursor(0,48);
m->print(String(inputs.roll));
m->print("Packet(s) Sent: ");
m->print(String(ble.sent_counter));
// m->print(String(inputs.throttle));
// m->setCursor(0,16);
// m->print(String(inputs.yaw));
// m->setCursor(0,32);
// m->print(String(inputs.pitch));
// m->setCursor(0,48);
// m->print(String(inputs.roll));
m->setCursor(64,64);
m->print("BLE GAMEPAD");

2
src/main.cpp

@ -140,6 +140,6 @@ void taskBLE(void *pvParameters) {
for(;;) {
ble.update();
vTaskDelay(10);
vTaskDelay(5);
}
}
Loading…
Cancel
Save