ui.c 1.1 KB

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