Merge branch 'master' into temp

This commit is contained in:
hathach committed 2023-11-30 16:12:19 +07:00
commit a71a669343
82 files changed
+51936 -51684

No files matched your search

@@ -18,21 +18,33 @@
*/
#include <bluefruit.h>
// Polling or callback implementation
#define POLLING 1
/*
* Polling or callback implementation
* 0 = Request data using a poll
* 1 = Use callbacks
*/
#define POLLING 0
/*
* Device Type flag for use in the example
* Change this if you want to demo the Gamepad!
* 0 = Keyboard + Mouse
* 1 = Gamepad
*/
#define DEVICE_TYPE 0
BLEClientHidAdafruit hid;
// Last checked report, to detect if there is changes between reports
hid_keyboard_report_t last_kbd_report = { 0 };
hid_mouse_report_t last_mse_report = { 0 };
hid_gamepad_report_t last_gpd_report = { 0 };
void setup()
{
Serial.begin(115200);
// while ( !Serial ) delay(10); // for nrf52840 with native usb
Serial.println("Bluefruit52 Central HID (Keyboard + Mouse) Example");
Serial.println("Bluefruit52 Central HID (Keyboard + Mouse + Gamepad) Example");
Serial.println("--------------------------------------------------\n");
// Initialize Bluefruit with maximum connections as Peripheral = 0, Central = 1
@@ -46,6 +58,7 @@ void setup()
#if POLLING == 0
hid.setKeyboardReportCallback(keyboard_report_callback);
hid.setGamepadReportCallback(gamepad_report_callback);
#endif
// Increase Blink rate to different from PrPh advertising mode
@@ -69,7 +82,7 @@ void setup()
Bluefruit.Scanner.restartOnDisconnect(true);
Bluefruit.Scanner.setInterval(160, 80); // in unit of 0.625 ms
Bluefruit.Scanner.filterService(hid); // only report HID service
Bluefruit.Scanner.useActiveScan(false);
Bluefruit.Scanner.useActiveScan(true);
Bluefruit.Scanner.start(0); // 0 = Don't stop scanning after n seconds
}
@@ -137,8 +150,11 @@ void connection_secured_callback(uint16_t conn_handle)
Serial.printf("HID Flags : 0x%02X\n", hidInfo[3]);
// BLEClientHidAdafruit currently only supports Boot Protocol Mode
// for Keyboard and Mouse. Let's set the protocol mode on prph to Boot Mode
// for Keyboard and Mouse. If we are using a Keyboard + Mouse,
// let's set the protocol mode on prph to Boot Mode.
#if DEVICE_TYPE == 0
hid.setBootMode(true);
#endif
// Enable Keyboard report notification if present on prph
if ( hid.keyboardPresent() ) hid.enableKeyboard();
@@ -146,6 +162,9 @@ void connection_secured_callback(uint16_t conn_handle)
// Enable Mouse report notification if present on prph
if ( hid.mousePresent() ) hid.enableMouse();
// Enable Gamepad report notification if present on prph
if ( hid.gamepadPresent() ) hid.enableGamepad();
Serial.println("Ready to receive from peripheral");
}
}
@@ -169,15 +188,26 @@ void loop()
#if POLLING == 1
// nothing to do if hid not discovered
if ( !hid.discovered() ) return;
if ( hid.keyboardPresent() ) {
/*------------- Polling Keyboard -------------*/
hid_keyboard_report_t kbd_report;
/*------------- Polling Keyboard -------------*/
hid_keyboard_report_t kbd_report;
// Get latest report
hid.getKeyboardReport(&kbd_report);
processKeyboardReport(&kbd_report);
// Get latest report
Serial.println("Get report from Keyboard");
hid.getKeyboardReport(&kbd_report);
processKeyboardReport(&kbd_report);
}
if ( hid.gamepadPresent() ) {
/*------------- Polling Gamepad -------------*/
hid_gamepad_report_t gpd_report;
// Get latest report
Serial.println("Get report from Gamepad");
hid.getGamepadReport(&gpd_report);
processGamepadReport(&gpd_report);
}
// polling interval is 5 ms
delay(5);
@@ -186,6 +216,24 @@ void loop()
}
void gamepad_report_callback(hid_gamepad_report_t* report)
{
Serial.println("Recieved report from Gamepad");
processGamepadReport(report);
}
void processGamepadReport(hid_gamepad_report_t* report)
{
memcpy(&last_gpd_report, report, sizeof(hid_gamepad_report_t));
Serial.print("Current Gamepad State: Buttons: ");
Serial.print(report->buttons, BIN);
Serial.print(" X: ");
Serial.print(report->x);
Serial.print(" Y: ");
Serial.println(report->y);
}
void keyboard_report_callback(hid_keyboard_report_t* report)
{
processKeyboardReport(report);
@@ -13,32 +13,34 @@
*********************************************************************/
#include <bluefruit.h>
// Beacon uses the Manufacturer Specific Data field in the advertising
// packet, which means you must provide a valid Manufacturer ID. Update
// Beacon uses the Manufacturer Specific Data field in the advertising packet,
// which means you must provide a valid Manufacturer ID. Update
// the field below to an appropriate value. For a list of valid IDs see:
// https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers
// 0x004C is Apple
// 0x0822 is Adafruit
// 0x0059 is Nordic
// - 0x004C is Apple
// - 0x0822 is Adafruit
// - 0x0059 is Nordic
// For testing with this sketch, you can use nRF Beacon app
// - on Android you may need change the MANUFACTURER_ID to Nordic
// - on iOS you may need to change the MANUFACTURER_ID to Apple.
// You will also need to "Add Other Beacon, then enter Major, Minor that you set in the sketch
#define MANUFACTURER_ID 0x0059
// "nRF Connect" app can be used to detect beacon
uint8_t beaconUuid[16] =
{
uint8_t beaconUuid[16] = {
0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78,
0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0
};
// A valid Beacon packet consists of the following information:
// UUID, Major, Minor, RSSI @ 1M
BLEBeacon beacon(beaconUuid, 0x0102, 0x0304, -54);
BLEBeacon beacon(beaconUuid, 1, 2, -54);
void setup()
{
void setup() {
Serial.begin(115200);
// Uncomment to blocking wait for Serial connection
// while ( !Serial ) delay(10);
// while ( !Serial ) delay(10);
Serial.println("Bluefruit52 Beacon Example");
Serial.println("--------------------------\n");
@@ -55,7 +57,10 @@ void setup()
// Setup the advertising packet
startAdv();
Serial.println("Broadcasting beacon, open your beacon app to test");
Serial.printf("Broadcasting beacon with MANUFACTURER_ID = 0x%04X\n", MANUFACTURER_ID);
Serial.println("open your beacon app to test such as: nRF Beacon");
Serial.println("- on Android you may need to change the MANUFACTURER_ID to 0x0059");
Serial.println("- on iOS you may need to change the MANUFACTURER_ID to 0x004C");
// Suspend Loop() to save power, since we didn't have any code there
suspendLoop();
@@ -78,17 +83,16 @@ void startAdv(void)
* - Start(timeout) with timeout = 0 will advertise forever (until connected)
*
* Apple Beacon specs
* - Type: Non connectable, undirected
* - Type: Non-connectable, scannable, undirected
* - Fixed interval: 100 ms -> fast = slow = 100 ms
*/
//Bluefruit.Advertising.setType(BLE_GAP_ADV_TYPE_ADV_NONCONN_IND);
Bluefruit.Advertising.setType(BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED);
Bluefruit.Advertising.restartOnDisconnect(true);
Bluefruit.Advertising.setInterval(160, 160); // in unit of 0.625 ms
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
}
void loop()
{
void loop() {
// loop is already suspended, CPU will not run loop() at all
}
@@ -42,7 +42,7 @@
BLEAdvertisingData::BLEAdvertisingData(void)
{
_count = 0;
varclr(_data);
arrclr(_data);
}
bool BLEAdvertisingData::addData(uint8_t type, const void* data, uint8_t len)
@@ -242,7 +242,7 @@ bool BLEAdvertisingData::setData(uint8_t const * data, uint8_t count)
void BLEAdvertisingData::clearData(void)
{
_count = 0;
varclr(_data);
arrclr(_data);
}
/*------------------------------------------------------------------*/
@@ -315,6 +315,10 @@ void BLEAdvertising::setStopCallback(stop_callback_t fp)
_stop_cb = fp;
}
void BLEAdvertising::setPeerAddress(const ble_gap_addr_t& peer_addr) {
_peer_addr = peer_addr;
}
bool BLEAdvertising::isRunning(void)
{
return _runnning;
@@ -338,8 +342,7 @@ void BLEAdvertising::restartOnDisconnect(bool enable)
bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout)
{
// ADV Params
ble_gap_adv_params_t adv_para =
{
ble_gap_adv_params_t adv_para = {
.properties = { .type = _type, .anonymous = 0 },
.p_peer_addr = NULL , // Undirected advertisement
.interval = interval , // advertising interval (in units of 0.625 ms)
@@ -354,9 +357,20 @@ bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout)
// , .set_id, .scan_req_notification
};
switch(_type) {
case BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED_HIGH_DUTY_CYCLE:
case BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED:
case BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_DIRECTED:
case BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_SCANNABLE_DIRECTED:
case BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_NONSCANNABLE_DIRECTED:
adv_para.p_peer_addr = &_peer_addr;
break;
default: break;
}
// gap_adv long-live is required by SD v6
static ble_gap_adv_data_t gap_adv =
{
static ble_gap_adv_data_t gap_adv = {
.adv_data = { .p_data = _data, .len = _count },
.scan_rsp_data = { .p_data = Bluefruit.ScanResponse.getData(), .len = Bluefruit.ScanResponse.count() }
};
@@ -464,5 +478,4 @@ void BLEAdvertising::_eventHandler(ble_evt_t* evt)
default: break;
}
}
}
@@ -134,6 +134,9 @@ public:
bool setBeacon(BLEBeacon& beacon);
bool setBeacon(EddyStoneUrl& eddy_url);
// Advertise to a single peer instead of broadcasting
void setPeerAddress(const ble_gap_addr_t& peer_addr);
bool isRunning(void);
void restartOnDisconnect(bool enable);
@@ -152,6 +155,7 @@ private:
uint8_t _type;
bool _start_if_disconnect;
bool _runnning;
ble_gap_addr_t _peer_addr; //! Target address for an ADV_DIRECT_IND advertisement
uint32_t _conn_mask;
@@ -240,6 +240,10 @@ void BLEDiscovery::_eventHandler(ble_evt_t* evt)
LOG_LV2("DISC", "[CHR] Characteristic Count: %d", chr_rsp->count);
for (uint8_t i=0; i < chr_rsp->count; i++) {
LOG_LV2("DISC", "[CHR] Characteristic #%d: 0x%04X", i, chr_rsp->chars[i].uuid.uuid);
}
if (gattc->gatt_status == BLE_GATT_STATUS_SUCCESS)
{
if ( chr_rsp->count )
@@ -101,6 +101,18 @@ class BLEDiscovery
return discoverCharacteristic(conn_handle, chr_arr, arrcount(chr_arr));
}
uint8_t discoverCharacteristic(uint16_t conn_handle, BLEClientCharacteristic& chr1, BLEClientCharacteristic& chr2, BLEClientCharacteristic& chr3, BLEClientCharacteristic& chr4, BLEClientCharacteristic& chr5, BLEClientCharacteristic& chr6, BLEClientCharacteristic& chr7)
{
BLEClientCharacteristic* chr_arr[] = {&chr1, &chr2, &chr3, &chr4, &chr5, &chr6, &chr7};
return discoverCharacteristic(conn_handle, chr_arr, arrcount(chr_arr));
}
uint8_t discoverCharacteristic(uint16_t conn_handle, BLEClientCharacteristic& chr1, BLEClientCharacteristic& chr2, BLEClientCharacteristic& chr3, BLEClientCharacteristic& chr4, BLEClientCharacteristic& chr5, BLEClientCharacteristic& chr6, BLEClientCharacteristic& chr7, BLEClientCharacteristic& chr8)
{
BLEClientCharacteristic* chr_arr[] = {&chr1, &chr2, &chr3, &chr4, &chr5, &chr6, &chr7, &chr8};
return discoverCharacteristic(conn_handle, chr_arr, arrcount(chr_arr));
}
/*------------------------------------------------------------------*/
/* INTERNAL USAGE ONLY
* Although declare as public, it is meant to be invoked by internal
+2
View File
@@ -62,6 +62,7 @@
#include "services/BLEDfu.h"
#include "services/BLEUart.h"
#include "services/BLEBas.h"
#include "services/BLEIas.h"
#include "services/BLEBeacon.h"
#include "services/BLEHidGeneric.h"
#include "services/BLEHidAdafruit.h"
@@ -75,6 +76,7 @@
#include "clients/BLEClientCts.h"
#include "clients/BLEClientHidAdafruit.h"
#include "clients/BLEClientBas.h"
#include "clients/BLEClientIas.h"
#include "utility/AdaCallback.h"
#include "utility/bonding.h"
@@ -41,12 +41,15 @@ BLEClientHidAdafruit::BLEClientHidAdafruit(void)
_protcol_mode(UUID16_CHR_PROTOCOL_MODE),
_hid_info(UUID16_CHR_HID_INFORMATION), _hid_control(UUID16_CHR_HID_CONTROL_POINT),
_kbd_boot_input(UUID16_CHR_BOOT_KEYBOARD_INPUT_REPORT), _kbd_boot_output(UUID16_CHR_BOOT_KEYBOARD_OUTPUT_REPORT),
_mse_boot_input(UUID16_CHR_BOOT_MOUSE_INPUT_REPORT)
_mse_boot_input(UUID16_CHR_BOOT_MOUSE_INPUT_REPORT),
_gpd_report(UUID16_CHR_REPORT)
{
_kbd_cb = NULL;
_mse_cb = NULL;
_gpd_cb = NULL;
varclr(&_last_kbd_report);
varclr(&_last_mse_report);
varclr(&_last_gpd_report);
}
@@ -62,6 +65,12 @@ void mse_client_notify_cb(BLEClientCharacteristic* chr, uint8_t* data, uint16_t
svc._handle_mse_input(data, len);
}
void gpd_client_notify_cb(BLEClientCharacteristic* chr, uint8_t* data, uint16_t len)
{
BLEClientHidAdafruit& svc = (BLEClientHidAdafruit&) chr->parentService();
svc._handle_gpd_input(data, len);
}
bool BLEClientHidAdafruit::begin(void)
{
@@ -77,10 +86,13 @@ bool BLEClientHidAdafruit::begin(void)
_mse_boot_input.begin(this);
_gpd_report.begin(this);
// set notify callback
_kbd_boot_input.setNotifyCallback(kbd_client_notify_cb);
_mse_boot_input.setNotifyCallback(mse_client_notify_cb);
_gpd_report.setNotifyCallback(gpd_client_notify_cb);
return true;
}
@@ -95,6 +107,12 @@ void BLEClientHidAdafruit::setMouseReportCallback(mse_callback_t fp)
_mse_cb = fp;
}
void BLEClientHidAdafruit::setGamepadReportCallback(gpd_callback_t fp)
{
_gpd_cb = fp;
}
bool BLEClientHidAdafruit::discover(uint16_t conn_handle)
{
// Call Base class discover
@@ -102,10 +120,10 @@ bool BLEClientHidAdafruit::discover(uint16_t conn_handle)
_conn_hdl = BLE_CONN_HANDLE_INVALID; // make as invalid until we found all chars
// Discover all characteristics
Bluefruit.Discovery.discoverCharacteristic(conn_handle, _protcol_mode, _kbd_boot_input, _kbd_boot_output, _mse_boot_input, _hid_info, _hid_control);
Bluefruit.Discovery.discoverCharacteristic(conn_handle, _protcol_mode, _kbd_boot_input, _kbd_boot_output, _mse_boot_input, _hid_info, _hid_control, _gpd_report);
VERIFY( _protcol_mode.discovered() && _hid_info.discovered() && _hid_control.discovered() );
VERIFY ( keyboardPresent() || mousePresent() );
VERIFY( _hid_info.discovered() && _hid_control.discovered() );
VERIFY (keyboardPresent() || mousePresent() || gamepadPresent());
_conn_hdl = conn_handle;
return true;
@@ -138,7 +156,7 @@ bool BLEClientHidAdafruit::setBootMode(bool boot)
*------------------------------------------------------------------*/
bool BLEClientHidAdafruit::keyboardPresent(void)
{
return _kbd_boot_input.discovered() && _kbd_boot_output.discovered();
return _kbd_boot_input.discovered() && _kbd_boot_output.discovered() && _protcol_mode.discovered();
}
bool BLEClientHidAdafruit::enableKeyboard(void)
@@ -169,7 +187,7 @@ void BLEClientHidAdafruit::getKeyboardReport(hid_keyboard_report_t* report)
*------------------------------------------------------------------*/
bool BLEClientHidAdafruit::mousePresent(void)
{
return _mse_boot_input.discovered();
return _mse_boot_input.discovered() && _protcol_mode.discovered();
}
bool BLEClientHidAdafruit::enableMouse(void)
@@ -195,3 +213,34 @@ void BLEClientHidAdafruit::getMouseReport(hid_mouse_report_t* report)
memcpy(report, &_last_mse_report, sizeof(hid_mouse_report_t));
}
/*------------------------------------------------------------------*/
/* Gamepad
*------------------------------------------------------------------*/
bool BLEClientHidAdafruit::gamepadPresent(void)
{
return _gpd_report.discovered();
}
bool BLEClientHidAdafruit::enableGamepad(void)
{
return _gpd_report.enableNotify();
}
bool BLEClientHidAdafruit::disableGamepad(void)
{
return _gpd_report.disableNotify();
}
void BLEClientHidAdafruit::_handle_gpd_input(uint8_t* data, uint16_t len)
{
varclr(&_last_gpd_report);
memcpy(&_last_gpd_report, data, len);
if ( _gpd_cb ) _gpd_cb(&_last_gpd_report);
}
void BLEClientHidAdafruit::getGamepadReport(hid_gamepad_report_t* report)
{
memcpy(report, &_last_gpd_report, sizeof(hid_gamepad_report_t));
}
@@ -49,6 +49,7 @@ class BLEClientHidAdafruit : public BLEClientService
// Callback Signatures
typedef void (*kbd_callback_t ) (hid_keyboard_report_t* report);
typedef void (*mse_callback_t ) (hid_mouse_report_t* report);
typedef void (*gpd_callback_t ) (hid_gamepad_report_t* report);
BLEClientHidAdafruit(void);
@@ -74,16 +75,26 @@ class BLEClientHidAdafruit : public BLEClientService
void getMouseReport(hid_mouse_report_t* report);
// Gamepad API
bool gamepadPresent(void);
bool enableGamepad(void);
bool disableGamepad(void);
void getGamepadReport(hid_gamepad_report_t* report);
// Report callback
void setKeyboardReportCallback(kbd_callback_t fp);
void setMouseReportCallback(mse_callback_t fp);
void setGamepadReportCallback(gpd_callback_t fp);
protected:
kbd_callback_t _kbd_cb;
mse_callback_t _mse_cb;
gpd_callback_t _gpd_cb;
hid_keyboard_report_t _last_kbd_report;
hid_mouse_report_t _last_mse_report;
hid_gamepad_report_t _last_gpd_report;
// Only support Boot protocol for keyboard and Mouse
BLEClientCharacteristic _protcol_mode;
@@ -95,11 +106,15 @@ class BLEClientHidAdafruit : public BLEClientService
BLEClientCharacteristic _mse_boot_input;
BLEClientCharacteristic _gpd_report;
void _handle_kbd_input(uint8_t* data, uint16_t len);
void _handle_mse_input(uint8_t* data, uint16_t len);
void _handle_gpd_input(uint8_t* data, uint16_t len);
friend void kbd_client_notify_cb(BLEClientCharacteristic* chr, uint8_t* data, uint16_t len);
friend void mse_client_notify_cb(BLEClientCharacteristic* chr, uint8_t* data, uint16_t len);
friend void gpd_client_notify_cb(BLEClientCharacteristic* chr, uint8_t* data, uint16_t len);
};
@@ -0,0 +1,42 @@
//
// Created by Charlie Bershatsky on 4/19/23.
//
#include "BLEClientIas.h"
#include "bluefruit.h"
BLEClientIas::BLEClientIas() :
BLEClientService(UUID16_SVC_IMMEDIATE_ALERT), _alert(UUID16_SVC_IMMEDIATE_ALERT) {
}
bool BLEClientIas::begin(void) {
// invoke superclass begin()
BLEClientService::begin();
_alert.begin(this);
return true;
}
bool BLEClientIas::discover(uint16_t conn_handle) {
VERIFY(BLEClientService::discover(conn_handle));
_conn_hdl = conn_handle;
return true;
}
uint16_t BLEClientIas::getAlertLevel() {
uint8_t level = 0;
ble_gattc_handle_range_t bck_range = Bluefruit.Discovery.getHandleRange();
_alert.begin(this);
if (Bluefruit.Discovery.discoverCharacteristic(_conn_hdl, _alert)) {
level = _alert.read8();
}
Bluefruit.Discovery.setHandleRange(bck_range);
return level;
}
@@ -0,0 +1,28 @@
//
// Created by Charlie Bershatsky on 4/19/23.
//
#ifndef ADAFRUIT_NRF52_ARDUINO_BLECLIENTIAS_H
#define ADAFRUIT_NRF52_ARDUINO_BLECLIENTIAS_H
#include "bluefruit_common.h"
#include "BLEClientCharacteristic.h"
#include "BLEClientService.h"
class BLEClientIas : public BLEClientService {
public:
BLEClientIas(void);
virtual bool begin(void);
virtual bool discover(uint16_t conn_handle);
uint16_t getAlertLevel (void);
private:
BLEClientCharacteristic _alert;
};
#endif //ADAFRUIT_NRF52_ARDUINO_BLECLIENTIAS_H
@@ -0,0 +1,32 @@
//
// Created by Charlie Bershatsky on 4/19/23.
//
#include "BLEIas.h"
#include "bluefruit.h"
#include "utility/utilities.h"
#include "BLEService.h"
BLEIas::BLEIas(void) :
BLEService(UUID16_SVC_IMMEDIATE_ALERT), _alert(UUID16_SVC_IMMEDIATE_ALERT) {
}
void BLEIas::write(uint8_t alert_level) {
_alert.write8(alert_level);
}
err_t BLEIas::begin(void) {
// Invoke the superclass begin()
VERIFY_STATUS(BLEService::begin());
_alert.setProperties(CHR_PROPS_READ);
_alert.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
_alert.setFixedLen(1);
VERIFY_STATUS( _alert.begin() );
return ERROR_NONE;
}
@@ -0,0 +1,29 @@
//
// Created by Charlie Bershatsky on 4/19/23.
//
#ifndef ADAFRUIT_NRF52_ARDUINO_BLEIAS_H
#define ADAFRUIT_NRF52_ARDUINO_BLEIAS_H
#include "bluefruit_common.h"
#include "BLEService.h"
#include "BLECharacteristic.h"
class BLEIas : public BLEService {
protected:
BLECharacteristic _alert;
public:
BLEIas(void);
void write(uint8_t level);
virtual err_t begin(void);
};
#endif //ADAFRUIT_NRF52_ARDUINO_BLEIAS_H
@@ -41,7 +41,10 @@
#include "bonding.h"
#include "bluefruit.h"
using namespace Adafruit_LittleFS_Namespace;
enum {
FO_READ = Adafruit_LittleFS_Namespace::FILE_O_READ,
FO_WRITE = Adafruit_LittleFS_Namespace::FILE_O_WRITE,
};
#define BOND_DEBUG 1
@@ -68,7 +71,7 @@ static void get_fname (char* fname, uint8_t role, uint8_t const mac[6])
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
static bool bdata_skip_field(File* file)
static bool bdata_skip_field(Adafruit_LittleFS_Namespace::File* file)
{
int len = file->read();
VERIFY(len > 0);
@@ -77,7 +80,7 @@ static bool bdata_skip_field(File* file)
return true;
}
static void bdata_write(File* file, void const* buffer, uint16_t bufsize)
static void bdata_write(Adafruit_LittleFS_Namespace::File* file, void const* buffer, uint16_t bufsize)
{
file->write( (uint8_t) bufsize );
file->write( (uint8_t const*) buffer, bufsize);
@@ -106,7 +109,7 @@ static void bond_save_keys_dfr (uint8_t role, uint16_t conn_hdl, bond_keys_t con
// delete if file already exists
if ( InternalFS.exists(filename) ) InternalFS.remove(filename);
File file(filename, FILE_O_WRITE, InternalFS);
Adafruit_LittleFS_Namespace::File file(filename, FO_WRITE, InternalFS);
VERIFY(file,);
//------------- save keys -------------//
@@ -150,8 +153,8 @@ bool bond_load_keys(uint8_t role, ble_gap_addr_t* addr, bond_keys_t* bkeys)
char filename[BOND_FNAME_LEN];
get_fname(filename, role, addr->addr);
File file(InternalFS);
if( file.open(filename, FILE_O_READ) )
Adafruit_LittleFS_Namespace::File file(InternalFS);
if( file.open(filename, FO_READ) )
{
int keylen = file.read();
if ( keylen > 0 )
@@ -172,10 +175,10 @@ bool bond_load_keys(uint8_t role, ble_gap_addr_t* addr, bond_keys_t* bkeys)
// Resolvable address, we have to go through the whole list to perform IRK Address matching
char const * dpath = (role == BLE_GAP_ROLE_PERIPH ? BOND_DIR_PRPH : BOND_DIR_CNTR);
File dir(dpath, FILE_O_READ, InternalFS);
File file(InternalFS);
Adafruit_LittleFS_Namespace::File dir(dpath, FO_READ, InternalFS);
Adafruit_LittleFS_Namespace::File file(InternalFS);
while ( !ret && (file = dir.openNextFile(FILE_O_READ)) )
while ( !ret && (file = dir.openNextFile(FO_READ)) )
{
int keylen = file.read();
if ( keylen == sizeof(bond_keys_t) )
@@ -217,7 +220,7 @@ static void bond_save_cccd_dfr (uint8_t role, uint16_t conn_hdl, ble_gap_addr_t
char filename[BOND_FNAME_LEN];
get_fname(filename, role, id_addr->addr);
File file(filename, FILE_O_WRITE, InternalFS);
Adafruit_LittleFS_Namespace::File file(filename, FO_WRITE, InternalFS);
VERIFY(file,);
file.seek(0); // write mode start at the end, seek to beginning
@@ -266,7 +269,7 @@ bool bond_load_cccd(uint8_t role, uint16_t conn_hdl, ble_gap_addr_t const* id_ad
char filename[BOND_FNAME_LEN];
get_fname(filename, role, id_addr->addr);
File file(filename, FILE_O_READ, InternalFS);
Adafruit_LittleFS_Namespace::File file(filename, FO_READ, InternalFS);
if ( file )
{
bdata_skip_field(&file); // skip key
@@ -298,10 +301,10 @@ void bond_print_list(uint8_t role)
{
char const * dpath = (role == BLE_GAP_ROLE_PERIPH ? BOND_DIR_PRPH : BOND_DIR_CNTR);
File dir(dpath, FILE_O_READ, InternalFS);
File file(InternalFS);
Adafruit_LittleFS_Namespace::File dir(dpath, FO_READ, InternalFS);
Adafruit_LittleFS_Namespace::File file(InternalFS);
while ( (file = dir.openNextFile(FILE_O_READ)) )
while ( (file = dir.openNextFile(FO_READ)) )
{
if ( !file.isDirectory() && bdata_skip_field(&file) ) // skip key
{
+3 -3
View File
@@ -120,14 +120,14 @@ void SwRotaryEncoder::clearAbs(void)
void SwRotaryEncoder::_irq_handler(void)
{
uint32_t val = NRF_GPIO->IN;
uint8_t bita = bitRead(val, _pina);
uint8_t bita = digitalRead(_pina);
uint8_t bitb = digitalRead(_pinb);
if ( bita != _a_last)
{
int32_t step;
if ( bita != bitRead(val, _pinb) )
if ( bita != bitb )
{
step = 1;
}else