Skip to content

Commit 7770836

Browse files
committed
RGB Pixel seems to work
1 parent 55d78cf commit 7770836

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

libraries/BLEAdafruitService/src/services/BLEAdafruitRgbPixel.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,36 @@ err_t BLEAdafruitRgbPixel::begin(uint8_t pin, uint8_t type)
103103
Data.setPermission(SECMODE_NO_ACCESS, SECMODE_OPEN);
104104
// Change to use VLOC STACK to USER due to lack of memroy
105105
// Data.setMaxLen(Bluefruit.getMaxMtu(BLE_GAP_ROLE_PERIPH));
106-
Data.setMaxLen(20);
106+
Data.setMaxLen(BLE_GATTS_VAR_ATTR_LEN_MAX);
107107
VERIFY_STATUS( Data.begin() );
108108

109+
Data.setWriteCallback(pixel_data_write_cb, true);
110+
109111
return ERROR_NONE;
110112
}
113+
114+
//--------------------------------------------------------------------+
115+
// Static callbacks
116+
//--------------------------------------------------------------------+
117+
void BLEAdafruitRgbPixel::pixel_data_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len)
118+
{
119+
(void) conn_hdl;
120+
121+
if (len < 3) return;
122+
123+
BLEAdafruitRgbPixel& svc = (BLEAdafruitRgbPixel&) chr->parentService();
124+
125+
uint16_t index;
126+
memcpy(&index, data, 2);
127+
uint8_t flag = data[2];
128+
129+
uint8_t* buffer = svc._neo->getPixels();
130+
131+
memcpy(buffer, data+3, len-3);
132+
133+
// show flag
134+
if ( flag & 0x01 )
135+
{
136+
svc._neo->show();
137+
}
138+
}

libraries/BLEAdafruitService/src/services/BLEAdafruitRgbPixel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class BLEAdafruitRgbPixel : public BLEService
5757
Adafruit_NeoPixel_Type* _neo;
5858

5959
err_t begin(uint8_t pin, uint8_t type);
60+
61+
static void pixel_data_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len);
6062
};
6163

6264

libraries/Bluefruit52Lib/examples/Peripheral/cplay_ble/cplay_ble.ino

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
All text above, and the splash screen below must be included in
1212
any redistribution
1313
*********************************************************************/
14-
#include <bluefruit.h>
14+
#include <Adafruit_CircuitPlayground.h>
1515
#include <Adafruit_LittleFS.h>
1616
#include <InternalFileSystem.h>
17+
#include <bluefruit.h>
1718
#include <BLEAdafruitService.h>
18-
#include <Adafruit_CircuitPlayground.h>
1919

2020
// BLE Service
2121
BLEDfu bledfu; // OTA DFU service
@@ -32,6 +32,8 @@ BLEAdafruitTone bleTone;
3232

3333
BLEAdafruitRgbPixel blePixel;
3434

35+
Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, CPLAY_NEOPIXELPIN, NEO_GRB + NEO_KHZ800);
36+
3537
uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
3638
{
3739
uint32_t button = 0;
@@ -127,7 +129,8 @@ void setup()
127129

128130
bleTone.begin(CPLAY_BUZZER);
129131

130-
blePixel.begin();
132+
strip.begin();
133+
blePixel.begin(&strip);
131134

132135
// Set up and start advertising
133136
startAdv();

0 commit comments

Comments
 (0)