Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PixelBuffer.h
- Committer:
- mutech
- Date:
- 2016-09-06
- Revision:
- 27:bc79f444883b
- Child:
- 28:b452e097da53
File content as of revision 27:bc79f444883b:
/* PixelBuffer.h * mbed Microcontroller Library * Copyright (c) 2016 muetch, t.kuroki * Allrights reserved. * * Rev 0.97 2016-09-07 */ #pragma once #ifndef PIXELBUFFER_H #define PIXELBUFFER_H #include "mbed.h" #include "ColorLib.h" //---------------------------------------------------------------------------- #ifndef MAX_PIXELS #define MAX_PIXELS 170 #endif #ifndef nullptr #define nullptr (0) #endif //---------------------------------------------------------------------------- /** * RGBPixels */ class RGBPixels { public: /** * Initializes the addressable led bus * * @param Buffer - The Pixel array buffer address. * @param maxPixels - Number of the addressable leds */ RGBPixels(RGBColor *buffer = nullptr, int maxPixels = MAX_PIXELS); RGBPixels(int maxPixels = MAX_PIXELS); ~RGBPixels(); void setPixelBuffer(RGBColor *buffer, int maxPixels); int maxPixels() { return _maxPixels; } int numPixels(int value = -1); void setPixels(int index, RGBColor *color, int len); void setPixels(int index, HSVColor *color, int len); void setPixels(RGBColor *color, int len) { setPixels(0, color, len); } void setPixels(HSVColor *color, int len) { setPixels(0, color, len); } void fillPixels(const RGBColor color, int index, int len); void fillPixels(const HSVColor color, int index, int len); void fillPixels(const int color, int index, int len) { fillPixels((RGBColor)color, index, len); } void fillPixels(const RGBColor color, int len = MAX_PIXELS) { fillPixels(color, 0, len); } void fillPixels(const HSVColor color, int len = MAX_PIXELS) { fillPixels(color, 0, len); } void fillPixels(const int color, int len = MAX_PIXELS) { fillPixels((RGBColor)color, 0, len); } void clear(const RGBColor color) { fillPixels(color); } void clear(const HSVColor color) { fillPixels(color); } void clear(const int color = 0) { fillPixels((RGBColor)color); } void repeatPixels(int block_size); void repeatPixels(RGBColor *source, int size); void repeatPixels(HSVColor *source, int size); RGBColor operator[](int index) const { if ((uint16_t)index < _numPixels) return _pixels[index]; return _dummyPixel; } RGBColor& operator[](int index) { if ((uint16_t)index < _numPixels) return _pixels[index]; return _dummyPixel; } RGBPixels& operator=(const RGBPixels& rhs); operator RGBColor*() const { return _pixels; } protected: uint16_t _maxPixels; uint16_t _numPixels; RGBColor *_pixels; private: bool _buf_owner; RGBColor _dummyPixel; }; //---------------------------------------------------------------------------- /** * HSVPixels */ class HSVPixels { public: /** * Initializes the addressable led bus * * @param Buffer - The Pixel array buffer address. * @param maxPixels - Number of the addressable leds */ HSVPixels(HSVColor *buffer = nullptr, int maxPixels = MAX_PIXELS); HSVPixels(int maxPixels = MAX_PIXELS); ~HSVPixels(); void setPixelBuffer(HSVColor *buffer, int maxPixels); int maxPixels() { return _maxPixels; } int numPixels(int value = -1); void setPixels(int index, HSVColor *color, int len); void setPixels(int index, RGBColor *color, int len); void setPixels(HSVColor *color, int len) { setPixels(0, color, len); } void setPixels(RGBColor *color, int len) { setPixels(0, color, len); } void fillPixels(const HSVColor color, int index, int len); void fillPixels(const RGBColor color, int index, int len); void fillPixels(const int color, int index, int len) { fillPixels((RGBColor)color, index, len); } void fillPixels(const HSVColor color, int len = MAX_PIXELS) { fillPixels(color, 0, len); } void fillPixels(const RGBColor color, int len = MAX_PIXELS) { fillPixels(color, 0, len); } void fillPixels(const int color, int len = MAX_PIXELS) { fillPixels((RGBColor)color, 0, len); } void clear(const HSVColor color) { fillPixels(color); } void clear(const RGBColor color) { fillPixels(color); } void clear(const int color = 0) { fillPixels((RGBColor)color); } void repeatPixels(int block_size); void repeatPixels(HSVColor *source, int size); void repeatPixels(RGBColor *source, int size); HSVColor operator[](int index) const { if ((uint16_t)index < _numPixels) return _pixels[index]; return _dummyPixel; } HSVColor& operator[](int index) { if ((uint16_t)index < _numPixels) return _pixels[index]; return _dummyPixel; } HSVPixels& operator=(const HSVPixels& rhs); operator HSVColor*() const { return _pixels; } protected: uint16_t _maxPixels; uint16_t _numPixels; HSVColor *_pixels; private: bool _buf_owner; HSVColor _dummyPixel; }; //---------------------------------------------------------------------------- #endif // end of PIXELBUFFER_H