@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.
- package/LICENSE +202 -0
- package/README.md +25 -0
- package/audio_runtime.cpp +807 -0
- package/bluetooth.cpp +125 -0
- package/geolocation.cpp +43 -0
- package/host/apps.cpp +20 -0
- package/host/audio.cpp +240 -0
- package/host/ble.cpp +239 -0
- package/host/camera.cpp +193 -0
- package/host/display.cpp +230 -0
- package/host/fetch.cpp +1060 -0
- package/host/geolocation.cpp +31 -0
- package/host/gpio.cpp +55 -0
- package/host/http.cpp +349 -0
- package/host/image.cpp +335 -0
- package/host/imu.cpp +51 -0
- package/host/input.cpp +12 -0
- package/host/media.cpp +579 -0
- package/host/memory.cpp +91 -0
- package/host/rtc.cpp +212 -0
- package/host/rtc_esp.cpp +291 -0
- package/host/tile_loader.cpp +478 -0
- package/host/timers.cpp +327 -0
- package/host/touch.cpp +25 -0
- package/host/websocket.cpp +279 -0
- package/host/wifi.cpp +99 -0
- package/include/gea/embedded-host.h +38 -0
- package/include/host/apps.h +15 -0
- package/include/host/audio.h +158 -0
- package/include/host/backends.h +455 -0
- package/include/host/battery.h +25 -0
- package/include/host/camera.h +236 -0
- package/include/host/clock.h +45 -0
- package/include/host/device_control.h +23 -0
- package/include/host/display.h +266 -0
- package/include/host/display_orientation.h +291 -0
- package/include/host/fetch.h +310 -0
- package/include/host/gpio.h +36 -0
- package/include/host/http.h +161 -0
- package/include/host/image.h +144 -0
- package/include/host/input.h +14 -0
- package/include/host/media.h +165 -0
- package/include/host/memory.h +44 -0
- package/include/host/navigator.h +283 -0
- package/include/host/notify.h +41 -0
- package/include/host/profiler.h +49 -0
- package/include/host/rtc.h +174 -0
- package/include/host/storage.h +141 -0
- package/include/host/tile_loader.h +59 -0
- package/include/host/timers.h +41 -0
- package/include/host/touch.h +20 -0
- package/include/host/websocket.h +179 -0
- package/include/host/window.h +31 -0
- package/input.cpp +68 -0
- package/package.json +27 -0
- package/services/app_state.cpp +19 -0
- package/services/battery_service.cpp +19 -0
- package/services/bluetooth_service.cpp +37 -0
- package/services/diagnostics.cpp +233 -0
- package/services/diagnostics_connection.cpp +231 -0
- package/services/diagnostics_internal.h +15 -0
- package/services/diagnostics_server.cpp +135 -0
- package/services/mirror.cpp +364 -0
- package/services/network_services.cpp +62 -0
- package/services/runtime_log.cpp +23 -0
- package/services/settings_surface.h +221 -0
- package/wifi.cpp +185 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
namespace gea::host {
|
|
7
|
+
|
|
8
|
+
// Async tile/image loader. `request()` queues a load by cache key: the worker
|
|
9
|
+
// (its own task, pinned to the SECOND core on esp32) reads the persistent
|
|
10
|
+
// cache path first, falls back to `GET url` (persisting the bytes to the path
|
|
11
|
+
// after a successful decode), and decodes into the image store. The app drains
|
|
12
|
+
// completions with poll()/key()/imageId()/status() — typically once per
|
|
13
|
+
// animation frame — so the frame task never blocks on SD, network, or PNG
|
|
14
|
+
// decode. Requests are deduplicated by key while in flight.
|
|
15
|
+
class TileLoaderService {
|
|
16
|
+
public:
|
|
17
|
+
// `num` is an app-chosen numeric id echoed back via keyNum() — the app's
|
|
18
|
+
// hot per-frame cache lookups then never build/compare strings (std::string
|
|
19
|
+
// tile keys cost 6-14ms per render on a 360MHz MCU).
|
|
20
|
+
void request(const std::string &key,
|
|
21
|
+
double num,
|
|
22
|
+
const std::string &path,
|
|
23
|
+
const std::string &url,
|
|
24
|
+
bool opaque,
|
|
25
|
+
bool rotate90 = false) const;
|
|
26
|
+
|
|
27
|
+
// Gate REMOTE loading: while false (an active pan/pinch), workers serve only
|
|
28
|
+
// the persistent cache — an SD miss completes immediately with status 0
|
|
29
|
+
// (retryable) instead of hitting the network. The app re-enables once the
|
|
30
|
+
// gesture settles and re-requests, so downloads never compete with a live
|
|
31
|
+
// gesture for bandwidth/CPU. Cache loads keep streaming mid-gesture.
|
|
32
|
+
void setNetworkAllowed(bool allowed) const;
|
|
33
|
+
|
|
34
|
+
// Drop all queued-but-not-started jobs (their keys become requestable
|
|
35
|
+
// again). Call before re-queuing the current visible set so stale zoom
|
|
36
|
+
// levels never starve the tiles actually on screen.
|
|
37
|
+
void purgeQueued() const;
|
|
38
|
+
|
|
39
|
+
// One-time maintenance: delete every persistent tiles/<z> level directory
|
|
40
|
+
// whose z is NOT in the comma-separated keep list (e.g. "2,5,8,11,13,15,17,19").
|
|
41
|
+
// Runs on the worker core before the census.
|
|
42
|
+
void pruneLevels(const std::string &keepCsv) const;
|
|
43
|
+
|
|
44
|
+
// Advance to the next completed result. False when none are ready.
|
|
45
|
+
bool poll() const;
|
|
46
|
+
// Key of the result selected by the last successful poll().
|
|
47
|
+
std::string key() const;
|
|
48
|
+
// Numeric id passed to request() for that result.
|
|
49
|
+
double keyNum() const;
|
|
50
|
+
// Decoded image-store id of that result; -1 when the load failed.
|
|
51
|
+
double imageId() const;
|
|
52
|
+
// HTTP status of that result (200/404/...); 0 = transport/WiFi failure —
|
|
53
|
+
// retryable: a later request() for the same key tries again.
|
|
54
|
+
double status() const;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
inline constexpr TileLoaderService tiles{};
|
|
58
|
+
|
|
59
|
+
} // namespace gea::host
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include <functional>
|
|
5
|
+
#include <cstdint>
|
|
6
|
+
|
|
7
|
+
namespace gea::host {
|
|
8
|
+
|
|
9
|
+
#if defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) && GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
|
|
10
|
+
using AnimationFrameTimestamp = float;
|
|
11
|
+
#else
|
|
12
|
+
using AnimationFrameTimestamp = double;
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
using AnimationFrameCallback = std::function<void(AnimationFrameTimestamp)>;
|
|
16
|
+
using TimerCallback = std::function<void()>;
|
|
17
|
+
|
|
18
|
+
struct AnimationFramePerfStats {
|
|
19
|
+
std::int64_t totalUs = 0;
|
|
20
|
+
std::int64_t prepareUs = 0;
|
|
21
|
+
std::int64_t callbackUs = 0;
|
|
22
|
+
std::int64_t maxCallbackUs = 0;
|
|
23
|
+
int pendingAtRun = 0;
|
|
24
|
+
int callbackCount = 0;
|
|
25
|
+
int requestCount = 0;
|
|
26
|
+
int droppedCount = 0;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
double setTimeout(TimerCallback callback, double delayMs);
|
|
30
|
+
double setInterval(TimerCallback callback, double delayMs);
|
|
31
|
+
void clearTimeout(double id);
|
|
32
|
+
void clearInterval(double id);
|
|
33
|
+
void resetScheduledTimers();
|
|
34
|
+
|
|
35
|
+
double requestAnimationFrame(AnimationFrameCallback callback);
|
|
36
|
+
void runAnimationFrameCallbacks(AnimationFrameTimestamp timestampMs);
|
|
37
|
+
void resetAnimationFrameCallbacks();
|
|
38
|
+
void animationFramePerfStatsReset();
|
|
39
|
+
AnimationFramePerfStats animationFramePerfStatsRead();
|
|
40
|
+
|
|
41
|
+
} // namespace gea::host
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
namespace gea::host {
|
|
5
|
+
|
|
6
|
+
struct TouchSample {
|
|
7
|
+
bool touching = false;
|
|
8
|
+
double x = 0;
|
|
9
|
+
double y = 0;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
class Touch {
|
|
13
|
+
public:
|
|
14
|
+
TouchSample read() const;
|
|
15
|
+
TouchSample readRaw() const { return read(); }
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
inline constexpr Touch touch{};
|
|
19
|
+
|
|
20
|
+
} // namespace gea::host
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include <cstdint>
|
|
5
|
+
#include <functional>
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <unordered_map>
|
|
9
|
+
#include <utility>
|
|
10
|
+
#include <vector>
|
|
11
|
+
|
|
12
|
+
namespace gea::host {
|
|
13
|
+
|
|
14
|
+
using NativeWebSocketHandle = std::uint32_t;
|
|
15
|
+
|
|
16
|
+
class WebSocketOnOpenProperty {
|
|
17
|
+
public:
|
|
18
|
+
NativeWebSocketHandle handle = 0;
|
|
19
|
+
constexpr WebSocketOnOpenProperty() = default;
|
|
20
|
+
explicit constexpr WebSocketOnOpenProperty(NativeWebSocketHandle h) : handle(h) {}
|
|
21
|
+
#ifdef GEA_CPP_VALUE_AVAILABLE
|
|
22
|
+
const WebSocketOnOpenProperty &operator=(gea_cpp_value callback) const;
|
|
23
|
+
#endif
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
class WebSocketOnMessageProperty {
|
|
27
|
+
public:
|
|
28
|
+
NativeWebSocketHandle handle = 0;
|
|
29
|
+
constexpr WebSocketOnMessageProperty() = default;
|
|
30
|
+
explicit constexpr WebSocketOnMessageProperty(NativeWebSocketHandle h) : handle(h) {}
|
|
31
|
+
#ifdef GEA_CPP_VALUE_AVAILABLE
|
|
32
|
+
const WebSocketOnMessageProperty &operator=(gea_cpp_value callback) const;
|
|
33
|
+
#endif
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
class WebSocketOnCloseProperty {
|
|
37
|
+
public:
|
|
38
|
+
NativeWebSocketHandle handle = 0;
|
|
39
|
+
constexpr WebSocketOnCloseProperty() = default;
|
|
40
|
+
explicit constexpr WebSocketOnCloseProperty(NativeWebSocketHandle h) : handle(h) {}
|
|
41
|
+
#ifdef GEA_CPP_VALUE_AVAILABLE
|
|
42
|
+
const WebSocketOnCloseProperty &operator=(gea_cpp_value callback) const;
|
|
43
|
+
#endif
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
class WebSocketOnErrorProperty {
|
|
47
|
+
public:
|
|
48
|
+
NativeWebSocketHandle handle = 0;
|
|
49
|
+
constexpr WebSocketOnErrorProperty() = default;
|
|
50
|
+
explicit constexpr WebSocketOnErrorProperty(NativeWebSocketHandle h) : handle(h) {}
|
|
51
|
+
#ifdef GEA_CPP_VALUE_AVAILABLE
|
|
52
|
+
const WebSocketOnErrorProperty &operator=(gea_cpp_value callback) const;
|
|
53
|
+
#endif
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
class WebSocket {
|
|
57
|
+
public:
|
|
58
|
+
static constexpr int CONNECTING = 0;
|
|
59
|
+
static constexpr int OPEN = 1;
|
|
60
|
+
static constexpr int CLOSING = 2;
|
|
61
|
+
static constexpr int CLOSED = 3;
|
|
62
|
+
|
|
63
|
+
NativeWebSocketHandle nativeHandle = 0;
|
|
64
|
+
mutable WebSocketOnOpenProperty onopen;
|
|
65
|
+
mutable WebSocketOnMessageProperty onmessage;
|
|
66
|
+
mutable WebSocketOnCloseProperty onclose;
|
|
67
|
+
mutable WebSocketOnErrorProperty onerror;
|
|
68
|
+
|
|
69
|
+
constexpr WebSocket() = default;
|
|
70
|
+
explicit WebSocket(NativeWebSocketHandle h)
|
|
71
|
+
: nativeHandle(h), onopen(h), onmessage(h), onclose(h), onerror(h) {}
|
|
72
|
+
explicit WebSocket(double h)
|
|
73
|
+
: nativeHandle(static_cast<NativeWebSocketHandle>(h)),
|
|
74
|
+
onopen(nativeHandle), onmessage(nativeHandle), onclose(nativeHandle), onerror(nativeHandle) {}
|
|
75
|
+
|
|
76
|
+
constexpr operator double() const { return static_cast<double>(nativeHandle); }
|
|
77
|
+
|
|
78
|
+
std::string url() const;
|
|
79
|
+
double readyState() const;
|
|
80
|
+
void send(const std::string &data) const;
|
|
81
|
+
void close() const;
|
|
82
|
+
void close(double code) const;
|
|
83
|
+
void close(double code, const std::string &reason) const;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
namespace websocket {
|
|
87
|
+
|
|
88
|
+
struct CallbackTable {
|
|
89
|
+
std::function<void()> on_open;
|
|
90
|
+
std::function<void(const std::string &)> on_message;
|
|
91
|
+
std::function<void(int, const std::string &)> on_close;
|
|
92
|
+
std::function<void(const std::string &)> on_error;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
std::unordered_map<NativeWebSocketHandle, CallbackTable> &callbackTable();
|
|
96
|
+
|
|
97
|
+
NativeWebSocketHandle create_handle(const std::string &url);
|
|
98
|
+
void destroy_handle(NativeWebSocketHandle handle);
|
|
99
|
+
|
|
100
|
+
void runCallbacks();
|
|
101
|
+
|
|
102
|
+
void test_inject_open(NativeWebSocketHandle handle);
|
|
103
|
+
void test_inject_message(NativeWebSocketHandle handle, const std::string &data);
|
|
104
|
+
void test_inject_close(NativeWebSocketHandle handle, int code, const std::string &reason);
|
|
105
|
+
|
|
106
|
+
void test_set_open_callback(NativeWebSocketHandle handle, std::function<void()> cb);
|
|
107
|
+
void test_set_message_callback(NativeWebSocketHandle handle, std::function<void(const std::string &)> cb);
|
|
108
|
+
void test_set_close_callback(NativeWebSocketHandle handle, std::function<void(int, const std::string &)> cb);
|
|
109
|
+
void test_set_error_callback(NativeWebSocketHandle handle, std::function<void(const std::string &)> cb);
|
|
110
|
+
|
|
111
|
+
} // namespace websocket
|
|
112
|
+
|
|
113
|
+
#ifdef GEA_CPP_VALUE_AVAILABLE
|
|
114
|
+
|
|
115
|
+
inline const WebSocketOnOpenProperty &WebSocketOnOpenProperty::operator=(gea_cpp_value cb) const {
|
|
116
|
+
if (cb.kind != gea_cpp_value::kind_t::callable || !cb.callable) {
|
|
117
|
+
websocket::callbackTable()[handle].on_open = nullptr;
|
|
118
|
+
return *this;
|
|
119
|
+
}
|
|
120
|
+
auto callable = cb.callable;
|
|
121
|
+
websocket::callbackTable()[handle].on_open = [callable]() {
|
|
122
|
+
(*callable)(std::vector<gea_cpp_value>{});
|
|
123
|
+
};
|
|
124
|
+
return *this;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
inline const WebSocketOnMessageProperty &WebSocketOnMessageProperty::operator=(gea_cpp_value cb) const {
|
|
128
|
+
if (cb.kind != gea_cpp_value::kind_t::callable || !cb.callable) {
|
|
129
|
+
websocket::callbackTable()[handle].on_message = nullptr;
|
|
130
|
+
return *this;
|
|
131
|
+
}
|
|
132
|
+
auto callable = cb.callable;
|
|
133
|
+
websocket::callbackTable()[handle].on_message = [callable](const std::string &data) {
|
|
134
|
+
gea_cpp_value event;
|
|
135
|
+
event.kind = gea_cpp_value::kind_t::record;
|
|
136
|
+
event.entries = std::make_shared<std::vector<std::pair<std::string, gea_cpp_value>>>();
|
|
137
|
+
event.record_set_literal("data", gea_cpp_value(data));
|
|
138
|
+
(*callable)(std::vector<gea_cpp_value>{event});
|
|
139
|
+
};
|
|
140
|
+
return *this;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
inline const WebSocketOnCloseProperty &WebSocketOnCloseProperty::operator=(gea_cpp_value cb) const {
|
|
144
|
+
if (cb.kind != gea_cpp_value::kind_t::callable || !cb.callable) {
|
|
145
|
+
websocket::callbackTable()[handle].on_close = nullptr;
|
|
146
|
+
return *this;
|
|
147
|
+
}
|
|
148
|
+
auto callable = cb.callable;
|
|
149
|
+
websocket::callbackTable()[handle].on_close = [callable](int code, const std::string &reason) {
|
|
150
|
+
gea_cpp_value event;
|
|
151
|
+
event.kind = gea_cpp_value::kind_t::record;
|
|
152
|
+
event.entries = std::make_shared<std::vector<std::pair<std::string, gea_cpp_value>>>();
|
|
153
|
+
event.record_set_literal("code", gea_cpp_value(static_cast<double>(code)));
|
|
154
|
+
event.record_set_literal("reason", gea_cpp_value(reason));
|
|
155
|
+
event.record_set_literal("wasClean", gea_cpp_value(code == 1000));
|
|
156
|
+
(*callable)(std::vector<gea_cpp_value>{event});
|
|
157
|
+
};
|
|
158
|
+
return *this;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
inline const WebSocketOnErrorProperty &WebSocketOnErrorProperty::operator=(gea_cpp_value cb) const {
|
|
162
|
+
if (cb.kind != gea_cpp_value::kind_t::callable || !cb.callable) {
|
|
163
|
+
websocket::callbackTable()[handle].on_error = nullptr;
|
|
164
|
+
return *this;
|
|
165
|
+
}
|
|
166
|
+
auto callable = cb.callable;
|
|
167
|
+
websocket::callbackTable()[handle].on_error = [callable](const std::string &message) {
|
|
168
|
+
gea_cpp_value event;
|
|
169
|
+
event.kind = gea_cpp_value::kind_t::record;
|
|
170
|
+
event.entries = std::make_shared<std::vector<std::pair<std::string, gea_cpp_value>>>();
|
|
171
|
+
event.record_set_literal("message", gea_cpp_value(message));
|
|
172
|
+
(*callable)(std::vector<gea_cpp_value>{event});
|
|
173
|
+
};
|
|
174
|
+
return *this;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
#endif // GEA_CPP_VALUE_AVAILABLE
|
|
178
|
+
|
|
179
|
+
} // namespace gea::host
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include <display.h>
|
|
5
|
+
#include <ui/document.h>
|
|
6
|
+
|
|
7
|
+
namespace gea::host {
|
|
8
|
+
|
|
9
|
+
struct WindowFacade {
|
|
10
|
+
double innerWidth() const {
|
|
11
|
+
#if defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) && GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
|
|
12
|
+
return static_cast<double>(gea::platform::display::kWidth);
|
|
13
|
+
#else
|
|
14
|
+
int w = gea::embedded::ui::Document::preferredMountWidth();
|
|
15
|
+
return static_cast<double>(w > 0 ? w : gea::platform::display::kWidth);
|
|
16
|
+
#endif
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
double innerHeight() const {
|
|
20
|
+
#if defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) && GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
|
|
21
|
+
return static_cast<double>(gea::platform::display::kHeight);
|
|
22
|
+
#else
|
|
23
|
+
int h = gea::embedded::ui::Document::preferredMountHeight();
|
|
24
|
+
return static_cast<double>(h > 0 ? h : gea::platform::display::kHeight);
|
|
25
|
+
#endif
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
inline constexpr WindowFacade window{};
|
|
30
|
+
|
|
31
|
+
} // namespace gea::host
|
package/input.cpp
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "input.h"
|
|
3
|
+
|
|
4
|
+
#include <atomic>
|
|
5
|
+
|
|
6
|
+
namespace gea::framework::input {
|
|
7
|
+
|
|
8
|
+
namespace {
|
|
9
|
+
|
|
10
|
+
// One-shot "back button pressed" flag. Atomic so the platform button task
|
|
11
|
+
// (priority 10 on a FreeRTOS core) can race-set without locks against the
|
|
12
|
+
// app's rAF tick (priority 23 on a different core).
|
|
13
|
+
std::atomic_bool g_back_pending{false};
|
|
14
|
+
std::atomic_int g_rotary_delta{0};
|
|
15
|
+
|
|
16
|
+
// Pending hardware key presses. A tiny ring keeps fast double-presses from
|
|
17
|
+
// coalescing (the single consumer is the frame loop, once per frame); a
|
|
18
|
+
// burst deeper than the ring just overwrites the oldest press.
|
|
19
|
+
constexpr unsigned kKeyQueueSize = 8;
|
|
20
|
+
std::atomic_int g_key_queue[kKeyQueueSize]{};
|
|
21
|
+
std::atomic<unsigned> g_key_write{0};
|
|
22
|
+
std::atomic<unsigned> g_key_read{0};
|
|
23
|
+
|
|
24
|
+
} // namespace
|
|
25
|
+
|
|
26
|
+
void pressBackButton()
|
|
27
|
+
{
|
|
28
|
+
g_back_pending.store(true, std::memory_order_release);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
bool consumeBackButton()
|
|
32
|
+
{
|
|
33
|
+
return g_back_pending.exchange(false, std::memory_order_acq_rel);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void queueRotaryDelta(int delta)
|
|
37
|
+
{
|
|
38
|
+
if (delta == 0) return;
|
|
39
|
+
g_rotary_delta.fetch_add(delta, std::memory_order_acq_rel);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
int consumeRotaryDelta()
|
|
43
|
+
{
|
|
44
|
+
return g_rotary_delta.exchange(0, std::memory_order_acq_rel);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
void queueKeyDown(int keyCode)
|
|
48
|
+
{
|
|
49
|
+
if (keyCode == 0) return;
|
|
50
|
+
const unsigned slot = g_key_write.fetch_add(1, std::memory_order_acq_rel) % kKeyQueueSize;
|
|
51
|
+
g_key_queue[slot].store(keyCode, std::memory_order_release);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
int consumeKeyDown()
|
|
55
|
+
{
|
|
56
|
+
const unsigned write = g_key_write.load(std::memory_order_acquire);
|
|
57
|
+
unsigned read = g_key_read.load(std::memory_order_acquire);
|
|
58
|
+
while (read != write) {
|
|
59
|
+
const unsigned slot = read % kKeyQueueSize;
|
|
60
|
+
const int code = g_key_queue[slot].exchange(0, std::memory_order_acq_rel);
|
|
61
|
+
g_key_read.store(read + 1, std::memory_order_release);
|
|
62
|
+
if (code != 0) return code;
|
|
63
|
+
read = g_key_read.load(std::memory_order_acquire);
|
|
64
|
+
}
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
} // namespace gea::framework::input
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@geastack/host",
|
|
3
|
+
"version": "0.1.8",
|
|
4
|
+
"description": "GeaStack host bindings and platform service sources.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/geastack/core.git",
|
|
9
|
+
"directory": "packages/host"
|
|
10
|
+
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=20.19"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"*.cpp",
|
|
19
|
+
"*.h",
|
|
20
|
+
"host",
|
|
21
|
+
"include",
|
|
22
|
+
"services"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "services/app_state.h"
|
|
3
|
+
|
|
4
|
+
#include "apps.h"
|
|
5
|
+
#include "services/mirror.h"
|
|
6
|
+
|
|
7
|
+
namespace gea::framework::services {
|
|
8
|
+
|
|
9
|
+
const char *AppState::currentAppId()
|
|
10
|
+
{
|
|
11
|
+
return gea::framework::apps::AppManager::currentId();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
void AppState::afterAppInit()
|
|
15
|
+
{
|
|
16
|
+
MirrorService::clearDirty();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
} // namespace gea::framework::services
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "services/battery_service.h"
|
|
3
|
+
|
|
4
|
+
#include "ble.h"
|
|
5
|
+
#include "power.h"
|
|
6
|
+
|
|
7
|
+
#include <cstdint>
|
|
8
|
+
|
|
9
|
+
namespace gea::framework::services {
|
|
10
|
+
|
|
11
|
+
void BatteryService::update()
|
|
12
|
+
{
|
|
13
|
+
int pct = gea::platform::power::Power::batteryPercent();
|
|
14
|
+
if (pct >= 0) {
|
|
15
|
+
gea::framework::bluetooth::bluetooth().hid().setBatteryLevel(static_cast<std::uint8_t>(pct));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
} // namespace gea::framework::services
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "services/bluetooth_service.h"
|
|
3
|
+
|
|
4
|
+
#include "ble.h"
|
|
5
|
+
#include "services/diagnostics.h"
|
|
6
|
+
|
|
7
|
+
namespace gea::framework::services {
|
|
8
|
+
|
|
9
|
+
void BluetoothService::preinitForApp()
|
|
10
|
+
{
|
|
11
|
+
#ifdef GEA_EMBEDDED_APP_USES_BLE
|
|
12
|
+
DiagnosticsServer::print("Preinitializing BLE controller...\n");
|
|
13
|
+
HeapProbe::log("app:before_ble_preinit");
|
|
14
|
+
gea::framework::bluetooth::bluetooth().hid().preinit();
|
|
15
|
+
HeapProbe::log("app:after_ble_preinit");
|
|
16
|
+
#endif
|
|
17
|
+
// When the macro is undefined the build omits the ESP32 BLE driver and bt
|
|
18
|
+
// component. Keeping this function a no-op lets the shared runtime remain
|
|
19
|
+
// source-compatible without retaining the controller's ~40 KB RAM footprint.
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void BluetoothService::notifyConnected()
|
|
23
|
+
{
|
|
24
|
+
DiagnosticsServer::print("BLE connected\n");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
void BluetoothService::notifyDisconnected()
|
|
28
|
+
{
|
|
29
|
+
DiagnosticsServer::print("BLE disconnected\n");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
void BluetoothService::notifyBound()
|
|
33
|
+
{
|
|
34
|
+
DiagnosticsServer::print("BLE HID bound\n");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
} // namespace gea::framework::services
|