Skip to content

allow to specify the framebuffer from the outside. #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions Adafruit_NeoPixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
#include "Adafruit_NeoPixel.h"

// Constructor when length, pin and type are known at compile-time:
Adafruit_NeoPixel::Adafruit_NeoPixel(uint16_t n, uint8_t p, neoPixelType t) :
Adafruit_NeoPixel::Adafruit_NeoPixel(uint16_t n, uint8_t p, neoPixelType t, uint8_t *pix) :
begun(false), brightness(0), pixels(NULL), endTime(0)
{
updateType(t);
updateLength(n);
updateType(t,pix);
updateLength(n,pix);
setPin(p);
}

Expand Down Expand Up @@ -69,7 +69,14 @@ void Adafruit_NeoPixel::begin(void) {
begun = true;
}

void Adafruit_NeoPixel::updateLength(uint16_t n) {
void Adafruit_NeoPixel::updateLength(uint16_t n, uint8_t *pix) {
if(pix) {
pixels = pix;
numBytes = n * ((wOffset == rOffset) ? 3 : 4);
memset(pixels, 0, numBytes);
numLEDs = n;
return;
}
if(pixels) free(pixels); // Free existing data (if any)

// Allocate new data -- note: ALL PIXELS ARE CLEARED
Expand All @@ -82,7 +89,7 @@ void Adafruit_NeoPixel::updateLength(uint16_t n) {
}
}

void Adafruit_NeoPixel::updateType(neoPixelType t) {
void Adafruit_NeoPixel::updateType(neoPixelType t, uint8_t *pix) {
boolean oldThreeBytesPerPixel = (wOffset == rOffset); // false if RGBW

wOffset = (t >> 6) & 0b11; // See notes in header file
Expand All @@ -97,7 +104,7 @@ void Adafruit_NeoPixel::updateType(neoPixelType t) {
// allocated), re-allocate to new size. Will clear any data.
if(pixels) {
boolean newThreeBytesPerPixel = (wOffset == rOffset);
if(newThreeBytesPerPixel != oldThreeBytesPerPixel) updateLength(numLEDs);
if(newThreeBytesPerPixel != oldThreeBytesPerPixel) updateLength(numLEDs,pix);
}
}

Expand Down
9 changes: 5 additions & 4 deletions Adafruit_NeoPixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Adafruit_NeoPixel {
public:

// Constructor: number of LEDs, pin number, LED type
Adafruit_NeoPixel(uint16_t n, uint8_t p=6, neoPixelType t=NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel(uint16_t n, uint8_t p=6, neoPixelType t=NEO_GRB + NEO_KHZ800, uint8_t *pix=NULL);
Adafruit_NeoPixel(void);
~Adafruit_NeoPixel();

Expand All @@ -131,8 +131,8 @@ class Adafruit_NeoPixel {
setPixelColor(uint16_t n, uint32_t c),
setBrightness(uint8_t),
clear(),
updateLength(uint16_t n),
updateType(neoPixelType t);
updateLength(uint16_t n,uint8_t *pix=NULL),
updateType(neoPixelType t,uint8_t *pix=NULL);
uint8_t
*getPixels(void) const,
getBrightness(void) const;
Expand All @@ -147,6 +147,8 @@ class Adafruit_NeoPixel {
getPixelColor(uint16_t n) const;
inline bool
canShow(void) { return (micros() - endTime) >= 50L; }
uint8_t
*pixels; // Holds LED color values (3 or 4 bytes each)

private:

Expand All @@ -162,7 +164,6 @@ class Adafruit_NeoPixel {
pin; // Output pin number (-1 if not yet set)
uint8_t
brightness,
*pixels, // Holds LED color values (3 or 4 bytes each)
rOffset, // Index of red byte within each 3- or 4-byte pixel
gOffset, // Index of green byte
bOffset, // Index of blue byte
Expand Down