Rework the Gyro Tilt screen (and the tilt->RGB lightbar) using the DS5's own factory IMU calibration, and fix two long-standing tilt-dot quirks. All three are display-only — the host input report (every gyro + accel axis) is still forwarded byte-for-byte, so in-game motion is unaffected. - Calibration: parse feature report 0x05 (already cached by bt.cpp) into per-axis bias + sensitivity and apply (raw-bias)*sens to the accel the tilt visuals use, keeping the +-8192 == 1g scale. Re-read per connection so it tracks across the 4 pairing slots; sanity-gated with raw fallback. New side-effect-free bt_peek_feature() accessor (never issues an L2CAP request, safe to poll). Parse/apply mirror SDL's SDL_hidapi_ps5.c (zlib). - Centred when flat: drive the dot from X (roll) + Z (pitch) instead of X + Y. Gravity rests on Y when flat, so the old Y mapping pegged the dot to the bottom edge at rest; it now sits centred. - Direction: negate both axes so the dot follows the tilt (tilt left -> dot left, tilt forward -> dot up) instead of mirroring it. Also fold in this session's charge-ETA robustness fix: cap each timed 10% step at 30 min and take the median over the last 5 steps, so one slow step can't balloon the estimate (was reading ~222m at 70% off a single ~47-min step). Shares src/oled.cpp with the gyro work. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
50 lines
1.6 KiB
C++
50 lines
1.6 KiB
C++
//
|
|
// Created by awalol on 2026/3/4.
|
|
//
|
|
|
|
#ifndef DS5_BRIDGE_BT_H
|
|
#define DS5_BRIDGE_BT_H
|
|
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
enum CHANNEL_TYPE {
|
|
INTERRUPT,
|
|
CONTROL
|
|
};
|
|
|
|
typedef void (*bt_data_callback_t)(CHANNEL_TYPE channel, uint8_t *data, uint16_t len);
|
|
|
|
int bt_init();
|
|
void bt_register_data_callback(bt_data_callback_t callback);
|
|
void bt_send_packet(uint8_t *data, uint16_t len);
|
|
void bt_send_control(uint8_t *data, uint16_t len);
|
|
void bt_write(const uint8_t *data, uint16_t len);
|
|
void bt_get_signal_strength(int8_t *rssi);
|
|
std::vector<uint8_t> get_feature_data(uint8_t reportId,uint16_t len);
|
|
// Side-effect-free read of an already-cached feature report (empty vector if it
|
|
// hasn't arrived yet). Unlike get_feature_data(), never issues an L2CAP request,
|
|
// so it is safe to poll every frame — used by the OLED IMU-calibration parse.
|
|
std::vector<uint8_t> bt_peek_feature(uint8_t reportId);
|
|
void init_feature();
|
|
void set_feature_data(uint8_t reportId, uint8_t* data,uint16_t len);
|
|
|
|
// Connection-attempt watchdog: call once per main-loop iteration. Recovers a
|
|
// stalled connection (auto re-inquiry) so a transient RF glitch — e.g. USB 3.0
|
|
// 2.4 GHz interference — doesn't hang the dongle on the amber lightbar.
|
|
void bt_connection_watchdog_tick();
|
|
|
|
// OLED add-on accessors.
|
|
bool bt_is_connected();
|
|
void bt_get_addr(uint8_t out[6]);
|
|
uint32_t bt_hci_err_count();
|
|
|
|
// Multi-slot persistent pairing (Phase G). Modeled on zurce/DS5Dongle-OLED.
|
|
int bt_get_slot();
|
|
void bt_set_slot(int slot);
|
|
void bt_forget_slot(int slot);
|
|
void bt_wipe_all_slots();
|
|
bool bt_slot_occupied(int slot);
|
|
void bt_slot_get_addr(int slot, uint8_t out[6]);
|
|
|
|
#endif //DS5_BRIDGE_BT_H
|