mirror of
https://github.com/Smartphone-Companions/ESP32-ANCS-Notifications.git
synced 2025-01-22 11:28:29 +00:00
Added some non-working code to the example app, with the API calls that will be used once the library is built.
This commit is contained in:
parent
fcc498ff28
commit
bccb3ea28a
79
examples/Connection/ble_connection.ino
Normal file
79
examples/Connection/ble_connection.ino
Normal file
@ -0,0 +1,79 @@
|
||||
// @author James Hudson bugs.feedback.whatever@gmail.com
|
||||
// @todo license text and header - please see github project for license
|
||||
|
||||
// You will need to add these hardware buttons
|
||||
#define BUTTON_A 4 // left button
|
||||
#define BUTTON_B 7 // center switch
|
||||
#define BUTTON_C 5 // right button
|
||||
|
||||
|
||||
BLENotifications notifications;;
|
||||
|
||||
void setup() {
|
||||
// Button configuration
|
||||
pinMode(BUTTON_A, INPUT_PULLUP);
|
||||
pinMode(BUTTON_B, INPUT_PULLUP);
|
||||
pinMode(BUTTON_C, INPUT_PULLUP);
|
||||
|
||||
Serial.begin(115200);
|
||||
while(!Serial) {
|
||||
delay(10);
|
||||
}
|
||||
|
||||
Serial.println("BLENotifications BLE ANCS on ESP32 Example");
|
||||
Serial.println("------------------------------------------");
|
||||
|
||||
notifications.begin()
|
||||
notifications.setName("deviceName");
|
||||
notifications.setConnectCallback(connect_callback);
|
||||
notifications.setDisconnectCallback(disconnect_callback);
|
||||
notifications.setNotificationCallback(notification_callback);
|
||||
}
|
||||
|
||||
void notification_callback(AncsNotification_t* notif)
|
||||
{
|
||||
Serial.println("Got notifications");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback invoked when a BLE connection is made.
|
||||
*/
|
||||
void connect_callback(uint16_t conn_handle)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback invoked when a connection is dropped
|
||||
* @param conn_handle
|
||||
* @param reason is a BLE_HCI_STATUS_CODE which can be found in ble_hci.h
|
||||
*/
|
||||
void disconnect_callback(uint16_t conn_handle, uint8_t reason)
|
||||
{
|
||||
(void) reason;
|
||||
|
||||
Serial.println();
|
||||
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
if (BLENotifications.numPending == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkButtons();
|
||||
|
||||
notifications.actionPositive();
|
||||
notifications.actionNegative();
|
||||
}
|
||||
|
||||
/*
|
||||
X- Connect/Disconnect
|
||||
X- Set Name of Peripheral
|
||||
X- Notification added
|
||||
- Notification removed
|
||||
- Notification Attributes
|
||||
- Perform Notification Actions (positive or negative)
|
||||
*/
|
Loading…
Reference in New Issue
Block a user