@geastack/targets 0.1.100 → 0.1.101

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 (47) hide show
  1. package/package.json +7 -7
  2. package/targets/cmake/geatsc-generated-archive-build.mjs +32 -1
  3. package/targets/esp32/app_project.cmake +2 -2
  4. package/targets/esp32/chip_bindings/audio/echo_cancellation.cpp +392 -28
  5. package/targets/esp32/chip_bindings/audio/echo_cancellation.h +18 -2
  6. package/targets/esp32/chip_bindings/audio/es8311.cpp +117 -13
  7. package/targets/esp32/chip_bindings/displays/co5300.cpp +68 -28
  8. package/targets/esp32/components/gea_framework/CMakeLists.txt +17 -1
  9. package/targets/esp32/components/gea_framework/idf_component.yml +4 -0
  10. package/targets/esp32/components/gea_vpx/CMakeLists.txt +1 -1
  11. package/targets/esp32/connectivity/wifi.cpp +800 -543
  12. package/targets/esp32/display.cpp +121 -26
  13. package/targets/esp32/gea_framework.cmake +22 -28
  14. package/targets/esp32/host_sources.cmake +1 -0
  15. package/targets/esp32/services/comparison_benchmark.h +137 -0
  16. package/targets/esp32/services/comparison_gesture.h +133 -0
  17. package/targets/esp32/services/comparison_input_trace.h +64 -0
  18. package/targets/esp32/services/comparison_upload_capture.h +125 -0
  19. package/targets/esp32/services/debugger.h +634 -0
  20. package/targets/esp32/services/device_control.cpp +965 -20
  21. package/targets/esp32/services/frame_scheduler.cpp +128 -4
  22. package/targets/esp32/services/heap.cpp +125 -0
  23. package/targets/esp32/services/opus_benchmark.h +1 -1
  24. package/targets/esp32/services/storage_service.cpp +119 -104
  25. package/targets/esp32-p4-m5stack-tab5/dependencies.lock +27 -16
  26. package/targets/esp32-s3-m5stack-stopwatch/README.md +14 -9
  27. package/targets/esp32-s3-m5stack-stopwatch/dependencies.lock +54 -1
  28. package/targets/esp32-s3-m5stack-stopwatch/main/CMakeLists.txt +10 -7
  29. package/targets/esp32-s3-m5stack-stopwatch/main/buttons.cpp +80 -0
  30. package/targets/esp32-s3-m5stack-stopwatch/main/idf_component.yml +18 -0
  31. package/targets/esp32-s3-m5stack-stopwatch/main/include/board.h +38 -17
  32. package/targets/esp32-s3-m5stack-stopwatch/main/panel_reset.cpp +132 -129
  33. package/targets/esp32-s3-m5stack-stopwatch/main/power.cpp +253 -0
  34. package/targets/esp32-s3-m5stack-stopwatch/main/touch.cpp +158 -88
  35. package/targets/esp32-s3-m5stack-stopwatch/sdkconfig.defaults +13 -0
  36. package/targets/esp32-s3-touch-amoled-1.8/main/CMakeLists.txt +30 -3
  37. package/targets/esp32-s3-touch-amoled-2.06/dependencies.lock +10 -148
  38. package/targets/esp32-s31-espressif-mosaico/README.md +34 -0
  39. package/targets/esp32-s31-espressif-mosaico/dependencies.lock +49 -1
  40. package/targets/esp32-s31-espressif-mosaico/main/CMakeLists.txt +23 -1
  41. package/targets/esp32-s31-espressif-mosaico/main/board_power.cpp +117 -0
  42. package/targets/esp32-s31-espressif-mosaico/main/camera.cpp +326 -0
  43. package/targets/esp32-s31-espressif-mosaico/main/idf_component.yml +11 -0
  44. package/targets/esp32-s31-espressif-mosaico/main/include/board.h +23 -0
  45. package/targets/esp32-s31-espressif-mosaico/main/nand_mount.cpp +172 -0
  46. package/targets/esp32-s31-espressif-mosaico/partitions.csv +7 -3
  47. package/targets/esp32-s31-espressif-mosaico/sdkconfig.defaults +24 -0
