separate display to its own file
This commit is contained in:
73
display.h
Normal file
73
display.h
Normal file
@@ -0,0 +1,73 @@
|
||||
|
||||
/* display.h
|
||||
* Generated from display.cpp — public declarations for the OLED helper
|
||||
*/
|
||||
|
||||
#ifndef DISPLAY_H
|
||||
#define DISPLAY_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
// Display API is provided via the C++ `DisplayManager` singleton below.
|
||||
|
||||
#ifdef __cplusplus
|
||||
// Expose the C++ DisplayManager so callers can use the class API directly.
|
||||
//
|
||||
// Note: The implementation constructs the `SSD1306` display object in-place
|
||||
// using static storage (no heap allocation). Construct a `DisplayManager` in
|
||||
// `main()` and pass it by reference to functions that need to update the
|
||||
// display. This avoids global singletons and makes ownership explicit.
|
||||
//
|
||||
// Example:
|
||||
// int main() {
|
||||
// stdio_init_all();
|
||||
// DisplayManager display;
|
||||
// // pass the display I2C address (common values: 0x3C or 0x3D)
|
||||
// display.init(0x3C);
|
||||
// while (true) {
|
||||
// wait_for_usb_connection();
|
||||
// run_echo_session(display);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// void run_echo_session(DisplayManager &display) {
|
||||
// display.refresh("> ", nullptr);
|
||||
// // ...
|
||||
// }
|
||||
//
|
||||
// Forward-declare the SSD1306 type to avoid pulling the full display header into
|
||||
// every translation unit that includes `display.h`.
|
||||
namespace pico_ssd1306 { class SSD1306; }
|
||||
|
||||
class DisplayManager {
|
||||
public:
|
||||
// Initialize the hardware and display.
|
||||
DisplayManager();
|
||||
~DisplayManager();
|
||||
// Initialize the hardware and display. Pass the SSD1306 I2C address (default 0x3C).
|
||||
void init(uint8_t i2c_addr = 0x3C);
|
||||
|
||||
// Refresh the display content. Either pointer may be nullptr.
|
||||
void refresh(const char *current_input, const char *last_echo);
|
||||
|
||||
// Update stored last-echo text used when `last_echo` is not provided to `refresh()`.
|
||||
void set_last_echo(const char *text);
|
||||
|
||||
// Non-copyable
|
||||
DisplayManager(const DisplayManager &) = delete;
|
||||
DisplayManager &operator=(const DisplayManager &) = delete;
|
||||
|
||||
// Implementation details kept small in the header: pointer to the concrete SSD1306
|
||||
// type (defined in `pico-ssd1306/ssd1306.h`).
|
||||
pico_ssd1306::SSD1306 *display_;
|
||||
char last_echo_[64];
|
||||
static const size_t LAST_ECHO_VISIBLE_CHARS = 10;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif // DISPLAY_H
|
||||
|
||||
Reference in New Issue
Block a user