@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,193 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #include "camera.h"
3
+ #include "gea/embedded-host.h"
4
+ #include "ui/camera_element.h"
5
+
6
+ #include <string>
7
+
8
+ namespace gea::framework::camera {
9
+
10
+ bool CameraBackend::isAvailable() {
11
+ return gea::platform::camera::Camera::isAvailable();
12
+ }
13
+
14
+ bool CameraBackend::hasPermission() {
15
+ return gea::platform::camera::Camera::hasPermission();
16
+ }
17
+
18
+ bool CameraBackend::requestPermission() {
19
+ return gea::platform::camera::Camera::requestPermission();
20
+ }
21
+
22
+ bool CameraBackend::open(const std::string &facing, double preferredWidth, double preferredHeight) {
23
+ return gea::platform::camera::Camera::open(facing, static_cast<int>(preferredWidth), static_cast<int>(preferredHeight));
24
+ }
25
+
26
+ void CameraBackend::close() {
27
+ gea::platform::camera::Camera::close();
28
+ }
29
+
30
+ bool CameraBackend::isOpen() {
31
+ return gea::platform::camera::Camera::isOpen();
32
+ }
33
+
34
+ double CameraBackend::width() {
35
+ return static_cast<double>(gea::platform::camera::Camera::width());
36
+ }
37
+
38
+ double CameraBackend::height() {
39
+ return static_cast<double>(gea::platform::camera::Camera::height());
40
+ }
41
+
42
+ double CameraBackend::orientation() {
43
+ return static_cast<double>(gea::platform::camera::Camera::orientation());
44
+ }
45
+
46
+ std::string CameraBackend::facing() {
47
+ return gea::platform::camera::Camera::currentFacingString();
48
+ }
49
+
50
+ double CameraBackend::deviceCount() {
51
+ return static_cast<double>(gea::platform::camera::Camera::deviceCount());
52
+ }
53
+
54
+ std::string CameraBackend::deviceIdAt(double index) {
55
+ return gea::platform::camera::Camera::deviceAt(static_cast<int>(index)).id;
56
+ }
57
+
58
+ std::string CameraBackend::deviceFacingAt(double index) {
59
+ const auto info = gea::platform::camera::Camera::deviceAt(static_cast<int>(index));
60
+ switch (info.facing) {
61
+ case gea::platform::camera::Facing::Front: return "front";
62
+ case gea::platform::camera::Facing::External: return "external";
63
+ case gea::platform::camera::Facing::Back:
64
+ default: return "back";
65
+ }
66
+ }
67
+
68
+ void CameraBackend::draw(double x, double y, double destWidth, double destHeight) {
69
+ gea::platform::camera::Camera::drawPreview(static_cast<int>(x), static_cast<int>(y),
70
+ static_cast<int>(destWidth), static_cast<int>(destHeight));
71
+ }
72
+
73
+ double CameraBackend::capture() {
74
+ return static_cast<double>(gea::platform::camera::Camera::capture(false));
75
+ }
76
+
77
+ double CameraBackend::captureMirrored() {
78
+ return static_cast<double>(gea::platform::camera::Camera::capture(true));
79
+ }
80
+
81
+ void CameraBackend::setFlash(const std::string &mode) {
82
+ gea::platform::camera::Camera::setFlash(mode);
83
+ }
84
+
85
+ void CameraBackend::setZoom(double factor) {
86
+ gea::platform::camera::Camera::setZoom(factor);
87
+ }
88
+
89
+ void CameraBackend::setMirror(bool mirror) {
90
+ gea::platform::camera::Camera::setMirror(mirror);
91
+ }
92
+
93
+ bool CameraBackend::startRecording(const std::string &path, double fps) {
94
+ return gea::platform::camera::Camera::startRecording(path, fps);
95
+ }
96
+
97
+ double CameraBackend::stopRecording() {
98
+ return gea::platform::camera::Camera::stopRecording();
99
+ }
100
+
101
+ bool CameraBackend::isRecording() {
102
+ return gea::platform::camera::Camera::isRecording();
103
+ }
104
+
105
+ void CameraBackend::setExposure(const std::string &mode, double bias, double iso, double durationMs) {
106
+ gea::platform::camera::Camera::setExposure(mode, bias, iso, durationMs);
107
+ }
108
+
109
+ void CameraBackend::setWhiteBalance(const std::string &mode, double temperatureK, double tint) {
110
+ gea::platform::camera::Camera::setWhiteBalance(mode, temperatureK, tint);
111
+ }
112
+
113
+ void CameraBackend::setFocus(const std::string &mode, double pointX, double pointY) {
114
+ gea::platform::camera::Camera::setFocus(mode, pointX, pointY);
115
+ }
116
+
117
+ void CameraBackend::setTorch(const std::string &mode, double level) {
118
+ gea::platform::camera::Camera::setTorch(mode, level);
119
+ }
120
+
121
+ // Bridge the runtime's board-independent camera preview seam
122
+ // (gea::embedded::ui::CameraSurface) to the platform camera backend. Targets
123
+ // with a camera call registerCameraSurface() during init (mirroring
124
+ // gea::targets::esp32::wifi::registerDriver()); camera-less targets never link
125
+ // this translation unit, so a <camera> element renders nothing there.
126
+ namespace {
127
+
128
+ class PlatformCameraSurfaceProvider final : public gea::embedded::ui::CameraSurfaceProvider {
129
+ public:
130
+ // JSX attributes can arrive as the literal strings "undefined"/"null" when an
131
+ // app passes an absent prop straight through; treat those as empty.
132
+ static std::string sanitize(const std::string &value) {
133
+ if (value == "undefined" || value == "null") return std::string();
134
+ return value;
135
+ }
136
+
137
+ bool ensureOpen(const std::string &facing,
138
+ const std::string &device,
139
+ int preferredWidth,
140
+ int preferredHeight) override {
141
+ const std::string dev = sanitize(device);
142
+ const std::string face = sanitize(facing);
143
+ std::string hint = !dev.empty() ? dev : (!face.empty() ? face : std::string("back"));
144
+ if (gea::platform::camera::Camera::isOpen() && hint == lastHint_) return true;
145
+ if (gea::platform::camera::Camera::isOpen() && hint != lastHint_) gea::platform::camera::Camera::close();
146
+ const bool ok = gea::platform::camera::Camera::open(hint, preferredWidth, preferredHeight);
147
+ if (ok) lastHint_ = hint;
148
+ return ok;
149
+ }
150
+
151
+ bool isStreaming() override { return gea::platform::camera::Camera::isOpen(); }
152
+
153
+ gea::embedded::ui::CameraPreviewMode previewMode() override {
154
+ return gea::platform::camera::Camera::previewMode() == 1
155
+ ? gea::embedded::ui::CameraPreviewMode::NativeOverlay
156
+ : gea::embedded::ui::CameraPreviewMode::Framebuffer;
157
+ }
158
+
159
+ bool fillPreview(gea::framework::graphics::pixel::native_t *dst,
160
+ int dstWidth,
161
+ int dstHeight,
162
+ gea::embedded::ui::CameraPreviewFit fit,
163
+ bool mirror) override {
164
+ return gea::platform::camera::Camera::fillPreview(dst, dstWidth, dstHeight, static_cast<int>(fit), mirror);
165
+ }
166
+
167
+ void positionPreviewLayer(int x, int y, int width, int height) override {
168
+ gea::platform::camera::Camera::positionPreviewLayer(x, y, width, height);
169
+ }
170
+
171
+ void hidePreviewLayer() override { gea::platform::camera::Camera::hidePreviewLayer(); }
172
+
173
+ void presentNativeOverlay() override { gea::platform::camera::Camera::presentNativeOverlay(); }
174
+
175
+ void release(int) override {
176
+ gea::platform::camera::Camera::hidePreviewLayer();
177
+ gea::platform::camera::Camera::close();
178
+ lastHint_.clear();
179
+ }
180
+
181
+ private:
182
+ std::string lastHint_;
183
+ };
184
+
185
+ PlatformCameraSurfaceProvider gPlatformCameraSurfaceProvider;
186
+
187
+ } // namespace
188
+
189
+ void registerCameraSurface() {
190
+ gea::embedded::ui::CameraSurface::setProvider(&gPlatformCameraSurfaceProvider);
191
+ }
192
+
193
+ } // namespace gea::framework::camera
@@ -0,0 +1,230 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #include "gea/embedded-host.h"
3
+ #include "canvas.h"
4
+ #include "display.h"
5
+ #include "host/display_orientation.h"
6
+
7
+ namespace gea::framework::display {
8
+
9
+ namespace {
10
+
11
+ namespace pixel = gea::framework::graphics::pixel;
12
+
13
+ pixel::Format &activePixelFormat()
14
+ {
15
+ static pixel::Format format =
16
+ #if GEA_EMBEDDED_PIXEL_FORMAT == GEA_PIXEL_RGBA8888
17
+ pixel::Format::Rgba8888;
18
+ #elif GEA_EMBEDDED_PIXEL_FORMAT == GEA_PIXEL_ARGB8888
19
+ pixel::Format::Argb8888;
20
+ #else
21
+ pixel::Format::Rgb565;
22
+ #endif
23
+ return format;
24
+ }
25
+
26
+ bool supportsPixelFormat(pixel::Format format)
27
+ {
28
+ #if GEA_EMBEDDED_PIXEL_FORMAT == GEA_PIXEL_RGBA8888
29
+ return format == pixel::Format::Rgba8888;
30
+ #elif GEA_EMBEDDED_PIXEL_FORMAT == GEA_PIXEL_ARGB8888
31
+ return format == pixel::Format::Argb8888;
32
+ #else
33
+ return format == pixel::Format::Rgb565;
34
+ #endif
35
+ }
36
+
37
+ } // namespace
38
+
39
+ double DisplayBackend::brightness() {
40
+ return static_cast<double>(gea::platform::display::Display::brightness());
41
+ }
42
+
43
+ void DisplayBackend::setBrightness(double brightness) {
44
+ gea::platform::display::Display::setBrightness(static_cast<int>(brightness));
45
+ }
46
+
47
+ void DisplayBackend::setAA(double samples) {
48
+ gea::platform::display::Display::setAA(static_cast<int>(samples));
49
+ }
50
+
51
+ void DisplayBackend::setFlushConfig(double rows, double depth) {
52
+ gea::platform::display::Display::setFlushConfig(static_cast<int>(rows), static_cast<int>(depth));
53
+ }
54
+
55
+ // E-paper refresh hooks. Weak no-op defaults so the host surface exists on
56
+ // every target; an e-paper board's display driver provides the strong
57
+ // definitions (the e-paper board's display.cpp in @geastack/targets).
58
+ extern "C" __attribute__((weak)) void gea_epaper_set_refresh_config(
59
+ int full_refresh_every_partials,
60
+ int full_refresh_hard_cap_partials,
61
+ int fast_streak_window_ms,
62
+ const std::uint8_t *partial_lut, int partial_lut_len,
63
+ const std::uint8_t *fast_lut, int fast_lut_len)
64
+ {
65
+ (void)full_refresh_every_partials;
66
+ (void)full_refresh_hard_cap_partials;
67
+ (void)fast_streak_window_ms;
68
+ (void)partial_lut;
69
+ (void)partial_lut_len;
70
+ (void)fast_lut;
71
+ (void)fast_lut_len;
72
+ }
73
+
74
+ extern "C" __attribute__((weak)) void gea_epaper_full_refresh(void) {}
75
+
76
+ extern "C" __attribute__((weak)) void gea_epaper_set_grayscale(int enabled)
77
+ {
78
+ (void)enabled;
79
+ }
80
+
81
+ // Whether a partial update whose rect covers the whole screen is promoted to a
82
+ // full (flashing) refresh. Drivers default to promoting — a full-coverage
83
+ // GL16/A2 partial leaves ghosting on view switches — but a reading app whose
84
+ // every page turn covers the screen can opt out and rely on the
85
+ // fullRefreshEveryPartials cadence to clear ghosting instead.
86
+ extern "C" __attribute__((weak)) void gea_epaper_set_full_on_cover(int enabled)
87
+ {
88
+ (void)enabled;
89
+ }
90
+
91
+ void DisplayBackend::setEpaperRefreshConfig(double fullRefreshEveryPartials,
92
+ double fullRefreshHardCapPartials,
93
+ double fastStreakWindowMs,
94
+ const std::vector<std::uint8_t> &partialLut, bool hasPartialLut,
95
+ const std::vector<std::uint8_t> &fastLut, bool hasFastLut) {
96
+ gea_epaper_set_refresh_config(static_cast<int>(fullRefreshEveryPartials),
97
+ static_cast<int>(fullRefreshHardCapPartials),
98
+ static_cast<int>(fastStreakWindowMs),
99
+ hasPartialLut ? partialLut.data() : nullptr,
100
+ hasPartialLut ? static_cast<int>(partialLut.size()) : -1,
101
+ hasFastLut ? fastLut.data() : nullptr,
102
+ hasFastLut ? static_cast<int>(fastLut.size()) : -1);
103
+ }
104
+
105
+ void DisplayBackend::epaperFullRefresh() {
106
+ gea_epaper_full_refresh();
107
+ }
108
+
109
+ void DisplayBackend::setEpaperGrayscale(bool enabled) {
110
+ gea_epaper_set_grayscale(enabled ? 1 : 0);
111
+ }
112
+
113
+ void DisplayBackend::setEpaperFullOnCover(bool enabled) {
114
+ gea_epaper_set_full_on_cover(enabled ? 1 : 0);
115
+ }
116
+
117
+ double DisplayBackend::nativeWidth() {
118
+ return static_cast<double>(detail::DisplayOrientationState::nativeWidth());
119
+ }
120
+
121
+ double DisplayBackend::nativeHeight() {
122
+ return static_cast<double>(detail::DisplayOrientationState::nativeHeight());
123
+ }
124
+
125
+ std::string DisplayBackend::orientation() {
126
+ return detail::DisplayOrientationState::orientationString();
127
+ }
128
+
129
+ void DisplayBackend::setOrientation(const std::string &orientation) {
130
+ detail::DisplayOrientationState::setOrientation(orientation);
131
+ }
132
+
133
+ std::vector<std::string> DisplayBackend::supportedOrientations() {
134
+ return detail::DisplayOrientationState::supportedOrientations();
135
+ }
136
+
137
+ void DisplayBackend::setSupportedOrientations(const std::vector<std::string> &orientations) {
138
+ detail::DisplayOrientationState::setSupportedOrientations(orientations);
139
+ }
140
+
141
+ void DisplayBackend::setSupportedOrientations(const std::string &orientation) {
142
+ detail::DisplayOrientationState::setSupportedOrientations(orientation);
143
+ }
144
+
145
+ bool DisplayBackend::autoRotate() {
146
+ return detail::DisplayOrientationState::autoRotate();
147
+ }
148
+
149
+ void DisplayBackend::setAutoRotate(bool enabled) {
150
+ detail::DisplayOrientationState::setAutoRotate(enabled);
151
+ }
152
+
153
+ void DisplayBackend::setVSync(bool on) {
154
+ gea::platform::display::Display::setVSync(on);
155
+ }
156
+
157
+ void DisplayBackend::setTextRasterCache(bool on) {
158
+ // The text sprite cache is pure shared-rasterizer state — forward straight to
159
+ // Canvas, no per-platform Display layer (unlike setVSync, which drives hardware TE).
160
+ gea::framework::graphics::Canvas::setTextRasterCacheEnabled(on);
161
+ }
162
+
163
+ void DisplayBackend::setTextSolidBackdrop(int rrggbb) {
164
+ // Pure shared-rasterizer state, same as setTextRasterCache.
165
+ gea::framework::graphics::Canvas::setTextSolidBackdrop(rrggbb);
166
+ }
167
+
168
+ void DisplayBackend::invalidate() {
169
+ gea::platform::display::Display::invalidate();
170
+ }
171
+
172
+ std::string DisplayBackend::pixelFormat() {
173
+ return pixel::name(activePixelFormat());
174
+ }
175
+
176
+ void DisplayBackend::setPixelFormat(const std::string &format) {
177
+ const pixel::Format requested = pixel::parseFormat(format.c_str(), activePixelFormat());
178
+ if (supportsPixelFormat(requested)) activePixelFormat() = requested;
179
+ }
180
+
181
+ std::string DisplayBackend::panelPixelFormat() {
182
+ return pixel::name(activePixelFormat());
183
+ }
184
+
185
+ std::vector<std::string> DisplayBackend::supportedPixelFormats() {
186
+ return {pixel::name(activePixelFormat())};
187
+ }
188
+
189
+ void DisplayBackend::updateAutoRotationFromAccelerometer() {
190
+ detail::DisplayOrientationState::updateAutoRotationFromAccelerometer();
191
+ }
192
+
193
+ void DisplayBackend::updateAutoRotation(double accelerationX, double accelerationY, double accelerationZ) {
194
+ detail::DisplayOrientationState::updateAutoRotation(accelerationX, accelerationY, accelerationZ);
195
+ }
196
+
197
+ } // namespace gea::framework::display
198
+
199
+ // Weak default for boards whose display has no batched-present diagnostics;
200
+ // the P4 backend provides the strong definition.
201
+ __attribute__((weak)) void gea::platform::display::Display::presentPathDebug(
202
+ int *calls, int *direct, int *general, int *rejected,
203
+ int *tileShapeFailKind, int *tileShapeFailType, int *tileShapeFailCount)
204
+ {
205
+ *calls = 0;
206
+ *direct = 0;
207
+ *general = 0;
208
+ *rejected = 0;
209
+ *tileShapeFailKind = 0;
210
+ *tileShapeFailType = 0;
211
+ *tileShapeFailCount = 0;
212
+ }
213
+
214
+ __attribute__((weak)) void gea::platform::display::Display::landFrameDebug(int *total, int *align, int *raster, int *text, int *flip)
215
+ {
216
+ *total = 0;
217
+ *align = 0;
218
+ *raster = 0;
219
+ *text = 0;
220
+ *flip = 0;
221
+ }
222
+
223
+ __attribute__((weak)) void gea::platform::display::Display::landPanDebug(int *detect, int *kick, int *strips, int *wait, int *interior)
224
+ {
225
+ *detect = 0;
226
+ *kick = 0;
227
+ *strips = 0;
228
+ *wait = 0;
229
+ *interior = 0;
230
+ }