10#ifndef M5_UNIT_RGB_UNIT_RECT_LED_HPP
11#define M5_UNIT_RGB_UNIT_RECT_LED_HPP
13#include <m5_utility/murmurhash3.hpp>
29template <const u
int8_t WIDTH, const u
int8_t HEIGHT,
class BaseClass>
30class UnitRectLED :
public BaseClass {
31 static_assert(WIDTH > 0,
"WIDTH must be greater than 0");
32 static_assert(HEIGHT > 0,
"HEIGHT must be greater than 0");
33 static_assert(std::is_base_of<UnitLED, BaseClass>::value,
"BaseClass must derive from UnitLED");
37 using BaseClass::BaseClass;
49 inline virtual uint16_t
width()
const override
51 return (this->rotation() & 1) ? HEIGHT : WIDTH;
57 inline virtual uint16_t
height()
const override
59 return (this->rotation() & 1) ? WIDTH : HEIGHT;
73 virtual uint16_t index_of(
const uint16_t n)
const override
75 switch (this->rotation()) {
77 uint8_t x = n % HEIGHT;
78 uint8_t y = n / HEIGHT;
79 return x * WIDTH + (WIDTH - 1 - y);
82 uint8_t x = n % WIDTH;
83 uint8_t y = n / WIDTH;
84 return (HEIGHT - 1 - y) * WIDTH + (WIDTH - 1 - x);
87 uint8_t x = n % HEIGHT;
88 uint8_t y = n / HEIGHT;
89 return (HEIGHT - 1 - x) * WIDTH + y;
100template <const u
int8_t WIDTH, const u
int8_t HEIGHT,
class BaseClass>
101const char UnitRectLED<WIDTH, HEIGHT, BaseClass>::name[] =
"UnitRectLED";
102template <const u
int8_t WIDTH, const u
int8_t HEIGHT,
class BaseClass>
103const types::uid_t UnitRectLED<WIDTH, HEIGHT, BaseClass>::uid{
104 m5::utility::mmh3::calculate(
"UnitRectLED",
sizeof(
"UnitRectLED") - 1)};
105template <const u
int8_t WIDTH, const u
int8_t HEIGHT,
class BaseClass>
106const types::attr_t UnitRectLED<WIDTH, HEIGHT, BaseClass>::attr{types::attribute::AccessGPIO};
static constexpr uint8_t LED_WIDTH
Physical width in pixels (not affected by rotation)
Definition unit_RectLED.hpp:42
virtual uint8_t maxRotation() const override
Get the max rotation (4 steps: 0/90/180/270 deg)
Definition unit_RectLED.hpp:66
UnitRectLED()
Default constructor (uses WIDTH x HEIGHT pixels)
Definition unit_RectLED.hpp:39
static constexpr uint8_t LED_HEIGHT
Physical height in pixels (not affected by rotation)
Definition unit_RectLED.hpp:43
virtual uint16_t height() const override
Logical height considering rotation (0/180: HEIGHT, 90/270: WIDTH)
Definition unit_RectLED.hpp:57
virtual uint16_t width() const override
Logical width considering rotation (0/180: WIDTH, 90/270: HEIGHT)
Definition unit_RectLED.hpp:49
Top level namespace of M5Stack.
LED base unit for M5UnitUnified.
SK6812 unit for M5UnitUnified.
WS2812 unit for M5UnitUnified.