17 template <
class OutputIt>
18 OutputIt
populate(OutputIt it, std::uint8_t b, rmt_item32_t zero, rmt_item32_t one);
20 template <
class OutputIt,
class T,
class = std::enable_if_t<not std::is_polymorphic_v<T>>>
21 OutputIt
populate(OutputIt it, T
const &t, rmt_item32_t zero, rmt_item32_t one);
31 [[nodiscard]]
virtual esp_err_t
update(std::vector<rgb>
const &colors, rmt_channel_t channel,
bool wait_tx_done) = 0;
32 [[nodiscard]]
virtual esp_err_t
update(
rgb color, rmt_channel_t channel,
bool wait_tx_done) = 0;
33 [[nodiscard]]
virtual std::size_t
size()
const = 0;
49 static constexpr float no_gamma = std::numeric_limits<float>::quiet_NaN();
51 static_assert(std::has_unique_object_representations_v<Led>,
"The Led class will be transmitted directly");
57 [[nodiscard]] esp_err_t
update(std::vector<rgb>
const &colors, rmt_channel_t channel,
bool wait_tx_done)
override;
58 [[nodiscard]] esp_err_t
update(
rgb color, rmt_channel_t channel,
bool wait_tx_done)
override;
60 [[nodiscard]] esp_err_t
transmit(rmt_channel_t channel,
bool wait_tx_done)
const;
62 template <
class Neopix,
class CRTPIt>
69 [[nodiscard]]
inline rmt_item32_t
zero()
const;
71 [[nodiscard]]
inline rmt_item32_t
one()
const;
73 [[nodiscard]]
inline std::size_t
size()
const override;
75 [[nodiscard]]
inline bool empty()
const;
77 [[nodiscard]]
inline float gamma()
const;
85 inline void resize(std::size_t new_size);
86 void resize(std::size_t new_size, Led
led);
107 template <
class Neopix,
class CRTPIt>
110 Neopix *_neopix =
nullptr;
111 std::size_t _i = std::numeric_limits<std::size_t>::max();
118 [[nodiscard]]
inline decltype(
auto)
operator*()
const;
128 [[nodiscard]]
inline bool operator==(CRTPIt
const &other)
const;
130 [[nodiscard]]
inline bool operator!=(CRTPIt
const &other)
const;
146 using value_type =
decltype(std::declval<strip const &>()[0]);
182 [[nodiscard]]
inline explicit operator Led()
const;
194 [[nodiscard]]
inline Led &
get_ref() {
return const_cast<Led &
>(
_cref); }
197 explicit ref(
strip<Led> const &
neo, Led &
ref, std::vector<rmt_item32_t>::iterator repr_it);
199 using cref<Led>::operator Led;
217 _gamma_table{nullptr} {
228 strip<Led>::strip(std::pair<rmt_item32_t, rmt_item32_t> zero_one, std::size_t size,
float gamma)
229 : _zero{zero_one.first},
230 _one{zero_one.second},
232 _gamma_table{nullptr} {
258 return _pixels.size();
263 resize(new_size, Led{});
268 const auto old_size = size();
269 _pixels.resize(new_size,
led);
270 _rmt_buffer.resize(new_size * 8 *
sizeof(Led), zero());
271 if (new_size > old_size) {
272 for (std::size_t i = old_size; i < new_size; ++i) {
285 template <
class Neopix,
class CRTPIt>
287 return (*_neopix)[_i];
292 template <
class Neopix,
class CRTPIt>
295 return *
reinterpret_cast<CRTPIt *
>(
this);
299 template <
class Neopix,
class CRTPIt>
301 CRTPIt copy = *
reinterpret_cast<CRTPIt *
>(
this);
307 template <
class Neopix,
class CRTPIt>
310 return *
reinterpret_cast<CRTPIt *
>(
this);
314 template <
class Neopix,
class CRTPIt>
316 CRTPIt copy = *
reinterpret_cast<CRTPIt *
>(
this);
323 template <
class Neopix,
class CRTPIt>
326 if (_neopix == other_base._neopix) {
327 if (_neopix !=
nullptr) {
328 return _i == other_base.
_i;
336 template <
class Neopix,
class CRTPIt>
338 return not operator==(other);
343 template <
class Neopix,
class CRTPIt>
346 return *
reinterpret_cast<CRTPIt *
>(
this);
351 template <
class Neopix,
class CRTPIt>
354 return *
reinterpret_cast<CRTPIt *
>(
this);
358 template <
class Neopix,
class CRTPIt>
360 CRTPIt copy = *
reinterpret_cast<CRTPIt
const *
>(
this);
366 template <
class Neopix,
class CRTPIt>
368 CRTPIt copy = *
reinterpret_cast<CRTPIt
const *
>(
this);
375 if (_neopix ==
nullptr) {
394 return {*
this, size() - 1};
400 return {*
this, size() - 1};
412 return {*
this, size() - 1};
417 using diff_t =
typename decltype(_rmt_buffer)::difference_type;
418 return ref{*
this, _pixels.at(i), std::begin(_rmt_buffer) + diff_t(i * 8 *
sizeof(Led))};
423 return cref{*
this, _pixels.at(i)};
428 return _pixels.empty();
438 return _cref.get_color(_strip.get_gamma_table());
452 get_ref().set_color(c, _strip.get_gamma_table());
454 populate(_repr_it, Led(*
this), _strip.zero(), _strip.one());
467 populate(_repr_it, Led(*
this), _strip.zero(), _strip.one());
471 template <
class OutputIt>
472 OutputIt
populate(OutputIt it, std::uint8_t b, rmt_item32_t zero, rmt_item32_t one) {
473 for (std::uint8_t mask = 1 << 7; mask != 0; mask >>= 1) {
474 *(it++) = (b & mask) != 0 ? one : zero;
479 template <
class OutputIt,
class T,
class>
480 OutputIt
populate(OutputIt it, T
const &t, rmt_item32_t zero, rmt_item32_t one) {
481 auto const *byte_rep =
reinterpret_cast<std::uint8_t
const *
>(&t);
482 for (std::size_t i = 0; i <
sizeof(T); ++i, ++byte_rep) {
483 it =
populate(it, *byte_rep, zero, one);
501 return rmt_write_items(channel, _rmt_buffer.data(), _rmt_buffer.size(), wait_tx_done);
505 esp_err_t
strip<Led>::update(std::vector<rgb>
const &colors, rmt_channel_t channel,
bool wait_tx_done) {
506 if (size() != colors.size()) {
507 resize(colors.size(), Led{});
509 std::copy(std::begin(colors), std::end(colors), std::begin(*
this));
510 return transmit(channel, wait_tx_done);
515 for (
auto led : *
this) {
518 return transmit(channel, wait_tx_done);
Definition: strip.hpp:174
Led const & _cref
Definition: strip.hpp:177
strip< Led > const & _strip
Definition: strip.hpp:176
cref(strip< Led > const &neo, Led const &cref)
Definition: strip.hpp:442
rgb get_color() const
Definition: strip.hpp:437
Definition: strip.hpp:189
std::vector< rmt_item32_t >::iterator _repr_it
Definition: strip.hpp:190
void set_color(rgb c)
Definition: strip.hpp:451
ref & operator=(Led v)
Definition: strip.hpp:464
ref(strip< Led > const &neo, Led &ref, std::vector< rmt_item32_t >::iterator repr_it)
Definition: strip.hpp:445
Led & get_ref()
Definition: strip.hpp:194
Definition: strip.hpp:143
decltype(std::declval< strip const & >()[0]) value_type
Definition: strip.hpp:146
void pointer
Definition: strip.hpp:148
std::random_access_iterator_tag iterator_category
Definition: strip.hpp:145
void reference
Definition: strip.hpp:149
void difference_type
Definition: strip.hpp:147
Definition: strip.hpp:108
CRTPIt & operator--()
Definition: strip.hpp:308
const CRTPIt operator--(int)
Definition: strip.hpp:315
CRTPIt & operator++()
Definition: strip.hpp:293
iterator_base(Neopix &neopix, std::size_t i)
Definition: strip.hpp:116
CRTPIt & operator-=(std::size_t n)
Definition: strip.hpp:352
bool operator==(CRTPIt const &other) const
Definition: strip.hpp:324
CRTPIt operator+(std::size_t n) const
Definition: strip.hpp:359
CRTPIt operator-(std::size_t n) const
Definition: strip.hpp:367
bool operator!=(CRTPIt const &other) const
Definition: strip.hpp:337
std::size_t _i
Definition: strip.hpp:111
CRTPIt & operator+=(std::size_t n)
Definition: strip.hpp:344
const CRTPIt operator++(int)
Definition: strip.hpp:300
Definition: strip.hpp:156
void difference_type
Definition: strip.hpp:164
decltype(std::declval< strip & >()[0]) value_type
Definition: strip.hpp:163
std::random_access_iterator_tag iterator_category
Definition: strip.hpp:162
void pointer
Definition: strip.hpp:165
void reference
Definition: strip.hpp:166
rmt_item32_t _one
Definition: strip.hpp:41
static constexpr float default_gamma
Definition: strip.hpp:48
void resize(std::size_t new_size)
Definition: strip.hpp:262
esp_err_t transmit(rmt_channel_t channel, bool wait_tx_done) const
Definition: strip.hpp:500
gamma_table const * _gamma_table
Definition: strip.hpp:43
const_iterator begin() const
Definition: strip.hpp:382
bool empty() const
Definition: strip.hpp:427
void clear()
Definition: strip.hpp:279
std::size_t size() const override
Definition: strip.hpp:257
const_iterator cend() const
Definition: strip.hpp:399
gamma_table const * get_gamma_table() const
Definition: strip.hpp:246
std::vector< Led > _pixels
Definition: strip.hpp:44
std::vector< rmt_item32_t > _rmt_buffer
Definition: strip.hpp:45
float _gamma
Definition: strip.hpp:42
strip(std::pair< rmt_item32_t, rmt_item32_t > zero_one, std::size_t size=0, float gamma=default_gamma)
Definition: strip.hpp:228
rmt_item32_t _zero
Definition: strip.hpp:40
const_iterator end() const
Definition: strip.hpp:393
const_iterator cbegin() const
Definition: strip.hpp:387
rmt_item32_t zero() const
Definition: strip.hpp:490
float gamma() const
Definition: strip.hpp:241
static constexpr float no_gamma
Definition: strip.hpp:49
void set_gamma(float gamma)
Definition: strip.hpp:251
ref< Led > operator[](std::size_t i)
Definition: strip.hpp:416
rmt_item32_t one() const
Definition: strip.hpp:495
esp_err_t update(std::vector< rgb > const &colors, rmt_channel_t channel, bool wait_tx_done) override
Definition: strip.hpp:505
virtual std::size_t size() const =0
virtual esp_err_t update(rgb color, rmt_channel_t channel, bool wait_tx_done)=0
virtual esp_err_t update(std::vector< rgb > const &colors, rmt_channel_t channel, bool wait_tx_done)=0
virtual ~transmittable_rgb_strip()=default
gamma_table const & get_cached_gamma_table(float gamma)
Definition: gamma.cpp:46
OutputIt populate(OutputIt it, std::uint8_t b, rmt_item32_t zero, rmt_item32_t one)
Definition: strip.hpp:472
std::pair< rmt_item32_t, rmt_item32_t > make_zero_one(rmt_manager const &manager, controller chip, bool inverted)
Definition: rmt.cpp:72
controller
Definition: rmt.hpp:15