added first device: esp32

This commit is contained in:
lathoub 2018-10-24 00:13:43 +02:00
parent f5ac29968e
commit ebc5cce602
6 changed files with 134 additions and 38 deletions

View File

@ -1,6 +1,9 @@
// Select your device
#define ESP32
#include "BleMidi.h"
BLEMIDI_CREATE_INSTANCE(BLEMIDI);
BLEMIDI_CREATE_INSTANCE(bm);
// -----------------------------------------------------------------------------
//
@ -13,6 +16,11 @@ void setup()
; // wait for serial port to connect. Needed for Leonardo only
}
bm.begin("hehe");
bm.onConnected(OnBleMidiConnected);
bm.onDisconnected(OnBleMidiDisconnected);
Serial.print(F("Getting IP address..."));
}
@ -23,3 +31,21 @@ void loop()
{
}
// ====================================================================================
// Event handlers for incoming MIDI messages
// ====================================================================================
// -----------------------------------------------------------------------------
// rtpMIDI session. Device connected
// -----------------------------------------------------------------------------
void OnBleMidiConnected() {
Serial.print(F("Connected"));
}
// -----------------------------------------------------------------------------
// rtpMIDI session. Device disconnected
// -----------------------------------------------------------------------------
void OnBleMidiDisconnected() {
Serial.println(F("Disconnected"));
}

View File

@ -4,24 +4,9 @@
#pragma once
#include "utility/BleMidi_Settings.h"
#include "utility/BleMidi_Defs.h"
BEGIN_BLEMIDI_NAMESPACE
/*! \brief The main class for AppleMidiInterface handling.\n
See member descriptions to know how to use it,
or check out the examples supplied with the library.
*/
class BleMidiInterface
{
public:
// Constructor and Destructor
inline BleMidiInterface();
inline ~BleMidiInterface();
};
END_BLEMIDI_NAMESPACE
// -----------------------------------------------------------------------------
#include "BleMidi.hpp"
#if defined(ESP32)
#include "Ble_esp32.h"
#endif

View File

@ -1,16 +0,0 @@
BEGIN_BLEMIDI_NAMESPACE
/*! \brief Default constructor for MIDI_Class. */
inline BleMidiInterface::BleMidiInterface()
{
}
/*! \brief Default destructor for MIDI_Class.
This is not really useful for the Arduino, as it is never called...
*/
inline BleMidiInterface::~BleMidiInterface()
{
}
END_BLEMIDI_NAMESPACE

101
src/Ble_esp32.h Normal file
View File

@ -0,0 +1,101 @@
#pragma once
#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:
// ESP32
BLEServer *pServer;
BLEAdvertising *pAdvertising;
BLECharacteristic *pCharacteristic;
void(*mConnectedCallback)();
void(*mDisconnectedCallback)();
public:
inline BleMidiInterface()
{
mConnectedCallback = NULL;
mDisconnectedCallback = NULL;
}
inline ~BleMidiInterface()
{
}
inline bool begin(const char* deviceName)
{
BLEDevice::init(deviceName);
pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks(this));
// Create the BLE Service
BLEService* pService = pServer->createService(BLEUUID(SERVICE_UUID));
// Create a BLE Characteristic
pCharacteristic = pService->createCharacteristic(
BLEUUID(CHARACTERISTIC_UUID),
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE |
BLECharacteristic::PROPERTY_NOTIFY |
BLECharacteristic::PROPERTY_WRITE_NR
);
pCharacteristic->setCallbacks(new MyCallbacks());
// Start the service
pService->start();
BLEAdvertisementData advertisementData = BLEAdvertisementData();
advertisementData.setFlags(0x04);
advertisementData.setCompleteServices(BLEUUID(SERVICE_UUID));
advertisementData.setName(deviceName);
// Start advertising
pAdvertising = pServer->getAdvertising();
pAdvertising->setAdvertisementData(advertisementData);
pAdvertising->start();
return true;
}
inline void onConnected(void(*fptr)()) {
mConnectedCallback = fptr;
}
inline void onDisconnected(void(*fptr)()) {
mDisconnectedCallback = fptr;
}
};
END_BLEMIDI_NAMESPACE

BIN
src/utility/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -19,9 +19,9 @@ BEGIN_BLEMIDI_NAMESPACE
BLEMIDI_NAMESPACE::BleMidiInterface Name;
/*! \brief Create an instance of the library with EnternetUDP.
/*! \brief
*/
#define BLEMIDI_CREATE_DEFAULT_INSTANCE() \
BLEMIDI_CREATE_INSTANCE(BleMIDI);
BLEMIDI_CREATE_INSTANCE(bm);
END_BLEMIDI_NAMESPACE