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
internal.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <cstddef>
5#include <cstdint>
6#include <utility>
7
21
23inline constexpr std::size_t PLANE_COUNT_ONE = 1;
24
26inline constexpr std::size_t PLANE_COUNT_TWO = 2;
27
29inline constexpr std::size_t PLANE_COUNT_THREE = 3;
30
42enum class PlaneCount : std::uint8_t {
43 One,
44 Two,
45 Three
46};
47
63[[nodiscard]] constexpr auto plane_count_value(PlaneCount count) noexcept -> std::size_t {
64 switch (count) {
65 case PlaneCount::One:
66 return PLANE_COUNT_ONE;
67 case PlaneCount::Two:
68 return PLANE_COUNT_TWO;
70 return PLANE_COUNT_THREE;
71 }
72 std::unreachable();
73}
74
111inline auto transform_coordinates(std::size_t x, std::size_t y, std::size_t width, std::size_t height,
112 Orientation orientation) -> std::pair<std::size_t, std::size_t> {
113 switch (orientation) {
115 // Identity transformation - no rotation applied
116 // Logical coordinate system matches physical display layout
117 return {x, y};
118
120 // 90° clockwise rotation:
121 // - Original top-left (0,0) → new top-right (width-1, 0)
122 // - Original top-right (width-1, 0) → new bottom-right (width-1, height-1)
123 // Transformation matrix: [x'] = [0 -1] [x] + [width-1]
124 // [y'] [1 0] [y] [0]
125 // Simplified: x' = width-1-y, y' = x
126 return {width - 1 - y, x};
127
129 // 180° rotation:
130 // - Original top-left (0,0) → new bottom-right (width-1, height-1)
131 // - Original center stays at center
132 // Transformation matrix: [x'] = [-1 0] [x] + [width-1]
133 // [y'] [0 -1] [y] [height-1]
134 // Simplified: x' = width-1-x, y' = height-1-y
135 return {width - 1 - x, height - 1 - y};
136
138 // 270° clockwise (90° counter-clockwise) rotation:
139 // - Original top-left (0,0) → new bottom-left (0, height-1)
140 // - Original bottom-right → new top-right
141 // Transformation matrix: [x'] = [0 1] [x] + [0]
142 // [y'] [-1 0] [y] [height-1]
143 // Simplified: x' = y, y' = height-1-x
144 return {y, height - 1 - x};
145
146 default:
147 // Fallback for any unexpected orientation values
148 // Returns identity transformation for safety
149 return {x, y};
150 }
151}
152} // namespace epaper::internal
Definition internal.hpp:20
constexpr std::size_t PLANE_COUNT_TWO
Number of planes for dual-plane displays (BWR, BWY)
Definition internal.hpp:26
constexpr std::size_t PLANE_COUNT_THREE
Number of planes for triple-plane displays (reserved for future modes)
Definition internal.hpp:29
constexpr auto plane_count_value(PlaneCount count) noexcept -> std::size_t
Definition internal.hpp:63
auto transform_coordinates(std::size_t x, std::size_t y, std::size_t width, std::size_t height, Orientation orientation) -> std::pair< std::size_t, std::size_t >
Definition internal.hpp:111
constexpr std::size_t PLANE_COUNT_ONE
Number of planes for single-plane displays (BW, Gray4, Spectra6)
Definition internal.hpp:23
PlaneCount
Type-safe enumeration for framebuffer plane counts.
Definition internal.hpp:42
@ One
Single plane (monochrome or packed multi-color)
@ Two
Dual plane (base + accent color)
@ Three
Triple plane (reserved for future use)
Orientation
Definition types.hpp:66
@ Portrait180
180° rotation (upside down portrait)
@ Landscape270
270° clockwise / 90° counter-clockwise (landscape mode)
@ Landscape90
90° clockwise rotation (landscape mode)
@ Portrait0
Default portrait orientation (0° rotation)