@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
package/wifi.cpp
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "wifi.h"
|
|
3
|
+
|
|
4
|
+
#ifdef __EMSCRIPTEN__
|
|
5
|
+
#include <emscripten/em_js.h>
|
|
6
|
+
|
|
7
|
+
EM_JS(int, gea_web_wifi_online, (), {
|
|
8
|
+
return (typeof navigator !== 'undefined' && 'onLine' in navigator) ? (navigator.onLine ? 1 : 0) : 1;
|
|
9
|
+
});
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
namespace gea::framework::network {
|
|
13
|
+
|
|
14
|
+
namespace {
|
|
15
|
+
|
|
16
|
+
class NullWifiDriver final : public WifiDriver {
|
|
17
|
+
public:
|
|
18
|
+
bool init() override { return false; }
|
|
19
|
+
bool enabled() const override { return false; }
|
|
20
|
+
void setEnabled(bool enabled) override { (void)enabled; }
|
|
21
|
+
bool connected() const override { return false; }
|
|
22
|
+
int rssi() override { return 0; }
|
|
23
|
+
std::string ssid() override { return {}; }
|
|
24
|
+
std::string ip() const override { return "0.0.0.0"; }
|
|
25
|
+
std::string mac() override { return {}; }
|
|
26
|
+
void configure(const std::string &ssid, const std::string &password) override
|
|
27
|
+
{
|
|
28
|
+
(void)ssid;
|
|
29
|
+
(void)password;
|
|
30
|
+
}
|
|
31
|
+
void scan() override {}
|
|
32
|
+
bool scanning() const override { return false; }
|
|
33
|
+
int scanCount() const override { return 0; }
|
|
34
|
+
WifiNetwork networkAt(int index) const override
|
|
35
|
+
{
|
|
36
|
+
(void)index;
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
std::vector<WifiNetwork> scanResults() const override { return {}; }
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
NullWifiDriver &nullDriver()
|
|
43
|
+
{
|
|
44
|
+
static NullWifiDriver driver;
|
|
45
|
+
return driver;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
#ifdef __EMSCRIPTEN__
|
|
49
|
+
// Browser builds (WASM simulator, web target): the network is ambient — the
|
|
50
|
+
// page either has connectivity or it doesn't, and fetch() rides the browser
|
|
51
|
+
// stack. Without this, the Null driver's connected()==false makes every app
|
|
52
|
+
// that gates fetches on WiFi.connected() (weather) sit on placeholders forever
|
|
53
|
+
// while the Emscripten fetch bridge would have worked fine. A web host can
|
|
54
|
+
// still install its own driver via WifiAdapter::setDriver (the DOM dev server
|
|
55
|
+
// shims do) — this is only the default.
|
|
56
|
+
class BrowserWifiDriver final : public WifiDriver {
|
|
57
|
+
public:
|
|
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 { return enabled_ && webConnected_ && gea_web_wifi_online() != 0; }
|
|
62
|
+
int rssi() override { return rssi_; }
|
|
63
|
+
std::string ssid() override { return ssid_; }
|
|
64
|
+
std::string ip() const override { return ip_; }
|
|
65
|
+
std::string mac() override { return {}; }
|
|
66
|
+
void configure(const std::string &ssid, const std::string &password) override
|
|
67
|
+
{
|
|
68
|
+
(void)password;
|
|
69
|
+
ssid_ = ssid;
|
|
70
|
+
}
|
|
71
|
+
void scan() override {}
|
|
72
|
+
bool scanning() const override { return false; }
|
|
73
|
+
int scanCount() const override { return static_cast<int>(networks_.size()); }
|
|
74
|
+
WifiNetwork networkAt(int index) const override
|
|
75
|
+
{
|
|
76
|
+
if (index < 0 || index >= static_cast<int>(networks_.size())) return {};
|
|
77
|
+
return networks_[static_cast<std::size_t>(index)];
|
|
78
|
+
}
|
|
79
|
+
std::vector<WifiNetwork> scanResults() const override { return networks_; }
|
|
80
|
+
// The simulator's Wi-Fi panel pushes its state through these hooks; honor
|
|
81
|
+
// them so unchecking "Connected" actually takes apps offline in the sim.
|
|
82
|
+
void setWebState(bool connected, const char *ssid, const char *ip, int rssi) override
|
|
83
|
+
{
|
|
84
|
+
webConnected_ = connected;
|
|
85
|
+
if (ssid) ssid_ = ssid;
|
|
86
|
+
if (ip) ip_ = ip;
|
|
87
|
+
rssi_ = rssi;
|
|
88
|
+
}
|
|
89
|
+
void setWebScanCount(int count) override
|
|
90
|
+
{
|
|
91
|
+
networks_.assign(count > 0 ? static_cast<std::size_t>(count) : 0, WifiNetwork{});
|
|
92
|
+
}
|
|
93
|
+
void setWebScanEntry(int index, const char *ssid, int rssi, bool secured) override
|
|
94
|
+
{
|
|
95
|
+
if (index < 0 || index >= static_cast<int>(networks_.size())) return;
|
|
96
|
+
auto &entry = networks_[static_cast<std::size_t>(index)];
|
|
97
|
+
entry.ssid = ssid ? ssid : "";
|
|
98
|
+
entry.rssi = rssi;
|
|
99
|
+
entry.secured = secured;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private:
|
|
103
|
+
bool enabled_ = true;
|
|
104
|
+
bool webConnected_ = true;
|
|
105
|
+
int rssi_ = -50;
|
|
106
|
+
std::string ssid_ = "browser";
|
|
107
|
+
std::string ip_ = "0.0.0.0";
|
|
108
|
+
std::vector<WifiNetwork> networks_;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
BrowserWifiDriver &browserDriver()
|
|
112
|
+
{
|
|
113
|
+
static BrowserWifiDriver driver;
|
|
114
|
+
return driver;
|
|
115
|
+
}
|
|
116
|
+
#endif
|
|
117
|
+
|
|
118
|
+
WifiDriver *&driverSlot()
|
|
119
|
+
{
|
|
120
|
+
#ifdef __EMSCRIPTEN__
|
|
121
|
+
static WifiDriver *driver = &browserDriver();
|
|
122
|
+
#else
|
|
123
|
+
static WifiDriver *driver = &nullDriver();
|
|
124
|
+
#endif
|
|
125
|
+
return driver;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
} // namespace
|
|
129
|
+
|
|
130
|
+
void WifiDriver::setWebState(bool connected, const char *ssid, const char *ip, int rssi)
|
|
131
|
+
{
|
|
132
|
+
(void)connected;
|
|
133
|
+
(void)ssid;
|
|
134
|
+
(void)ip;
|
|
135
|
+
(void)rssi;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
void WifiDriver::setWebScanCount(int count)
|
|
139
|
+
{
|
|
140
|
+
(void)count;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
void WifiDriver::setWebScanEntry(int index, const char *ssid, int rssi, bool secured)
|
|
144
|
+
{
|
|
145
|
+
(void)index;
|
|
146
|
+
(void)ssid;
|
|
147
|
+
(void)rssi;
|
|
148
|
+
(void)secured;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
void WifiAdapter::setDriver(WifiDriver *driver)
|
|
152
|
+
{
|
|
153
|
+
driverSlot() = driver ? driver : &nullDriver();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
WifiDriver *WifiAdapter::driver()
|
|
157
|
+
{
|
|
158
|
+
return driverSlot();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
bool WifiAdapter::init() const { return driver()->init(); }
|
|
162
|
+
bool WifiAdapter::enabled() const { return driver()->enabled(); }
|
|
163
|
+
void WifiAdapter::setEnabled(bool enabled) const { driver()->setEnabled(enabled); }
|
|
164
|
+
bool WifiAdapter::connected() const { return driver()->connected(); }
|
|
165
|
+
int WifiAdapter::rssi() const { return driver()->rssi(); }
|
|
166
|
+
std::string WifiAdapter::ssid() const { return driver()->ssid(); }
|
|
167
|
+
std::string WifiAdapter::ip() const { return driver()->ip(); }
|
|
168
|
+
std::string WifiAdapter::mac() const { return driver()->mac(); }
|
|
169
|
+
void WifiAdapter::configure(const std::string &ssid, const std::string &password) const { driver()->configure(ssid, password); }
|
|
170
|
+
void WifiAdapter::scan() const { driver()->scan(); }
|
|
171
|
+
bool WifiAdapter::scanning() const { return driver()->scanning(); }
|
|
172
|
+
int WifiAdapter::scanCount() const { return driver()->scanCount(); }
|
|
173
|
+
WifiNetwork WifiAdapter::networkAt(int index) const { return driver()->networkAt(index); }
|
|
174
|
+
std::vector<WifiNetwork> WifiAdapter::scanResults() const { return driver()->scanResults(); }
|
|
175
|
+
void WifiAdapter::setWebState(bool connected, const char *ssid, const char *ip, int rssi) const
|
|
176
|
+
{
|
|
177
|
+
driver()->setWebState(connected, ssid, ip, rssi);
|
|
178
|
+
}
|
|
179
|
+
void WifiAdapter::setWebScanCount(int count) const { driver()->setWebScanCount(count); }
|
|
180
|
+
void WifiAdapter::setWebScanEntry(int index, const char *ssid, int rssi, bool secured) const
|
|
181
|
+
{
|
|
182
|
+
driver()->setWebScanEntry(index, ssid, rssi, secured);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
} // namespace gea::framework::network
|