TLIGHT_PRODUCTS / WS281X
Committer:
mutech
Date:
Tue Dec 20 03:22:01 2016 +0000
Revision:
46:2374900f8845
Parent:
32:64c391617f6c
Child:
49:27d8f1d43ca9
WS2811/WS2812 support Library;

Who changed what in which revision?

UserRevisionLine numberNew 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 28:b452e097da53 7 * Rev 0.98 2016-09-08
mutech 27:bc79f444883b 8 */
mutech 27:bc79f444883b 9
mutech 27:bc79f444883b 10 #pragma once
mutech 27:bc79f444883b 11
mutech 27:bc79f444883b 12 #ifndef PIXELBUFFER_H
mutech 27:bc79f444883b 13 #define PIXELBUFFER_H
mutech 27:bc79f444883b 14
mutech 28:b452e097da53 15 #ifdef _WIN32
mutech 28:b452e097da53 16 #include <stdint.h>
mutech 28:b452e097da53 17 #include <string.h>
mutech 28:b452e097da53 18 #else
mutech 27:bc79f444883b 19 #include "mbed.h"
mutech 28:b452e097da53 20 #endif
mutech 27:bc79f444883b 21 #include "ColorLib.h"
mutech 27:bc79f444883b 22
mutech 27:bc79f444883b 23 //----------------------------------------------------------------------------
mutech 27:bc79f444883b 24 #ifndef MAX_PIXELS
mutech 27:bc79f444883b 25 #define MAX_PIXELS 170
mutech 27:bc79f444883b 26 #endif
mutech 27:bc79f444883b 27
mutech 27:bc79f444883b 28 #ifndef nullptr
mutech 27:bc79f444883b 29 #define nullptr (0)
mutech 27:bc79f444883b 30 #endif
mutech 27:bc79f444883b 31
mutech 27:bc79f444883b 32 //----------------------------------------------------------------------------
mutech 27:bc79f444883b 33 /**
mutech 27:bc79f444883b 34 * RGBPixels
mutech 27:bc79f444883b 35 */
mutech 27:bc79f444883b 36 class RGBPixels
mutech 27:bc79f444883b 37 {
mutech 27:bc79f444883b 38 public:
mutech 27:bc79f444883b 39 /**
mutech 27:bc79f444883b 40 * Initializes the addressable led bus
mutech 27:bc79f444883b 41 *
mutech 27:bc79f444883b 42 * @param Buffer - The Pixel array buffer address.
mutech 27:bc79f444883b 43 * @param maxPixels - Number of the addressable leds
mutech 27:bc79f444883b 44 */
mutech 27:bc79f444883b 45 RGBPixels(RGBColor *buffer = nullptr, int maxPixels = MAX_PIXELS);
mutech 27:bc79f444883b 46 RGBPixels(int maxPixels = MAX_PIXELS);
mutech 46:2374900f8845 47 virtual ~RGBPixels();
mutech 27:bc79f444883b 48
mutech 27:bc79f444883b 49 void setPixelBuffer(RGBColor *buffer, int maxPixels);
mutech 46:2374900f8845 50 int maxPixels() { return _max_pixels; }
mutech 27:bc79f444883b 51 int numPixels(int value = -1);
mutech 27:bc79f444883b 52
mutech 27:bc79f444883b 53 void setPixels(int index, RGBColor *color, int len);
mutech 27:bc79f444883b 54 void setPixels(int index, HSVColor *color, int len);
mutech 27:bc79f444883b 55 void setPixels(RGBColor *color, int len) { setPixels(0, color, len); }
mutech 27:bc79f444883b 56 void setPixels(HSVColor *color, int len) { setPixels(0, color, len); }
mutech 28:b452e097da53 57
mutech 46:2374900f8845 58 void setGammaPixels(int index, RGBColor *color, int len);
mutech 46:2374900f8845 59 void setGammaPixels(int index, HSVColor *color, int len);
mutech 46:2374900f8845 60 void setGammaPixels(RGBColor *color, int len) { setGammaPixels(0, color, len); }
mutech 46:2374900f8845 61 void setGammaPixels(HSVColor *color, int len) { setGammaPixels(0, color, len); }
mutech 46:2374900f8845 62
mutech 29:a362df191524 63 void fillPixels(int index, const RGBColor color, int len);
mutech 29:a362df191524 64 void fillPixels(int index, const HSVColor color, int len);
mutech 30:59b70f91b471 65 void fillPixels(int index, const int color, int len) { fillPixels(index, (RGBColor)color, len); }
mutech 28:b452e097da53 66 void fillPixels(const RGBColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); }
mutech 28:b452e097da53 67 void fillPixels(const HSVColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); }
mutech 30:59b70f91b471 68 void fillPixels(const int color, int len = MAX_PIXELS) { fillPixels(0, (RGBColor)color, len); }
mutech 30:59b70f91b471 69
mutech 30:59b70f91b471 70 void fill(int index, const RGBColor color, int len) { fillPixels(index, color, len); }
mutech 30:59b70f91b471 71 void fill(int index, const HSVColor color, int len) { fillPixels(index, color, len); }
mutech 30:59b70f91b471 72 void fill(int index, const int color, int len) { fillPixels(index, (RGBColor)color, len); }
mutech 30:59b70f91b471 73 void fill(const RGBColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); }
mutech 30:59b70f91b471 74 void fill(const HSVColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); }
mutech 30:59b70f91b471 75 void fill(const int color, int len = MAX_PIXELS) { fillPixels(0, (RGBColor)color, len); }
mutech 28:b452e097da53 76
mutech 27:bc79f444883b 77 void clear(const RGBColor color) { fillPixels(color); }
mutech 27:bc79f444883b 78 void clear(const HSVColor color) { fillPixels(color); }
mutech 30:59b70f91b471 79 void clear(const int color = 0) { fillPixels((RGBColor)color); }
mutech 28:b452e097da53 80
mutech 27:bc79f444883b 81 void repeatPixels(int block_size);
mutech 27:bc79f444883b 82 void repeatPixels(RGBColor *source, int size);
mutech 27:bc79f444883b 83 void repeatPixels(HSVColor *source, int size);
mutech 27:bc79f444883b 84
mutech 28:b452e097da53 85 void makeGradation(int index, RGBColor from, RGBColor to, int len);
mutech 28:b452e097da53 86 void makeGradation(RGBColor from, RGBColor to, int len = MAX_PIXELS) { makeGradation(0, from, to, len); }
mutech 28:b452e097da53 87
mutech 28:b452e097da53 88 void makeRainbow(int index, HSVColor color, int len, int direction);
mutech 28:b452e097da53 89 void makeRainbow(HSVColor color, int len = MAX_PIXELS, int direction = 1) { makeRainbow(0, color, len, direction); }
mutech 28:b452e097da53 90
mutech 27:bc79f444883b 91 RGBColor operator[](int index) const
mutech 27:bc79f444883b 92 {
mutech 46:2374900f8845 93 if (_pixels && (uint16_t)index < _num_pixels)
mutech 27:bc79f444883b 94 return _pixels[index];
mutech 46:2374900f8845 95 return _dummy_pixel;
mutech 27:bc79f444883b 96 }
mutech 27:bc79f444883b 97
mutech 27:bc79f444883b 98 RGBColor& operator[](int index)
mutech 27:bc79f444883b 99 {
mutech 46:2374900f8845 100 if (_pixels && (uint16_t)index < _num_pixels)
mutech 27:bc79f444883b 101 return _pixels[index];
mutech 46:2374900f8845 102 return _dummy_pixel;
mutech 27:bc79f444883b 103 }
mutech 27:bc79f444883b 104
mutech 27:bc79f444883b 105 RGBPixels& operator=(const RGBPixels& rhs);
mutech 27:bc79f444883b 106
mutech 27:bc79f444883b 107 operator RGBColor*() const { return _pixels; }
mutech 27:bc79f444883b 108
mutech 27:bc79f444883b 109 protected:
mutech 46:2374900f8845 110 uint16_t _max_pixels;
mutech 46:2374900f8845 111 uint16_t _num_pixels;
mutech 27:bc79f444883b 112 RGBColor *_pixels;
mutech 46:2374900f8845 113 RGBColor _dummy_pixel;
mutech 27:bc79f444883b 114
mutech 27:bc79f444883b 115 private:
mutech 32:64c391617f6c 116 bool _owned_buffer;
mutech 27:bc79f444883b 117
mutech 27:bc79f444883b 118 };
mutech 27:bc79f444883b 119
mutech 27:bc79f444883b 120 //----------------------------------------------------------------------------
mutech 27:bc79f444883b 121 /**
mutech 27:bc79f444883b 122 * HSVPixels
mutech 27:bc79f444883b 123 */
mutech 27:bc79f444883b 124 class HSVPixels
mutech 27:bc79f444883b 125 {
mutech 27:bc79f444883b 126 public:
mutech 27:bc79f444883b 127 /**
mutech 27:bc79f444883b 128 * Initializes the addressable led bus
mutech 27:bc79f444883b 129 *
mutech 27:bc79f444883b 130 * @param Buffer - The Pixel array buffer address.
mutech 27:bc79f444883b 131 * @param maxPixels - Number of the addressable leds
mutech 27:bc79f444883b 132 */
mutech 27:bc79f444883b 133 HSVPixels(HSVColor *buffer = nullptr, int maxPixels = MAX_PIXELS);
mutech 27:bc79f444883b 134 HSVPixels(int maxPixels = MAX_PIXELS);
mutech 46:2374900f8845 135 virtual ~HSVPixels();
mutech 27:bc79f444883b 136
mutech 27:bc79f444883b 137 void setPixelBuffer(HSVColor *buffer, int maxPixels);
mutech 46:2374900f8845 138 int maxPixels() { return _max_pixels; }
mutech 27:bc79f444883b 139 int numPixels(int value = -1);
mutech 27:bc79f444883b 140
mutech 27:bc79f444883b 141 void setPixels(int index, HSVColor *color, int len);
mutech 27:bc79f444883b 142 void setPixels(int index, RGBColor *color, int len);
mutech 27:bc79f444883b 143 void setPixels(HSVColor *color, int len) { setPixels(0, color, len); }
mutech 27:bc79f444883b 144 void setPixels(RGBColor *color, int len) { setPixels(0, color, len); }
mutech 28:b452e097da53 145
mutech 29:a362df191524 146 void fillPixels(int index, const HSVColor color, int len);
mutech 29:a362df191524 147 void fillPixels(int index, const RGBColor color, int len);
mutech 30:59b70f91b471 148 void fillPixels(int index, const int color, int len) { fillPixels(index, (RGBColor)color, len); }
mutech 29:a362df191524 149 void fillPixels(const HSVColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); }
mutech 29:a362df191524 150 void fillPixels(const RGBColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); }
mutech 30:59b70f91b471 151 void fillPixels(const int color, int len = MAX_PIXELS) { fillPixels(0, (RGBColor)color, len); }
mutech 30:59b70f91b471 152
mutech 30:59b70f91b471 153 void fill(int index, const HSVColor color, int len) { fillPixels(index, color, len); }
mutech 30:59b70f91b471 154 void fill(int index, const RGBColor color, int len) { fillPixels(index, color, len); }
mutech 30:59b70f91b471 155 void fill(int index, const int color, int len) { fillPixels(index, (RGBColor)color, len); }
mutech 30:59b70f91b471 156 void fill(const HSVColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); }
mutech 30:59b70f91b471 157 void fill(const RGBColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); }
mutech 30:59b70f91b471 158 void fill(const int color, int len = MAX_PIXELS) { fillPixels(0, (RGBColor)color, len); }
mutech 28:b452e097da53 159
mutech 27:bc79f444883b 160 void clear(const HSVColor color) { fillPixels(color); }
mutech 27:bc79f444883b 161 void clear(const RGBColor color) { fillPixels(color); }
mutech 28:b452e097da53 162 void clear(const int color = 0) { fillPixels((RGBColor)color); }
mutech 28:b452e097da53 163
mutech 27:bc79f444883b 164 void repeatPixels(int block_size);
mutech 27:bc79f444883b 165 void repeatPixels(HSVColor *source, int size);
mutech 27:bc79f444883b 166 void repeatPixels(RGBColor *source, int size);
mutech 27:bc79f444883b 167
mutech 28:b452e097da53 168 void makeGradation(int index, HSVColor from, HSVColor to, int len);
mutech 28:b452e097da53 169 void makeGradation(HSVColor from, HSVColor to, int len = MAX_PIXELS) { makeGradation(0, from, to, len); }
mutech 28:b452e097da53 170
mutech 28:b452e097da53 171 void makeRainbow(int index, HSVColor color, int len, int direction);
mutech 28:b452e097da53 172 void makeRainbow(HSVColor color, int len = MAX_PIXELS, int direction = 1) { makeRainbow(0, color, len, direction); }
mutech 28:b452e097da53 173
mutech 27:bc79f444883b 174 HSVColor operator[](int index) const
mutech 27:bc79f444883b 175 {
mutech 46:2374900f8845 176 if (_pixels && (uint16_t)index < _num_pixels)
mutech 27:bc79f444883b 177 return _pixels[index];
mutech 46:2374900f8845 178 return _dummy_pixel;
mutech 27:bc79f444883b 179 }
mutech 27:bc79f444883b 180
mutech 27:bc79f444883b 181 HSVColor& operator[](int index)
mutech 27:bc79f444883b 182 {
mutech 46:2374900f8845 183 if (_pixels && (uint16_t)index < _num_pixels)
mutech 27:bc79f444883b 184 return _pixels[index];
mutech 46:2374900f8845 185 return _dummy_pixel;
mutech 27:bc79f444883b 186 }
mutech 27:bc79f444883b 187
mutech 27:bc79f444883b 188 HSVPixels& operator=(const HSVPixels& rhs);
mutech 27:bc79f444883b 189
mutech 27:bc79f444883b 190 operator HSVColor*() const { return _pixels; }
mutech 27:bc79f444883b 191
mutech 27:bc79f444883b 192 protected:
mutech 46:2374900f8845 193 uint16_t _max_pixels;
mutech 46:2374900f8845 194 uint16_t _num_pixels;
mutech 27:bc79f444883b 195 HSVColor *_pixels;
mutech 46:2374900f8845 196 HSVColor _dummy_pixel;
mutech 27:bc79f444883b 197
mutech 27:bc79f444883b 198 private:
mutech 32:64c391617f6c 199 bool _owned_buffer;
mutech 27:bc79f444883b 200
mutech 27:bc79f444883b 201 };
mutech 27:bc79f444883b 202
mutech 27:bc79f444883b 203 //----------------------------------------------------------------------------
mutech 27:bc79f444883b 204 #endif // end of PIXELBUFFER_H