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
errors.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <string_view>
5
6namespace epaper {
7
14enum class ErrorCode {
15 // Device errors
25
26 // Driver errors
30 Timeout,
31
32 // Display errors
35
36 // Bitmap errors
41};
42
49[[nodiscard]] constexpr auto to_string(ErrorCode code) -> std::string_view {
50 switch (code) {
51 // Device errors
53 return "Device not initialized";
55 return "Device initialization failed";
57 return "GPIO initialization failed";
59 return "GPIO line request failed";
61 return "SPI initialization failed";
63 return "SPI device open failed";
65 return "SPI configuration failed";
67 return "Invalid pin number";
69 return "Data transfer failed";
70
71 // Driver errors
73 return "Driver not initialized";
75 return "Driver initialization failed";
77 return "Invalid display mode";
79 return "Operation timed out";
80
81 // Display errors
83 return "Display not ready";
85 return "Display refresh failed";
86
87 // Bitmap errors
89 return "File not found";
91 return "Invalid format";
93 return "Load failed";
95 return "Invalid dimensions";
96 }
97 return "Unknown error";
98}
99
140struct Error {
142 std::string message;
143
149 constexpr Error(ErrorCode c) : code(c) {}
150
157 Error(ErrorCode c, std::string msg) : code(c), message(std::move(msg)) {}
158
167 [[nodiscard]] auto what() const -> std::string_view {
168 if (!message.empty()) {
169 return message;
170 }
171 return to_string(code);
172 }
173};
174
204[[nodiscard]] inline auto make_error(ErrorCode code, std::string_view context = {}) -> Error {
205 if (context.empty()) {
206 return {code};
207 }
208 return {code, std::string(to_string(code)) + ": " + std::string(context)};
209}
210
211} // namespace epaper
Definition color.hpp:5
ErrorCode
Unified error codes for all libepaper operations.
Definition errors.hpp:14
@ InvalidPin
Invalid GPIO pin number.
@ DeviceNotInitialized
Device has not been initialized.
@ SPIInitFailed
SPI initialization failed.
@ FileNotFound
Image file not found.
@ DriverNotInitialized
Driver has not been initialized.
@ LoadFailed
Failed to load image data.
@ InvalidDimensions
Invalid image dimensions.
@ InvalidMode
Invalid display mode specified.
@ DisplayNotReady
Display is not ready for operation.
@ DriverInitFailed
Driver initialization failed.
@ GPIOInitFailed
GPIO initialization failed (libgpiod)
@ DeviceInitFailed
Device initialization failed.
@ GPIORequestFailed
GPIO line request failed.
@ SPIConfigFailed
SPI configuration failed.
@ Timeout
Operation timed out.
@ SPIDeviceOpenFailed
SPI device open failed.
@ InvalidFormat
Invalid or unsupported image format.
@ TransferFailed
SPI/data transfer failed.
@ RefreshFailed
Display refresh operation failed.
auto make_error(ErrorCode code, std::string_view context={}) -> Error
Definition errors.hpp:204
constexpr auto to_string(ErrorCode code) -> std::string_view
Convert error code to string representation.
Definition errors.hpp:49
Definition errors.hpp:140
constexpr Error(ErrorCode c)
Construct error with code only.
Definition errors.hpp:149
std::string message
Optional detailed error message.
Definition errors.hpp:142
ErrorCode code
Error code.
Definition errors.hpp:141
auto what() const -> std::string_view
Get string representation of the error.
Definition errors.hpp:167
Error(ErrorCode c, std::string msg)
Construct error with code and message.
Definition errors.hpp:157