RGB Pixel seems to work
This commit is contained in:
1 parent
55d78cfb9b
commit
7770836fbe
3 files changed
+37
-4
No files matched your search
@@ -103,8 +103,36 @@ err_t BLEAdafruitRgbPixel::begin(uint8_t pin, uint8_t type)
|
||||
Data.setPermission(SECMODE_NO_ACCESS, SECMODE_OPEN);
|
||||
// Change to use VLOC STACK to USER due to lack of memroy
|
||||
// Data.setMaxLen(Bluefruit.getMaxMtu(BLE_GAP_ROLE_PERIPH));
|
||||
Data.setMaxLen(20);
|
||||
Data.setMaxLen(BLE_GATTS_VAR_ATTR_LEN_MAX);
|
||||
VERIFY_STATUS( Data.begin() );
|
||||
|
||||
Data.setWriteCallback(pixel_data_write_cb, true);
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Static callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
void BLEAdafruitRgbPixel::pixel_data_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len)
|
||||
{
|
||||
(void) conn_hdl;
|
||||
|
||||
if (len < 3) return;
|
||||
|
||||
BLEAdafruitRgbPixel& svc = (BLEAdafruitRgbPixel&) chr->parentService();
|
||||
|
||||
uint16_t index;
|
||||
memcpy(&index, data, 2);
|
||||
uint8_t flag = data[2];
|
||||
|
||||
uint8_t* buffer = svc._neo->getPixels();
|
||||
|
||||
memcpy(buffer, data+3, len-3);
|
||||
|
||||
// show flag
|
||||
if ( flag & 0x01 )
|
||||
{
|
||||
svc._neo->show();
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,8 @@ class BLEAdafruitRgbPixel : public BLEService
|
||||
Adafruit_NeoPixel_Type* _neo;
|
||||
|
||||
err_t begin(uint8_t pin, uint8_t type);
|
||||
|
||||
static void pixel_data_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
All text above, and the splash screen below must be included in
|
||||
any redistribution
|
||||
*********************************************************************/
|
||||
#include <bluefruit.h>
|
||||
#include <Adafruit_CircuitPlayground.h>
|
||||
#include <Adafruit_LittleFS.h>
|
||||
#include <InternalFileSystem.h>
|
||||
#include <bluefruit.h>
|
||||
#include <BLEAdafruitService.h>
|
||||
#include <Adafruit_CircuitPlayground.h>
|
||||
|
||||
// BLE Service
|
||||
BLEDfu bledfu; // OTA DFU service
|
||||
@@ -32,6 +32,8 @@ BLEAdafruitTone bleTone;
|
||||
|
||||
BLEAdafruitRgbPixel blePixel;
|
||||
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, CPLAY_NEOPIXELPIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
|
||||
{
|
||||
uint32_t button = 0;
|
||||
@@ -127,7 +129,8 @@ void setup()
|
||||
|
||||
bleTone.begin(CPLAY_BUZZER);
|
||||
|
||||
blePixel.begin();
|
||||
strip.begin();
|
||||
blePixel.begin(&strip);
|
||||
|
||||
// Set up and start advertising
|
||||
startAdv();
|
||||
|
||||
Reference in new issue
Block a user