TLIGHT_PRODUCTS / WS281X
Committer:
mutech
Date:
Sat Sep 10 01:06:41 2016 +0000
Revision:
30:59b70f91b471
Parent:
29:a362df191524
Child:
32:64c391617f6c
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 27:bc79f444883b 47 ~RGBPixels();
mutech 27:bc79f444883b 48
mutech 27:bc79f444883b 49 void setPixelBuffer(RGBColor *buffer, int maxPixels);
mutech 27:bc79f444883b 50 int maxPixels() { return _maxPixels; }
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 29:a362df191524 58 void fillPixels(int index, const RGBColor color, int len);
mutech 29:a362df191524 59 void fillPixels(int index, const HSVColor color, int len);
mutech 30:59b70f91b471 60 void fillPixels(int index, const int color, int len) { fillPixels(index, (RGBColor)color, len); }
mutech 28:b452e097da53 61 void fillPixels(const RGBColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); }
mutech 28:b452e097da53 62 void fillPixels(const HSVColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); }
mutech 30:59b70f91b471 63 void fillPixels(const int color, int len = MAX_PIXELS) { fillPixels(0, (RGBColor)color, len); }
mutech 30:59b70f91b471 64
mutech 30:59b70f91b471 65 void fill(int index, const RGBColor color, int len) { fillPixels(index, color, len); }
mutech 30:59b70f91b471 66 void fill(int index, const HSVColor color, int len) { fillPixels(index, color, len); }
mutech 30:59b70f91b471 67 void fill(int index, const int color, int len) { fillPixels(index, (RGBColor)color, len); }
mutech 30:59b70f91b471 68 void fill(const RGBColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); }
mutech 30:59b70f91b471 69 void fill(const HSVColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); }
mutech 30:59b70f91b471 70 void fill(const int color, int len = MAX_PIXELS) { fillPixels(0, (RGBColor)color, len); }
mutech 28:b452e097da53 71
mutech 27:bc79f444883b 72 void clear(const RGBColor color) { fillPixels(color); }
mutech 27:bc79f444883b 73 void clear(const HSVColor color) { fillPixels(color); }
mutech 30:59b70f91b471 74 void clear(const int color = 0) { fillPixels((RGBColor)color); }
mutech 28:b452e097da53 75
mutech 27:bc79f444883b 76 void repeatPixels(int block_size);
mutech 27:bc79f444883b 77 void repeatPixels(RGBColor *source, int size);
mutech 27:bc79f444883b 78 void repeatPixels(HSVColor *source, int size);
mutech 27:bc79f444883b 79
mutech 28:b452e097da53 80 void makeGradation(int index, RGBColor from, RGBColor to, int len);
mutech 28:b452e097da53 81 void makeGradation(RGBColor from, RGBColor to, int len = MAX_PIXELS) { makeGradation(0, from, to, len); }
mutech 28:b452e097da53 82
mutech 28:b452e097da53 83 void makeRainbow(int index, HSVColor color, int len, int direction);
mutech 28:b452e097da53 84 void makeRainbow(HSVColor color, int len = MAX_PIXELS, int direction = 1) { makeRainbow(0, color, len, direction); }
mutech 28:b452e097da53 85
mutech 27:bc79f444883b 86 RGBColor operator[](int index) const
mutech 27:bc79f444883b 87 {
mutech 27:bc79f444883b 88 if ((uint16_t)index < _numPixels)
mutech 27:bc79f444883b 89 return _pixels[index];
mutech 27:bc79f444883b 90 return _dummyPixel;
mutech 27:bc79f444883b 91 }
mutech 27:bc79f444883b 92
mutech 27:bc79f444883b 93 RGBColor& operator[](int index)
mutech 27:bc79f444883b 94 {
mutech 27:bc79f444883b 95 if ((uint16_t)index < _numPixels)
mutech 27:bc79f444883b 96 return _pixels[index];
mutech 27:bc79f444883b 97 return _dummyPixel;
mutech 27:bc79f444883b 98 }
mutech 27:bc79f444883b 99
mutech 27:bc79f444883b 100 RGBPixels& operator=(const RGBPixels& rhs);
mutech 27:bc79f444883b 101
mutech 27:bc79f444883b 102 operator RGBColor*() const { return _pixels; }
mutech 27:bc79f444883b 103
mutech 27:bc79f444883b 104 protected:
mutech 27:bc79f444883b 105 uint16_t _maxPixels;
mutech 27:bc79f444883b 106 uint16_t _numPixels;
mutech 27:bc79f444883b 107 RGBColor *_pixels;
mutech 27:bc79f444883b 108
mutech 27:bc79f444883b 109 private:
mutech 27:bc79f444883b 110 bool _buf_owner;
mutech 27:bc79f444883b 111 RGBColor _dummyPixel;
mutech 27:bc79f444883b 112
mutech 27:bc79f444883b 113 };
mutech 27:bc79f444883b 114
mutech 27:bc79f444883b 115 //----------------------------------------------------------------------------
mutech 27:bc79f444883b 116 /**
mutech 27:bc79f444883b 117 * HSVPixels
mutech 27:bc79f444883b 118 */
mutech 27:bc79f444883b 119 class HSVPixels
mutech 27:bc79f444883b 120 {
mutech 27:bc79f444883b 121 public:
mutech 27:bc79f444883b 122 /**
mutech 27:bc79f444883b 123 * Initializes the addressable led bus
mutech 27:bc79f444883b 124 *
mutech 27:bc79f444883b 125 * @param Buffer - The Pixel array buffer address.
mutech 27:bc79f444883b 126 * @param maxPixels - Number of the addressable leds
mutech 27:bc79f444883b 127 */
mutech 27:bc79f444883b 128 HSVPixels(HSVColor *buffer = nullptr, int maxPixels = MAX_PIXELS);
mutech 27:bc79f444883b 129 HSVPixels(int maxPixels = MAX_PIXELS);
mutech 27:bc79f444883b 130 ~HSVPixels();
mutech 27:bc79f444883b 131
mutech 27:bc79f444883b 132 void setPixelBuffer(HSVColor *buffer, int maxPixels);
mutech 27:bc79f444883b 133 int maxPixels() { return _maxPixels; }
mutech 27:bc79f444883b 134 int numPixels(int value = -1);
mutech 27:bc79f444883b 135
mutech 27:bc79f444883b 136 void setPixels(int index, HSVColor *color, int len);
mutech 27:bc79f444883b 137 void setPixels(int index, RGBColor *color, int len);
mutech 27:bc79f444883b 138 void setPixels(HSVColor *color, int len) { setPixels(0, color, len); }
mutech 27:bc79f444883b 139 void setPixels(RGBColor *color, int len) { setPixels(0, color, len); }
mutech 28:b452e097da53 140
mutech 29:a362df191524 141 void fillPixels(int index, const HSVColor color, int len);
mutech 29:a362df191524 142 void fillPixels(int index, const RGBColor color, int len);
mutech 30:59b70f91b471 143 void fillPixels(int index, const int color, int len) { fillPixels(index, (RGBColor)color, len); }
mutech 29:a362df191524 144 void fillPixels(const HSVColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); }
mutech 29:a362df191524 145 void fillPixels(const RGBColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); }
mutech 30:59b70f91b471 146 void fillPixels(const int color, int len = MAX_PIXELS) { fillPixels(0, (RGBColor)color, len); }
mutech 30:59b70f91b471 147
mutech 30:59b70f91b471 148 void fill(int index, const HSVColor color, int len) { fillPixels(index, color, len); }
mutech 30:59b70f91b471 149 void fill(int index, const RGBColor color, int len) { fillPixels(index, color, len); }
mutech 30:59b70f91b471 150 void fill(int index, const int color, int len) { fillPixels(index, (RGBColor)color, len); }
mutech 30:59b70f91b471 151 void fill(const HSVColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); }
mutech 30:59b70f91b471 152 void fill(const RGBColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); }
mutech 30:59b70f91b471 153 void fill(const int color, int len = MAX_PIXELS) { fillPixels(0, (RGBColor)color, len); }
mutech 28:b452e097da53 154
mutech 27:bc79f444883b 155 void clear(const HSVColor color) { fillPixels(color); }
mutech 27:bc79f444883b 156 void clear(const RGBColor color) { fillPixels(color); }
mutech 28:b452e097da53 157 void clear(const int color = 0) { fillPixels((RGBColor)color); }
mutech 28:b452e097da53 158
mutech 27:bc79f444883b 159 void repeatPixels(int block_size);
mutech 27:bc79f444883b 160 void repeatPixels(HSVColor *source, int size);
mutech 27:bc79f444883b 161 void repeatPixels(RGBColor *source, int size);
mutech 27:bc79f444883b 162
mutech 28:b452e097da53 163 void makeGradation(int index, HSVColor from, HSVColor to, int len);
mutech 28:b452e097da53 164 void makeGradation(HSVColor from, HSVColor to, int len = MAX_PIXELS) { makeGradation(0, from, to, len); }
mutech 28:b452e097da53 165
mutech 28:b452e097da53 166 void makeRainbow(int index, HSVColor color, int len, int direction);
mutech 28:b452e097da53 167 void makeRainbow(HSVColor color, int len = MAX_PIXELS, int direction = 1) { makeRainbow(0, color, len, direction); }
mutech 28:b452e097da53 168
mutech 27:bc79f444883b 169 HSVColor operator[](int index) const
mutech 27:bc79f444883b 170 {
mutech 27:bc79f444883b 171 if ((uint16_t)index < _numPixels)
mutech 27:bc79f444883b 172 return _pixels[index];
mutech 27:bc79f444883b 173 return _dummyPixel;
mutech 27:bc79f444883b 174 }
mutech 27:bc79f444883b 175
mutech 27:bc79f444883b 176 HSVColor& operator[](int index)
mutech 27:bc79f444883b 177 {
mutech 27:bc79f444883b 178 if ((uint16_t)index < _numPixels)
mutech 27:bc79f444883b 179 return _pixels[index];
mutech 27:bc79f444883b 180 return _dummyPixel;
mutech 27:bc79f444883b 181 }
mutech 27:bc79f444883b 182
mutech 27:bc79f444883b 183 HSVPixels& operator=(const HSVPixels& rhs);
mutech 27:bc79f444883b 184
mutech 27:bc79f444883b 185 operator HSVColor*() const { return _pixels; }
mutech 27:bc79f444883b 186
mutech 27:bc79f444883b 187 protected:
mutech 27:bc79f444883b 188 uint16_t _maxPixels;
mutech 27:bc79f444883b 189 uint16_t _numPixels;
mutech 27:bc79f444883b 190 HSVColor *_pixels;
mutech 27:bc79f444883b 191
mutech 27:bc79f444883b 192 private:
mutech 27:bc79f444883b 193 bool _buf_owner;
mutech 27:bc79f444883b 194 HSVColor _dummyPixel;
mutech 27:bc79f444883b 195
mutech 27:bc79f444883b 196 };
mutech 27:bc79f444883b 197
mutech 27:bc79f444883b 198 //----------------------------------------------------------------------------
mutech 27:bc79f444883b 199 #endif // end of PIXELBUFFER_H