libepaper 2.0.0
A C++23 library for controlling Waveshare e-paper displays on Raspberry Pi, featuring transparent sleep/wake management and a fluent builder API.
Loading...
Searching...
No Matches
device_color.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "epaper/color/color.hpp" // Added include for RGB
5#include <cstdint>
6
7namespace epaper {
8
26template <DisplayMode Mode> struct DeviceColor {
27 std::uint8_t value;
28
29 constexpr explicit DeviceColor(std::uint8_t val = 0) : value(val) {}
30
31 constexpr auto operator==(const DeviceColor &other) const noexcept -> bool = default;
32};
33
55template <> struct DeviceColor<DisplayMode::BlackWhite> {
56 bool is_white;
57
58 constexpr explicit DeviceColor(bool white = true) : is_white(white) {}
59
60 constexpr auto operator==(const DeviceColor &other) const noexcept -> bool = default;
61
62 [[nodiscard]] constexpr auto to_byte() const noexcept -> std::uint8_t { return is_white ? 0xFF : 0x00; }
63 [[nodiscard]] constexpr auto to_rgb() const noexcept -> RGB { return is_white ? colors::White : colors::Black; }
64};
65
99template <> struct DeviceColor<DisplayMode::Grayscale4> {
100 std::uint8_t level;
101
102 constexpr explicit DeviceColor(std::uint8_t gray_level = 3) : level(gray_level & 0x03) {}
103
104 constexpr auto operator==(const DeviceColor &other) const noexcept -> bool = default;
105
106 [[nodiscard]] constexpr auto to_byte() const noexcept -> std::uint8_t {
107 // Map 2-bit level to 8-bit value
108 // 0 -> 0x00 (black), 1 -> 0x40, 2 -> 0x80, 3 -> 0xC0 (white)
109 return static_cast<std::uint8_t>(level << 6);
110 }
111
112 [[nodiscard]] constexpr auto to_rgb() const noexcept -> RGB {
113 switch (level) {
114 case 0:
115 return colors::Black;
116 case 1:
117 return colors::DarkGray;
118 case 2:
119 return colors::LightGray;
120 default:
121 return colors::White;
122 }
123 }
124};
125
144enum class TriColor : std::uint8_t {
145 Black = 0,
146 White = 1,
147 Third = 2
148};
149
175template <> struct DeviceColor<DisplayMode::BWR> {
177
178 constexpr explicit DeviceColor(TriColor c = TriColor::White) : color(c) {}
179
180 constexpr auto operator==(const DeviceColor &other) const noexcept -> bool = default;
181
182 [[nodiscard]] constexpr auto to_byte() const noexcept -> std::uint8_t { return static_cast<std::uint8_t>(color); }
183
184 [[nodiscard]] constexpr auto get_bw_bit() const noexcept -> bool { return color != TriColor::Black; }
185 [[nodiscard]] constexpr auto get_color_bit() const noexcept -> bool { return color != TriColor::Third; }
186
187 [[nodiscard]] constexpr auto to_rgb() const noexcept -> RGB {
188 switch (color) {
189 case TriColor::Black:
190 return colors::Black;
191 case TriColor::Third:
192 return colors::Red;
193 default:
194 return colors::White;
195 }
196 }
197};
198
202template <> struct DeviceColor<DisplayMode::BWY> {
204
205 constexpr explicit DeviceColor(TriColor c = TriColor::White) : color(c) {}
206
207 constexpr auto operator==(const DeviceColor &other) const noexcept -> bool = default;
208
209 [[nodiscard]] constexpr auto to_byte() const noexcept -> std::uint8_t { return static_cast<std::uint8_t>(color); }
210
211 [[nodiscard]] constexpr auto get_bw_bit() const noexcept -> bool { return color != TriColor::Black; }
212 [[nodiscard]] constexpr auto get_color_bit() const noexcept -> bool { return color != TriColor::Third; }
213
214 [[nodiscard]] constexpr auto to_rgb() const noexcept -> RGB {
215 switch (color) {
216 case TriColor::Black:
217 return colors::Black;
218 case TriColor::Third:
219 return colors::Yellow;
220 default:
221 return colors::White;
222 }
223 }
224};
225
248enum class Spectra6Color : std::uint8_t { Black = 0, White = 1, Red = 2, Yellow = 3, Blue = 4, Green = 5 };
249
253template <> struct DeviceColor<DisplayMode::Spectra6> {
255
256 constexpr explicit DeviceColor(Spectra6Color c = Spectra6Color::White) : color(c) {}
257
258 constexpr auto operator==(const DeviceColor &other) const noexcept -> bool = default;
259
260 [[nodiscard]] constexpr auto to_byte() const noexcept -> std::uint8_t { return static_cast<std::uint8_t>(color); }
261
262 [[nodiscard]] constexpr auto to_uint8() const noexcept -> std::uint8_t { return static_cast<std::uint8_t>(color); }
263
264 [[nodiscard]] constexpr auto to_rgb() const noexcept -> RGB {
265 switch (color) {
267 return colors::Black;
269 return colors::Red;
271 return colors::Green;
273 return colors::Blue;
275 return colors::Yellow;
276 default:
277 return colors::White;
278 }
279 }
280};
281
282} // namespace epaper
constexpr RGB Blue
Definition color.hpp:189
constexpr RGB Yellow
Definition color.hpp:190
constexpr RGB DarkGray
Definition color.hpp:194
constexpr RGB LightGray
Definition color.hpp:195
constexpr RGB Black
Definition color.hpp:185
constexpr RGB White
Definition color.hpp:186
constexpr RGB Red
Definition color.hpp:187
constexpr RGB Green
Definition color.hpp:188
Definition color.hpp:5
TriColor
Color values for 3-color displays (Black/White/Red or Black/White/Yellow).
Definition device_color.hpp:144
@ Third
Red for BWR, Yellow for BWY.
DisplayMode
Definition driver.hpp:46
@ BWY
Black, White, Yellow (3 colors, typically 2-bit)
@ Spectra6
6-color: Black, White, Red, Yellow, Blue, Green (3-bit)
@ BlackWhite
1-bit black and white (2 colors)
@ Grayscale4
2-bit 4-level grayscale
@ BWR
Black, White, Red (3 colors, typically 2-bit)
Spectra6Color
Color values for Spectra 6 displays.
Definition device_color.hpp:248
constexpr auto to_rgb() const noexcept -> RGB
Definition device_color.hpp:187
TriColor color
Color value (Black, White, or Red)
Definition device_color.hpp:176
constexpr auto get_bw_bit() const noexcept -> bool
Definition device_color.hpp:184
constexpr auto to_byte() const noexcept -> std::uint8_t
Definition device_color.hpp:182
constexpr auto get_color_bit() const noexcept -> bool
Definition device_color.hpp:185
constexpr auto operator==(const DeviceColor &other) const noexcept -> bool=default
constexpr DeviceColor(TriColor c=TriColor::White)
Definition device_color.hpp:178
constexpr auto to_rgb() const noexcept -> RGB
Definition device_color.hpp:214
constexpr auto get_color_bit() const noexcept -> bool
Definition device_color.hpp:212
constexpr auto operator==(const DeviceColor &other) const noexcept -> bool=default
TriColor color
Color value (Black, White, or Yellow)
Definition device_color.hpp:203
constexpr auto get_bw_bit() const noexcept -> bool
Definition device_color.hpp:211
constexpr auto to_byte() const noexcept -> std::uint8_t
Definition device_color.hpp:209
constexpr DeviceColor(TriColor c=TriColor::White)
Definition device_color.hpp:205
constexpr auto operator==(const DeviceColor &other) const noexcept -> bool=default
constexpr auto to_byte() const noexcept -> std::uint8_t
Definition device_color.hpp:62
bool is_white
true = white, false = black
Definition device_color.hpp:56
constexpr DeviceColor(bool white=true)
Definition device_color.hpp:58
constexpr auto to_rgb() const noexcept -> RGB
Definition device_color.hpp:63
constexpr auto operator==(const DeviceColor &other) const noexcept -> bool=default
constexpr auto to_rgb() const noexcept -> RGB
Definition device_color.hpp:112
std::uint8_t level
Grayscale level (0-3, where 3 is white)
Definition device_color.hpp:100
constexpr auto to_byte() const noexcept -> std::uint8_t
Definition device_color.hpp:106
constexpr DeviceColor(std::uint8_t gray_level=3)
Definition device_color.hpp:102
constexpr auto to_rgb() const noexcept -> RGB
Definition device_color.hpp:264
constexpr auto to_byte() const noexcept -> std::uint8_t
Definition device_color.hpp:260
constexpr auto operator==(const DeviceColor &other) const noexcept -> bool=default
constexpr DeviceColor(Spectra6Color c=Spectra6Color::White)
Definition device_color.hpp:256
Spectra6Color color
Color value (one of 6 colors)
Definition device_color.hpp:254
constexpr auto to_uint8() const noexcept -> std::uint8_t
Definition device_color.hpp:262
Device-specific color representation (generic template).
Definition device_color.hpp:26
constexpr DeviceColor(std::uint8_t val=0)
Definition device_color.hpp:29
constexpr auto operator==(const DeviceColor &other) const noexcept -> bool=default
std::uint8_t value
Raw color value.
Definition device_color.hpp:27
Definition color.hpp:50