diff --git a/src/BLE.cpp b/src/BLE.cpp index ee495b3..94f512d 100644 --- a/src/BLE.cpp +++ b/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; diff --git a/src/BLE.h b/src/BLE.h index 04fb17b..1c98e82 100644 --- a/src/BLE.h +++ b/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; diff --git a/src/BLEGamepad.cpp b/src/BLEGamepad.cpp index 173e85d..8f51e8b 100644 --- a/src/BLEGamepad.cpp +++ b/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"); diff --git a/src/main.cpp b/src/main.cpp index 23e2209..9c5aad6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -140,6 +140,6 @@ void taskBLE(void *pvParameters) { for(;;) { ble.update(); - vTaskDelay(10); + vTaskDelay(5); } }