Bluetooth (#518)
* Bluetooth LE addition * fixes * use the psram! helps a little on S3 (t-deck) * custom device name * Update symbols.c * Feedback + fixes Fixes external app start/stop server (child devices) Fixes BtManage causing a full system hang upon disabling bt when a device is connected to the host. * updoot * more updoot * move back! * Revert "move back!" This reverts commit d3694365c634acc5db62ac59771c496cb971a727. * fix some of the things * Addressing feedback? hmm * Fixes Bug 1 — Reconnect loop / Reconnect not working fixed Bug 2 — Name-only advertising overwrites HID advertising Bug 3 — BleHidDeviceCtx leak on re-enable Enhancement — HID device auto-start on radio re-enable * stuff... * update for consistency with others * fix crashes and some bonus symbols * a few symbols, i2c speed, cdn message 100kHz i2c speed seems to be more compatible with m5stack modules...and probably in general. cdn message no longer applies * Hide BT Settings when bt not enabled * Addressing things and device fixes * Missed one! * stuff
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
namespace tt::app::btmanage {
|
||||
|
||||
typedef void (*OnBtToggled)(bool enable);
|
||||
typedef void (*OnScanToggled)(bool enable);
|
||||
typedef void (*OnConnectPeer)(const std::array<uint8_t, 6>& addr, int profileId);
|
||||
typedef void (*OnDisconnectPeer)(const std::array<uint8_t, 6>& addr, int profileId);
|
||||
typedef void (*OnPairPeer)(const std::array<uint8_t, 6>& addr);
|
||||
typedef void (*OnForgetPeer)(const std::array<uint8_t, 6>& addr);
|
||||
|
||||
struct Bindings {
|
||||
OnBtToggled onBtToggled;
|
||||
OnScanToggled onScanToggled;
|
||||
OnConnectPeer onConnectPeer;
|
||||
OnDisconnectPeer onDisconnectPeer;
|
||||
OnPairPeer onPairPeer;
|
||||
OnForgetPeer onForgetPeer;
|
||||
};
|
||||
|
||||
} // namespace tt::app::btmanage
|
||||
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "./View.h"
|
||||
#include "./State.h"
|
||||
|
||||
#include <Tactility/app/App.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <Tactility/bluetooth/Bluetooth.h>
|
||||
#include <tactility/drivers/bluetooth.h>
|
||||
|
||||
namespace tt::app::btmanage {
|
||||
|
||||
class BtManage final : public App {
|
||||
|
||||
Mutex mutex;
|
||||
Bindings bindings = { };
|
||||
State state;
|
||||
View view = View(&bindings, &state);
|
||||
bool isViewEnabled = false;
|
||||
struct Device* btDevice = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
void onBtEvent(const struct BtEvent& event);
|
||||
|
||||
BtManage();
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override;
|
||||
void onHide(AppContext& app) override;
|
||||
|
||||
Bindings& getBindings() { return bindings; }
|
||||
State& getState() { return state; }
|
||||
|
||||
void requestViewUpdate();
|
||||
};
|
||||
|
||||
} // namespace tt::app::btmanage
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/bluetooth/Bluetooth.h>
|
||||
#include <Tactility/RecursiveMutex.h>
|
||||
|
||||
namespace tt::app::btmanage {
|
||||
|
||||
class State final {
|
||||
|
||||
mutable RecursiveMutex mutex;
|
||||
bool scanning = false;
|
||||
bluetooth::RadioState radioState = bluetooth::RadioState::Off;
|
||||
std::vector<bluetooth::PeerRecord> scanResults;
|
||||
std::vector<bluetooth::PeerRecord> pairedPeers;
|
||||
|
||||
public:
|
||||
State() = default;
|
||||
|
||||
void setScanning(bool isScanning);
|
||||
bool isScanning() const;
|
||||
|
||||
void setRadioState(bluetooth::RadioState state);
|
||||
bluetooth::RadioState getRadioState() const;
|
||||
|
||||
void updateScanResults();
|
||||
void updatePairedPeers();
|
||||
|
||||
std::vector<bluetooth::PeerRecord> getScanResults() const {
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
return scanResults;
|
||||
}
|
||||
|
||||
std::vector<bluetooth::PeerRecord> getPairedPeers() const {
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
return pairedPeers;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace tt::app::btmanage
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include "./Bindings.h"
|
||||
#include "./State.h"
|
||||
|
||||
#include <Tactility/app/AppContext.h>
|
||||
#include <Tactility/app/AppPaths.h>
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
namespace tt::app::btmanage {
|
||||
|
||||
class View final {
|
||||
|
||||
Bindings* bindings;
|
||||
State* state;
|
||||
std::unique_ptr<AppPaths> paths;
|
||||
lv_obj_t* root = nullptr;
|
||||
lv_obj_t* enable_switch = nullptr;
|
||||
lv_obj_t* enable_on_boot_switch = nullptr;
|
||||
lv_obj_t* scanning_spinner = nullptr;
|
||||
lv_obj_t* peers_list = nullptr;
|
||||
|
||||
void updateBtToggle();
|
||||
void updateEnableOnBootToggle();
|
||||
void updateScanning();
|
||||
void updatePeerList();
|
||||
|
||||
void createPeerListItem(const bluetooth::PeerRecord& record, bool isPaired, size_t index);
|
||||
|
||||
static void onConnect(lv_event_t* event);
|
||||
|
||||
public:
|
||||
|
||||
View(Bindings* bindings, State* state) : bindings(bindings), state(state) {}
|
||||
|
||||
void init(const AppContext& app, lv_obj_t* parent);
|
||||
void update();
|
||||
};
|
||||
|
||||
} // namespace tt::app::btmanage
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace tt::app::btpeersettings {
|
||||
|
||||
void start(const std::string& addrHex);
|
||||
|
||||
} // namespace tt::app::btpeersettings
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/bluetooth/Bluetooth.h>
|
||||
|
||||
#include <tactility/drivers/bluetooth.h>
|
||||
|
||||
struct Device;
|
||||
|
||||
namespace tt::bluetooth {
|
||||
|
||||
/** Cache a BLE address and its type from a scan result (used by HID host for addr_type lookup). */
|
||||
void cacheScanAddr(const uint8_t addr[6], uint8_t addr_type);
|
||||
|
||||
/**
|
||||
* Look up the ble_addr_t (including address type) for a peer address in the last scan.
|
||||
* Returns false and fills type=0 (PUBLIC) if not found.
|
||||
*/
|
||||
bool getCachedScanAddrType(const uint8_t addr[6], uint8_t* addr_type_out);
|
||||
|
||||
/** Called from BluetoothHidHost.cpp to trigger auto-connect check after scan finishes. */
|
||||
void autoConnectHidHost();
|
||||
|
||||
/**
|
||||
* Returns the BLE address of the currently fully-connected HID host peer (i.e.
|
||||
* all CCCDs subscribed and ready). Returns false if no HID host peer is connected.
|
||||
*/
|
||||
bool hidHostGetConnectedPeer(std::array<uint8_t, 6>& addr_out);
|
||||
|
||||
} // namespace tt::bluetooth
|
||||
Reference in New Issue
Block a user