1#include "../../Defines.h"
18LED_DisPlay::LED_DisPlay()
22LED_DisPlay::~LED_DisPlay()
26void LED_DisPlay::begin(uint8_t LEDNumber)
28 FastLED.addLeds<WS2812,
DATA_PIN, GRB>(_ledbuff, LEDNumber);
29 _xSemaphore = xSemaphoreCreateMutex();
30 _numberled = LEDNumber;
36void LED_DisPlay::run(
void *data)
40 for (
int num = 0; num < NUM_LEDS; num++)
42 _ledbuff[num] = 0x000000;
45 FastLED.setBrightness(20);
49 xSemaphoreTake(_xSemaphore, portMAX_DELAY);
50 if (_mode == kAnimation_run)
52 _displaybuff(_am_buffptr, _count_x, _count_y);
54 if ((_am_mode & kMoveRight) || (_am_mode & kMoveLeft))
56 if (_am_mode & kMoveRight)
65 if ((_am_mode & kMoveTop) || (_am_mode & kMoveBottom))
67 if (_am_mode & kMoveTop)
76 if ((_am_count != -1) && (_am_count != 0))
81 _mode = kAnimation_stop;
86 else if (_mode == kAnimation_frush)
88 _mode = kAnimation_stop;
90 FastLED.setBrightness(20);
92 xSemaphoreGive(_xSemaphore);
97void LED_DisPlay::_displaybuff(uint8_t *buffptr, int32_t offsetx, int32_t offsety)
99 uint16_t xsize = 0, ysize = 0;
103 offsetx = offsetx % xsize;
104 offsety = offsety % ysize;
106 int16_t setdatax = (offsetx < 0) ? (-offsetx) : (xsize - offsetx);
107 int16_t setdatay = (offsety < 0) ? (-offsety) : (ysize - offsety);
108 for (
int x = 0; x < 5; x++)
110 for (
int y = 0; y < 5; y++)
112 _ledbuff[x + y * 5].raw[1] = buffptr[2 + ((setdatax + x) % xsize + ((setdatay + y) % ysize) * xsize) * 3 + 0];
113 _ledbuff[x + y * 5].raw[0] = buffptr[2 + ((setdatax + x) % xsize + ((setdatay + y) % ysize) * xsize) * 3 + 1];
114 _ledbuff[x + y * 5].raw[2] = buffptr[2 + ((setdatax + x) % xsize + ((setdatay + y) % ysize) * xsize) * 3 + 2];
117 FastLED.setBrightness(Brightness);
120void LED_DisPlay::animation(uint8_t *buffptr, uint8_t amspeed, uint8_t ammode, int64_t amcount)
122 xSemaphoreTake(_xSemaphore, portMAX_DELAY);
123 if (_mode == kAnimation_run)
125 _mode = kAnimation_stop;
127 _am_buffptr = buffptr;
131 _count_x = _count_y = 0;
132 _mode = kAnimation_run;
133 xSemaphoreGive(_xSemaphore);
136void LED_DisPlay::displaybuff(uint8_t *buffptr, int32_t offsetx, int32_t offsety)
138 uint16_t xsize = 0, ysize = 0;
142 offsetx = offsetx % xsize;
143 offsety = offsety % ysize;
145 int16_t setdatax = (offsetx < 0) ? (-offsetx) : (xsize - offsetx);
146 int16_t setdatay = (offsety < 0) ? (-offsety) : (ysize - offsety);
147 xSemaphoreTake(_xSemaphore, portMAX_DELAY);
149 for (
int x = 0; x < 5; x++)
151 for (
int y = 0; y < 5; y++)
153 _ledbuff[x + y * 5].raw[1] = buffptr[2 + ((setdatax + x) % xsize + ((setdatay + y) % ysize) * xsize) * 3 + 0];
154 _ledbuff[x + y * 5].raw[0] = buffptr[2 + ((setdatax + x) % xsize + ((setdatay + y) % ysize) * xsize) * 3 + 1];
155 _ledbuff[x + y * 5].raw[2] = buffptr[2 + ((setdatax + x) % xsize + ((setdatay + y) % ysize) * xsize) * 3 + 2];
159 _mode = kAnimation_frush;
161 xSemaphoreGive(_xSemaphore);
162 FastLED.setBrightness(Brightness);
165void LED_DisPlay::setBrightness(uint8_t brightness)
167 xSemaphoreTake(_xSemaphore, portMAX_DELAY);
168 brightness = (brightness > 100) ? 100 : brightness;
169 brightness = (40 * brightness / 100);
170 Brightness = brightness;
171 FastLED.setBrightness(Brightness);
172 xSemaphoreGive(_xSemaphore);
175void LED_DisPlay::drawpix(uint8_t xpos, uint8_t ypos, CRGB Color)
177 if ((xpos >= 5) || (ypos >= 5))
181 xSemaphoreTake(_xSemaphore, portMAX_DELAY);
182 _ledbuff[xpos + ypos * 5] = Color;
183 _mode = kAnimation_frush;
184 xSemaphoreGive(_xSemaphore);
187void LED_DisPlay::drawpix(uint8_t Number, CRGB Color)
189 if (Number >= NUM_LEDS)
193 xSemaphoreTake(_xSemaphore, portMAX_DELAY);
194 _ledbuff[Number] = Color;
195 _mode = kAnimation_frush;
196 xSemaphoreGive(_xSemaphore);
199void LED_DisPlay::fillpix(CRGB Color)
201 xSemaphoreTake(_xSemaphore, portMAX_DELAY);
202 for (
int i = 0; i < NUM_LEDS; i++)
206 _mode = kAnimation_frush;
207 xSemaphoreGive(_xSemaphore);
210void LED_DisPlay::clear()
212 xSemaphoreTake(_xSemaphore, portMAX_DELAY);
213 for (int8_t i = 0; i < NUM_LEDS; i++)
217 _mode = kAnimation_frush;
218 xSemaphoreGive(_xSemaphore);
221boolean LED_DisPlay::animationrunning()
223 if (_mode == kAnimation_run)
227 else if (_mode == kAnimation_stop)
234void LED_DisPlay::setWidthHeight(uint16_t xColumns, uint16_t yRows)
236 _xColumns = xColumns;
boolean registerPinUse_mainModule(long pin, String pinName, String moduleName, boolean isI2C)