Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove blocking semaphore, display initial state and allow large matrix #14

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/Basics/LEDDisplay/LEDDisplay.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ void setup()
{
M5.begin(true, false, true);
delay(50);
M5.dis.animation((uint8_t *)AtomImageData, 200, LED_Display::kMoveLeft, 18);
M5.dis.animation((uint8_t *)AtomImageData, 200, LED_Display::kMoveLeft, 19);
}

void loop()
{
delay(500);
M5.update();
}
}
1 change: 1 addition & 0 deletions library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ category=Device Control
url=https://github.com/m5stack/M5Atom
architectures=esp32
includes=M5Atom.h
depends=FastLED
34 changes: 16 additions & 18 deletions src/utility/LED_DisPlay.cpp → src/utility/LED_Display.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "LED_Display.h"

LED_Display::LED_Display(uint8_t LEDNumbre)
LED_Display::LED_Display(uint8_t LEDNumber)
{
FastLED.addLeds<WS2812, DATA_PIN>(_ledbuff, LEDNumbre);
FastLED.addLeds<WS2812, DATA_PIN>(_ledbuff, LEDNumber);
_xSemaphore = xSemaphoreCreateMutex();
_numberled = LEDNumbre;
_numberled = LEDNumber;
}

LED_Display::~LED_Display()
Expand All @@ -16,7 +16,7 @@ void LED_Display::run(void *data)
{
data = nullptr;

for (int num = 0; num < 26; num++)
for (int num = 0; num < NUM_LEDS; num++)
{
_ledbuff[num] = 0x000000;
}
Expand All @@ -26,8 +26,9 @@ void LED_Display::run(void *data)
while (1)
{
xSemaphoreTake(_xSemaphore, portMAX_DELAY);
if (_mode == kAnmiation_run)
if (_mode == kAnimation_run)
{
displaybuff(_am_buffptr, _count_x, _count_y);
if ((_am_mode & kMoveRight) || (_am_mode & kMoveLeft))
{
if (_am_mode & kMoveRight)
Expand All @@ -39,7 +40,7 @@ void LED_Display::run(void *data)
_count_x--;
}
}
if ((_am_mode & kMoveTop) || (_am_mode & kMoveButtom))
if ((_am_mode & kMoveTop) || (_am_mode & kMoveBottom))
{
if (_am_mode & kMoveTop)
{
Expand All @@ -55,10 +56,9 @@ void LED_Display::run(void *data)
_am_count--;
if (_am_count == 0)
{
_mode = kAnmiation_stop;
_mode = kAnimation_stop;
}
}
displaybuff(_am_buffptr, _count_x, _count_y);
delay(_am_speed);
delay(10);
xSemaphoreGive(_xSemaphore);
Expand All @@ -70,26 +70,27 @@ void LED_Display::run(void *data)
}

FastLED.show();
FastLED.setBrightness(20);
}
}

void LED_Display::animation(uint8_t *buffptr, uint8_t amspeed, uint8_t ammode, int64_t amcount)
{
xSemaphoreTake(_xSemaphore, portMAX_DELAY);
if (_mode == kAnmiation_run)
if (_mode == kAnimation_run)
{
_mode = kAnmiation_stop;
_mode = kAnimation_stop;
}
_am_buffptr = buffptr;
_am_speed = amspeed;
_am_mode = ammode;
_am_count = amcount;
_count_x = _count_y = 0;
_mode = kAnmiation_run;
_mode = kAnimation_run;
xSemaphoreGive(_xSemaphore);
}

void LED_Display::displaybuff(uint8_t *buffptr, int8_t offsetx, int8_t offsety)
void LED_Display::displaybuff(uint8_t *buffptr, int32_t offsetx, int32_t offsety)
{
uint16_t xsize = 0, ysize = 0;
xsize = buffptr[0];
Expand All @@ -98,9 +99,8 @@ void LED_Display::displaybuff(uint8_t *buffptr, int8_t offsetx, int8_t offsety)
offsetx = offsetx % xsize;
offsety = offsety % ysize;

int8_t setdatax = (offsetx < 0) ? (-offsetx) : (xsize - offsetx);
int8_t setdatay = (offsety < 0) ? (-offsety) : (ysize - offsety);
xSemaphoreTake(_xSemaphore, portMAX_DELAY);
int16_t setdatax = (offsetx < 0) ? (-offsetx) : (xsize - offsetx);
int16_t setdatay = (offsety < 0) ? (-offsety) : (ysize - offsety);
for (int x = 0; x < 5; x++)
{
for (int y = 0; y < 5; y++)
Expand All @@ -110,8 +110,6 @@ void LED_Display::displaybuff(uint8_t *buffptr, int8_t offsetx, int8_t offsety)
_ledbuff[x + y * 5].raw[2] = buffptr[2 + ((setdatax + x) % xsize + ((setdatay + y) % ysize) * xsize) * 3 + 2];
}
}
xSemaphoreGive(_xSemaphore);
FastLED.setBrightness(20);
}

void LED_Display::setBrightness(uint8_t brightness)
Expand Down Expand Up @@ -146,7 +144,7 @@ void LED_Display::drawpix(uint8_t Number, CRGB Color)
void LED_Display::clear()
{
xSemaphoreTake(_xSemaphore, portMAX_DELAY);
for (int8_t i = 0; i < 25; i++)
for (int8_t i = 0; i < NUM_LEDS; i++)
{
_ledbuff[i] = 0;
}
Expand Down
11 changes: 5 additions & 6 deletions src/utility/LED_Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,25 @@ class LED_Display : public Task
enum
{
kStatic = 0,
kAnmiation_run,
kAnmiation_stop,
kAnimation_run,
kAnimation_stop,
} Dismode;
enum
{
kMoveRight = 0x01,
kMoveLeft = 0x02,
kMoveTop = 0x04,
kMoveButtom = 0x08,
kMoveBottom = 0x08,
} Am_mode;

/* data */
public:
LED_Display(uint8_t LEDNumbre = 25);
LED_Display(uint8_t LEDNumber = NUM_LEDS);
~LED_Display();
void run(void *data);

void animation(uint8_t *buffptr, uint8_t amspeed, uint8_t ammode, int64_t amcount = -1);
void displaybuff(uint8_t *buffptr, int8_t offsetx = 0, int8_t offsety = 0);
void MoveDisPlayBuff(int8_t offsetx = 0, int8_t offsety = 0);
void displaybuff(uint8_t *buffptr, int32_t offsetx = 0, int32_t offsety = 0);

void setBrightness(uint8_t brightness);
void drawpix(uint8_t xpos, uint8_t ypos, CRGB Color);
Expand Down