feat: Basic read/write characteristic
This commit is contained in:
2
driver.h
Normal file
2
driver.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#define BOARD_SCREEN_COMBO 505 // 1.54 inch monochrome ePaper Screen
|
||||
#define USE_XIAO_EPAPER_BREAKOUT_BOARD
|
||||
114
scoobytag.ino
Normal file
114
scoobytag.ino
Normal file
@@ -0,0 +1,114 @@
|
||||
|
||||
#include <bluefruit.h>
|
||||
|
||||
#include "TFT_eSPI.h"
|
||||
|
||||
#define SCBT_BLUETOOTH_PIN "123456"
|
||||
|
||||
// 69420 ... ... 42069
|
||||
// 00010F2C-DEAD-BEEF-A455-DEAD69BEEF69
|
||||
const uint8_t SCBT_UUID_SERVICE[] =
|
||||
{
|
||||
0x69, 0xEF, 0xBE, 0x69, 0xAD, 0xDE, 0x55, 0xA4,
|
||||
0xEF, 0xBE, 0xAD, 0xDE, 0x2C, 0x0F, 0x01, 0x00
|
||||
};
|
||||
// 00010F2D-DEAD-BEEF-A455-DEAD69BEEF69
|
||||
const uint8_t SCBT_UUID_CHR_PET[] =
|
||||
{
|
||||
0x69, 0xEF, 0xBE, 0x69, 0xAD, 0xDE, 0x55, 0xA4,
|
||||
0xEF, 0xBE, 0xAD, 0xDE, 0x2D, 0x0F, 0x01, 0x00
|
||||
};
|
||||
|
||||
BLEService scbtSvc(SCBT_UUID_SERVICE);
|
||||
BLECharacteristic scbtPet(SCBT_UUID_CHR_PET);
|
||||
|
||||
EPaper epaper;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
pinMode(LED_GREEN, OUTPUT);
|
||||
pinMode(LED_RED, OUTPUT);
|
||||
|
||||
epaper.begin();
|
||||
epaper.fillScreen(TFT_WHITE);
|
||||
epaper.drawFastHLine(0, 0, 32, TFT_BLACK);
|
||||
epaper.drawRect(19, 19, 102, 22, TFT_BLACK);
|
||||
epaper.update();
|
||||
epaper.setTextSize(2);
|
||||
|
||||
// Init as peripheral
|
||||
Bluefruit.begin(1, 0);
|
||||
Bluefruit.setTxPower(4);
|
||||
Bluefruit.autoConnLed(false);
|
||||
Bluefruit.Security.setPIN(SCBT_BLUETOOTH_PIN);
|
||||
Bluefruit.Periph.setConnectCallback(connectCallback);
|
||||
Bluefruit.Periph.setDisconnectCallback(diconnectCallback);
|
||||
|
||||
// Init service
|
||||
scbtSvc.begin();
|
||||
|
||||
// Init pet
|
||||
scbtPet.setProperties(CHR_PROPS_WRITE | CHR_PROPS_READ);
|
||||
scbtPet.setPermission(SECMODE_OPEN, SECMODE_OPEN);
|
||||
scbtPet.setFixedLen(4);
|
||||
scbtPet.begin();
|
||||
scbtPet.setWriteCallback(scbtPetWriteCallback);
|
||||
|
||||
// Setup advertising
|
||||
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
||||
Bluefruit.Advertising.addTxPower();
|
||||
|
||||
// Add service
|
||||
Bluefruit.Advertising.addService(scbtSvc);
|
||||
|
||||
// Set name for secondary scan response
|
||||
Bluefruit.setName("Scbt");
|
||||
Bluefruit.Advertising.addName();
|
||||
|
||||
// Start advertising
|
||||
Bluefruit.Advertising.restartOnDisconnect(true);
|
||||
Bluefruit.Advertising.setInterval(32, 2056); // *.625ms = 20ms and 1285ms; see https://developer.apple.com/library/content/qa/qa1931/_index.html
|
||||
Bluefruit.Advertising.setFastTimeout(30);
|
||||
Bluefruit.Advertising.start(0);
|
||||
|
||||
Serial.println("=== START ===");
|
||||
}
|
||||
|
||||
void connectCallback(uint16_t conn_handle)
|
||||
{
|
||||
(void)conn_handle;
|
||||
}
|
||||
|
||||
void diconnectCallback(uint16_t conn_handle, uint8_t reason)
|
||||
{
|
||||
(void)conn_handle;
|
||||
(void)reason;
|
||||
Bluefruit.Advertising.start(0); //Resume adverstising
|
||||
}
|
||||
|
||||
void scbtPetWriteCallback(uint16_t conn_hdl, BLECharacteristic *chr, uint8_t *data, uint16_t len)
|
||||
{
|
||||
(void)conn_hdl;
|
||||
(void)chr;
|
||||
(void)len; //Always 4
|
||||
|
||||
uint32_t value = *(uint32_t*)data;
|
||||
|
||||
char str[32] = { 0 };
|
||||
sprintf(str, "Got pet write %d\n", value);
|
||||
Serial.write(str);
|
||||
|
||||
if (value == 0)
|
||||
digitalWrite(LED_RED, LOW);
|
||||
else
|
||||
digitalWrite(LED_RED, HIGH);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
digitalWrite(LED_GREEN, LOW);
|
||||
delay(1);
|
||||
digitalWrite(LED_GREEN, HIGH);
|
||||
delay(3999);
|
||||
Serial.write("Alive\n");
|
||||
}
|
||||
Reference in New Issue
Block a user