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@27:bc79f444883b, 2016-09-06 (annotated)
- Committer:
- mutech
- Date:
- Tue Sep 06 22:12:59 2016 +0000
- Revision:
- 27:bc79f444883b
- Child:
- 28:b452e097da53
WS2811/WS2812 support Library;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mutech | 27:bc79f444883b | 1 | /* PixelBuffer.h |
mutech | 27:bc79f444883b | 2 | * mbed Microcontroller Library |
mutech | 27:bc79f444883b | 3 | * Copyright (c) 2016 muetch, t.kuroki |
mutech | 27:bc79f444883b | 4 | * Allrights reserved. |
mutech | 27:bc79f444883b | 5 | * |
mutech | 27:bc79f444883b | 6 | * Rev 0.97 2016-09-07 |
mutech | 27:bc79f444883b | 7 | */ |
mutech | 27:bc79f444883b | 8 | |
mutech | 27:bc79f444883b | 9 | #pragma once |
mutech | 27:bc79f444883b | 10 | |
mutech | 27:bc79f444883b | 11 | #ifndef PIXELBUFFER_H |
mutech | 27:bc79f444883b | 12 | #define PIXELBUFFER_H |
mutech | 27:bc79f444883b | 13 | |
mutech | 27:bc79f444883b | 14 | #include "mbed.h" |
mutech | 27:bc79f444883b | 15 | #include "ColorLib.h" |
mutech | 27:bc79f444883b | 16 | |
mutech | 27:bc79f444883b | 17 | //---------------------------------------------------------------------------- |
mutech | 27:bc79f444883b | 18 | #ifndef MAX_PIXELS |
mutech | 27:bc79f444883b | 19 | #define MAX_PIXELS 170 |
mutech | 27:bc79f444883b | 20 | #endif |
mutech | 27:bc79f444883b | 21 | |
mutech | 27:bc79f444883b | 22 | #ifndef nullptr |
mutech | 27:bc79f444883b | 23 | #define nullptr (0) |
mutech | 27:bc79f444883b | 24 | #endif |
mutech | 27:bc79f444883b | 25 | |
mutech | 27:bc79f444883b | 26 | //---------------------------------------------------------------------------- |
mutech | 27:bc79f444883b | 27 | /** |
mutech | 27:bc79f444883b | 28 | * RGBPixels |
mutech | 27:bc79f444883b | 29 | */ |
mutech | 27:bc79f444883b | 30 | class RGBPixels |
mutech | 27:bc79f444883b | 31 | { |
mutech | 27:bc79f444883b | 32 | public: |
mutech | 27:bc79f444883b | 33 | /** |
mutech | 27:bc79f444883b | 34 | * Initializes the addressable led bus |
mutech | 27:bc79f444883b | 35 | * |
mutech | 27:bc79f444883b | 36 | * @param Buffer - The Pixel array buffer address. |
mutech | 27:bc79f444883b | 37 | * @param maxPixels - Number of the addressable leds |
mutech | 27:bc79f444883b | 38 | */ |
mutech | 27:bc79f444883b | 39 | RGBPixels(RGBColor *buffer = nullptr, int maxPixels = MAX_PIXELS); |
mutech | 27:bc79f444883b | 40 | RGBPixels(int maxPixels = MAX_PIXELS); |
mutech | 27:bc79f444883b | 41 | ~RGBPixels(); |
mutech | 27:bc79f444883b | 42 | |
mutech | 27:bc79f444883b | 43 | void setPixelBuffer(RGBColor *buffer, int maxPixels); |
mutech | 27:bc79f444883b | 44 | int maxPixels() { return _maxPixels; } |
mutech | 27:bc79f444883b | 45 | int numPixels(int value = -1); |
mutech | 27:bc79f444883b | 46 | |
mutech | 27:bc79f444883b | 47 | void setPixels(int index, RGBColor *color, int len); |
mutech | 27:bc79f444883b | 48 | void setPixels(int index, HSVColor *color, int len); |
mutech | 27:bc79f444883b | 49 | void setPixels(RGBColor *color, int len) { setPixels(0, color, len); } |
mutech | 27:bc79f444883b | 50 | void setPixels(HSVColor *color, int len) { setPixels(0, color, len); } |
mutech | 27:bc79f444883b | 51 | void fillPixels(const RGBColor color, int index, int len); |
mutech | 27:bc79f444883b | 52 | void fillPixels(const HSVColor color, int index, int len); |
mutech | 27:bc79f444883b | 53 | void fillPixels(const int color, int index, int len) { fillPixels((RGBColor)color, index, len); } |
mutech | 27:bc79f444883b | 54 | void fillPixels(const RGBColor color, int len = MAX_PIXELS) { fillPixels(color, 0, len); } |
mutech | 27:bc79f444883b | 55 | void fillPixels(const HSVColor color, int len = MAX_PIXELS) { fillPixels(color, 0, len); } |
mutech | 27:bc79f444883b | 56 | void fillPixels(const int color, int len = MAX_PIXELS) { fillPixels((RGBColor)color, 0, len); } |
mutech | 27:bc79f444883b | 57 | void clear(const RGBColor color) { fillPixels(color); } |
mutech | 27:bc79f444883b | 58 | void clear(const HSVColor color) { fillPixels(color); } |
mutech | 27:bc79f444883b | 59 | void clear(const int color = 0) { fillPixels((RGBColor)color); } |
mutech | 27:bc79f444883b | 60 | void repeatPixels(int block_size); |
mutech | 27:bc79f444883b | 61 | void repeatPixels(RGBColor *source, int size); |
mutech | 27:bc79f444883b | 62 | void repeatPixels(HSVColor *source, int size); |
mutech | 27:bc79f444883b | 63 | |
mutech | 27:bc79f444883b | 64 | RGBColor operator[](int index) const |
mutech | 27:bc79f444883b | 65 | { |
mutech | 27:bc79f444883b | 66 | if ((uint16_t)index < _numPixels) |
mutech | 27:bc79f444883b | 67 | return _pixels[index]; |
mutech | 27:bc79f444883b | 68 | return _dummyPixel; |
mutech | 27:bc79f444883b | 69 | } |
mutech | 27:bc79f444883b | 70 | |
mutech | 27:bc79f444883b | 71 | RGBColor& operator[](int index) |
mutech | 27:bc79f444883b | 72 | { |
mutech | 27:bc79f444883b | 73 | if ((uint16_t)index < _numPixels) |
mutech | 27:bc79f444883b | 74 | return _pixels[index]; |
mutech | 27:bc79f444883b | 75 | return _dummyPixel; |
mutech | 27:bc79f444883b | 76 | } |
mutech | 27:bc79f444883b | 77 | |
mutech | 27:bc79f444883b | 78 | RGBPixels& operator=(const RGBPixels& rhs); |
mutech | 27:bc79f444883b | 79 | |
mutech | 27:bc79f444883b | 80 | operator RGBColor*() const { return _pixels; } |
mutech | 27:bc79f444883b | 81 | |
mutech | 27:bc79f444883b | 82 | protected: |
mutech | 27:bc79f444883b | 83 | uint16_t _maxPixels; |
mutech | 27:bc79f444883b | 84 | uint16_t _numPixels; |
mutech | 27:bc79f444883b | 85 | RGBColor *_pixels; |
mutech | 27:bc79f444883b | 86 | |
mutech | 27:bc79f444883b | 87 | private: |
mutech | 27:bc79f444883b | 88 | bool _buf_owner; |
mutech | 27:bc79f444883b | 89 | RGBColor _dummyPixel; |
mutech | 27:bc79f444883b | 90 | |
mutech | 27:bc79f444883b | 91 | }; |
mutech | 27:bc79f444883b | 92 | |
mutech | 27:bc79f444883b | 93 | //---------------------------------------------------------------------------- |
mutech | 27:bc79f444883b | 94 | /** |
mutech | 27:bc79f444883b | 95 | * HSVPixels |
mutech | 27:bc79f444883b | 96 | */ |
mutech | 27:bc79f444883b | 97 | class HSVPixels |
mutech | 27:bc79f444883b | 98 | { |
mutech | 27:bc79f444883b | 99 | public: |
mutech | 27:bc79f444883b | 100 | /** |
mutech | 27:bc79f444883b | 101 | * Initializes the addressable led bus |
mutech | 27:bc79f444883b | 102 | * |
mutech | 27:bc79f444883b | 103 | * @param Buffer - The Pixel array buffer address. |
mutech | 27:bc79f444883b | 104 | * @param maxPixels - Number of the addressable leds |
mutech | 27:bc79f444883b | 105 | */ |
mutech | 27:bc79f444883b | 106 | HSVPixels(HSVColor *buffer = nullptr, int maxPixels = MAX_PIXELS); |
mutech | 27:bc79f444883b | 107 | HSVPixels(int maxPixels = MAX_PIXELS); |
mutech | 27:bc79f444883b | 108 | ~HSVPixels(); |
mutech | 27:bc79f444883b | 109 | |
mutech | 27:bc79f444883b | 110 | void setPixelBuffer(HSVColor *buffer, int maxPixels); |
mutech | 27:bc79f444883b | 111 | int maxPixels() { return _maxPixels; } |
mutech | 27:bc79f444883b | 112 | int numPixels(int value = -1); |
mutech | 27:bc79f444883b | 113 | |
mutech | 27:bc79f444883b | 114 | void setPixels(int index, HSVColor *color, int len); |
mutech | 27:bc79f444883b | 115 | void setPixels(int index, RGBColor *color, int len); |
mutech | 27:bc79f444883b | 116 | void setPixels(HSVColor *color, int len) { setPixels(0, color, len); } |
mutech | 27:bc79f444883b | 117 | void setPixels(RGBColor *color, int len) { setPixels(0, color, len); } |
mutech | 27:bc79f444883b | 118 | void fillPixels(const HSVColor color, int index, int len); |
mutech | 27:bc79f444883b | 119 | void fillPixels(const RGBColor color, int index, int len); |
mutech | 27:bc79f444883b | 120 | void fillPixels(const int color, int index, int len) { fillPixels((RGBColor)color, index, len); } |
mutech | 27:bc79f444883b | 121 | void fillPixels(const HSVColor color, int len = MAX_PIXELS) { fillPixels(color, 0, len); } |
mutech | 27:bc79f444883b | 122 | void fillPixels(const RGBColor color, int len = MAX_PIXELS) { fillPixels(color, 0, len); } |
mutech | 27:bc79f444883b | 123 | void fillPixels(const int color, int len = MAX_PIXELS) { fillPixels((RGBColor)color, 0, len); } |
mutech | 27:bc79f444883b | 124 | void clear(const HSVColor color) { fillPixels(color); } |
mutech | 27:bc79f444883b | 125 | void clear(const RGBColor color) { fillPixels(color); } |
mutech | 27:bc79f444883b | 126 | void clear(const int color = 0) { fillPixels((RGBColor)color); } |
mutech | 27:bc79f444883b | 127 | void repeatPixels(int block_size); |
mutech | 27:bc79f444883b | 128 | void repeatPixels(HSVColor *source, int size); |
mutech | 27:bc79f444883b | 129 | void repeatPixels(RGBColor *source, int size); |
mutech | 27:bc79f444883b | 130 | |
mutech | 27:bc79f444883b | 131 | HSVColor operator[](int index) const |
mutech | 27:bc79f444883b | 132 | { |
mutech | 27:bc79f444883b | 133 | if ((uint16_t)index < _numPixels) |
mutech | 27:bc79f444883b | 134 | return _pixels[index]; |
mutech | 27:bc79f444883b | 135 | return _dummyPixel; |
mutech | 27:bc79f444883b | 136 | } |
mutech | 27:bc79f444883b | 137 | |
mutech | 27:bc79f444883b | 138 | HSVColor& operator[](int index) |
mutech | 27:bc79f444883b | 139 | { |
mutech | 27:bc79f444883b | 140 | if ((uint16_t)index < _numPixels) |
mutech | 27:bc79f444883b | 141 | return _pixels[index]; |
mutech | 27:bc79f444883b | 142 | return _dummyPixel; |
mutech | 27:bc79f444883b | 143 | } |
mutech | 27:bc79f444883b | 144 | |
mutech | 27:bc79f444883b | 145 | HSVPixels& operator=(const HSVPixels& rhs); |
mutech | 27:bc79f444883b | 146 | |
mutech | 27:bc79f444883b | 147 | operator HSVColor*() const { return _pixels; } |
mutech | 27:bc79f444883b | 148 | |
mutech | 27:bc79f444883b | 149 | protected: |
mutech | 27:bc79f444883b | 150 | uint16_t _maxPixels; |
mutech | 27:bc79f444883b | 151 | uint16_t _numPixels; |
mutech | 27:bc79f444883b | 152 | HSVColor *_pixels; |
mutech | 27:bc79f444883b | 153 | |
mutech | 27:bc79f444883b | 154 | private: |
mutech | 27:bc79f444883b | 155 | bool _buf_owner; |
mutech | 27:bc79f444883b | 156 | HSVColor _dummyPixel; |
mutech | 27:bc79f444883b | 157 | |
mutech | 27:bc79f444883b | 158 | }; |
mutech | 27:bc79f444883b | 159 | |
mutech | 27:bc79f444883b | 160 | //---------------------------------------------------------------------------- |
mutech | 27:bc79f444883b | 161 | #endif // end of PIXELBUFFER_H |