main.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include "lvgl/lvgl.h"
  4. // #include "lv_examples/lv_apps/demo/demo.h"
  5. #include "config.h"
  6. #include "runtime.h"
  7. #include "messageQueue.h"
  8. #include "oboo.h"
  9. int main(int argc, char *argv[]) {
  10. int status;
  11. int counter = 0;
  12. int activeTab = 0;
  13. int bDemoActive = 0;
  14. int numActiveCards = 0;
  15. int tmp;
  16. lv_obj_t* pCard;
  17. bool clean_session = true;
  18. struct mosquitto *mosq = NULL;
  19. /* parse arguments */
  20. if (argc > 1) {
  21. if (strcmp(argv[1], "demo") == 0) {
  22. bDemoActive = 1;
  23. }
  24. }
  25. printf("Program version: %s %s\n", __DATE__, __TIME__);
  26. /*duktape init*/
  27. initRuntime();
  28. /* graphics init */
  29. oboo_graphics_init();
  30. /* mqtt init */
  31. status = initMessageQueue(MQ_HOST, MQ_HOST_PORT);
  32. if (status != 0) {
  33. fprintf(stderr, "ERROR: could not properly initialize!\n");
  34. return -1;
  35. }
  36. /* run the main program */
  37. // if (bDemoActive) {
  38. // numActiveCards = 6;
  39. // demo_setup(lv_oboo_obj_get_card_manager());
  40. // } else if (0) {
  41. // printf("parsing JSON!\n");
  42. // /*lvgl - create an initial tab with an image */
  43. // printf("adding card #1\n");
  44. // tmp = lv_add_card(0);
  45. // printf("added initial card with index '%d'\n", tmp);
  46. // pCard = ob_cardview_get_card(lv_oboo_obj_get_card_manager(), tmp);
  47. // printf("found card with index %d\n", tmp);
  48. // if (pCard != NULL) {
  49. // printf("card is not null!\n");
  50. // LV_IMG_DECLARE(img_tiger);
  51. // lv_img_create_file("img_tiger", img_tiger); /*Create a file in the RAM FS*/
  52. // lv_obj_t *img_src = lv_img_create(pCard, NULL); /*Crate an image object*/
  53. // lv_img_set_file(img_src, "U:/img_tiger"); /*Set the created file as image */
  54. // lv_obj_set_pos(img_src, 0, 0); /*Set the positions*/
  55. // lv_obj_t * btn = lv_btn_create(pCard, NULL);
  56. // lv_obj_set_pos(btn, 50, 10);
  57. // lv_obj_t * label = lv_label_create(btn, NULL);
  58. // lv_label_set_text(label, "base card!");
  59. // numActiveCards++;
  60. // printf("base card configured!\n");
  61. // }
  62. // /*duktape - process JSON input */
  63. // printf("pushing string '%s' to ctx\n", argv[1]);
  64. // duk_push_string(ctx, argv[1]);
  65. // duk_json_decode(ctx, -1);
  66. // // todo: catch error for bad json
  67. // duk_pcall(ctx, 1);
  68. // duk_pop_2(ctx);
  69. // numActiveCards++;
  70. // printf("dynamic card configured!\n");
  71. // // enable demoActive to switch between the cards
  72. // bDemoActive = 1;
  73. // }
  74. /*Handle LitlevGL tasks (tickless mode)*/
  75. while(1) {
  76. if (bDemoActive && ++counter > 300) {
  77. activeTab = (++activeTab) % numActiveCards;
  78. ob_cardview_set_card_act(lv_oboo_obj_get_card_manager(), activeTab, true);
  79. printf("switching to tab %d\n", activeTab);
  80. counter = 0;
  81. }
  82. oboo_graphics_handle();
  83. usleep(5000);
  84. }
  85. /* duktape release */
  86. destroyRuntime();
  87. /* mqtt release */
  88. destroyMessageQueue();
  89. return 0;
  90. }