@@ -0,0 +1,634 @@
1
+ #pragma once
2
+ // Debug builds only. No VM on the board: bounded native operations and a
3
+ // snapshot taken under the same lock as rendering and input dispatch.
4
+ #include "cJSON.h"
5
+ #include "esp_random.h"
6
+ #include "esp_app_desc.h"
7
+ #include "pixel.h"
8
+ #include "services/app_state.h"
9
+ #include "services/frame_scheduler.h"
10
+ #include "ui/tree_internal.h"
11
+ #include "ui/tree_state.h"
12
+ #include "ui/debugger_overlay.h"
13
+ #include "ui/debugger_picker.h"
14
+ #include "ui/debugger_listeners.h"
15
+ #include <cstdio>
16
+ #include <cstdlib>
17
+ #include <cstring>
18
+ #include <string>
19
+ #include <vector>
20
+
21
+ namespace gea::debugger {
22
+ using namespace gea::embedded::ui;
23
+ // Command dispatch is serialized by the device-control mutex. Expected
24
+ // validation failures use explicit status, never C++ exception unwinding.
25
+ inline const char *lastError = nullptr;
26
+ inline unsigned bootToken() {
27
+ static const unsigned token = esp_random();
28
+ return token;
29
+ }
30
+ inline std::string elfHash() {
31
+ const auto *description = esp_app_get_description();
32
+ static constexpr char digits[] = "0123456789abcdef";
33
+ std::string out;
34
+ out.reserve(64);
35
+ for (unsigned char byte : description->app_elf_sha256) {
36
+ out += digits[byte >> 4]; out += digits[byte & 15];
37
+ }
38
+ return out;
39
+ }
40
+ struct Lock {
41
+ Lock() { gea::framework::services::AppState::lock(); }
42
+ ~Lock() { gea::framework::services::AppState::unlock(); }
43
+ };
44
+ struct Json {
45
+ cJSON *value;
46
+ explicit Json(cJSON *v) : value(v) {
47
+ if (!v)
48
+ lastError = "JSON allocation failed";
49
+ }
50
+ ~Json() { cJSON_Delete(value); }
51
+ };
52
+ inline void string(cJSON *o, const char *k, const std::string &v) {
53
+ if (!cJSON_AddStringToObject(o, k, v.c_str()))
54
+ lastError = "JSON allocation failed";
55
+ }
56
+ inline void number(cJSON *o, const char *k, double v) {
57
+ if (!cJSON_AddNumberToObject(o, k, v))
58
+ lastError = "JSON allocation failed";
59
+ }
60
+ inline std::string encode(cJSON *o) {
61
+ char *p = cJSON_PrintUnformatted(o);
62
+ if (!p) {
63
+ lastError = "JSON allocation failed";
64
+ return "";
65
+ }
66
+ std::string s(p);
67
+ cJSON_free(p);
68
+ return s;
69
+ }
70
+ inline int identity(int slot) {
71
+ return int(Tree::instance().node(slot).debugger_identity * 2 + 2);
72
+ }
73
+ inline int slot(int id) {
74
+ auto &t = Tree::instance();
75
+ if (id < 4 || id % 2) {
76
+ lastError = "invalid element identity";
77
+ return -1;
78
+ }
79
+ for (int i = 0; i < t.nodeCount(); ++i)
80
+ if (identity(i) == id && treeState().nodeActive[i])
81
+ return i;
82
+ lastError = "stale element identity";
83
+ return -1;
84
+ }
85
+ inline std::string px(int n) { return std::to_string(n) + "px"; }
86
+ inline std::string color(gea::framework::graphics::pixel::native_t value) {
87
+ #if GEA_EMBEDDED_PIXEL_FORMAT == GEA_PIXEL_ARGB8888
88
+ unsigned v = value;
89
+ int r = (v >> 16) & 255, g = (v >> 8) & 255, b = v & 255;
90
+ #elif GEA_EMBEDDED_PIXEL_FORMAT == GEA_PIXEL_RGBA8888
91
+ unsigned v = value;
92
+ int r = v & 255, g = (v >> 8) & 255, b = (v >> 16) & 255;
93
+ #else
94
+ auto v = gea::framework::graphics::pixel::toRgb565(value);
95
+ int r = ((v >> 11) & 31) * 255 / 31, g = ((v >> 5) & 63) * 255 / 63,
96
+ b = (v & 31) * 255 / 31;
97
+ #endif
98
+ return "rgb(" + std::to_string(r) + ", " + std::to_string(g) + ", " +
99
+ std::to_string(b) + ")";
100
+ }
101
+ inline cJSON *computed(int id) {
102
+ auto &n = Tree::instance().node(id);
103
+ const auto &s = n.computedStyle();
104
+ Json j(cJSON_CreateObject());
105
+ string(j.value, "width", px(n.layout.width));
106
+ string(j.value, "height", px(n.layout.height));
107
+ string(j.value, "left",
108
+ px(GEA_CSS_POSITION_PX_3(s) == kUnset ? 0 : GEA_CSS_POSITION_PX_3(s)));
109
+ string(j.value, "top",
110
+ px(GEA_CSS_POSITION_PX_0(s) == kUnset ? 0 : GEA_CSS_POSITION_PX_0(s)));
111
+ string(j.value, "position",
112
+ s.position == 1 ? "absolute"
113
+ : s.position == 2 ? "relative"
114
+ : s.position == 3 ? "fixed"
115
+ : "static");
116
+ string(j.value, "color", color(s.text_color));
117
+ string(j.value, "background-color",
118
+ s.has_bg ? color(s.bg_color) : "rgba(0, 0, 0, 0)");
119
+ string(j.value, "opacity", std::to_string(s.opacity / 255.0));
120
+ string(j.value, "font-size", px(s.font_size));
121
+ string(j.value, "font-weight", std::to_string(s.font_weight));
122
+ string(j.value, "display",
123
+ s.display == kDisplayNone ? "none"
124
+ : s.display == kDisplayFlex ? "flex"
125
+ : s.display == kDisplayGrid ? "grid"
126
+ : "block");
127
+ const char *sides[] = {"top", "right", "bottom", "left"};
128
+ for (int i = 0; i < 4; ++i) {
129
+ string(j.value, (std::string("padding-") + sides[i]).c_str(),
130
+ px(s.padding[i]));
131
+ string(j.value, (std::string("margin-") + sides[i]).c_str(),
132
+ px(s.margin[i]));
133
+ string(j.value, (std::string("border-") + sides[i] + "-width").c_str(),
134
+ px(computedBorderWidth(s, i)));
135
+ }
136
+ cJSON *result = j.value;
137
+ j.value = nullptr;
138
+ return result;
139
+ }
140
+ inline cJSON *inlineStyle(int id) {
141
+ Json result(cJSON_CreateObject());
142
+ const auto *rare = rareDataFor(id);
143
+ if (!rare) {
144
+ auto *v = result.value;
145
+ result.value = nullptr;
146
+ return v;
147
+ }
148
+ Json used(computed(id));
149
+ for (size_t i = 0; i < rare->inlineStyles.size(); ++i) {
150
+ const auto &e = rare->inlineStyles.at(i);
151
+ const char *name = nullptr;
152
+ bool length = true, percent = false;
153
+ switch (e.property) {
154
+ case Property::Width:
155
+ name = "width";
156
+ break;
157
+ case Property::Height:
158
+ name = "height";
159
+ break;
160
+ case Property::WidthPercent:
161
+ name = "width";
162
+ percent = true;
163
+ break;
164
+ case Property::HeightPercent:
165
+ name = "height";
166
+ percent = true;
167
+ break;
168
+ case Property::Left:
169
+ name = "left";
170
+ break;
171
+ case Property::Top:
172
+ name = "top";
173
+ break;
174
+ case Property::Right:
175
+ name = "right";
176
+ break;
177
+ case Property::Bottom:
178
+ name = "bottom";
179
+ break;
180
+ case Property::PaddingTop:
181
+ name = "padding-top";
182
+ break;
183
+ case Property::PaddingRight:
184
+ name = "padding-right";
185
+ break;
186
+ case Property::PaddingBottom:
187
+ name = "padding-bottom";
188
+ break;
189
+ case Property::PaddingLeft:
190
+ name = "padding-left";
191
+ break;
192
+ case Property::MarginTop:
193
+ name = "margin-top";
194
+ break;
195
+ case Property::MarginRight:
196
+ name = "margin-right";
197
+ break;
198
+ case Property::MarginBottom:
199
+ name = "margin-bottom";
200
+ break;
201
+ case Property::MarginLeft:
202
+ name = "margin-left";
203
+ break;
204
+ case Property::FontSize:
205
+ name = "font-size";
206
+ break;
207
+ case Property::BackgroundColor:
208
+ name = "background-color";
209
+ length = false;
210
+ break;
211
+ case Property::Color:
212
+ name = "color";
213
+ length = false;
214
+ break;
215
+ case Property::Opacity:
216
+ name = "opacity";
217
+ length = false;
218
+ break;
219
+ case Property::Display:
220
+ name = "display";
221
+ length = false;
222
+ break;
223
+ default:
224
+ break;
225
+ }
226
+ if (!name || e.value == kUnset)
227
+ continue;
228
+ char buffer[48];
229
+ if (percent) {
230
+ std::snprintf(buffer, sizeof(buffer), "%.5g%%", e.value / 10.0);
231
+ string(result.value, name, buffer);
232
+ } else if (length) {
233
+ float pixels;
234
+ if (rare->inlineStyles.getCssPixels(e.property, pixels)) {
235
+ std::snprintf(buffer, sizeof(buffer), "%.5gpx", double(pixels));
236
+ string(result.value, name, buffer);
237
+ } else
238
+ string(result.value, name, px(e.value));
239
+ } else {
240
+ auto *v = cJSON_GetObjectItemCaseSensitive(used.value, name);
241
+ if (cJSON_IsString(v))
242
+ string(result.value, name, v->valuestring);
243
+ }
244
+ }
245
+ auto *v = result.value;
246
+ result.value = nullptr;
247
+ return v;
248
+ }
249
+ using Writer = bool (*)(const void *, std::size_t);
250
+ inline void snapshot(unsigned sequence, Writer writer) {
251
+ std::vector<std::string> lines;
252
+ int root = -1, width = 0, height = 0;
253
+ std::string pickerStatus;
254
+ {
255
+ Lock lock;
256
+ auto &t = Tree::instance();
257
+ root = t.mountedRoot();
258
+ width = t.mountedWidth();
259
+ height = t.mountedHeight();
260
+ debuggerPicker.expire();
261
+ pickerStatus = " picker=1 inspectToken=" + std::to_string(debuggerPicker.token) +
262
+ " inspectActive=" + std::to_string(debuggerPicker.active) +
263
+ " inspectHover=" + std::to_string(debuggerPicker.hoverId()) +
264
+ " inspectNode=" + std::to_string(debuggerPicker.selectedId()) +
265
+ " inspectRevision=" + std::to_string(debuggerPicker.revision);
266
+ std::vector<int> pending;
267
+ for (int i = t.nodeCount() - 1; i >= 0; --i)
268
+ if (treeState().nodeActive[i])
269
+ pending.push_back(i);
270
+ while (!pending.empty()) {
271
+ if (lines.size() >= 2048) {
272
+ lastError = "tree exceeds debugger limit of 2048 nodes";
273
+ return;
274
+ }
275
+ int i = pending.back();
276
+ pending.pop_back();
277
+ auto &n = t.node(i);
278
+ Json j(cJSON_CreateObject());
279
+ number(j.value, "id", identity(i));
280
+ number(j.value, "parent", n.parent >= 0 ? identity(n.parent) : 2);
281
+ string(j.value, "tag", t.tagName(i) ? t.tagName(i) : "div");
282
+ string(j.value, "text", n.text.c_str());
283
+ number(j.value, "type", n.type == NodeType::Text ? 3 : 1);
284
+ number(j.value, "x", n.layout.x);
285
+ number(j.value, "y", n.layout.y);
286
+ number(j.value, "width", n.layout.width);
287
+ number(j.value, "height", n.layout.height);
288
+ auto *attrs = cJSON_AddObjectToObject(j.value, "attributes");
289
+ #if GEA_UI_NODE_ATTRIBUTES
290
+ const auto *rd = rareDataFor(i);
291
+ if (rd)
292
+ for (auto *entry = rd->attributes.values.get(); entry;
293
+ entry = entry->next.get())
294
+ string(attrs, entry->name(), entry->value());
295
+ #endif
296
+ string(attrs, "class", t.className(i));
297
+ auto *children = cJSON_AddArrayToObject(j.value, "children");
298
+ for (int child = n.first_child; child >= 0;
299
+ child = t.node(child).next_sibling) {
300
+ cJSON_AddItemToArray(children, cJSON_CreateNumber(identity(child)));
301
+ }
302
+ cJSON_AddItemToObject(j.value, "computed", computed(i));
303
+ cJSON_AddItemToObject(j.value, "inline", inlineStyle(i));
304
+ auto *rules = cJSON_AddArrayToObject(j.value, "rules");
305
+ for (const auto &r : debuggerMatchedCssRules(i)) {
306
+ auto *rule = cJSON_CreateObject();
307
+ string(rule, "selector", r.selector);
308
+ string(rule, "property", r.property);
309
+ string(rule, "value", r.value);
310
+ string(rule, "media", r.media);
311
+ cJSON_AddBoolToObject(rule, "userAgent", r.userAgent);
312
+ cJSON_AddItemToArray(rules, rule);
313
+ }
314
+ lines.push_back(encode(j.value));
315
+ if (lastError)
316
+ return;
317
+ }
318
+ if (root >= 0)
319
+ root = identity(root);
320
+ }
321
+ // Release rendering lock before USB output. Console command mutex serializes
322
+ // these replies; host uses one in-flight request for the physical connection.
323
+ // Never hold the render lock while streaming. The USB driver write-all
324
+ // callback handles partial writes; stdio's per-character VFS path does not.
325
+ flockfile(stdout);
326
+ std::fflush(stdout);
327
+ auto write = [&](const std::string &text) {
328
+ return writer ? writer(text.data(), text.size())
329
+ : std::fwrite(text.data(), 1, text.size(), stdout) ==
330
+ text.size();
331
+ };
332
+ unsigned checksum = 2166136261u;
333
+ bool ok =
334
+ write("GEADEV:DEBUG BEGIN sequence=" + std::to_string(sequence) + "\n");
335
+ for (const auto &line : lines) {
336
+ for (unsigned char c : line) {
337
+ checksum ^= c;
338
+ checksum *= 16777619u;
339
+ }
340
+ checksum ^= '\n';
341
+ checksum *= 16777619u;
342
+ if (ok)
343
+ ok = write("GEADEV:DEBUG NODE " + line + "\n");
344
+ }
345
+ if (ok)
346
+ ok = write(
347
+ "GEADEV:DEBUG END root=" + std::to_string(root) + " width=" +
348
+ std::to_string(width) + " height=" + std::to_string(height) + " boot=" +
349
+ std::to_string(bootToken()) + " sequence=" + std::to_string(sequence) +
350
+ " count=" + std::to_string(lines.size()) + " fps=" +
351
+ std::to_string(
352
+ gea::framework::services::FrameScheduler::debuggerFrameRate()) +
353
+ " overlay=1 listeners=1" + pickerStatus + " checksum=" + std::to_string(checksum) + " elf=" + elfHash() + "\n");
354
+ funlockfile(stdout);
355
+ if (!ok)
356
+ lastError = "snapshot transport write failed";
357
+ }
358
+ // JSX listeners of the given elements, with their registering call sites.
359
+ // Reply: BEGIN, one LISTENER line per handler, END with count and boot.
360
+ inline void listeners(const char *args, Writer writer) {
361
+ char *end = nullptr;
362
+ const unsigned long sequence = std::strtoul(args, &end, 10);
363
+ if (end == args || *end != ' ') {
364
+ lastError = "invalid listeners request";
365
+ return;
366
+ }
367
+ std::vector<std::uint32_t> ids;
368
+ for (const char *cursor = end + 1; *cursor;) {
369
+ const unsigned long id = std::strtoul(cursor, &end, 10);
370
+ if (end == cursor || id < 4 || id % 2 || ids.size() >= 64 || (*end && *end != ',')) {
371
+ lastError = "invalid listener identity list";
372
+ return;
373
+ }
374
+ ids.push_back(std::uint32_t(id));
375
+ cursor = *end ? end + 1 : end;
376
+ }
377
+ std::vector<std::string> lines;
378
+ {
379
+ Lock lock;
380
+ auto &registry = debuggerListeners();
381
+ for (auto id : ids) {
382
+ auto found = registry.find((id - 2) / 2);
383
+ if (found == registry.end())
384
+ continue;
385
+ for (const auto &listener : found->second) {
386
+ Json j(cJSON_CreateObject());
387
+ number(j.value, "id", id);
388
+ string(j.value, "type", listener.type);
389
+ auto *sites = cJSON_AddArrayToObject(j.value, "sites");
390
+ for (int i = 0; i < listener.count; ++i)
391
+ cJSON_AddItemToArray(sites, cJSON_CreateNumber(listener.sites[i]));
392
+ lines.push_back(encode(j.value));
393
+ if (lastError)
394
+ return;
395
+ }
396
+ }
397
+ }
398
+ flockfile(stdout);
399
+ std::fflush(stdout);
400
+ auto write = [&](const std::string &text) {
401
+ return writer ? writer(text.data(), text.size())
402
+ : std::fwrite(text.data(), 1, text.size(), stdout) == text.size();
403
+ };
404
+ bool ok = write("GEADEV:DEBUG LISTENERS BEGIN sequence=" + std::to_string(sequence) + "\n");
405
+ for (const auto &line : lines)
406
+ if (ok)
407
+ ok = write("GEADEV:DEBUG LISTENER " + line + "\n");
408
+ if (ok)
409
+ ok = write("GEADEV:DEBUG LISTENERS END sequence=" + std::to_string(sequence) +
410
+ " count=" + std::to_string(lines.size()) + " boot=" + std::to_string(bootToken()) + "\n");
411
+ funlockfile(stdout);
412
+ if (!ok)
413
+ lastError = "listeners transport write failed";
414
+ }
415
+ inline const char *field(cJSON *j, const char *key) {
416
+ auto *v = cJSON_GetObjectItemCaseSensitive(j, key);
417
+ return cJSON_IsString(v) ? v->valuestring : "";
418
+ }
419
+ inline int integer(cJSON *j, const char *key) {
420
+ auto *v = cJSON_GetObjectItemCaseSensitive(j, key);
421
+ if (!cJSON_IsNumber(v) || v->valuedouble != v->valueint) {
422
+ lastError = "missing or invalid numeric field";
423
+ return -1;
424
+ }
425
+ return v->valueint;
426
+ }
427
+ inline std::string decode(const char *text) {
428
+ const std::string alphabet =
429
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
430
+ std::string out;
431
+ unsigned bits = 0;
432
+ int count = 0;
433
+ const size_t length = std::strlen(text);
434
+ if (length > 480 || length % 4) {
435
+ lastError = "invalid request encoding";
436
+ return "";
437
+ }
438
+ for (size_t i = 0; i < length; ++i) {
439
+ char c = text[i];
440
+ if (c == '=') {
441
+ for (; i < length; ++i)
442
+ if (text[i] != '=') {
443
+ lastError = "invalid base64 padding";
444
+ return "";
445
+ }
446
+ break;
447
+ }
448
+ auto v = alphabet.find(c);
449
+ if (v == std::string::npos) {
450
+ lastError = "invalid base64";
451
+ return "";
452
+ }
453
+ bits = (bits << 6) | unsigned(v);
454
+ count += 6;
455
+ if (count >= 8) {
456
+ count -= 8;
457
+ out += char((bits >> count) & 255);
458
+ }
459
+ }
460
+ return out;
461
+ }
462
+ inline void mutate(const char *encoded) {
463
+ const auto decoded = decode(encoded);
464
+ if (lastError)
465
+ return;
466
+ Json j(cJSON_Parse(decoded.c_str()));
467
+ if (!cJSON_IsObject(j.value)) {
468
+ lastError = "invalid JSON request";
469
+ return;
470
+ }
471
+ const char *requestBoot = field(j.value, "boot");
472
+ char *end = nullptr;
473
+ const unsigned long token = std::strtoul(requestBoot, &end, 10);
474
+ if (!*requestBoot || !end || *end || token != bootToken()) {
475
+ lastError = "device rebooted or debugger boot token missing; reconnect";
476
+ return;
477
+ }
478
+ const std::string op = field(j.value, "op"), key = field(j.value, "key"),
479
+ value = field(j.value, "value");
480
+ int result = 0;
481
+ {
482
+ Lock lock;
483
+ auto &t = Tree::instance();
484
+ if (op == "fps") {
485
+ const int fps = integer(j.value, "fps");
486
+ if (lastError || fps < 0 || fps > 120) {
487
+ lastError = "debug FPS must be between 0 and 120";
488
+ return;
489
+ }
490
+ gea::framework::services::FrameScheduler::setDebuggerFrameRate(fps);
491
+ result = fps;
492
+ } else if (op == "inspect" || op == "inspectPoint") {
493
+ const int owner = integer(j.value, "token");
494
+ if (lastError || owner <= 0) {
495
+ lastError = "invalid inspector token";
496
+ return;
497
+ }
498
+ const std::string mode = field(j.value, "mode");
499
+ if (op == "inspectPoint") {
500
+ if (mode == "leave") {
501
+ debuggerPicker.expire();
502
+ if (debuggerPicker.active && debuggerPicker.token == unsigned(owner)) {
503
+ debuggerPicker.hovered = -1;
504
+ debuggerPicker.hoverIdentity = 0;
505
+ debuggerPicker.outline(-1);
506
+ }
507
+ } else if (mode == "hover" || mode == "select") {
508
+ const int x = integer(j.value, "x"), y = integer(j.value, "y");
509
+ if (lastError) return;
510
+ debuggerPicker.point(unsigned(owner), x, y, mode == "select");
511
+ } else { lastError = "invalid inspector point mode"; return; }
512
+ } else if (mode == "searchForNode" || mode == "searchForUAShadowDOM") {
513
+ debuggerPicker.begin(unsigned(owner));
514
+ } else if (mode == "keepAlive") {
515
+ debuggerPicker.renew(unsigned(owner));
516
+ } else if (mode == "none") {
517
+ debuggerPicker.cancel(unsigned(owner));
518
+ } else { lastError = "unsupported inspect mode"; return; }
519
+ result = int(debuggerPicker.token);
520
+ } else if (op == "highlight") {
521
+ const int id = integer(j.value, "id");
522
+ if (lastError) return;
523
+ int node = id ? slot(id) : -1;
524
+ if (lastError) return;
525
+ int red = integer(j.value, "red"), green = integer(j.value, "green"),
526
+ blue = integer(j.value, "blue");
527
+ if (lastError || red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) {
528
+ lastError = "invalid overlay color";
529
+ return;
530
+ }
531
+ debuggerPicker.expire();
532
+ if (!debuggerPicker.active)
533
+ debuggerOverlay.set(node, gea::framework::graphics::pixel::nativeColor(red, green, blue));
534
+ } else if (op == "rule") {
535
+ if (!debuggerSetCssRule(field(j.value, "selector"), field(j.value, "media"), key, value)) {
536
+ lastError = "stale or read-only stylesheet rule";
537
+ return;
538
+ }
539
+ } else if (op == "create") {
540
+ int i = key == "button" ? t.createButton()
541
+ : key == "span" ? t.createText()
542
+ : t.createView();
543
+ if (i < 0) {
544
+ lastError = "node allocation failed";
545
+ return;
546
+ }
547
+ t.setTagName(i, key.c_str());
548
+ result = identity(i);
549
+ } else {
550
+ int i = slot(integer(j.value, "id"));
551
+ if (lastError || i < 0)
552
+ return;
553
+ if (op == "style") {
554
+ if (value.empty())
555
+ Style(i).removeProperty(key);
556
+ else
557
+ Style(i).setProperty(key, value);
558
+ } else if (op == "attribute")
559
+ t.setAttribute(i, key.c_str(), value.c_str());
560
+ else if (op == "removeAttribute")
561
+ t.removeAttribute(i, key.c_str());
562
+ else if (op == "text") {
563
+ if (t.node(i).type == NodeType::Text)
564
+ t.setText(i, value.c_str());
565
+ else {
566
+ while (t.node(i).first_child >= 0)
567
+ t.removeNode(t.node(i).first_child);
568
+ t.setText(i, "");
569
+ if (!value.empty()) {
570
+ int child = t.createText();
571
+ if (child < 0) {
572
+ lastError = "node allocation failed";
573
+ return;
574
+ }
575
+ t.setText(child, value.c_str());
576
+ t.setParent(child, i);
577
+ }
578
+ }
579
+ } else if (op == "remove") {
580
+ if (i == t.mountedRoot()) {
581
+ lastError = "cannot remove app root";
582
+ return;
583
+ }
584
+ t.removeNode(i);
585
+ } else if (op == "append") {
586
+ int parent = slot(integer(j.value, "parent"));
587
+ if (lastError || parent < 0)
588
+ return;
589
+ if (t.containsNode(i, parent)) {
590
+ lastError = "tree cycle";
591
+ return;
592
+ }
593
+ t.setParent(i, parent);
594
+ } else if (op == "scroll")
595
+ t.scrollIntoView(i);
596
+ else if (op == "click") {
597
+ for (auto type : {gea::framework::events::PointerEventType::TouchStart,
598
+ gea::framework::events::PointerEventType::TouchEnd,
599
+ gea::framework::events::PointerEventType::Click}) {
600
+ int current = slot(integer(j.value, "id"));
601
+ if (lastError || current < 0)
602
+ return;
603
+ gea::framework::events::PointerEvent event;
604
+ event.type = type;
605
+ event.targetId = current;
606
+ t.dispatchEvent(event);
607
+ }
608
+ } else {
609
+ lastError = "unsupported native operation";
610
+ return;
611
+ }
612
+ }
613
+ }
614
+ std::printf("GEADEV:DEBUG OK id=%d\n", result);
615
+ }
616
+ inline void handle(char *args, Writer writer = nullptr) {
617
+ lastError = nullptr;
618
+ while (*args == ' ')
619
+ ++args;
620
+ if (std::strncmp(args, "SNAPSHOT ", 9) == 0) {
621
+ char *end = nullptr;
622
+ unsigned long sequence = std::strtoul(args + 9, &end, 10);
623
+ if (!*(args + 9) || !end || *end) {
624
+ lastError = "invalid snapshot sequence";
625
+ } else
626
+ snapshot(unsigned(sequence), writer);
627
+ } else if (std::strncmp(args, "LISTENERS ", 10) == 0)
628
+ listeners(args + 10, writer);
629
+ else
630
+ mutate(args);
631
+ if (lastError)
632
+ std::printf("GEADEV:ERR DEBUG %s\n", lastError);
633
+ }
634
+ } // namespace gea::debugger