@geastack/host 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +25 -0
  3. package/audio_runtime.cpp +807 -0
  4. package/bluetooth.cpp +125 -0
  5. package/geolocation.cpp +43 -0
  6. package/host/apps.cpp +20 -0
  7. package/host/audio.cpp +240 -0
  8. package/host/ble.cpp +239 -0
  9. package/host/camera.cpp +193 -0
  10. package/host/display.cpp +230 -0
  11. package/host/fetch.cpp +1060 -0
  12. package/host/geolocation.cpp +31 -0
  13. package/host/gpio.cpp +55 -0
  14. package/host/http.cpp +349 -0
  15. package/host/image.cpp +335 -0
  16. package/host/imu.cpp +51 -0
  17. package/host/input.cpp +12 -0
  18. package/host/media.cpp +579 -0
  19. package/host/memory.cpp +91 -0
  20. package/host/rtc.cpp +212 -0
  21. package/host/rtc_esp.cpp +291 -0
  22. package/host/tile_loader.cpp +478 -0
  23. package/host/timers.cpp +327 -0
  24. package/host/touch.cpp +25 -0
  25. package/host/websocket.cpp +279 -0
  26. package/host/wifi.cpp +99 -0
  27. package/include/gea/embedded-host.h +38 -0
  28. package/include/host/apps.h +15 -0
  29. package/include/host/audio.h +158 -0
  30. package/include/host/backends.h +455 -0
  31. package/include/host/battery.h +25 -0
  32. package/include/host/camera.h +236 -0
  33. package/include/host/clock.h +45 -0
  34. package/include/host/device_control.h +23 -0
  35. package/include/host/display.h +266 -0
  36. package/include/host/display_orientation.h +291 -0
  37. package/include/host/fetch.h +310 -0
  38. package/include/host/gpio.h +36 -0
  39. package/include/host/http.h +161 -0
  40. package/include/host/image.h +144 -0
  41. package/include/host/input.h +14 -0
  42. package/include/host/media.h +165 -0
  43. package/include/host/memory.h +44 -0
  44. package/include/host/navigator.h +283 -0
  45. package/include/host/notify.h +41 -0
  46. package/include/host/profiler.h +49 -0
  47. package/include/host/rtc.h +174 -0
  48. package/include/host/storage.h +141 -0
  49. package/include/host/tile_loader.h +59 -0
  50. package/include/host/timers.h +41 -0
  51. package/include/host/touch.h +20 -0
  52. package/include/host/websocket.h +179 -0
  53. package/include/host/window.h +31 -0
  54. package/input.cpp +68 -0
  55. package/package.json +27 -0
  56. package/services/app_state.cpp +19 -0
  57. package/services/battery_service.cpp +19 -0
  58. package/services/bluetooth_service.cpp +37 -0
  59. package/services/diagnostics.cpp +233 -0
  60. package/services/diagnostics_connection.cpp +231 -0
  61. package/services/diagnostics_internal.h +15 -0
  62. package/services/diagnostics_server.cpp +135 -0
  63. package/services/mirror.cpp +364 -0
  64. package/services/network_services.cpp +62 -0
  65. package/services/runtime_log.cpp +23 -0
  66. package/services/settings_surface.h +221 -0
  67. package/wifi.cpp +185 -0
