Skip to content

Commit 81ba6c3

Browse files
committed
fix rm neopixel
1 parent 6e7732c commit 81ba6c3

File tree

5 files changed

+29
-36
lines changed

5 files changed

+29
-36
lines changed

src/Wippersnapper_V2.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,10 +1361,7 @@ ws_status_t Wippersnapper_V2::run() {
13611361

13621362
// TODO: Process I2C sensor events
13631363
WsV2._i2c_controller->update();
1364-
1365-
// Process Pixels events
1366-
// TODO: Add update() method to PixelsController if needed
1367-
1364+
13681365
// TODO: Process UART sensor events
13691366

13701367
return WS_NET_CONNECTED; // TODO: Make this funcn void!

src/components/pixels/controller.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ bool PixelsController::Handle_Pixels_Add(pb_istream_t *stream) {
6060
msg_add->pixels_type, msg_add->pixels_ordering, msg_add->pixels_num,
6161
msg_add->pixels_brightness, msg_add->pixels_pin_data,
6262
msg_add->pixels_pin_dotstar_clock);
63-
if (! did_init) {
63+
if (!did_init) {
6464
WS_DEBUG_PRINTLN("[pixels] Failed to create strand!");
6565
} else {
6666
_num_strands++;
@@ -69,11 +69,11 @@ bool PixelsController::Handle_Pixels_Add(pb_istream_t *stream) {
6969
}
7070

7171
// Publish PixelsAdded message to the broker
72-
if (! _pixels_model->EncodePixelsAdded(msg_add->pixels_pin_data, did_init)) {
72+
if (!_pixels_model->EncodePixelsAdded(msg_add->pixels_pin_data, did_init)) {
7373
WS_DEBUG_PRINTLN("[pixels]: Failed to encode PixelsAdded message!");
7474
return false;
7575
}
76-
if (! WsV2.PublishSignal(wippersnapper_signal_DeviceToBroker_pixels_added_tag,
76+
if (!WsV2.PublishSignal(wippersnapper_signal_DeviceToBroker_pixels_added_tag,
7777
_pixels_model->GetPixelsAddedMsg())) {
7878
WS_DEBUG_PRINTLN("[pixels]: Unable to publish PixelsAdded message!");
7979
return false;

src/components/pixels/controller.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
#include "hardware.h"
1919
#include "model.h"
2020

21-
#define MAX_PIXEL_STRANDS 5 ///< Maximum number of pixel strands connected to a WipperSnapper device
21+
#define MAX_PIXEL_STRANDS 10 ///< Maximum number of pixel strands connected to a WipperSnapper device
22+
#define STRAND_NOT_FOUND 0xFF ///< Strand not found in the array
2223

2324
class Wippersnapper_V2; ///< Forward declaration
24-
class PixelsModel; ///< Forward declaration
25-
class PixelsHardware; ///< Forward declaration
25+
class PixelsModel; ///< Forward declaration
26+
class PixelsHardware; ///< Forward declaration
2627

2728
/**************************************************************************/
2829
/*!
@@ -35,7 +36,6 @@ class PixelsController {
3536
public:
3637
PixelsController();
3738
~PixelsController();
38-
// Called by the cbDecodeBrokerToDevice router function
3939
bool Handle_Pixels_Add(pb_istream_t *stream);
4040
bool Handle_Pixels_Write(pb_istream_t *stream);
4141
bool Handle_Pixels_Remove(pb_istream_t *stream);
@@ -45,5 +45,5 @@ class PixelsController {
4545
uint8_t _num_strands; ///< Number of pixel strands
4646
uint16_t GetStrandIndex(uint16_t pin_data); // Returns 0xFF if not found
4747
};
48-
extern Wippersnapper_V2 WsV2; ///< Wippersnapper V2 instance
48+
extern Wippersnapper_V2 WsV2; ///< Global V2 instance
4949
#endif // WS_PIXELS_CONTROLLER_H

src/components/pixels/hardware.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* @file hardware.cpp
33
*
4-
* Hardware implementation for pixel strands.
4+
* Hardware interface for NeoPixel/DotStar strands.
55
*
66
* Adafruit invests time and resources providing this open source code,
77
* please support Adafruit and open-source hardware by purchasing
@@ -204,21 +204,31 @@ uint32_t PixelsHardware::ApplyGammaCorrection(uint32_t color) {
204204
void PixelsHardware::RemoveStrand() {
205205
if (_type == wippersnapper_pixels_PixelsType_PIXELS_TYPE_NEOPIXEL) {
206206
if (_neopixel != nullptr) {
207+
_neopixel->clear();
208+
_neopixel->show();
207209
delete _neopixel;
208210
_neopixel = nullptr;
209211
}
210212
} else if (_type == wippersnapper_pixels_PixelsType_PIXELS_TYPE_DOTSTAR) {
211213
if (_dotstar != nullptr) {
214+
_dotstar->clear();
215+
_dotstar->show();
212216
delete _dotstar;
213217
_dotstar = nullptr;
214218
}
215219
} else {
216220
WS_DEBUG_PRINTLN("[pixels] Unknown pixel type!");
217221
}
218-
219222
// Optionally re-init the status pixel for reuse by app.
220-
if (getStatusNeoPixelPin() == _pin_data && !WsV2.lockStatusNeoPixelV2)
223+
if (getStatusNeoPixelPin() == _pin_data && !WsV2.lockStatusNeoPixelV2) {
224+
WS_DEBUG_PRINTLN("[pixels] Re-initializing status pixel");
221225
initStatusLED();
226+
}
227+
WS_DEBUG_PRINT("[pixels] Removed pixel strand from pin: ");
228+
WS_DEBUG_PRINTLN(_pin_data);
229+
230+
_pin_data = 0; // Reset the pin data
231+
_type = wippersnapper_pixels_PixelsType_PIXELS_TYPE_UNSPECIFIED;
222232
}
223233

224234
/**************************************************************************/

src/components/pixels/hardware.h

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* @file hardware.h
33
*
4-
* Hardware interface for pixel strands.
4+
* Hardware interface for NeoPixel/DotStar strands.
55
*
66
* Adafruit invests time and resources providing this open source code,
77
* please support Adafruit and open-source hardware by purchasing
@@ -16,23 +16,10 @@
1616
#define WS_PIXELS_HARDWARE_H
1717
#include "Wippersnapper_V2.h"
1818

19-
// TODO: Do we need this?
20-
/**
21-
* @struct PixelStrand
22-
* @brief This struct represents a NeoPixel or DotStar strand.
23-
*/
24-
struct PixelStrand {
25-
uint8_t pin_data; ///< Data pin
26-
uint8_t pin_clock; ///< Clock pin (for DotStar)
27-
wippersnapper_pixels_PixelsType type; ///< Pixel type
28-
wippersnapper_pixels_PixelsOrder order; ///< Color ordering
29-
uint32_t num_pixels; ///< Number of pixels
30-
uint32_t brightness; ///< Current brightness (0-255)
31-
};
32-
3319
/**************************************************************************/
3420
/*!
35-
@brief Interface for interacting with hardware's pixel strands.
21+
@brief Interface for interacting with NeoPixel or Dotstar
22+
pixel strands
3623
*/
3724
/**************************************************************************/
3825
class PixelsHardware {
@@ -46,12 +33,11 @@ class PixelsHardware {
4633
uint16_t GetPinData();
4734
void FillStrand(uint32_t color);
4835
void RemoveStrand();
49-
5036
private:
51-
Adafruit_NeoPixel *_neopixel = nullptr; ///< Used for NeoPixel pixel strands
52-
Adafruit_DotStar *_dotstar = nullptr; ///< Used for DotStar pixel strands
53-
wippersnapper_pixels_PixelsType _type;
54-
uint16_t _pin_data; ///< Data pin for the pixel strand
37+
Adafruit_NeoPixel *_neopixel = nullptr; ///< Used for NeoPixel strands
38+
Adafruit_DotStar *_dotstar = nullptr; ///< Used for DotStar strands
39+
wippersnapper_pixels_PixelsType _type; ///< Holds the type of strand
40+
uint16_t _pin_data; ///< Data pin for the strand
5541
bool AddNeoPixel(uint16_t num_pixels, uint16_t pin_data, neoPixelType order,
5642
uint8_t brightness);
5743
bool AddDotStar(uint16_t num_pixels, uint16_t pin_data, uint16_t pin_clock,

0 commit comments

Comments
 (0)