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
/mnt/nas/libepaper/include/epaper/internal/internal.hpp

Convert PlaneCount enum to numeric value.

Convert PlaneCount enum to numeric value.Provides compile-time conversion from type-safe PlaneCount to std::size_t for array sizing and iteration.

Parameters
countThe plane count to convert
Returns
Numeric plane count (1, 2, or 3)
Note
This function is constexpr and will be evaluated at compile time when passed a constant expression.

constexpr auto num_planes = plane_count_value(PlaneCount::Two); // 2

#pragma once
#include <cstddef>
#include <cstdint>
#include <utility>
namespace epaper::internal {
inline constexpr std::size_t PLANE_COUNT_ONE = 1;
inline constexpr std::size_t PLANE_COUNT_TWO = 2;
inline constexpr std::size_t PLANE_COUNT_THREE = 3;
enum class PlaneCount : std::uint8_t {
One,
Two,
};
[[nodiscard]] constexpr auto plane_count_value(PlaneCount count) noexcept -> std::size_t {
switch (count) {
}
std::unreachable();
}
inline 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> {
switch (orientation) {
// Identity transformation - no rotation applied
// Logical coordinate system matches physical display layout
return {x, y};
// 90° clockwise rotation:
// - Original top-left (0,0) → new top-right (width-1, 0)
// - Original top-right (width-1, 0) → new bottom-right (width-1, height-1)
// Transformation matrix: [x'] = [0 -1] [x] + [width-1]
// [y'] [1 0] [y] [0]
// Simplified: x' = width-1-y, y' = x
return {width - 1 - y, x};
// 180° rotation:
// - Original top-left (0,0) → new bottom-right (width-1, height-1)
// - Original center stays at center
// Transformation matrix: [x'] = [-1 0] [x] + [width-1]
// [y'] [0 -1] [y] [height-1]
// Simplified: x' = width-1-x, y' = height-1-y
return {width - 1 - x, height - 1 - y};
// 270° clockwise (90° counter-clockwise) rotation:
// - Original top-left (0,0) → new bottom-left (0, height-1)
// - Original bottom-right → new top-right
// Transformation matrix: [x'] = [0 1] [x] + [0]
// [y'] [-1 0] [y] [height-1]
// Simplified: x' = y, y' = height-1-x
return {y, height - 1 - x};
default:
// Fallback for any unexpected orientation values
// Returns identity transformation for safety
return {x, y};
}
}
} // 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)