@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,364 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "services/mirror.h"
|
|
3
|
+
|
|
4
|
+
#include "memory.h"
|
|
5
|
+
#include "services/app_state.h"
|
|
6
|
+
#include "services/diagnostics.h"
|
|
7
|
+
|
|
8
|
+
#include <cstddef>
|
|
9
|
+
#include <cstdint>
|
|
10
|
+
#include <cstdio>
|
|
11
|
+
#include <cstring>
|
|
12
|
+
|
|
13
|
+
namespace gea::framework::services {
|
|
14
|
+
|
|
15
|
+
namespace {
|
|
16
|
+
|
|
17
|
+
constexpr int kChannelMirror = 2;
|
|
18
|
+
constexpr int kMirrorIntervalMs = 16;
|
|
19
|
+
constexpr char kCmdEnableMirror = 'M';
|
|
20
|
+
constexpr char kCmdDisableMirror = 'm';
|
|
21
|
+
constexpr bool kForwardLogsDuringMirror = false;
|
|
22
|
+
constexpr bool kMirrorDebug = false;
|
|
23
|
+
|
|
24
|
+
class MirrorMemory {
|
|
25
|
+
public:
|
|
26
|
+
static void *allocate(std::size_t size)
|
|
27
|
+
{
|
|
28
|
+
return gea::framework::memory::Allocator::allocatePreferSpiram(size);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static void release(void *ptr)
|
|
32
|
+
{
|
|
33
|
+
gea::framework::memory::Allocator::free(ptr);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
class MirrorRecord {
|
|
38
|
+
public:
|
|
39
|
+
static int writeError(unsigned char *dst, int cap, const char *message)
|
|
40
|
+
{
|
|
41
|
+
if (!dst || cap < 2) return 0;
|
|
42
|
+
if (!message) message = "store mirror is unavailable for this app";
|
|
43
|
+
int msg_len = static_cast<int>(std::strlen(message));
|
|
44
|
+
if (msg_len > 255) msg_len = 255;
|
|
45
|
+
if (msg_len > cap - 2) msg_len = cap - 2;
|
|
46
|
+
if (msg_len < 0) msg_len = 0;
|
|
47
|
+
dst[0] = 7;
|
|
48
|
+
dst[1] = static_cast<unsigned char>(msg_len & 0xFF);
|
|
49
|
+
if (msg_len > 0) std::memcpy(dst + 2, message, static_cast<std::size_t>(msg_len));
|
|
50
|
+
return msg_len + 2;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static void readCurrentAppId(char *dst, std::size_t cap)
|
|
54
|
+
{
|
|
55
|
+
if (!dst || cap == 0) return;
|
|
56
|
+
dst[0] = '\0';
|
|
57
|
+
AppState::lock();
|
|
58
|
+
const char *app_id = AppState::currentAppId();
|
|
59
|
+
if (app_id && app_id[0]) std::snprintf(dst, cap, "%s", app_id);
|
|
60
|
+
AppState::unlock();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static std::uint16_t readU16(const unsigned char *src)
|
|
64
|
+
{
|
|
65
|
+
return static_cast<std::uint16_t>(src[0]) | (static_cast<std::uint16_t>(src[1]) << 8);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static std::int32_t readI32(const unsigned char *src)
|
|
69
|
+
{
|
|
70
|
+
std::uint32_t raw = static_cast<std::uint32_t>(src[0]) |
|
|
71
|
+
(static_cast<std::uint32_t>(src[1]) << 8) |
|
|
72
|
+
(static_cast<std::uint32_t>(src[2]) << 16) |
|
|
73
|
+
(static_cast<std::uint32_t>(src[3]) << 24);
|
|
74
|
+
return static_cast<std::int32_t>(raw);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static std::uint32_t readU32(const unsigned char *src)
|
|
78
|
+
{
|
|
79
|
+
return static_cast<std::uint32_t>(src[0]) |
|
|
80
|
+
(static_cast<std::uint32_t>(src[1]) << 8) |
|
|
81
|
+
(static_cast<std::uint32_t>(src[2]) << 16) |
|
|
82
|
+
(static_cast<std::uint32_t>(src[3]) << 24);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
class MirrorDebugLog {
|
|
87
|
+
public:
|
|
88
|
+
static void record(const char *direction, const unsigned char *record, int len)
|
|
89
|
+
{
|
|
90
|
+
if (!kMirrorDebug) {
|
|
91
|
+
(void)direction;
|
|
92
|
+
(void)record;
|
|
93
|
+
(void)len;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!record || len <= 0) return;
|
|
98
|
+
switch (record[0]) {
|
|
99
|
+
case 1:
|
|
100
|
+
logBegin(direction, record, len);
|
|
101
|
+
break;
|
|
102
|
+
case 2:
|
|
103
|
+
if (len >= 7) DiagnosticsServer::print("mirror %s int field=%u value=%ld len=%d\n",
|
|
104
|
+
direction,
|
|
105
|
+
static_cast<unsigned>(MirrorRecord::readU16(record + 1)),
|
|
106
|
+
static_cast<long>(MirrorRecord::readI32(record + 3)),
|
|
107
|
+
len);
|
|
108
|
+
else DiagnosticsServer::print("mirror %s int malformed len=%d\n", direction, len);
|
|
109
|
+
break;
|
|
110
|
+
case 3:
|
|
111
|
+
if (len >= 5) DiagnosticsServer::print("mirror %s string field=%u bytes=%u len=%d\n",
|
|
112
|
+
direction,
|
|
113
|
+
static_cast<unsigned>(MirrorRecord::readU16(record + 1)),
|
|
114
|
+
static_cast<unsigned>(MirrorRecord::readU16(record + 3)),
|
|
115
|
+
len);
|
|
116
|
+
else DiagnosticsServer::print("mirror %s string malformed len=%d\n", direction, len);
|
|
117
|
+
break;
|
|
118
|
+
case 4:
|
|
119
|
+
if (len >= 5) DiagnosticsServer::print("mirror %s array_len field=%u value=%u len=%d\n",
|
|
120
|
+
direction,
|
|
121
|
+
static_cast<unsigned>(MirrorRecord::readU16(record + 1)),
|
|
122
|
+
static_cast<unsigned>(MirrorRecord::readU16(record + 3)),
|
|
123
|
+
len);
|
|
124
|
+
else DiagnosticsServer::print("mirror %s array_len malformed len=%d\n", direction, len);
|
|
125
|
+
break;
|
|
126
|
+
case 5:
|
|
127
|
+
if (len >= 10) DiagnosticsServer::print("mirror %s array_int field=%u index=%u subfield=%u value=%ld len=%d\n",
|
|
128
|
+
direction,
|
|
129
|
+
static_cast<unsigned>(MirrorRecord::readU16(record + 1)),
|
|
130
|
+
static_cast<unsigned>(MirrorRecord::readU16(record + 3)),
|
|
131
|
+
static_cast<unsigned>(record[5]),
|
|
132
|
+
static_cast<long>(MirrorRecord::readI32(record + 6)),
|
|
133
|
+
len);
|
|
134
|
+
else DiagnosticsServer::print("mirror %s array_int malformed len=%d\n", direction, len);
|
|
135
|
+
break;
|
|
136
|
+
case 8:
|
|
137
|
+
if (len >= 7) DiagnosticsServer::print("mirror %s scroll node=%u y=%ld len=%d\n",
|
|
138
|
+
direction,
|
|
139
|
+
static_cast<unsigned>(MirrorRecord::readU16(record + 1)),
|
|
140
|
+
static_cast<long>(MirrorRecord::readI32(record + 3)),
|
|
141
|
+
len);
|
|
142
|
+
else DiagnosticsServer::print("mirror %s scroll malformed len=%d\n", direction, len);
|
|
143
|
+
break;
|
|
144
|
+
case 6:
|
|
145
|
+
DiagnosticsServer::print("mirror %s end len=%d\n", direction, len);
|
|
146
|
+
break;
|
|
147
|
+
case 7:
|
|
148
|
+
DiagnosticsServer::print("mirror %s error len=%d\n", direction, len);
|
|
149
|
+
break;
|
|
150
|
+
default:
|
|
151
|
+
DiagnosticsServer::print("mirror %s unknown kind=%u len=%d\n", direction, static_cast<unsigned>(record[0]), len);
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private:
|
|
157
|
+
static void logBegin(const char *direction, const unsigned char *record, int len)
|
|
158
|
+
{
|
|
159
|
+
int msg_kind = len > 1 ? record[1] : 0;
|
|
160
|
+
int app_len = len > 2 ? record[2] : 0;
|
|
161
|
+
if (app_len > len - 3) app_len = len > 3 ? len - 3 : 0;
|
|
162
|
+
if (app_len < 0) app_len = 0;
|
|
163
|
+
char app_id[64];
|
|
164
|
+
int copy_len = app_len < static_cast<int>(sizeof(app_id)) - 1 ? app_len : static_cast<int>(sizeof(app_id)) - 1;
|
|
165
|
+
if (copy_len > 0) std::memcpy(app_id, record + 3, static_cast<std::size_t>(copy_len));
|
|
166
|
+
app_id[copy_len] = '\0';
|
|
167
|
+
if (len >= 3 + app_len + 6) {
|
|
168
|
+
int schema_off = 3 + app_len;
|
|
169
|
+
DiagnosticsServer::print("mirror %s begin type=%s app=%s fields=%u schema=0x%08lx len=%d\n",
|
|
170
|
+
direction,
|
|
171
|
+
msg_kind == 1 ? "snapshot" : (msg_kind == 2 ? "diff" : "unknown"),
|
|
172
|
+
app_id,
|
|
173
|
+
static_cast<unsigned>(MirrorRecord::readU16(record + schema_off)),
|
|
174
|
+
static_cast<unsigned long>(MirrorRecord::readU32(record + schema_off + 2)),
|
|
175
|
+
len);
|
|
176
|
+
} else {
|
|
177
|
+
DiagnosticsServer::print("mirror %s begin type=%s app=%s len=%d\n",
|
|
178
|
+
direction,
|
|
179
|
+
msg_kind == 1 ? "snapshot" : (msg_kind == 2 ? "diff" : "unknown"),
|
|
180
|
+
app_id,
|
|
181
|
+
len);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
} // namespace
|
|
187
|
+
|
|
188
|
+
int MirrorService::beginSnapshot() { return 0; }
|
|
189
|
+
int MirrorService::beginDiff() { return 0; }
|
|
190
|
+
int MirrorService::nextRecord(unsigned char *dst, int capacity) { (void)dst; (void)capacity; return 0; }
|
|
191
|
+
void MirrorService::clearDirty() {}
|
|
192
|
+
|
|
193
|
+
MirrorTransport::~MirrorTransport()
|
|
194
|
+
{
|
|
195
|
+
releaseBuffer();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
int MirrorTransport::pollIntervalMs()
|
|
199
|
+
{
|
|
200
|
+
return kMirrorIntervalMs;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
bool MirrorTransport::enabled() const
|
|
204
|
+
{
|
|
205
|
+
return enabled_;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
bool MirrorTransport::suppressesLogForwarding() const
|
|
209
|
+
{
|
|
210
|
+
return enabled_ && !kForwardLogsDuringMirror;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
void MirrorTransport::reset()
|
|
214
|
+
{
|
|
215
|
+
enabled_ = false;
|
|
216
|
+
forceSnapshot_ = true;
|
|
217
|
+
messageActive_ = false;
|
|
218
|
+
heldLen_ = 0;
|
|
219
|
+
appId_[0] = '\0';
|
|
220
|
+
nextAt_ = 0;
|
|
221
|
+
releaseBuffer();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
bool MirrorTransport::handleCommand(char command)
|
|
225
|
+
{
|
|
226
|
+
if (command == kCmdEnableMirror) {
|
|
227
|
+
enable();
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
if (command == kCmdDisableMirror) {
|
|
231
|
+
disable();
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
void MirrorTransport::enable()
|
|
238
|
+
{
|
|
239
|
+
DiagnosticsServer::print("mirror rx command enable\n");
|
|
240
|
+
enabled_ = true;
|
|
241
|
+
forceSnapshot_ = true;
|
|
242
|
+
messageActive_ = false;
|
|
243
|
+
heldLen_ = 0;
|
|
244
|
+
appId_[0] = '\0';
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
void MirrorTransport::disable()
|
|
248
|
+
{
|
|
249
|
+
DiagnosticsServer::print("mirror rx command disable\n");
|
|
250
|
+
reset();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
bool MirrorTransport::ready(std::int64_t now) const
|
|
254
|
+
{
|
|
255
|
+
return enabled_ && (messageActive_ || forceSnapshot_ || now >= nextAt_);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
void MirrorTransport::syncCurrentApp()
|
|
259
|
+
{
|
|
260
|
+
if (!enabled_) return;
|
|
261
|
+
char current_app_id[sizeof(appId_)];
|
|
262
|
+
MirrorRecord::readCurrentAppId(current_app_id, sizeof(current_app_id));
|
|
263
|
+
if (std::strcmp(current_app_id, appId_) != 0) {
|
|
264
|
+
DiagnosticsServer::print("mirror active app changed: '%s' -> '%s'\n", appId_, current_app_id);
|
|
265
|
+
std::snprintf(appId_, sizeof(appId_), "%s", current_app_id);
|
|
266
|
+
forceSnapshot_ = true;
|
|
267
|
+
messageActive_ = false;
|
|
268
|
+
heldLen_ = 0;
|
|
269
|
+
nextAt_ = 0;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
bool MirrorTransport::ensureBuffer(DiagnosticsFrame &pending)
|
|
274
|
+
{
|
|
275
|
+
if (!enabled_ || buffer_) return true;
|
|
276
|
+
cap_ = pending.payloadCapacity();
|
|
277
|
+
buffer_ = static_cast<unsigned char *>(MirrorMemory::allocate(static_cast<std::size_t>(cap_)));
|
|
278
|
+
if (buffer_) return true;
|
|
279
|
+
|
|
280
|
+
unsigned char err_payload[96];
|
|
281
|
+
int err_len = MirrorRecord::writeError(err_payload, sizeof(err_payload), "mirror alloc failed");
|
|
282
|
+
MirrorDebugLog::record("tx", err_payload, err_len);
|
|
283
|
+
pending.queue(kChannelMirror, 1, err_payload, err_len);
|
|
284
|
+
enabled_ = false;
|
|
285
|
+
cap_ = 0;
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
void MirrorTransport::beginIfDue(std::int64_t now, DiagnosticsFrame &pending)
|
|
290
|
+
{
|
|
291
|
+
if (!enabled_ || now < nextAt_ || messageActive_) return;
|
|
292
|
+
|
|
293
|
+
int is_snapshot = forceSnapshot_;
|
|
294
|
+
AppState::lock();
|
|
295
|
+
int started = is_snapshot ? MirrorService::beginSnapshot() : MirrorService::beginDiff();
|
|
296
|
+
AppState::unlock();
|
|
297
|
+
if (started > 0) {
|
|
298
|
+
if (is_snapshot) DiagnosticsServer::print("mirror begin snapshot for app=%s\n", appId_);
|
|
299
|
+
messageActive_ = true;
|
|
300
|
+
heldLen_ = 0;
|
|
301
|
+
forceSnapshot_ = false;
|
|
302
|
+
} else if (forceSnapshot_) {
|
|
303
|
+
unsigned char err_payload[160];
|
|
304
|
+
int err_len = MirrorRecord::writeError(err_payload, sizeof(err_payload), "store mirror is unavailable for this app");
|
|
305
|
+
MirrorDebugLog::record("tx", err_payload, err_len);
|
|
306
|
+
pending.queue(kChannelMirror, 1, err_payload, err_len);
|
|
307
|
+
forceSnapshot_ = false;
|
|
308
|
+
nextAt_ = now + static_cast<std::int64_t>(kMirrorIntervalMs) * 1000;
|
|
309
|
+
} else {
|
|
310
|
+
nextAt_ = now + static_cast<std::int64_t>(kMirrorIntervalMs) * 1000;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
void MirrorTransport::appendBatch(std::int64_t now, DiagnosticsFrame &pending)
|
|
315
|
+
{
|
|
316
|
+
if (!enabled_ || !messageActive_ || !buffer_ || !pending.empty()) return;
|
|
317
|
+
|
|
318
|
+
int batch_len = 0;
|
|
319
|
+
unsigned char *batch = pending.payload();
|
|
320
|
+
const int payload_capacity = pending.payloadCapacity();
|
|
321
|
+
while (batch_len < payload_capacity) {
|
|
322
|
+
int rec_len = heldLen_;
|
|
323
|
+
if (rec_len <= 0) {
|
|
324
|
+
AppState::lock();
|
|
325
|
+
rec_len = MirrorService::nextRecord(buffer_, cap_);
|
|
326
|
+
AppState::unlock();
|
|
327
|
+
}
|
|
328
|
+
if (rec_len <= 0) {
|
|
329
|
+
endMessage(now);
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
if (rec_len > payload_capacity) rec_len = payload_capacity;
|
|
333
|
+
if (batch_len > 0 && batch_len + rec_len > payload_capacity) {
|
|
334
|
+
heldLen_ = rec_len;
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
MirrorDebugLog::record("tx", buffer_, rec_len);
|
|
338
|
+
std::memcpy(batch + batch_len, buffer_, static_cast<std::size_t>(rec_len));
|
|
339
|
+
batch_len += rec_len;
|
|
340
|
+
heldLen_ = 0;
|
|
341
|
+
if (buffer_[0] == 6 || buffer_[0] == 7) {
|
|
342
|
+
endMessage(now);
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (batch_len > 0) pending.queue(kChannelMirror, 1, batch, batch_len);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
void MirrorTransport::endMessage(std::int64_t now)
|
|
350
|
+
{
|
|
351
|
+
messageActive_ = false;
|
|
352
|
+
heldLen_ = 0;
|
|
353
|
+
nextAt_ = now + static_cast<std::int64_t>(kMirrorIntervalMs) * 1000;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
void MirrorTransport::releaseBuffer()
|
|
357
|
+
{
|
|
358
|
+
if (!buffer_) return;
|
|
359
|
+
MirrorMemory::release(buffer_);
|
|
360
|
+
buffer_ = nullptr;
|
|
361
|
+
cap_ = 0;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
} // namespace gea::framework::services
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "services/network_services.h"
|
|
3
|
+
|
|
4
|
+
#include "services/diagnostics.h"
|
|
5
|
+
#include "services/ota.h"
|
|
6
|
+
#include "wifi.h"
|
|
7
|
+
|
|
8
|
+
namespace gea::framework::services {
|
|
9
|
+
|
|
10
|
+
namespace {
|
|
11
|
+
// Requested network-service options, stashed by start() at boot and applied by
|
|
12
|
+
// startDeferredServers() once WiFi is actually brought up on demand.
|
|
13
|
+
NetworkServicesOptions g_options{};
|
|
14
|
+
bool g_optionsReady = false;
|
|
15
|
+
} // namespace
|
|
16
|
+
|
|
17
|
+
bool NetworkServices::start(const NetworkServicesOptions &options)
|
|
18
|
+
{
|
|
19
|
+
#ifdef GEA_EMBEDDED_WIFI_DISABLED
|
|
20
|
+
(void)options;
|
|
21
|
+
DiagnosticsServer::print("WiFi disabled for this app; OTA and store mirror unavailable.\n");
|
|
22
|
+
return false;
|
|
23
|
+
#else
|
|
24
|
+
// WiFi is opt-in: it is NOT brought up at boot. Stash the requested service
|
|
25
|
+
// options; the WiFi driver brings the radio up lazily the first time an app
|
|
26
|
+
// enables WiFi, and that bring-up worker then calls startDeferredServers().
|
|
27
|
+
g_options = options;
|
|
28
|
+
g_optionsReady = true;
|
|
29
|
+
if (network::wifi().connected()) {
|
|
30
|
+
startDeferredServers();
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
DiagnosticsServer::print("WiFi opt-in: deferred until an app enables it.\n");
|
|
34
|
+
return false;
|
|
35
|
+
#endif
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
void NetworkServices::startDeferredServers()
|
|
39
|
+
{
|
|
40
|
+
#ifndef GEA_EMBEDDED_WIFI_DISABLED
|
|
41
|
+
// Early WiFi can acquire an address before Runtime has supplied its service
|
|
42
|
+
// policy. The later start() call observes the connected driver and returns
|
|
43
|
+
// here again after setting g_optionsReady.
|
|
44
|
+
if (!g_optionsReady) return;
|
|
45
|
+
HeapProbe::log("app:after_wifi_init");
|
|
46
|
+
// Firmware recovery gets the first network task allocation on RAM-constrained
|
|
47
|
+
// boards. Starting diagnostics first could consume the final internal stack
|
|
48
|
+
// block and leave the OTA HTTP server absent even though WiFi was connected.
|
|
49
|
+
if (g_options.otaEnabled) {
|
|
50
|
+
OtaServer::start();
|
|
51
|
+
}
|
|
52
|
+
if (g_options.diagnosticsEnabled) {
|
|
53
|
+
HeapProbe::log("app:before_diag_start");
|
|
54
|
+
DiagnosticsServer::start();
|
|
55
|
+
}
|
|
56
|
+
if (g_options.diagnosticsEnabled || g_options.otaEnabled) {
|
|
57
|
+
HeapProbe::log("app:after_diag_ota_start");
|
|
58
|
+
}
|
|
59
|
+
#endif
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
} // namespace gea::framework::services
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "services/runtime_log.h"
|
|
3
|
+
|
|
4
|
+
#include "services/diagnostics.h"
|
|
5
|
+
|
|
6
|
+
namespace gea::framework::services {
|
|
7
|
+
|
|
8
|
+
void RuntimeLog::printRuntimeBanner()
|
|
9
|
+
{
|
|
10
|
+
DiagnosticsServer::print("\n--- gea_embedded: gea TSX app (vite-plugin-gea -> geatsc) ---\n\n");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
void RuntimeLog::appStarted(bool networkReady)
|
|
14
|
+
{
|
|
15
|
+
DiagnosticsServer::print("\n--- app started, entering event loop ---\n");
|
|
16
|
+
if (networkReady) {
|
|
17
|
+
DiagnosticsServer::print("Ready for OTA. Use: curl -X POST http://<ip>:8080/ota --data-binary @build/gea_embedded.bin\n");
|
|
18
|
+
} else {
|
|
19
|
+
DiagnosticsServer::print("OTA unavailable. USB flash still works.\n");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
} // namespace gea::framework::services
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
//
|
|
4
|
+
// gea::framework — watchOS-style settings surface (the "control center"). A
|
|
5
|
+
// full-screen overlay toggled by the SettingsToggle event from host controls.
|
|
6
|
+
// Shows the running app + an interactive brightness control (-/+), with a Done
|
|
7
|
+
// button to dismiss.
|
|
8
|
+
//
|
|
9
|
+
// Header-only singleton (links into runtime.cpp's TU without a build source-list
|
|
10
|
+
// change). Built directly in the live UI tree on top of the running app, the
|
|
11
|
+
// While it is up, runtime.cpp renders RefreshOnly
|
|
12
|
+
// (the app underneath is frozen, so it doesn't reconcile the overlay away) and
|
|
13
|
+
// routes taps here. See docs/geaos-grand-vision.md (M10).
|
|
14
|
+
//
|
|
15
|
+
// Coordinates: C++-built surfaces use PHYSICAL device pixels (410×502 here),
|
|
16
|
+
// NOT the CSS÷DPR space that geatsc TSX apps lay out in — taps arrive in the same
|
|
17
|
+
// physical pixels, so handleTap hit-tests the layout rects directly.
|
|
18
|
+
|
|
19
|
+
#include <cstdint>
|
|
20
|
+
#include <cstdio>
|
|
21
|
+
#include <cstring>
|
|
22
|
+
|
|
23
|
+
#include "display.h"
|
|
24
|
+
#include "apps.h"
|
|
25
|
+
#include "ui/document.h"
|
|
26
|
+
#include "ui/node.h"
|
|
27
|
+
#include "ui/style.h"
|
|
28
|
+
|
|
29
|
+
namespace gea::framework {
|
|
30
|
+
|
|
31
|
+
class SettingsSurface {
|
|
32
|
+
public:
|
|
33
|
+
static SettingsSurface &instance()
|
|
34
|
+
{
|
|
35
|
+
static SettingsSurface s;
|
|
36
|
+
return s;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
bool active() const { return active_; }
|
|
40
|
+
|
|
41
|
+
void toggle()
|
|
42
|
+
{
|
|
43
|
+
if (active_)
|
|
44
|
+
close();
|
|
45
|
+
else
|
|
46
|
+
open();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Handle a tap (physical pixels) while the surface is up. Modal — always
|
|
50
|
+
// consumes the tap; returns true so the caller skips routing it to the app.
|
|
51
|
+
bool handleTap(int x, int y)
|
|
52
|
+
{
|
|
53
|
+
if (!active_) return false;
|
|
54
|
+
if (inRect(x, y, kMinusX, kBtnY, kBtnSize, kBtnSize))
|
|
55
|
+
adjustBrightness(-10);
|
|
56
|
+
else if (inRect(x, y, kPlusX, kBtnY, kBtnSize, kBtnSize))
|
|
57
|
+
adjustBrightness(10);
|
|
58
|
+
else if (inRect(x, y, kDoneX, kDoneY, kDoneW, kDoneH))
|
|
59
|
+
close();
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private:
|
|
64
|
+
SettingsSurface() = default;
|
|
65
|
+
|
|
66
|
+
using Document = gea::embedded::ui::Document;
|
|
67
|
+
using Property = gea::embedded::ui::Property;
|
|
68
|
+
using Style = gea::embedded::ui::Style;
|
|
69
|
+
using ViewElement = gea::embedded::ui::ViewElement;
|
|
70
|
+
using TextElement = gea::embedded::ui::TextElement;
|
|
71
|
+
using NodeHandle = gea::embedded::ui::NodeHandle;
|
|
72
|
+
|
|
73
|
+
void open()
|
|
74
|
+
{
|
|
75
|
+
brightness_ = clampPct(static_cast<int>(gea::platform::display::Display::brightness()));
|
|
76
|
+
buildPanel();
|
|
77
|
+
active_ = true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
void close()
|
|
81
|
+
{
|
|
82
|
+
if (rootId_ >= 0) NodeHandle(rootId_).remove();
|
|
83
|
+
rootId_ = -1;
|
|
84
|
+
valueId_ = -1;
|
|
85
|
+
active_ = false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static int clampPct(int v) { return v < 0 ? 0 : (v > 100 ? 100 : v); }
|
|
89
|
+
static bool inRect(int x, int y, int rx, int ry, int rw, int rh)
|
|
90
|
+
{
|
|
91
|
+
return x >= rx && x < rx + rw && y >= ry && y < ry + rh;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
void adjustBrightness(int delta)
|
|
95
|
+
{
|
|
96
|
+
brightness_ = clampPct(brightness_ + delta);
|
|
97
|
+
gea::platform::display::Display::setBrightness(brightness_);
|
|
98
|
+
if (valueId_ >= 0) {
|
|
99
|
+
char buf[8];
|
|
100
|
+
std::snprintf(buf, sizeof(buf), "%d%%", brightness_);
|
|
101
|
+
NodeHandle(valueId_).setText(buf);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
TextElement label(const char *text, int left, int top, int fontSize, int rgb565, int width, int textAlign)
|
|
106
|
+
{
|
|
107
|
+
TextElement t = Document::instance().createText(text);
|
|
108
|
+
Style s = t.style();
|
|
109
|
+
s.set(Property::Position, 1);
|
|
110
|
+
s.set(Property::Left, left);
|
|
111
|
+
s.set(Property::Top, top);
|
|
112
|
+
if (width > 0) s.set(Property::Width, width);
|
|
113
|
+
s.set(Property::FontSize, fontSize);
|
|
114
|
+
s.color(rgb565);
|
|
115
|
+
if (textAlign >= 0) s.set(Property::TextAlign, textAlign);
|
|
116
|
+
return t;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
ViewElement chip(const char *glyph, int left, int rgb565)
|
|
120
|
+
{
|
|
121
|
+
ViewElement v = Document::instance().createView();
|
|
122
|
+
Style s = v.style();
|
|
123
|
+
s.set(Property::Position, 1);
|
|
124
|
+
s.set(Property::Left, left);
|
|
125
|
+
s.set(Property::Top, kBtnY);
|
|
126
|
+
s.set(Property::Width, kBtnSize);
|
|
127
|
+
s.set(Property::Height, kBtnSize);
|
|
128
|
+
s.set(Property::BorderRadiusTopLeft, 14);
|
|
129
|
+
s.set(Property::BorderRadiusTopRight, 14);
|
|
130
|
+
s.set(Property::BorderRadiusBottomRight, 14);
|
|
131
|
+
s.set(Property::BorderRadiusBottomLeft, 14);
|
|
132
|
+
s.set(Property::HasBackground, 1);
|
|
133
|
+
s.backgroundColor(rgb565);
|
|
134
|
+
s.set(Property::Display, 0);
|
|
135
|
+
s.set(Property::JustifyContent, 1);
|
|
136
|
+
s.set(Property::AlignItems, 1);
|
|
137
|
+
TextElement g = Document::instance().createText(glyph);
|
|
138
|
+
g.style().color(0xFFFF);
|
|
139
|
+
g.style().set(Property::FontSize, 34);
|
|
140
|
+
v.appendChild(g);
|
|
141
|
+
return v;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
void buildPanel()
|
|
145
|
+
{
|
|
146
|
+
Document &doc = Document::instance();
|
|
147
|
+
ViewElement root = doc.createView();
|
|
148
|
+
rootId_ = root.id();
|
|
149
|
+
{
|
|
150
|
+
Style s = root.style();
|
|
151
|
+
s.set(Property::Position, 1);
|
|
152
|
+
s.set(Property::Left, 0);
|
|
153
|
+
s.set(Property::Top, 0);
|
|
154
|
+
s.set(Property::Width, 410);
|
|
155
|
+
s.set(Property::Height, 502);
|
|
156
|
+
s.set(Property::HasBackground, 1);
|
|
157
|
+
s.backgroundColor(0x0863); // #0B0F19 — opaque control-center scrim
|
|
158
|
+
}
|
|
159
|
+
doc.body().appendChild(root);
|
|
160
|
+
|
|
161
|
+
root.appendChild(label("Settings", 0, 40, 30, 0xFFFF, 410, 1));
|
|
162
|
+
root.appendChild(label("Brightness", 40, 150, 22, 0x9CD3, -1, -1));
|
|
163
|
+
|
|
164
|
+
root.appendChild(chip("-", kMinusX, 0x3186));
|
|
165
|
+
TextElement value = label("100%", 150, 222, 30, 0xFFFF, 110, 1);
|
|
166
|
+
valueId_ = value.id();
|
|
167
|
+
{
|
|
168
|
+
char buf[8];
|
|
169
|
+
std::snprintf(buf, sizeof(buf), "%d%%", brightness_);
|
|
170
|
+
NodeHandle(valueId_).setText(buf);
|
|
171
|
+
}
|
|
172
|
+
root.appendChild(value);
|
|
173
|
+
root.appendChild(chip("+", kPlusX, 0x3186));
|
|
174
|
+
|
|
175
|
+
const char *appId = apps::AppManager::currentId();
|
|
176
|
+
char appLine[80];
|
|
177
|
+
std::snprintf(appLine, sizeof(appLine), "App %s", appId ? appId : "?");
|
|
178
|
+
root.appendChild(label(appLine, 40, 320, 20, 0x9CD3, 330, -1));
|
|
179
|
+
|
|
180
|
+
ViewElement done = doc.createView();
|
|
181
|
+
{
|
|
182
|
+
Style s = done.style();
|
|
183
|
+
s.set(Property::Position, 1);
|
|
184
|
+
s.set(Property::Left, kDoneX);
|
|
185
|
+
s.set(Property::Top, kDoneY);
|
|
186
|
+
s.set(Property::Width, kDoneW);
|
|
187
|
+
s.set(Property::Height, kDoneH);
|
|
188
|
+
s.set(Property::BorderRadiusTopLeft, 14);
|
|
189
|
+
s.set(Property::BorderRadiusTopRight, 14);
|
|
190
|
+
s.set(Property::BorderRadiusBottomRight, 14);
|
|
191
|
+
s.set(Property::BorderRadiusBottomLeft, 14);
|
|
192
|
+
s.set(Property::HasBackground, 1);
|
|
193
|
+
s.backgroundColor(0x1A8B);
|
|
194
|
+
s.set(Property::Display, 0);
|
|
195
|
+
s.set(Property::JustifyContent, 1);
|
|
196
|
+
s.set(Property::AlignItems, 1);
|
|
197
|
+
}
|
|
198
|
+
TextElement doneLabel = doc.createText("Done");
|
|
199
|
+
doneLabel.style().color(0xFFFF);
|
|
200
|
+
doneLabel.style().set(Property::FontSize, 24);
|
|
201
|
+
done.appendChild(doneLabel);
|
|
202
|
+
root.appendChild(done);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Physical-pixel layout rects (410×502). Buttons hit-tested in handleTap.
|
|
206
|
+
static constexpr int kBtnY = 205;
|
|
207
|
+
static constexpr int kBtnSize = 70;
|
|
208
|
+
static constexpr int kMinusX = 40;
|
|
209
|
+
static constexpr int kPlusX = 300;
|
|
210
|
+
static constexpr int kDoneX = 125;
|
|
211
|
+
static constexpr int kDoneY = 410;
|
|
212
|
+
static constexpr int kDoneW = 160;
|
|
213
|
+
static constexpr int kDoneH = 64;
|
|
214
|
+
|
|
215
|
+
bool active_ = false;
|
|
216
|
+
int brightness_ = 80;
|
|
217
|
+
int rootId_ = -1;
|
|
218
|
+
int valueId_ = -1;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
} // namespace gea::framework
|