@@ -0,0 +1,236 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #include "backends.h"
5
+ #include "image.h"
6
+
7
+ #include <string>
8
+ #include <utility>
9
+
10
+ namespace gea::host {
11
+
12
+ // Typed still-capture result. `Camera.capturePhoto()` (and the runtime's
13
+ // `capture()` alias) resolve synchronously on-device, so the promise carries
14
+ // the photo struct natively and `then(f)` invokes `f` immediately — the app's
15
+ // `Camera.capturePhoto().then(photo => photo.imageId …)` lowers to native
16
+ // member reads with no gea_cpp_value boxing.
17
+ struct CameraPhoto {
18
+ double imageId = -1.0;
19
+ double width = 0.0;
20
+ double height = 0.0;
21
+ double orientation = 0.0;
22
+ void dispose() const { image.dispose(imageId); }
23
+ };
24
+
25
+ struct CameraPhotoPromise {
26
+ CameraPhoto photo;
27
+ template <typename F>
28
+ auto then(F &&onResolved) const {
29
+ return std::forward<F>(onResolved)(photo);
30
+ }
31
+ };
32
+
33
+ // Typed recording-stop result; same synchronous-promise shape as capture.
34
+ struct CameraClip {
35
+ double durationMs = -1.0;
36
+ std::string path;
37
+ };
38
+
39
+ struct CameraClipPromise {
40
+ CameraClip clip;
41
+ template <typename F>
42
+ auto then(F &&onResolved) const {
43
+ return std::forward<F>(onResolved)(clip);
44
+ }
45
+ };
46
+
47
+ // Path of the in-flight recording so `stopRecording()` can return it on the
48
+ // clip (mirrors the TS runtime shim's module-level `cameraRecordingPath`).
49
+ inline std::string &cameraRecordingPath() {
50
+ static std::string path;
51
+ return path;
52
+ }
53
+
54
+ inline CameraPhoto makePhoto(double imageId) {
55
+ return CameraPhoto{
56
+ imageId,
57
+ gea::framework::camera::CameraBackend::width(),
58
+ gea::framework::camera::CameraBackend::height(),
59
+ gea::framework::camera::CameraBackend::orientation(),
60
+ };
61
+ }
62
+
63
+ class CameraValueProperty {
64
+ public:
65
+ using Getter = double (*)();
66
+
67
+ constexpr CameraValueProperty() = default;
68
+ explicit constexpr CameraValueProperty(Getter getter) : getter_(getter) {}
69
+
70
+ double operator()() const { return getter_ ? getter_() : 0.0; }
71
+ operator double() const { return (*this)(); }
72
+
73
+ private:
74
+ Getter getter_ = nullptr;
75
+ };
76
+
77
+ class CameraStringProperty {
78
+ public:
79
+ using Getter = std::string (*)();
80
+
81
+ constexpr CameraStringProperty() = default;
82
+ explicit constexpr CameraStringProperty(Getter getter) : getter_(getter) {}
83
+
84
+ std::string operator()() const { return getter_ ? getter_() : std::string(); }
85
+ operator std::string() const { return (*this)(); }
86
+
87
+ private:
88
+ Getter getter_ = nullptr;
89
+ };
90
+
91
+ class CameraFacade {
92
+ public:
93
+ constexpr CameraFacade()
94
+ : width(gea::framework::camera::CameraBackend::width),
95
+ height(gea::framework::camera::CameraBackend::height),
96
+ orientation(gea::framework::camera::CameraBackend::orientation),
97
+ deviceCount(gea::framework::camera::CameraBackend::deviceCount),
98
+ facing(gea::framework::camera::CameraBackend::facing) {}
99
+
100
+ bool isAvailable() const { return gea::framework::camera::CameraBackend::isAvailable(); }
101
+ bool hasPermission() const { return gea::framework::camera::CameraBackend::hasPermission(); }
102
+ bool requestPermission() const { return gea::framework::camera::CameraBackend::requestPermission(); }
103
+
104
+ bool open(const std::string &facing, double width, double height) const {
105
+ return gea::framework::camera::CameraBackend::open(facing, width, height);
106
+ }
107
+ bool open(const std::string &facing) const { return open(facing, 0.0, 0.0); }
108
+ bool open() const { return open(std::string("back"), 0.0, 0.0); }
109
+
110
+ // Single-arg form accepting an options record. Fields are
111
+ // resolved by name on the structured record at the call site
112
+ // (geatsc lowers the options literal to gea_cpp_value).
113
+ template <typename Options>
114
+ bool open(const Options &options) const {
115
+ return gea::framework::camera::CameraBackend::openWithOptions(options);
116
+ }
117
+
118
+ void close() const { gea::framework::camera::CameraBackend::close(); }
119
+ bool isOpen() const { return gea::framework::camera::CameraBackend::isOpen(); }
120
+
121
+ // Draw the latest preview frame into the destination region (framebuffer
122
+ // pixels). When destWidth/destHeight are 0 or omitted, the frame is drawn
123
+ // at its native size.
124
+ void draw(double x, double y) const {
125
+ gea::framework::camera::CameraBackend::draw(x, y, 0.0, 0.0);
126
+ }
127
+ void draw(double x, double y, double destWidth, double destHeight) const {
128
+ gea::framework::camera::CameraBackend::draw(x, y, destWidth, destHeight);
129
+ }
130
+
131
+ // Returns image id of a still capture, suitable to pass to image.draw().
132
+ double capture() const { return gea::framework::camera::CameraBackend::capture(); }
133
+ double captureMirrored() const { return gea::framework::camera::CameraBackend::captureMirrored(); }
134
+
135
+ // Single-arg form accepting an options record. Reads `mirror` to choose
136
+ // the path; ignores unknown fields. Lets call sites use the same shape
137
+ // as `open({...})`.
138
+ template <typename Options>
139
+ double capture(const Options &options) const {
140
+ return gea::framework::camera::CameraBackend::captureWithOptions(options);
141
+ }
142
+
143
+ // Typed still capture: the TS `Camera.capture()`/`capturePhoto()` calls
144
+ // lower here. Resolves synchronously with the photo's id + dimensions.
145
+ CameraPhotoPromise capturePhoto() const {
146
+ return {makePhoto(gea::framework::camera::CameraBackend::capture())};
147
+ }
148
+ template <typename Options>
149
+ CameraPhotoPromise capturePhoto(const Options &options) const {
150
+ return {makePhoto(gea::framework::camera::CameraBackend::captureWithOptions(options))};
151
+ }
152
+
153
+ // Video recording. Returns true when recording started; stopRecording
154
+ // returns the clip duration in ms (-1 on failure).
155
+ bool startRecording(const std::string &path, double fps) const {
156
+ cameraRecordingPath() = path;
157
+ return gea::framework::camera::CameraBackend::startRecording(path, fps);
158
+ }
159
+ bool startRecording(const std::string &path) const { return startRecording(path, 0.0); }
160
+ // Options-record form (mirrors open({...})): reads `path` and `fps`. A typed
161
+ // options struct (geatsc interface struct / plugin anonymous struct) reads
162
+ // the member directly; a dynamic gea_cpp_value record reads through
163
+ // record_get_literal via optionString.
164
+ template <typename Options>
165
+ bool startRecording(const Options &options) const {
166
+ if constexpr (requires { options.path; })
167
+ cameraRecordingPath() = static_cast<std::string>(options.path);
168
+ else
169
+ cameraRecordingPath() = gea::framework::camera::CameraBackend::optionString(options, "path", "");
170
+ return gea::framework::camera::CameraBackend::startRecordingWithOptions(options);
171
+ }
172
+ double stopRecording() const { return gea::framework::camera::CameraBackend::stopRecording(); }
173
+ // Typed stop: the TS `Camera.stopRecording()` call lowers here. Resolves
174
+ // synchronously with the clip duration and the path recording started with.
175
+ CameraClipPromise stopRecordingClip() const {
176
+ return {CameraClip{gea::framework::camera::CameraBackend::stopRecording(), cameraRecordingPath()}};
177
+ }
178
+ bool isRecording() const { return gea::framework::camera::CameraBackend::isRecording(); }
179
+
180
+ void setFlash(const std::string &mode) const { gea::framework::camera::CameraBackend::setFlash(mode); }
181
+ void setZoom(double factor) const { gea::framework::camera::CameraBackend::setZoom(factor); }
182
+ void setMirror(bool mirror) const { gea::framework::camera::CameraBackend::setMirror(mirror); }
183
+
184
+ // Capture controls. Numeric args default to 0 ("leave as is"); see camera.h
185
+ // for the accepted `mode` keywords. Each control also has an options-record
186
+ // form (mirrors open({...})) so call sites can pass the TypeScript shape.
187
+ void setExposure(const std::string &mode, double bias, double iso, double durationMs) const {
188
+ gea::framework::camera::CameraBackend::setExposure(mode, bias, iso, durationMs);
189
+ }
190
+ void setExposure(const std::string &mode) const {
191
+ gea::framework::camera::CameraBackend::setExposure(mode, 0.0, 0.0, 0.0);
192
+ }
193
+ template <typename Options>
194
+ void setExposure(const Options &options) const {
195
+ gea::framework::camera::CameraBackend::setExposureWithOptions(options);
196
+ }
197
+ void setWhiteBalance(const std::string &mode, double temperatureK, double tint) const {
198
+ gea::framework::camera::CameraBackend::setWhiteBalance(mode, temperatureK, tint);
199
+ }
200
+ void setWhiteBalance(const std::string &mode) const {
201
+ gea::framework::camera::CameraBackend::setWhiteBalance(mode, 0.0, 0.0);
202
+ }
203
+ template <typename Options>
204
+ void setWhiteBalance(const Options &options) const {
205
+ gea::framework::camera::CameraBackend::setWhiteBalanceWithOptions(options);
206
+ }
207
+ void setFocus(const std::string &mode, double pointX, double pointY) const {
208
+ gea::framework::camera::CameraBackend::setFocus(mode, pointX, pointY);
209
+ }
210
+ void setFocus(const std::string &mode) const {
211
+ gea::framework::camera::CameraBackend::setFocus(mode, 0.0, 0.0);
212
+ }
213
+ template <typename Options>
214
+ void setFocus(const Options &options) const {
215
+ gea::framework::camera::CameraBackend::setFocusWithOptions(options);
216
+ }
217
+ void setTorch(const std::string &mode, double level) const {
218
+ gea::framework::camera::CameraBackend::setTorch(mode, level);
219
+ }
220
+ void setTorch(const std::string &mode) const {
221
+ gea::framework::camera::CameraBackend::setTorch(mode, 0.0);
222
+ }
223
+
224
+ std::string deviceIdAt(double index) const { return gea::framework::camera::CameraBackend::deviceIdAt(index); }
225
+ std::string deviceFacingAt(double index) const { return gea::framework::camera::CameraBackend::deviceFacingAt(index); }
226
+
227
+ CameraValueProperty width;
228
+ CameraValueProperty height;
229
+ CameraValueProperty orientation;
230
+ CameraValueProperty deviceCount;
231
+ CameraStringProperty facing;
232
+ };
233
+
234
+ inline constexpr CameraFacade Camera{};
235
+
236
+ } // namespace gea::host
@@ -0,0 +1,45 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #if defined(_WIN32)
5
+ #include <chrono>
6
+ #else
7
+ #include <sys/time.h>
8
+ #endif
9
+
10
+ namespace gea::host {
11
+
12
+ // Wall-clock access for app code.
13
+ //
14
+ // `epochMs()` returns milliseconds since the Unix epoch read from the platform
15
+ // real-time clock (`gettimeofday`). Crucially, this DOES reflect a host-set
16
+ // time — `GEADEV SETTIME` calls `settimeofday`, and the companion app issues it
17
+ // on launch — so a watch face can show real wall-clock time once the host has
18
+ // synced it.
19
+ //
20
+ // This is deliberately distinct from JavaScript `Date.now()`, whose generated
21
+ // runtime impl (runtime/date.cpp) reads `std::chrono::system_clock`, which is
22
+ // monotonic on this ESP32 build and is NOT affected by `settimeofday`. A face
23
+ // reads `epochMs()` and falls back to a boot frame clock when the value is
24
+ // implausibly small (the RTC has never been set this power cycle).
25
+ //
26
+ // Header-only by design: it links from any translation unit that includes
27
+ // gea/embedded.h without needing a new entry in the protected
28
+ // idf_component_register(SRCS ...) list.
29
+ struct ClockFacade {
30
+ double epochMs() const {
31
+ #if defined(_WIN32)
32
+ return std::chrono::duration<double, std::milli>(
33
+ std::chrono::system_clock::now().time_since_epoch()).count();
34
+ #else
35
+ struct timeval tv{};
36
+ if (gettimeofday(&tv, nullptr) != 0) return 0.0;
37
+ return static_cast<double>(tv.tv_sec) * 1000.0 +
38
+ static_cast<double>(tv.tv_usec) / 1000.0;
39
+ #endif
40
+ }
41
+ };
42
+
43
+ inline constexpr ClockFacade Clock{};
44
+
45
+ } // namespace gea::host
@@ -0,0 +1,23 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #include <string>
5
+
6
+ namespace gea::host {
7
+
8
+ // Run a host shell command and return its combined stdout+stderr. This is the
9
+ // gea-app (CSS runtime) equivalent of @geajs/apple's runDeviceCommand: the gea
10
+ // Companion uses it to drive the device (GEADEV over USB) and to install and
11
+ // uninstall apps. Both are the `gea` CLI now (@geastack/cli); the scripts this
12
+ // used to name lived in the old single repo and are archived there. Unlike the
13
+ // other host facades this one is NOT header-only — exec() needs NSTask, so the
14
+ // impl is a macOS .mm in @geastack/apple. The header
15
+ // is included by gea/embedded.h on every target, but exec() is only referenced
16
+ // by the macOS companion, so non-macOS targets need no implementation.
17
+ struct DeviceControlFacade {
18
+ std::string exec(const std::string &command) const;
19
+ };
20
+
21
+ inline constexpr DeviceControlFacade DeviceControl{};
22
+
23
+ } // namespace gea::host
@@ -0,0 +1,266 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #include <display.h>
5
+ #include "backends.h"
6
+ #include "display_orientation.h"
7
+ #include "services/frame_scheduler.h"
8
+ #include "ui/document.h"
9
+ #include "ui/style.h"
10
+
11
+ namespace gea::host {
12
+
13
+ namespace detail {
14
+
15
+ template <typename Config>
16
+ double displayFlushRows(const Config &config) {
17
+ if constexpr (requires { config.rows; }) {
18
+ return static_cast<double>(config.rows);
19
+ } else if constexpr (requires { config.record_get_literal("rows"); }) {
20
+ auto rows = config.record_get_literal("rows");
21
+ return rows.is_nullish() ? 0.0 : static_cast<double>(rows);
22
+ } else {
23
+ return 0.0;
24
+ }
25
+ }
26
+
27
+ template <typename Config>
28
+ double displayFlushDepth(const Config &config) {
29
+ if constexpr (requires { config.depth; }) {
30
+ return static_cast<double>(config.depth);
31
+ } else if constexpr (requires { config.record_get_literal("depth"); }) {
32
+ auto depth = config.record_get_literal("depth");
33
+ return depth.is_nullish() ? 0.0 : static_cast<double>(depth);
34
+ } else {
35
+ return 0.0;
36
+ }
37
+ }
38
+
39
+ // Optional-number field for the e-paper refresh config: -1 = absent/unchanged.
40
+ template <typename Field>
41
+ double epaperConfigNumber(const Field &field) {
42
+ if constexpr (requires { field.has_value(); *field; }) {
43
+ return field.has_value() ? epaperConfigNumber(*field) : -1.0;
44
+ } else if constexpr (requires { field.is_nullish(); }) {
45
+ return field.is_nullish() ? -1.0 : static_cast<double>(field);
46
+ } else {
47
+ return static_cast<double>(field);
48
+ }
49
+ }
50
+
51
+ // Optional LUT-bytes field: returns true when the field is present (an empty
52
+ // array means "restore the vendor default") and fills `out` with its bytes.
53
+ template <typename Field>
54
+ bool epaperConfigLut(const Field &field, std::vector<std::uint8_t> &out) {
55
+ if constexpr (requires { field.has_value(); *field; }) {
56
+ if (!field.has_value()) return false;
57
+ return epaperConfigLut(*field, out);
58
+ } else if constexpr (requires { field.is_nullish(); }) {
59
+ if (field.is_nullish()) return false;
60
+ if constexpr (requires { field.size(); field[0]; }) {
61
+ for (std::size_t i = 0; i < static_cast<std::size_t>(field.size()); ++i)
62
+ out.push_back(static_cast<std::uint8_t>(static_cast<double>(field[i])));
63
+ }
64
+ return true;
65
+ } else if constexpr (requires { field.size(); field.begin(); field.end(); }) {
66
+ for (const auto &item : field) out.push_back(static_cast<std::uint8_t>(static_cast<double>(item)));
67
+ return true;
68
+ } else {
69
+ return false;
70
+ }
71
+ }
72
+
73
+ } // namespace detail
74
+
75
+ struct DisplayFacade {
76
+ // Logical viewport dimensions in pixels — equal to whatever was passed
77
+ // to Application::init by the platform target. Apps that need to size
78
+ // content to the actual panel (bouncing balls' bounce extent, layout
79
+ // breakpoints, etc.) can read these without hardcoding per-device sizes.
80
+ double width() const {
81
+ #if defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) && GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
82
+ return static_cast<double>(gea::platform::display::kWidth);
83
+ #else
84
+ int w = gea::embedded::ui::Document::preferredMountWidth();
85
+ return static_cast<double>(w > 0 ? w : gea::platform::display::kWidth);
86
+ #endif
87
+ }
88
+ double height() const {
89
+ #if defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) && GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
90
+ return static_cast<double>(gea::platform::display::kHeight);
91
+ #else
92
+ int h = gea::embedded::ui::Document::preferredMountHeight();
93
+ return static_cast<double>(h > 0 ? h : gea::platform::display::kHeight);
94
+ #endif
95
+ }
96
+ double nativeWidth() const { return gea::framework::display::DisplayBackend::nativeWidth(); }
97
+ double nativeHeight() const { return gea::framework::display::DisplayBackend::nativeHeight(); }
98
+
99
+ gea::embedded::ui::CanvasRenderingContext2D ctx() const {
100
+ #if defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) && GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
101
+ gea::embedded::ui::Document::markDirectCanvasContextUsed();
102
+ return gea::embedded::ui::CanvasRenderingContext2D(-1);
103
+ #else
104
+ auto &document = gea::embedded::ui::Document::instance();
105
+ // Idempotent getter: if a previous ctx() call already mounted a canvas
106
+ // document, hand back a context on that node. Apps and libraries (gea3d's
107
+ // Renderer::render, per-frame HUD helpers) re-read Display.ctx freely —
108
+ // direct-canvas builds make that a trivial getter, and the tree path must
109
+ // match. Rebuilding here instead would clear the document MID-FRAME while
110
+ // the style mount batch is open: the fresh canvas node gets no layout, so
111
+ // ensureCanvas() sees a 0x0 node and every subsequent draw is dropped.
112
+ //
113
+ // The flag says "the app presents the display itself, so the document
114
+ // render can stand down". That is only true where the mounted canvas can
115
+ // actually BE display-backed. On web it never can:
116
+ // `canUseDisplayFramebuffer` (ui/tree_nodes.cpp) returns false under
117
+ // __EMSCRIPTEN__ by design, because the browser framebuffer IS the surface
118
+ // the document render paints, so a canvas presenting into it would be
119
+ // clobbered by the same frame's document render. Web therefore uses the
120
+ // owned-surface + document-blit path -- and setting the flag here disabled
121
+ // exactly the blit that path depends on (Document::refreshMountedIfDirty
122
+ // returns early on it), leaving every tree-build Display.ctx app with a
123
+ // permanently black panel. Mark it only where display-backing is reachable.
124
+ #ifndef __EMSCRIPTEN__
125
+ #define GEA_DISPLAY_CTX_MARK_DIRECT() gea::embedded::ui::Document::markDirectCanvasContextUsed()
126
+ #else
127
+ #define GEA_DISPLAY_CTX_MARK_DIRECT() ((void)0)
128
+ #endif
129
+ {
130
+ const int mounted = document.mountedCanvasNode();
131
+ if (mounted >= 0) {
132
+ GEA_DISPLAY_CTX_MARK_DIRECT();
133
+ return gea::embedded::ui::CanvasRenderingContext2D(mounted);
134
+ }
135
+ }
136
+ document.clear();
137
+ auto canvas = document.createCanvas();
138
+ const int w = static_cast<int>(width());
139
+ const int h = static_cast<int>(height());
140
+ canvas.style().width(w);
141
+ canvas.style().height(h);
142
+ document.mount(canvas, w, h);
143
+ GEA_DISPLAY_CTX_MARK_DIRECT();
144
+ #undef GEA_DISPLAY_CTX_MARK_DIRECT
145
+ return canvas.getContext2D();
146
+ #endif
147
+ }
148
+
149
+ double getBrightness() const { return gea::framework::display::DisplayBackend::brightness(); }
150
+ void setBrightness(double brightness) const { gea::framework::display::DisplayBackend::setBrightness(brightness); }
151
+ std::string orientation() const { return gea::framework::display::DisplayBackend::orientation(); }
152
+ std::string getOrientation() const { return orientation(); }
153
+ void setOrientation(const std::string &orientation) const { gea::framework::display::DisplayBackend::setOrientation(orientation); }
154
+ std::vector<std::string> supportedOrientations() const {
155
+ return gea::framework::display::DisplayBackend::supportedOrientations();
156
+ }
157
+ std::vector<std::string> getSupportedOrientations() const { return supportedOrientations(); }
158
+ template <typename Options>
159
+ void setSupportedOrientations(const Options &orientations) const {
160
+ gea::framework::display::detail::DisplayOrientationState::setSupportedOrientationsFrom(orientations);
161
+ }
162
+ bool autoRotate() const { return gea::framework::display::DisplayBackend::autoRotate(); }
163
+ bool getAutoRotate() const { return autoRotate(); }
164
+ void setAutoRotate(bool enabled) const { gea::framework::display::DisplayBackend::setAutoRotate(enabled); }
165
+ void setVSync(bool on) const { gea::framework::display::DisplayBackend::setVSync(on); }
166
+ void setTextRasterCache(bool on) const { gea::framework::display::DisplayBackend::setTextRasterCache(on); }
167
+ void setTextSolidBackdrop(int rrggbb) const { gea::framework::display::DisplayBackend::setTextSolidBackdrop(rrggbb); }
168
+ void invalidate() const { gea::framework::display::DisplayBackend::invalidate(); }
169
+ std::string pixelFormat() const { return gea::framework::display::DisplayBackend::pixelFormat(); }
170
+ std::string getPixelFormat() const { return pixelFormat(); }
171
+ void setPixelFormat(const std::string &format) const { gea::framework::display::DisplayBackend::setPixelFormat(format); }
172
+ std::string panelPixelFormat() const { return gea::framework::display::DisplayBackend::panelPixelFormat(); }
173
+ std::string getPanelPixelFormat() const { return panelPixelFormat(); }
174
+ std::vector<std::string> supportedPixelFormats() const {
175
+ return gea::framework::display::DisplayBackend::supportedPixelFormats();
176
+ }
177
+ std::vector<std::string> getSupportedPixelFormats() const { return supportedPixelFormats(); }
178
+ double getDevicePixelRatio() const {
179
+ #if defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) && GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
180
+ return 1.0;
181
+ #else
182
+ return gea::embedded::ui::devicePixelRatio();
183
+ #endif
184
+ }
185
+ void setDevicePixelRatio(double devicePixelRatio) const {
186
+ #if defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) && GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
187
+ (void)devicePixelRatio;
188
+ #else
189
+ gea::embedded::ui::setDevicePixelRatio(devicePixelRatio);
190
+ #endif
191
+ }
192
+ double getFrameIntervalMs() const { return gea::framework::services::FrameScheduler::frameIntervalMs(); }
193
+ void setFrameIntervalMs(double intervalMs) const {
194
+ gea::framework::services::FrameScheduler::setFrameIntervalMs(static_cast<int>(intervalMs));
195
+ }
196
+ double getFrameRate() const { return gea::framework::services::FrameScheduler::frameRate(); }
197
+ void setFrameRate(double fps) const { gea::framework::services::FrameScheduler::setFrameRate(fps); }
198
+ void setAA(double samples) const { gea::framework::display::DisplayBackend::setAA(samples); }
199
+ template <typename Config>
200
+ void setFlushConfig(const Config &config) const {
201
+ gea::framework::display::DisplayBackend::setFlushConfig(
202
+ detail::displayFlushRows(config),
203
+ detail::displayFlushDepth(config));
204
+ }
205
+ template <typename Config>
206
+ void setMemoryConfig(const Config &) const {}
207
+ // E-paper refresh policy + custom waveform LUTs (no-op on non-e-paper
208
+ // boards). Omitted fields keep their current value; an empty LUT array
209
+ // restores the board's vendor waveform.
210
+ template <typename Config>
211
+ void setEpaperRefreshConfig(const Config &config) const {
212
+ double fullEvery = -1.0;
213
+ double hardCap = -1.0;
214
+ double fastWindowMs = -1.0;
215
+ std::vector<std::uint8_t> partialLut;
216
+ std::vector<std::uint8_t> fastLut;
217
+ bool hasPartialLut = false;
218
+ bool hasFastLut = false;
219
+ if constexpr (requires { config.fullRefreshEveryPartials; })
220
+ fullEvery = detail::epaperConfigNumber(config.fullRefreshEveryPartials);
221
+ else if constexpr (requires { config.record_get_literal("fullRefreshEveryPartials"); })
222
+ fullEvery = detail::epaperConfigNumber(config.record_get_literal("fullRefreshEveryPartials"));
223
+ if constexpr (requires { config.fullRefreshHardCapPartials; })
224
+ hardCap = detail::epaperConfigNumber(config.fullRefreshHardCapPartials);
225
+ else if constexpr (requires { config.record_get_literal("fullRefreshHardCapPartials"); })
226
+ hardCap = detail::epaperConfigNumber(config.record_get_literal("fullRefreshHardCapPartials"));
227
+ if constexpr (requires { config.fastStreakWindowMs; })
228
+ fastWindowMs = detail::epaperConfigNumber(config.fastStreakWindowMs);
229
+ else if constexpr (requires { config.record_get_literal("fastStreakWindowMs"); })
230
+ fastWindowMs = detail::epaperConfigNumber(config.record_get_literal("fastStreakWindowMs"));
231
+ if constexpr (requires { config.partialLut; })
232
+ hasPartialLut = detail::epaperConfigLut(config.partialLut, partialLut);
233
+ else if constexpr (requires { config.record_get_literal("partialLut"); })
234
+ hasPartialLut = detail::epaperConfigLut(config.record_get_literal("partialLut"), partialLut);
235
+ if constexpr (requires { config.fastLut; })
236
+ hasFastLut = detail::epaperConfigLut(config.fastLut, fastLut);
237
+ else if constexpr (requires { config.record_get_literal("fastLut"); })
238
+ hasFastLut = detail::epaperConfigLut(config.record_get_literal("fastLut"), fastLut);
239
+ gea::framework::display::DisplayBackend::setEpaperRefreshConfig(
240
+ fullEvery, hardCap, fastWindowMs, partialLut, hasPartialLut, fastLut, hasFastLut);
241
+ // Optional grayscale toggle: -1 = absent (leave unchanged), 0/1 = off/on.
242
+ double grayscale = -1.0;
243
+ if constexpr (requires { config.grayscale; })
244
+ grayscale = detail::epaperConfigNumber(config.grayscale);
245
+ else if constexpr (requires { config.record_get_literal("grayscale"); })
246
+ grayscale = detail::epaperConfigNumber(config.record_get_literal("grayscale"));
247
+ if (grayscale >= 0.0)
248
+ gea::framework::display::DisplayBackend::setEpaperGrayscale(grayscale != 0.0);
249
+ // Optional cover-promotion toggle: -1 = absent (leave unchanged), 0/1 =
250
+ // whether a full-screen-covering partial is promoted to a flashing full
251
+ // refresh. A reading app whose page turns cover the screen sets 0 and
252
+ // relies on fullRefreshEveryPartials to clear ghosting.
253
+ double fullOnCover = -1.0;
254
+ if constexpr (requires { config.fullOnCover; })
255
+ fullOnCover = detail::epaperConfigNumber(config.fullOnCover);
256
+ else if constexpr (requires { config.record_get_literal("fullOnCover"); })
257
+ fullOnCover = detail::epaperConfigNumber(config.record_get_literal("fullOnCover"));
258
+ if (fullOnCover >= 0.0)
259
+ gea::framework::display::DisplayBackend::setEpaperFullOnCover(fullOnCover != 0.0);
260
+ }
261
+ void epaperFullRefresh() const { gea::framework::display::DisplayBackend::epaperFullRefresh(); }
262
+ };
263
+
264
+ inline constexpr DisplayFacade Display{};
265
+
266
+ } // namespace gea::host