luat_airui_lvgl_top.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "luat_base.h"
  2. // #include "luat_lvgl.h"
  3. #include "luat_airui.h"
  4. #include "math.h"
  5. #include <stdlib.h>
  6. #define LUAT_LOG_TAG "airui"
  7. #include "luat_log.h"
  8. static int top_device_parser(luat_airui_ctx_t* ctx, jsmntok_t *tok, int pos);
  9. static int top_schema_parser(luat_airui_ctx_t* ctx, jsmntok_t *tok, int pos);
  10. static int top_screens_parser(luat_airui_ctx_t* ctx, jsmntok_t *tok, int pos);
  11. airui_parser_t airui_top_parsers[] = {
  12. // 注意顺序, 先处理schema, 再处理screens, 因为后者依赖前者.
  13. {.name = "device", .cb = top_device_parser},
  14. {.name = "screens", .cb = top_screens_parser},
  15. {.name = "schema", .cb = top_schema_parser},
  16. {.name = "", .cb = NULL}
  17. };
  18. // 处理设备信息, 实际上没啥用, 仅调试日志
  19. static int top_device_parser(luat_airui_ctx_t* ctx, jsmntok_t *tok, int pos) {
  20. // LLOGD("parse device");
  21. // int width_pos = jsmn_find_by_key(ctx->data, "width", tok, pos + 1);
  22. // int height_pos = jsmn_find_by_key(ctx->data, "height", tok, pos + 1);
  23. // if (width_pos > 0 && height_pos > 0) {
  24. // LLOGD("device width %d height %d",
  25. // jsmn_toint(ctx->data, &tok[width_pos + 1]),
  26. // jsmn_toint(ctx->data, &tok[height_pos + 1])
  27. // );
  28. // }
  29. // else {
  30. // LLOGD("device width height not found");
  31. // }
  32. return 0;
  33. }
  34. int top_screens_one(luat_airui_ctx_t* ctx, jsmntok_t *tok, int pos);
  35. // 重头戏, 解析screens
  36. static int top_screens_parser(luat_airui_ctx_t* ctx, jsmntok_t *tok, int pos) {
  37. LLOGD("parse screens");
  38. pos ++;
  39. jsmntok_t* screens = &tok[pos];
  40. if (screens->type != JSMN_ARRAY) {
  41. LLOGW("screens must be array");
  42. return -1;
  43. }
  44. if (screens->size == 0) {
  45. LLOGW("screens is emtry");
  46. return 0;
  47. }
  48. else {
  49. LLOGD("screens count %d", screens->size);
  50. }
  51. size_t scount = screens->size;
  52. pos ++; // 移动到一个元素
  53. for (size_t i = 0; i < scount; i++)
  54. {
  55. top_screens_one(ctx, tok, pos);
  56. jsmn_skip_object(tok, &pos);
  57. }
  58. return 0;
  59. }
  60. // 解析schema
  61. static int top_schema_parser(luat_airui_ctx_t* ctx, jsmntok_t *tok, int pos) {
  62. //LLOGD("parse schema");
  63. return 0;
  64. }