#include "ui.h" #include "lcd.h" #include "gpio.h" #include "thread.h" #include #include #include #if 1 #define LOGD log_d #define LOGE log_e #else #define LOGD printf #define LOGE printf #endif typedef struct { int tp; int key; int up; //0: release 1: press }key_data_t; typedef struct { int fd; }ui_handle_t; static ui_handle_t uiHandle={0}; static int key_init(ui_handle_t *h) { h->fd = open("/dev/input/event0", O_RDWR, 0); return (h->fd<0)?-1:0; } static int key_deinit(ui_handle_t *h) { close(h->fd); return 0; } static int key_get(ui_handle_t *h, key_data_t *k) { int r; struct input_event event; r = read(h->fd, &event, sizeof(event)); if(r<0) { return -1; } printf("_____ evt.type: %d, value: %d, code: %d\n", event.type, event.value, event.code); switch (event.type) { case EV_KEY: { k->tp = event.type; k->up = (event.value==0)?1:0; k->key = event.code; } break; } return 0; } static int menu_init(ui_handle_t *h) { key_init(h); lcd_init(LCD_WIDTH,LCD_HEIGHT,LCD_COLOR); lcd_fill(0); //lcd_draw_string(10, 10, 80, 30, "Smart; Hello!", FONT_0806, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER); //lcd_draw_string(10, 30, 80, 30, "Voltage: 22.4V", FONT_0806, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER); lcd_draw_string(10, 30, 80, 30, "Voltage: 22.4V", FONT_1206, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER); lcd_refresh(); return 0; } static int menu_deinit(ui_handle_t *h) { key_deinit(h); lcd_deinit(); return 0; } static int menu_handle(ui_handle_t *h) { int r; key_data_t kd; r = key_get(h, &kd); if(r==0) { switch(kd.key) { case KEY_LEFT: break; } } return 0; } static void *ui_thread(void *arg) { int r; thread_handle_t *th=(thread_handle_t*)arg; ui_handle_t *h=(ui_handle_t*)th->arg; menu_init(h); while(th->quit==0) { menu_handle(h); } menu_deinit(h); pthread_exit(NULL); } ///////////////////////////////////////////////////// int ui_init(void) { ui_handle_t *h=&uiHandle; thread_start(THREAD_ID_UI, ui_thread, h); return 0; }