added connected/disconnected events
This commit is contained in:
parent
ebc5cce602
commit
c6b246f9dd
|
|
@ -7,6 +7,9 @@
|
|||
#include "utility/BleMidi_Settings.h"
|
||||
#include "utility/BleMidi_Defs.h"
|
||||
|
||||
#define SERVICE_UUID "03b80e5a-ede8-4b33-a751-6ce34ec4c700"
|
||||
#define CHARACTERISTIC_UUID "7772e5db-3868-4112-a1a9-f2669d106bf3"
|
||||
|
||||
#if defined(ESP32)
|
||||
#include "Ble_esp32.h"
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,38 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
// Headers for ESP32 BLE
|
||||
#include <BLEDevice.h>
|
||||
#include <BLEUtils.h>
|
||||
#include <BLEServer.h>
|
||||
|
||||
#define SERVICE_UUID "03b80e5a-ede8-4b33-a751-6ce34ec4c700"
|
||||
#define CHARACTERISTIC_UUID "7772e5db-3868-4112-a1a9-f2669d106bf3"
|
||||
|
||||
BEGIN_BLEMIDI_NAMESPACE
|
||||
|
||||
class BleMidiInterface;
|
||||
|
||||
class MyServerCallbacks: public BLEServerCallbacks {
|
||||
public:
|
||||
MyServerCallbacks(BleMidiInterface* bleMidiInterface) {
|
||||
_bleMidiInterface = bleMidiInterface;
|
||||
}
|
||||
protected:
|
||||
BleMidiInterface* _bleMidiInterface;
|
||||
|
||||
void onConnect(BLEServer* pServer) {
|
||||
// _bleMidiInterface->mConnectedCallback();
|
||||
};
|
||||
|
||||
void onDisconnect(BLEServer* pServer) {
|
||||
// _bleMidiInterface->mDisconnectedCallback();
|
||||
}
|
||||
};
|
||||
|
||||
class MyCallbacks: public BLECharacteristicCallbacks {
|
||||
void onWrite(BLECharacteristic *pCharacteristic) {
|
||||
}
|
||||
};
|
||||
|
||||
class BleMidiInterface
|
||||
{
|
||||
protected:
|
||||
|
|
@ -41,6 +15,7 @@ protected:
|
|||
BLEAdvertising *pAdvertising;
|
||||
BLECharacteristic *pCharacteristic;
|
||||
|
||||
public:
|
||||
void(*mConnectedCallback)();
|
||||
void(*mDisconnectedCallback)();
|
||||
|
||||
|
|
@ -55,7 +30,39 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
inline bool begin(const char* deviceName)
|
||||
inline bool begin(const char* deviceName);
|
||||
|
||||
inline void onConnected(void(*fptr)()) {
|
||||
mConnectedCallback = fptr;
|
||||
}
|
||||
inline void onDisconnected(void(*fptr)()) {
|
||||
mDisconnectedCallback = fptr;
|
||||
}
|
||||
};
|
||||
|
||||
class MyServerCallbacks: public BLEServerCallbacks {
|
||||
public:
|
||||
MyServerCallbacks(BleMidiInterface* bleMidiInterface) {
|
||||
_bleMidiInterface = bleMidiInterface;
|
||||
}
|
||||
protected:
|
||||
BleMidiInterface* _bleMidiInterface;
|
||||
|
||||
void onConnect(BLEServer* pServer) {
|
||||
_bleMidiInterface->mConnectedCallback();
|
||||
};
|
||||
|
||||
void onDisconnect(BLEServer* pServer) {
|
||||
_bleMidiInterface->mDisconnectedCallback();
|
||||
}
|
||||
};
|
||||
|
||||
class MyCallbacks: public BLECharacteristicCallbacks {
|
||||
void onWrite(BLECharacteristic *pCharacteristic) {
|
||||
}
|
||||
};
|
||||
|
||||
bool BleMidiInterface::begin(const char* deviceName)
|
||||
{
|
||||
BLEDevice::init(deviceName);
|
||||
|
||||
|
|
@ -90,12 +97,4 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
inline void onConnected(void(*fptr)()) {
|
||||
mConnectedCallback = fptr;
|
||||
}
|
||||
inline void onDisconnected(void(*fptr)()) {
|
||||
mDisconnectedCallback = fptr;
|
||||
}
|
||||
};
|
||||
|
||||
END_BLEMIDI_NAMESPACE
|
||||
|
|
|
|||
Loading…
Reference in New Issue