Is there a way to draw circles or lines (from point A to point B) in a scrolling layer or Indexed layer?
Is there a readPixel function for index or scrolling layers?
I found out how to draw lines and such in the Indexed layer.
How do you check if the pixel at a location is lit up in the Indexed layer?
A sort of readPixel that spit out a 1 or a 0.
indexedLayer.readPixel(x,y) does not seem to work.
Louis
July 10, 2024, 7:06am
3
There’s a readPixel. Works like this, but will return 0/1 for indexed later
// background brightness
currentMillis = millis();
while (millis() - currentMillis < transitionTime) {
int x0, y0;
rgb24 color;
x0 = random(matrix.getScreenWidth());
y0 = random(matrix.getScreenHeight());
color = backgroundLayer.readPixel(x0, y0);
// quick hack to (usually) stay within color wheel
if(color.red == 0 && color.green == 0 && color.blue == 0)
continue;
// draw crosshairs - sometimes they will be obscured by the scrolling text
indexedLayer.drawPixel(x0+1, y0, true);
indexedLayer.drawPixel(x0+2, y0, true);
indexedLayer.drawPixel(x0+3, y0, true);
indexedLayer.drawPixel(x0+4, y0, true);
I tried using:
bool pixelcheck = indexedLayer.readPixel(5,6);
and it gives me an error message:
‘class SMLayerGFXMono<rgb24, bool, 0u>’ has no member named ‘readPixel’
Maybe I misunderstood, but do you mean that if you use:
backgroundLayer.readPixel(x,y)
and that pixel is lit up by the index layer, it will return a 1 instead of an rgb value?
I thought the backgroundLayer.readPixel(x,y) would only read what is on the background layer and not the index layer.
Louis
July 10, 2024, 7:33pm
5
Sorry, I didn’t remember that Indexed and Scrolling layers are missing a readPixel method. It’s something that should be added ideally, but I’m not actively working on this library anymore. There’s already an open issue on GitHub that mentions this missing features among other things:
opened 11:00PM - 11 Nov 15 UTC
@embedded-creations:
i'd have two suggestion for smartmatrix:
- would it be pos… sible to add a version information? (#define's)
eg:
`#define SMARTMATRIX_VERSION_MAJOR 3`
`#define SMARTMATRIX_VERSION_MINOR 1`
plus optionally:
`#define SMARTMATRIX_VERSION_BRANCH colourspaces`
- (public) access to layer buffer or pixel information for all three layer-types
- background layer has:
- `RGB* backBuffer()`
- `const RGB readPixel(x, y)`
- `RGB* getRealBackBuffer()`
- scolling layer has:
- `uint8_t\* scollingBitmap;
- indexed layer has:
- nothing :(
at least access to the bitmap information for all three types would be fine, `readPixel()` would be even better. especially indexed layer is missing this functionality.
background:
i'm currently developing a framework on top of smartmatrix3 that uses panes for displaying information - and these make heavy use of sm3's layer drawing functions.
the defines would be handy for en/disabling features in the framework according to the smartmatrix-version/branch used.
the API of my new toy is currently stabilising and i hope that i'm able to release a somewhat usable version at github soon.
Thanks for the prompt responses, I and everyone here appreciates your guidance! I will have to find a work around then.
Louis
July 10, 2024, 11:15pm
7
You might be able to use an Adafruit_GFX compatible layer, and the getPixel() method through Adafruit_GFX.
/// A GFX 16-bit canvas context for graphics
class GFXcanvas16 : public Adafruit_GFX {
public:
GFXcanvas16(uint16_t w, uint16_t h);
~GFXcanvas16(void);
void drawPixel(int16_t x, int16_t y, uint16_t color);
void fillScreen(uint16_t color);
void byteSwap(void);
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
uint16_t getPixel(int16_t x, int16_t y) const;
/**********************************************************************/
/*!
@brief Get a pointer to the internal buffer memory
@returns A pointer to the allocated buffer
*/
/**********************************************************************/
uint16_t *getBuffer(void) const { return buffer; }
protected:
uint16_t getRawPixel(int16_t x, int16_t y) const;
Sorry there’s no read example code for that I can think of, but try modifying this example (use SMARTMATRIX_ALLOCATE_GFX_MONO_LAYER
for the equivalent of indexedLayer) and see if readPixel works:
const uint32_t kMatrixOptions = (SM_HUB75_OPTIONS_NONE); // see docs for options: https://github.com/pixelmatix/SmartMatrix/wiki
SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
// There are two Adafruit_GFX compatible layers, a Mono layer and an RGB layer, and this example sketch works with either (choose one):
#if 1
const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);
#else
const uint8_t kMonoLayerOptions = (SM_GFX_MONO_OPTIONS_NONE);
SMARTMATRIX_ALLOCATE_GFX_MONO_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kMonoLayerOptions);
// these backwards compatible ALLOCATE macros also work:
//SMARTMATRIX_ALLOCATE_SCROLLING_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kMonoLayerOptions);
//SMARTMATRIX_ALLOCATE_INDEXED_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kMonoLayerOptions);
#endif
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800