fix ble connection , ok !

This commit is contained in:
feeling001@gmail.com
2026-06-21 11:50:44 +02:00
parent c40d7516b1
commit d44aaa3318
13 changed files with 483 additions and 83 deletions
+10 -1
View File
@@ -67,10 +67,17 @@ public:
void providePasskey(uint32_t pin);
private:
// BLE callback trampolines declared in BleManager.cpp
friend void navNotifyCB(NimBLERemoteCharacteristic*, uint8_t*, size_t, bool);
friend void windNotifyCB(NimBLERemoteCharacteristic*, uint8_t*, size_t, bool);
friend void autopilotNotifyCB(NimBLERemoteCharacteristic*, uint8_t*, size_t, bool);
friend void perfNotifyCB(NimBLERemoteCharacteristic*, uint8_t*, size_t, bool);
friend void adminNotifyCB(NimBLERemoteCharacteristic*, uint8_t*, size_t, bool);
// ── NimBLEClientCallbacks ─────────────────────────────────────────────────
void onConnect(NimBLEClient* pClient) override;
void onDisconnect(NimBLEClient* pClient, int reason) override;
bool onConfirmPasskey(NimBLEConnInfo& connInfo, uint32_t pin) override;
void onConfirmPasskey(NimBLEConnInfo& connInfo, uint32_t pin) override;
void onAuthenticationComplete(NimBLEConnInfo& connInfo) override;
// ── NimBLEScanCallbacks ───────────────────────────────────────────────────
@@ -102,6 +109,8 @@ private:
NimBLEAddress _targetAddr;
bool _targetFound = false;
bool _doConnect = false;
bool _subscribePending = false;
bool _subscribed = false;
uint32_t _reconnectAt = 0; ///< millis() when next reconnect is due
AppState::BleStatus _status = AppState::BleStatus::IDLE;
+17 -8
View File
@@ -26,11 +26,11 @@
// =============================================================================
namespace Pins {
// ── E-Ink display ─────────────────────────────────────────────────────────
constexpr uint8_t EPD_CS = 9; ///< Chip Select
constexpr uint8_t EPD_DC = 8; ///< Data/Command
constexpr uint8_t EPD_RST = 7; ///< Reset
constexpr uint8_t EPD_BUSY = 6; ///< Busy signal (active LOW)
constexpr uint8_t EPD_SCK = 10; ///< SPI clock (HSPI SCK)
constexpr uint8_t EPD_CS = 7; ///< Chip Select
constexpr uint8_t EPD_DC = 6; ///< Data/Command
constexpr uint8_t EPD_RST = 5; ///< Reset
constexpr uint8_t EPD_BUSY = 4; ///< Busy signal (active LOW)
constexpr uint8_t EPD_SCK = 12; ///< SPI clock (HSPI SCK)
constexpr uint8_t EPD_MOSI = 11; ///< SPI MOSI (HSPI MOSI)
// ── Capacitive touch buttons (ESP32-S3 native touch) ─────────────────────
@@ -80,9 +80,18 @@ namespace BleUUID {
// =============================================================================
namespace BleConfig {
constexpr const char* DEVICE_NAME = BLE_DEVICE_NAME;
constexpr uint32_t SCAN_DURATION = 10; ///< seconds per scan window
constexpr uint32_t RECONNECT_MS = 5000; ///< delay before reconnect attempt
constexpr uint32_t STALE_TIMEOUT = 15; ///< seconds before data is marked stale
// Optional fixed BLE address ("aa:bb:cc:dd:ee:ff"). Keep empty to disable.
constexpr const char* TARGET_ADDR = "";
// Fallback name fragment (case-insensitive) for peripherals that do not
// expose the full local name in every advertisement packet.
constexpr const char* NAME_FALLBACK = "MarineGateway";
// Some firmwares expose only a 16-bit service UUID in advertising payload.
// 0xFE9F observed in field logs.
constexpr uint16_t FALLBACK_SVC16 = 0xFE9F;
constexpr uint32_t DEFAULT_PASSKEY = 123456; ///< default pairing PIN used if UI has not overridden it
constexpr uint32_t SCAN_DURATION = 10000; ///< scan window in milliseconds
constexpr uint32_t RECONNECT_MS = 5000; ///< delay before reconnect attempt
constexpr uint32_t STALE_TIMEOUT = 15; ///< seconds before data is marked stale
}
// =============================================================================
+9 -8
View File
@@ -23,10 +23,11 @@
#include <Fonts/FreeMonoBold12pt7b.h>
#include <Fonts/FreeMono9pt7b.h>
// ── Display model — Waveshare 4.2" mono GDEY042T81 (400×300) ─────────────────
// Adjust the model constant if your display differs.
using DisplayType = GxEPD2_BW<GxEPD2_420_GDEY042T81,
GxEPD2_420_GDEY042T81::HEIGHT>;
// ── Display model — match the validated reference sketch for the 4.2" panel.
// The generic 420 driver is used here to avoid a controller mismatch that can
// leave the panel completely blank during init.
using DisplayType = GxEPD2_BW<GxEPD2_420,
GxEPD2_420::HEIGHT>;
class DisplayManager {
public:
@@ -70,10 +71,10 @@ public:
private:
DisplayType _display {
GxEPD2_420_GDEY042T81(Pins::EPD_CS,
Pins::EPD_DC,
Pins::EPD_RST,
Pins::EPD_BUSY)
GxEPD2_420(Pins::EPD_CS,
Pins::EPD_DC,
Pins::EPD_RST,
Pins::EPD_BUSY)
};
bool _initialised = false;
+4 -3
View File
@@ -35,6 +35,7 @@ public:
private:
// Per-pad state machine
struct PadState {
explicit PadState(uint8_t p = 0) : pin(p) {}
uint8_t pin;
bool wasDown = false;
uint32_t pressedAt = 0;
@@ -42,9 +43,9 @@ private:
};
PadState _pads[3] = {
{Pins::TOUCH_NEXT},
{Pins::TOUCH_PREV},
{Pins::TOUCH_ACTION}
PadState(Pins::TOUCH_NEXT),
PadState(Pins::TOUCH_PREV),
PadState(Pins::TOUCH_ACTION)
};
uint32_t _lastDebounce = 0;