From 9a4193ee75ca2e25ff8dc1de5fa1e14802725e04 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sat, 28 May 2022 11:45:42 +0200 Subject: [PATCH] Refactor block helper --- eink.hpp | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/eink.hpp b/eink.hpp index f8c9daa..418ce91 100644 --- a/eink.hpp +++ b/eink.hpp @@ -33,6 +33,31 @@ class Eink { static io::Pin m_dc; static io::Pin m_bsy; + static constexpr auto BLOCK_SIZE = 5; + + enum class Color : uint8_t { + BLACK = 0b00, + WHITE = 0b01, + RED = 0b10, + ERROR = 0b11, + }; + + class ImageBlock { + public: + inline Color &operator[](const size_t idx) + { + return data[idx]; + } + + inline const Color &operator[](const size_t idx) const + { + return data[idx]; + } + + private: + Color data[BLOCK_SIZE]; + }; + public: static void init() { @@ -113,33 +138,8 @@ class Eink { template static void draw(const Image &image) { - constexpr auto BLOCK_SIZE = 5; - - enum class Color : uint8_t { - BLACK = 0b00, - WHITE = 0b01, - RED = 0b10, - ERROR = 0b11, - }; - - class Block { - public: - inline Color &operator[](const size_t idx) - { - return data[idx]; - } - - inline const Color &operator[](const size_t idx) const - { - return data[idx]; - } - - private: - Color data[BLOCK_SIZE]; - }; - constexpr auto lookup = [](uint8_t bits) { - auto block = Block{}; + auto block = ImageBlock{}; for_constexpr( [&](const auto idx) { block[idx.value] = static_cast(bits % 3);