@geastack/host 0.1.14 → 0.1.16
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/README.md +6 -0
- package/audio_runtime.cpp +183 -98
- package/host/audio.cpp +47 -24
- package/host/audio_buffer_runtime.cpp +117 -0
- package/host/audio_worklet.cpp +29 -17
- package/host/camera.cpp +34 -1
- package/host/device.cpp +36 -0
- package/host/http.cpp +155 -56
- package/host/image.cpp +188 -97
- package/host/media.cpp +18 -6
- package/host/mjpeg.cpp +1 -1
- package/host/rtc.cpp +1 -1
- package/host/rtc_esp.cpp +2 -2
- package/host/timers.cpp +2 -2
- package/host/websocket.cpp +7 -5
- package/host/wifi.cpp +30 -32
- package/include/gea/audio-worklet-runtime.h +4 -3
- package/include/gea/http-native-runtime.h +127 -0
- package/include/host/audio.h +84 -13
- package/include/host/backends.h +88 -51
- package/include/host/battery.h +10 -0
- package/include/host/camera.h +1 -0
- package/include/host/camera_frame.h +69 -0
- package/include/host/clock.h +6 -0
- package/include/host/http.h +80 -20
- package/include/host/image.h +1 -0
- package/include/host/navigator.h +238 -89
- package/include/host/storage.h +9 -6
- package/include/host/timers.h +2 -5
- package/include/host/websocket.h +43 -3
- package/include/platform/internal_stack.h +89 -0
- package/input.cpp +57 -33
- package/package.json +1 -1
- package/wifi.cpp +140 -121
package/input.cpp
CHANGED
|
@@ -17,52 +17,76 @@ std::atomic_int g_rotary_delta{0};
|
|
|
17
17
|
// coalescing (the single consumer is the frame loop, once per frame); a
|
|
18
18
|
// burst deeper than the ring just overwrites the oldest press.
|
|
19
19
|
constexpr unsigned kKeyQueueSize = 8;
|
|
20
|
-
std::
|
|
20
|
+
std::atomic_uint g_key_queue[kKeyQueueSize]{};
|
|
21
21
|
std::atomic<unsigned> g_key_write{0};
|
|
22
22
|
std::atomic<unsigned> g_key_read{0};
|
|
23
23
|
|
|
24
|
-
}
|
|
24
|
+
} // namespace
|
|
25
25
|
|
|
26
|
-
void pressBackButton()
|
|
27
|
-
|
|
28
|
-
g_back_pending.store(true, std::memory_order_release);
|
|
26
|
+
void pressBackButton() {
|
|
27
|
+
g_back_pending.store(true, std::memory_order_release);
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
bool consumeBackButton()
|
|
32
|
-
|
|
33
|
-
return g_back_pending.exchange(false, std::memory_order_acq_rel);
|
|
30
|
+
bool consumeBackButton() {
|
|
31
|
+
return g_back_pending.exchange(false, std::memory_order_acq_rel);
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
void queueRotaryDelta(int delta)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
void queueRotaryDelta(int delta) {
|
|
35
|
+
if (delta == 0)
|
|
36
|
+
return;
|
|
37
|
+
g_rotary_delta.fetch_add(delta, std::memory_order_acq_rel);
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
int consumeRotaryDelta()
|
|
43
|
-
|
|
44
|
-
return g_rotary_delta.exchange(0, std::memory_order_acq_rel);
|
|
40
|
+
int consumeRotaryDelta() {
|
|
41
|
+
return g_rotary_delta.exchange(0, std::memory_order_acq_rel);
|
|
45
42
|
}
|
|
46
43
|
|
|
47
|
-
void
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
void queueKey(int keyCode, bool pressed) {
|
|
45
|
+
if (keyCode <= 0)
|
|
46
|
+
return;
|
|
47
|
+
const unsigned slot =
|
|
48
|
+
g_key_write.fetch_add(1, std::memory_order_acq_rel) % kKeyQueueSize;
|
|
49
|
+
g_key_queue[slot].store((static_cast<unsigned>(keyCode) << 1) |
|
|
50
|
+
unsigned(pressed),
|
|
51
|
+
std::memory_order_release);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
int
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
54
|
+
void queueKeyDown(int keyCode) { queueKey(keyCode, true); }
|
|
55
|
+
|
|
56
|
+
void queueKeyUp(int keyCode) { queueKey(keyCode, false); }
|
|
57
|
+
|
|
58
|
+
bool consumeKeyEvent(HardwareKeyEvent &event) {
|
|
59
|
+
const unsigned write = g_key_write.load(std::memory_order_acquire);
|
|
60
|
+
unsigned read = g_key_read.load(std::memory_order_acquire);
|
|
61
|
+
// Keep only the newest ring's worth of reservations after overflow. Without
|
|
62
|
+
// this, overwritten slots leave holes that can never be published again.
|
|
63
|
+
if (write - read > kKeyQueueSize) {
|
|
64
|
+
read = write - kKeyQueueSize;
|
|
65
|
+
g_key_read.store(read, std::memory_order_release);
|
|
66
|
+
}
|
|
67
|
+
if (read != write) {
|
|
68
|
+
const unsigned slot = read % kKeyQueueSize;
|
|
69
|
+
const unsigned code =
|
|
70
|
+
g_key_queue[slot].exchange(0, std::memory_order_acq_rel);
|
|
71
|
+
// A producer reserves its ticket before publishing the key. Leave that
|
|
72
|
+
// reservation pending so the next frame can consume it after publication.
|
|
73
|
+
// Zero key codes never reserve a ticket in queueKeyDown().
|
|
74
|
+
if (code == 0)
|
|
75
|
+
return false;
|
|
76
|
+
g_key_read.store(read + 1, std::memory_order_release);
|
|
77
|
+
event = {static_cast<int>(code >> 1), (code & 1) != 0};
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
int consumeKeyDown() {
|
|
84
|
+
HardwareKeyEvent event{};
|
|
85
|
+
while (consumeKeyEvent(event)) {
|
|
86
|
+
if (event.pressed)
|
|
87
|
+
return event.keyCode;
|
|
88
|
+
}
|
|
89
|
+
return 0;
|
|
66
90
|
}
|
|
67
91
|
|
|
68
|
-
}
|
|
92
|
+
} // namespace gea::framework::input
|
package/package.json
CHANGED
package/wifi.cpp
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
#include <emscripten/em_js.h>
|
|
6
6
|
|
|
7
7
|
EM_JS(int, gea_web_wifi_online, (), {
|
|
8
|
-
return (typeof navigator !== 'undefined' && 'onLine' in navigator)
|
|
8
|
+
return (typeof navigator !== 'undefined' && 'onLine' in navigator)
|
|
9
|
+
? (navigator.onLine ? 1 : 0)
|
|
10
|
+
: 1;
|
|
9
11
|
});
|
|
10
12
|
#endif
|
|
11
13
|
|
|
@@ -15,34 +17,32 @@ namespace {
|
|
|
15
17
|
|
|
16
18
|
class NullWifiDriver final : public WifiDriver {
|
|
17
19
|
public:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
std::vector<WifiNetwork> scanResults() const override { return {}; }
|
|
20
|
+
bool init() override { return false; }
|
|
21
|
+
bool enabled() const override { return false; }
|
|
22
|
+
void setEnabled(bool enabled) override { (void)enabled; }
|
|
23
|
+
bool connected() const override { return false; }
|
|
24
|
+
int rssi() override { return 0; }
|
|
25
|
+
std::string ssid() override { return {}; }
|
|
26
|
+
std::string ip() const override { return "0.0.0.0"; }
|
|
27
|
+
std::string mac() override { return {}; }
|
|
28
|
+
void configure(const std::string &ssid,
|
|
29
|
+
const std::string &password) override {
|
|
30
|
+
(void)ssid;
|
|
31
|
+
(void)password;
|
|
32
|
+
}
|
|
33
|
+
void scan() override {}
|
|
34
|
+
bool scanning() const override { return false; }
|
|
35
|
+
int scanCount() const override { return 0; }
|
|
36
|
+
WifiNetwork networkAt(int index) const override {
|
|
37
|
+
(void)index;
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
std::vector<WifiNetwork> scanResults() const override { return {}; }
|
|
40
41
|
};
|
|
41
42
|
|
|
42
|
-
NullWifiDriver &nullDriver()
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return driver;
|
|
43
|
+
NullWifiDriver &nullDriver() {
|
|
44
|
+
static NullWifiDriver driver;
|
|
45
|
+
return driver;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
#ifdef __EMSCRIPTEN__
|
|
@@ -55,131 +55,150 @@ NullWifiDriver &nullDriver()
|
|
|
55
55
|
// shims do) — this is only the default.
|
|
56
56
|
class BrowserWifiDriver final : public WifiDriver {
|
|
57
57
|
public:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
58
|
+
bool init() override { return true; }
|
|
59
|
+
bool enabled() const override { return enabled_; }
|
|
60
|
+
void setEnabled(bool enabled) override { enabled_ = enabled; }
|
|
61
|
+
bool connected() const override {
|
|
62
|
+
return enabled_ && webConnected_ && gea_web_wifi_online() != 0;
|
|
63
|
+
}
|
|
64
|
+
int rssi() override { return rssi_; }
|
|
65
|
+
std::string ssid() override { return ssid_; }
|
|
66
|
+
std::string ip() const override { return ip_; }
|
|
67
|
+
std::string mac() override { return {}; }
|
|
68
|
+
void configure(const std::string &ssid,
|
|
69
|
+
const std::string &password) override {
|
|
70
|
+
(void)password;
|
|
71
|
+
ssid_ = ssid;
|
|
72
|
+
}
|
|
73
|
+
void scan() override {}
|
|
74
|
+
bool scanning() const override { return false; }
|
|
75
|
+
int scanCount() const override { return static_cast<int>(networks_.size()); }
|
|
76
|
+
WifiNetwork networkAt(int index) const override {
|
|
77
|
+
if (index < 0 || index >= static_cast<int>(networks_.size()))
|
|
78
|
+
return {};
|
|
79
|
+
return networks_[static_cast<std::size_t>(index)];
|
|
80
|
+
}
|
|
81
|
+
std::vector<WifiNetwork> scanResults() const override { return networks_; }
|
|
82
|
+
// The simulator's Wi-Fi panel pushes its state through these hooks; honor
|
|
83
|
+
// them so unchecking "Connected" actually takes apps offline in the sim.
|
|
84
|
+
void setWebState(bool connected, const char *ssid, const char *ip,
|
|
85
|
+
int rssi) override {
|
|
86
|
+
webConnected_ = connected;
|
|
87
|
+
if (ssid)
|
|
88
|
+
ssid_ = ssid;
|
|
89
|
+
if (ip)
|
|
90
|
+
ip_ = ip;
|
|
91
|
+
rssi_ = rssi;
|
|
92
|
+
}
|
|
93
|
+
void setWebScanCount(int count) override {
|
|
94
|
+
networks_.assign(count > 0 ? static_cast<std::size_t>(count) : 0,
|
|
95
|
+
WifiNetwork{});
|
|
96
|
+
}
|
|
97
|
+
void setWebScanEntry(int index, const char *ssid, int rssi,
|
|
98
|
+
bool secured) override {
|
|
99
|
+
if (index < 0 || index >= static_cast<int>(networks_.size()))
|
|
100
|
+
return;
|
|
101
|
+
auto &entry = networks_[static_cast<std::size_t>(index)];
|
|
102
|
+
entry.ssid = ssid ? ssid : "";
|
|
103
|
+
entry.rssi = rssi;
|
|
104
|
+
entry.secured = secured;
|
|
105
|
+
}
|
|
101
106
|
|
|
102
107
|
private:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
bool enabled_ = true;
|
|
109
|
+
bool webConnected_ = true;
|
|
110
|
+
int rssi_ = -50;
|
|
111
|
+
std::string ssid_ = "browser";
|
|
112
|
+
std::string ip_ = "0.0.0.0";
|
|
113
|
+
std::vector<WifiNetwork> networks_;
|
|
109
114
|
};
|
|
110
115
|
|
|
111
|
-
BrowserWifiDriver &browserDriver()
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return driver;
|
|
116
|
+
BrowserWifiDriver &browserDriver() {
|
|
117
|
+
static BrowserWifiDriver driver;
|
|
118
|
+
return driver;
|
|
115
119
|
}
|
|
116
120
|
#endif
|
|
117
121
|
|
|
118
|
-
WifiDriver *&driverSlot()
|
|
119
|
-
{
|
|
122
|
+
WifiDriver *&driverSlot() {
|
|
120
123
|
#ifdef __EMSCRIPTEN__
|
|
121
|
-
|
|
124
|
+
static WifiDriver *driver = &browserDriver();
|
|
122
125
|
#else
|
|
123
|
-
|
|
126
|
+
static WifiDriver *driver = &nullDriver();
|
|
124
127
|
#endif
|
|
125
|
-
|
|
128
|
+
return driver;
|
|
126
129
|
}
|
|
127
130
|
|
|
128
|
-
}
|
|
131
|
+
} // namespace
|
|
129
132
|
|
|
130
|
-
void WifiDriver::setWebState(bool connected, const char *ssid, const char *ip,
|
|
131
|
-
{
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
void WifiDriver::setWebState(bool connected, const char *ssid, const char *ip,
|
|
134
|
+
int rssi) {
|
|
135
|
+
(void)connected;
|
|
136
|
+
(void)ssid;
|
|
137
|
+
(void)ip;
|
|
138
|
+
(void)rssi;
|
|
136
139
|
}
|
|
137
140
|
|
|
138
|
-
void WifiDriver::setWebScanCount(int count)
|
|
139
|
-
{
|
|
140
|
-
(void)count;
|
|
141
|
-
}
|
|
141
|
+
void WifiDriver::setWebScanCount(int count) { (void)count; }
|
|
142
142
|
|
|
143
|
-
void WifiDriver::setWebScanEntry(int index, const char *ssid, int rssi,
|
|
144
|
-
{
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
143
|
+
void WifiDriver::setWebScanEntry(int index, const char *ssid, int rssi,
|
|
144
|
+
bool secured) {
|
|
145
|
+
(void)index;
|
|
146
|
+
(void)ssid;
|
|
147
|
+
(void)rssi;
|
|
148
|
+
(void)secured;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
void WifiAdapter::setDriver(WifiDriver *driver)
|
|
152
|
-
|
|
153
|
-
driverSlot() = driver ? driver : &nullDriver();
|
|
151
|
+
void WifiAdapter::setDriver(WifiDriver *driver) {
|
|
152
|
+
driverSlot() = driver ? driver : &nullDriver();
|
|
154
153
|
}
|
|
155
154
|
|
|
156
|
-
WifiDriver *WifiAdapter::driver()
|
|
157
|
-
{
|
|
158
|
-
return driverSlot();
|
|
159
|
-
}
|
|
155
|
+
WifiDriver *WifiAdapter::driver() { return driverSlot(); }
|
|
160
156
|
|
|
161
157
|
bool WifiAdapter::init() const { return driver()->init(); }
|
|
162
158
|
bool WifiAdapter::enabled() const { return driver()->enabled(); }
|
|
163
|
-
void WifiAdapter::setEnabled(bool enabled) const {
|
|
159
|
+
void WifiAdapter::setEnabled(bool enabled) const {
|
|
160
|
+
driver()->setEnabled(enabled);
|
|
161
|
+
}
|
|
164
162
|
bool WifiAdapter::connected() const { return driver()->connected(); }
|
|
165
163
|
int WifiAdapter::rssi() const { return driver()->rssi(); }
|
|
166
164
|
std::string WifiAdapter::ssid() const { return driver()->ssid(); }
|
|
167
165
|
std::string WifiAdapter::ip() const { return driver()->ip(); }
|
|
168
166
|
std::string WifiAdapter::mac() const { return driver()->mac(); }
|
|
169
|
-
void WifiAdapter::configure(const std::string &ssid,
|
|
167
|
+
void WifiAdapter::configure(const std::string &ssid,
|
|
168
|
+
const std::string &password) const {
|
|
169
|
+
driver()->configure(ssid, password);
|
|
170
|
+
}
|
|
171
|
+
bool WifiAdapter::startAccessPoint(const std::string &ssid,
|
|
172
|
+
const std::string &password) const {
|
|
173
|
+
return driver()->startAccessPoint(ssid, password);
|
|
174
|
+
}
|
|
175
|
+
void WifiAdapter::stopAccessPoint() const { driver()->stopAccessPoint(); }
|
|
176
|
+
std::string WifiAdapter::accessPointMac() const {
|
|
177
|
+
return driver()->accessPointMac();
|
|
178
|
+
}
|
|
179
|
+
bool WifiAdapter::startCaptivePortal() const {
|
|
180
|
+
return driver()->startCaptivePortal();
|
|
181
|
+
}
|
|
182
|
+
void WifiAdapter::stopCaptivePortal() const { driver()->stopCaptivePortal(); }
|
|
170
183
|
void WifiAdapter::scan() const { driver()->scan(); }
|
|
171
184
|
bool WifiAdapter::scanning() const { return driver()->scanning(); }
|
|
172
185
|
int WifiAdapter::scanCount() const { return driver()->scanCount(); }
|
|
173
|
-
WifiNetwork WifiAdapter::networkAt(int index) const {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
{
|
|
177
|
-
|
|
186
|
+
WifiNetwork WifiAdapter::networkAt(int index) const {
|
|
187
|
+
return driver()->networkAt(index);
|
|
188
|
+
}
|
|
189
|
+
std::vector<WifiNetwork> WifiAdapter::scanResults() const {
|
|
190
|
+
return driver()->scanResults();
|
|
191
|
+
}
|
|
192
|
+
void WifiAdapter::setWebState(bool connected, const char *ssid, const char *ip,
|
|
193
|
+
int rssi) const {
|
|
194
|
+
driver()->setWebState(connected, ssid, ip, rssi);
|
|
195
|
+
}
|
|
196
|
+
void WifiAdapter::setWebScanCount(int count) const {
|
|
197
|
+
driver()->setWebScanCount(count);
|
|
178
198
|
}
|
|
179
|
-
void WifiAdapter::
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
driver()->setWebScanEntry(index, ssid, rssi, secured);
|
|
199
|
+
void WifiAdapter::setWebScanEntry(int index, const char *ssid, int rssi,
|
|
200
|
+
bool secured) const {
|
|
201
|
+
driver()->setWebScanEntry(index, ssid, rssi, secured);
|
|
183
202
|
}
|
|
184
203
|
|
|
185
|
-
}
|
|
204
|
+
} // namespace gea::framework::network
|