ui.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "ui.h"
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include "menu.h"
  5. #include "sys.h"
  6. #include "thread.h"
  7. #include "cfg.h"
  8. #if 1
  9. #define LOGD log_d
  10. #define LOGE log_e
  11. #else
  12. #define LOGD printf
  13. #define LOGE printf
  14. #endif
  15. typedef struct {
  16. int fd;
  17. }ui_handle_t;
  18. static ui_handle_t uiHandle={0};
  19. static void msleep(int ms)
  20. {
  21. usleep(ms*1000);
  22. }
  23. static void *ui_thread(void *arg)
  24. {
  25. int r;
  26. thread_handle_t *th=(thread_handle_t*)arg;
  27. ui_handle_t *h=(ui_handle_t*)th->arg;
  28. menu_init();
  29. while(th->quit==0) {
  30. menu_handle();
  31. msleep(50);
  32. }
  33. menu_deinit();
  34. pthread_exit(NULL);
  35. }
  36. /////////////////////////////////////////////////////
  37. static void rm_qt(void)
  38. {
  39. #if 0
  40. sys_kill("Qt_Test");
  41. remove("/root/run/app/Qt_Test");
  42. #else
  43. system("killall Qt_Test; rm /root/run/app/Qt_Test");
  44. #endif
  45. }
  46. int ui_init(void)
  47. {
  48. ui_handle_t *h=&uiHandle;
  49. #ifdef USE_UI
  50. rm_qt();
  51. thread_start(THREAD_ID_UI, ui_thread, h);
  52. #endif
  53. return 0;
  54. }