Skip to content

Commit

Permalink
improve examples
Browse files Browse the repository at this point in the history
  • Loading branch information
phkehl committed May 19, 2019
1 parent c5c6b08 commit 2fbd43d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ menu "LED Display"
# these don't work:
#
#config LEDDISPLAY_TYPE_32X16_4SCAN
# bool "32x16 1/4 scan (doesn't work)
# bool "32x16 1/4 scan (doesn't work)"
#
#config LEDDISPLAY_TYPE_32X32_8SCAN
# bool "32x32 1/8 scan (doesn't work!)"
Expand Down
19 changes: 10 additions & 9 deletions examples/leddisplay_nyancat/main/leddisplay_nyancat.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,14 @@ static void sAnimNyan(leddisplay_frame_t *p_frame, uint32_t delay, int frame)
// clear display
leddisplay_pixel_fill_rgb(0, 0, 0);

const uint16_t x_max = LEDDISPLAY_WIDTH < 64 ? LEDDISPLAY_WIDTH : 64;
const uint16_t y_max = LEDDISPLAY_HEIGHT < 32 ? LEDDISPLAY_HEIGHT : 32;

// which frames to play?
int startFrame = (frame < 0) || (frame >= nFrames) ? 0 : frame;
int endFrame = (frame < 0) || (frame >= nFrames) ? (nFrames - 1) : frame;

// offset animation if display is smaller than the animation
const int16_t nxOffs = LEDDISPLAY_WIDTH < 64 ? (64 - LEDDISPLAY_WIDTH) / 2 : 0;
const int16_t nyOffs = LEDDISPLAY_HEIGHT < 32 ? (32 - LEDDISPLAY_HEIGHT) / 2 : 0;

// play each frame
uint32_t prevTick = xTaskGetTickCount();
for (frame = startFrame; frame <= endFrame; frame++)
Expand All @@ -206,23 +207,23 @@ static void sAnimNyan(leddisplay_frame_t *p_frame, uint32_t delay, int frame)
// pixel based
if (p_frame == NULL)
{
for (uint16_t x = 0; x < x_max; x++)
for (uint16_t x = 0; x < LEDDISPLAY_WIDTH; x++)
{
for (uint16_t y = 0; y < y_max; y++)
for (uint16_t y = 0; y < LEDDISPLAY_HEIGHT; y++)
{
const uint8_t *rgb = data->yx[y][x];
const uint8_t *rgb = data->yx[(nyOffs + y) % 32][(nxOffs + x) % 64];
leddisplay_pixel_xy_rgb(x, y, rgb[0], rgb[1], rgb[2]);
}
}
}
// frame based
else
{
for (uint16_t x = 0; x < x_max; x++)
for (uint16_t x = 0; x < LEDDISPLAY_WIDTH; x++)
{
for (uint16_t y = 0; y < y_max; y++)
for (uint16_t y = 0; y < LEDDISPLAY_HEIGHT; y++)
{
const uint8_t *rgb = data->yx[y][x];
const uint8_t *rgb = data->yx[(nyOffs + y) % 32][(nxOffs + x) % 64];
leddisplay_frame_xy_rgb(p_frame, x, y, rgb[0], rgb[1], rgb[2]);
}
}
Expand Down
19 changes: 10 additions & 9 deletions examples/leddisplay_test/main/leddisplay_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,14 @@ static void sAnimNyan(leddisplay_frame_t *p_frame, uint32_t delay, int frame)
// clear display
leddisplay_pixel_fill_rgb(0, 0, 0);

const uint16_t x_max = LEDDISPLAY_WIDTH < 64 ? LEDDISPLAY_WIDTH : 64;
const uint16_t y_max = LEDDISPLAY_HEIGHT < 32 ? LEDDISPLAY_HEIGHT : 32;

// which frames to play?
int startFrame = (frame < 0) || (frame >= nFrames) ? 0 : frame;
int endFrame = (frame < 0) || (frame >= nFrames) ? (nFrames - 1) : frame;

// offset animation if display is smaller than the animation
const int16_t nxOffs = LEDDISPLAY_WIDTH < 64 ? (64 - LEDDISPLAY_WIDTH) / 2 : 0;
const int16_t nyOffs = LEDDISPLAY_HEIGHT < 32 ? (32 - LEDDISPLAY_HEIGHT) / 2 : 0;

// play each frame
uint32_t prevTick = xTaskGetTickCount();
for (frame = startFrame; frame <= endFrame; frame++)
Expand All @@ -775,23 +776,23 @@ static void sAnimNyan(leddisplay_frame_t *p_frame, uint32_t delay, int frame)
// pixel based
if (p_frame == NULL)
{
for (uint16_t x = 0; x < x_max; x++)
for (uint16_t x = 0; x < LEDDISPLAY_WIDTH; x++)
{
for (uint16_t y = 0; y < y_max; y++)
for (uint16_t y = 0; y < LEDDISPLAY_HEIGHT; y++)
{
const uint8_t *rgb = data->yx[y][x];
const uint8_t *rgb = data->yx[(nyOffs + y) % 32][(nxOffs + x) % 64];
leddisplay_pixel_xy_rgb(x, y, rgb[0], rgb[1], rgb[2]);
}
}
}
// frame based
else
{
for (uint16_t x = 0; x < x_max; x++)
for (uint16_t x = 0; x < LEDDISPLAY_WIDTH; x++)
{
for (uint16_t y = 0; y < y_max; y++)
for (uint16_t y = 0; y < LEDDISPLAY_HEIGHT; y++)
{
const uint8_t *rgb = data->yx[y][x];
const uint8_t *rgb = data->yx[(nyOffs + y) % 32][(nxOffs + x) % 64];
leddisplay_frame_xy_rgb(p_frame, x, y, rgb[0], rgb[1], rgb[2]);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/leddisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,21 @@
// configuration (see also leddisplay.h)

#if CONFIG_LEDDISPLAY_TYPE_32X16_4SCAN // doesn't work
# error CONFIG_LEDDISPLAY_TYPE_32X16_4SCAN does not work
# warning CONFIG_LEDDISPLAY_TYPE_32X16_4SCAN does not work
# define LEDDISPLAY_ROWS_IN_PARALLEL 4

#elif CONFIG_LEDDISPLAY_TYPE_32X16_8SCAN // tested, works
# define LEDDISPLAY_ROWS_IN_PARALLEL 2

#elif CONFIG_LEDDISPLAY_TYPE_32X32_8SCAN // doesn't work
# error CONFIG_LEDDISPLAY_TYPE_32X32_8SCAN does not work
# warning CONFIG_LEDDISPLAY_TYPE_32X32_8SCAN does not work
# define LEDDISPLAY_ROWS_IN_PARALLEL 4

#elif CONFIG_LEDDISPLAY_TYPE_32X32_16SCAN // tested, works
# define LEDDISPLAY_ROWS_IN_PARALLEL 2

#elif CONFIG_LEDDISPLAY_TYPE_64X32_8SCAN // doesn't work
# error CONFIG_LEDDISPLAY_TYPE_64X32_8SCAN does not work
# warning CONFIG_LEDDISPLAY_TYPE_64X32_8SCAN does not work
# define LEDDISPLAY_ROWS_IN_PARALLEL 4

#elif CONFIG_LEDDISPLAY_TYPE_64X32_16SCAN // tested, works
Expand Down

0 comments on commit 2fbd43d

Please sign in to comment.