mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 22:57:50 +03:00
build fixes and others
This commit is contained in:
parent
05a9102441
commit
97c0af702b
@ -11,7 +11,7 @@ framework = arduino
|
||||
monitor_speed = 115200
|
||||
upload_speed = 921600
|
||||
check_tool = cppcheck
|
||||
check_flags = --enable=all --suppress=missingIncludeSystem --suppress=unusedFunction --suppress=unmatchedSuppression --suppress=*:*/.pio/* --inline-suppr
|
||||
check_flags = --enable=all --suppress=missingIncludeSystem --suppress=missingInclude --suppress=unusedFunction --suppress=unmatchedSuppression --suppress=*:*/.pio/* --inline-suppr
|
||||
check_skip_packages = yes
|
||||
|
||||
board_upload.flash_size = 16MB
|
||||
|
||||
@ -1,6 +1,18 @@
|
||||
#include "BLEKeyboardHandler.h"
|
||||
|
||||
// Platform-specific includes
|
||||
#ifdef ARDUINO
|
||||
#include "Arduino.h"
|
||||
#include "MappedInputManager.h"
|
||||
#else
|
||||
// For static analysis, provide minimal declarations
|
||||
extern "C" {
|
||||
unsigned long millis();
|
||||
int ESP_getFreeHeap();
|
||||
void Serial_printf(const char* format, ...);
|
||||
}
|
||||
#define Serial Serial_printf
|
||||
#endif
|
||||
|
||||
// Static instance definition
|
||||
BLEKeyboardHandler BLEKeyboardHandler::instance;
|
||||
@ -16,23 +28,20 @@ bool BLEKeyboardHandler::initialize(NimBLEServer* server) {
|
||||
try {
|
||||
pServer = server;
|
||||
|
||||
// Create HID device
|
||||
pHidDevice = new NimBLEHIDDevice(pServer);
|
||||
|
||||
// Setup HID descriptor
|
||||
if (!setupHidDescriptor()) {
|
||||
Serial.printf("[%lu] [KBD] Failed to setup HID descriptor\n", millis());
|
||||
delete pHidDevice;
|
||||
pHidDevice = nullptr;
|
||||
// Create custom keyboard service
|
||||
pService = pServer->createService("12345678-1234-1234-1234-123456789abc");
|
||||
if (!pService) {
|
||||
Serial.printf("[%lu] [KBD] Failed to create service\n", millis());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get input characteristic
|
||||
pInputCharacteristic = pHidDevice->inputReport();
|
||||
// Create input characteristic
|
||||
pInputCharacteristic = pService->createCharacteristic(
|
||||
"87654321-4321-4321-4321-cba987654321",
|
||||
NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::NOTIFY
|
||||
);
|
||||
if (!pInputCharacteristic) {
|
||||
Serial.printf("[%lu] [KBD] Failed to get input characteristic\n", millis());
|
||||
delete pHidDevice;
|
||||
pHidDevice = nullptr;
|
||||
Serial.printf("[%lu] [KBD] Failed to create input characteristic\n", millis());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -5,9 +5,11 @@
|
||||
|
||||
// Forward declarations for conditional compilation
|
||||
#ifdef CONFIG_BT_ENABLED
|
||||
#include <NimBLEHIDDevice.h>
|
||||
#include <NimBLEServer.h>
|
||||
#include <NimBLEHID.h>
|
||||
#include <NimBLECharacteristic.h>
|
||||
#include <NimBLEService.h>
|
||||
#include <NimBLEHIDDevice.h>
|
||||
#include <HIDKeyboardTypes.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -33,10 +35,10 @@ private:
|
||||
uint32_t lastActivityTime = 0;
|
||||
|
||||
#ifdef CONFIG_BT_ENABLED
|
||||
// BLE HID components (only allocated when needed)
|
||||
NimBLEHIDDevice* pHidDevice = nullptr;
|
||||
NimBLECharacteristic* pInputCharacteristic = nullptr;
|
||||
// BLE components (only allocated when needed)
|
||||
NimBLEServer* pServer = nullptr;
|
||||
NimBLEService* pService = nullptr;
|
||||
NimBLECharacteristic* pInputCharacteristic = nullptr;
|
||||
|
||||
// Keyboard report buffer (minimal size for our needs)
|
||||
uint8_t keyboardReport[8] = {0};
|
||||
@ -58,7 +60,7 @@ public:
|
||||
static BLEKeyboardHandler& getInstance() { return instance; }
|
||||
|
||||
/**
|
||||
* Initialize BLE HID Keyboard service
|
||||
* Initialize BLE Keyboard service
|
||||
* @param server Pointer to existing BLE server
|
||||
* @return true if initialization successful
|
||||
*/
|
||||
@ -131,9 +133,9 @@ private:
|
||||
*/
|
||||
class KeyboardCallbacks : public NimBLECharacteristicCallbacks {
|
||||
public:
|
||||
void onWrite(NimBLECharacteristic* pCharacteristic) override;
|
||||
void onSubscribe(NimBLECharacteristic* pCharacteristic, ble_gap_conn_desc* desc) override;
|
||||
void onUnsubscribe(NimBLECharacteristic* pCharacteristic, ble_gap_conn_desc* desc) override;
|
||||
void onWrite(NimBLECharacteristic* pCharacteristic);
|
||||
void onSubscribe(NimBLECharacteristic* pCharacteristic, ble_gap_conn_desc* desc);
|
||||
void onUnsubscribe(NimBLECharacteristic* pCharacteristic, ble_gap_conn_desc* desc);
|
||||
};
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -1,6 +1,19 @@
|
||||
#include "BluetoothManager.h"
|
||||
#include "BLEKeyboardHandler.h"
|
||||
|
||||
// Platform-specific includes
|
||||
#ifdef ARDUINO
|
||||
#include <Arduino.h>
|
||||
#include "CrossPointSettings.h"
|
||||
#else
|
||||
// For static analysis, provide minimal declarations
|
||||
extern "C" {
|
||||
unsigned long millis();
|
||||
int ESP_getFreeHeap();
|
||||
void Serial_printf(const char* format, ...);
|
||||
}
|
||||
#define Serial Serial_printf
|
||||
#endif
|
||||
|
||||
// Static instance definition
|
||||
BluetoothManager BluetoothManager::instance;
|
||||
@ -167,7 +180,7 @@ bool BluetoothManager::createServer() {
|
||||
pServer->setCallbacks(new ServerCallbacks());
|
||||
|
||||
// Initialize keyboard handler if enabled
|
||||
if (SETTINGS.bluetoothKeyboardEnabled == CrossPointSettings::BLUETOOTH_KEYBOARD_MODE::ENABLED) {
|
||||
if (SETTINGS.bluetoothKeyboardEnabled == CrossPointSettings::BLUETOOTH_KEYBOARD_MODE::KBD_ENABLED) {
|
||||
pKeyboardHandler = new BLEKeyboardHandler();
|
||||
if (!pKeyboardHandler->initialize(pServer)) {
|
||||
Serial.printf("[%lu] [BLE] Failed to initialize keyboard handler\n", millis());
|
||||
|
||||
@ -62,7 +62,7 @@ class CrossPointSettings {
|
||||
enum BLUETOOTH_MODE { OFF = 0, ON = 1 };
|
||||
|
||||
// Bluetooth keyboard mode settings
|
||||
enum BLUETOOTH_KEYBOARD_MODE { DISABLED = 0, ENABLED = 1 };
|
||||
enum BLUETOOTH_KEYBOARD_MODE { KBD_DISABLED = 0, KBD_ENABLED = 1 };
|
||||
|
||||
// Sleep screen settings
|
||||
uint8_t sleepScreen = DARK;
|
||||
@ -103,7 +103,7 @@ class CrossPointSettings {
|
||||
// Bluetooth enabled setting
|
||||
uint8_t bluetoothEnabled = OFF;
|
||||
// Bluetooth keyboard enabled setting
|
||||
uint8_t bluetoothKeyboardEnabled = DISABLED;
|
||||
uint8_t bluetoothKeyboardEnabled = KBD_DISABLED;
|
||||
|
||||
~CrossPointSettings() = default;
|
||||
|
||||
|
||||
@ -166,7 +166,7 @@ void SettingsActivity::enterCategory(int categoryIndex) {
|
||||
}
|
||||
}
|
||||
} else if (strcmp(setting.name, "Bluetooth Keyboard") == 0) {
|
||||
if (newValue == CrossPointSettings::BLUETOOTH_KEYBOARD_MODE::ENABLED) {
|
||||
if (newValue == CrossPointSettings::BLUETOOTH_KEYBOARD_MODE::KBD_ENABLED) {
|
||||
// Enable keyboard requires Bluetooth to be on
|
||||
if (!BLUETOOTH_MANAGER.isInitialized()) {
|
||||
// Force Bluetooth on first
|
||||
@ -174,7 +174,7 @@ void SettingsActivity::enterCategory(int categoryIndex) {
|
||||
if (!BLUETOOTH_MANAGER.initialize()) {
|
||||
// Failed, revert both to OFF
|
||||
SETTINGS.bluetoothEnabled = CrossPointSettings::BLUETOOTH_MODE::OFF;
|
||||
SETTINGS.*(setting.valuePtr) = CrossPointSettings::BLUETOOTH_KEYBOARD_MODE::DISABLED;
|
||||
SETTINGS.*(setting.valuePtr) = CrossPointSettings::BLUETOOTH_KEYBOARD_MODE::KBD_DISABLED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user