From c7f63e628618f84a6f82885a96d051f1b8e8f7fe Mon Sep 17 00:00:00 2001 From: Neucrack Date: Tue, 19 Nov 2024 18:48:20 +0800 Subject: [PATCH] fix 7 inch touchscreen touch bug, add disp_max_backlight board config --- .../vision/port/maixcam/maix_display_mmf.hpp | 88 ++++++------------- .../port/maixcam/maix_touchscreen_maixcam.hpp | 14 ++- 2 files changed, 40 insertions(+), 62 deletions(-) diff --git a/components/vision/port/maixcam/maix_display_mmf.hpp b/components/vision/port/maixcam/maix_display_mmf.hpp index 97d19d31..2d708bfd 100644 --- a/components/vision/port/maixcam/maix_display_mmf.hpp +++ b/components/vision/port/maixcam/maix_display_mmf.hpp @@ -24,15 +24,6 @@ using namespace maix::peripheral; namespace maix::display { - static bool _get_board_config_path(char *path, int path_size) - { - if (fs::exists("/boot/board")) { - snprintf(path, path_size, "/boot/board"); - return true; - } - return false; - } - __attribute__((unused)) static int _get_vo_max_size(int *width, int *height, int rotate) { int w = 0, h = 0; @@ -107,61 +98,37 @@ namespace maix::display } - static std::vector _get_disp_flip_mirror(void) { - char path[64]; - char line[1024]; - char flip_str[128] = {0}; - char mirror_str[128] = {0}; - bool flip = 0, mirror = 0; - bool flip_is_found = false, mirror_is_found = false; - - err::check_bool_raise(_get_board_config_path(path, sizeof(path)), "Can't find board config file"); - FILE *file = fopen(path, "r"); - if (file == NULL) { - perror("Error opening file"); - return std::vector{false, false}; - } - - while (fgets(line, sizeof(line), file)) { - if (strncmp(line, "disp_flip=", 10) == 0) { - strcpy(flip_str, line + 10); - flip_str[strcspn(flip_str, "\n")] = '\0'; - flip_is_found = true; - } - - if (strncmp(line, "disp_mirror=", 12) == 0) { - strcpy(mirror_str, line + 12); - mirror_str[strcspn(mirror_str, "\n")] = '\0'; - mirror_is_found = true; - } + static void _get_disp_configs(bool &flip, bool &mirror, float &max_backlight) { + std::string flip_str; + bool flip_is_found = false; - if (flip_is_found && mirror_is_found) { - break; - } + auto device_configs = sys::device_configs(); + auto it = device_configs.find("disp_flip"); + if (it != device_configs.end()) { + flip_str = it->second; + flip_is_found = true; + } + auto it2 = device_configs.find("disp_mirror"); + if (it2 != device_configs.end()) { + if (it2->second.size() > 0) + mirror = atoi(it2->second.c_str()); + } + auto it3 = device_configs.find("disp_max_backlight"); + if (it3 != device_configs.end()) { + if (it3->second.size() > 0) + max_backlight = atof(it3->second.c_str()); } - fclose(file); - - log::info("disp flip=%s, disp mirror=%s", flip_str, mirror_str); - - if (flip_is_found && strlen(flip_str) > 0) { - flip = atoi(flip_str); + if (flip_is_found && flip_str.size() > 0) { + flip = atoi(flip_str.c_str()); } else { std::string board_id = sys::device_id(); if (board_id == "maixcam_pro") { flip = true; - } else { - flip = false; } } - if (mirror_is_found && strlen(mirror_str) > 0) { - mirror = atoi(mirror_str); - } else { - mirror = false; // maixcam and maixcam pro default mirror is false - } - - return {flip, mirror}; + log::info("disp config flip: %d, mirror: %d, max_backlight: %.1f", flip, mirror, max_backlight); } @@ -188,9 +155,8 @@ namespace maix::display if (this->_layer == 0) { bool flip = false; bool mirror = false; - auto disp_flip_mirror = _get_disp_flip_mirror(); - flip = disp_flip_mirror[0]; - mirror = disp_flip_mirror[1]; + _max_backlight = 50.0; + _get_disp_configs(flip, mirror, _max_backlight); mmf_set_vo_video_hmirror(0, mirror); mmf_set_vo_video_flip(0, flip); this->_invert_flip = flip; @@ -216,6 +182,7 @@ namespace maix::display this->_format = format; this->_invert_flip = false; this->_invert_mirror = false; + this->_max_backlight = 50.0; this->_layer = layer; // layer 0 means vedio layer // layer 1 means osd layer err::check_bool_raise(_format == image::FMT_BGRA8888, "Format not support"); @@ -435,8 +402,7 @@ namespace maix::display void set_backlight(float value) { - float max_duty = 50; - _bl_pwm->duty(value * max_duty / 100.0); + _bl_pwm->duty(value * _max_backlight / 100.0); _bl_pwm->disable(); if(value == 0) return; @@ -445,8 +411,7 @@ namespace maix::display float get_backlight() { - float max_duty = 50; - return _bl_pwm->duty() / max_duty * 100; + return _bl_pwm->duty() / _max_backlight * 100; } int get_ch_nums() @@ -507,6 +472,7 @@ namespace maix::display bool _opened; bool _invert_flip; bool _invert_mirror; + float _max_backlight; pwm::PWM *_bl_pwm; }; } diff --git a/components/vision/port/maixcam/maix_touchscreen_maixcam.hpp b/components/vision/port/maixcam/maix_touchscreen_maixcam.hpp index b66cb77a..30144a68 100644 --- a/components/vision/port/maixcam/maix_touchscreen_maixcam.hpp +++ b/components/vision/port/maixcam/maix_touchscreen_maixcam.hpp @@ -172,7 +172,8 @@ namespace maix::touchscreen // struct epoll_event events[1]; bool event_press = false; bool event_move = false; - + bool wait_pos_x = false; + bool wait_pos_y = false; while(1) { // int nfds = epoll_wait(_epoll_fd, events, 1, 0); @@ -200,6 +201,7 @@ namespace maix::touchscreen // anti-clockwise 90 degree _y = event.value; event_move = true; + wait_pos_y = false; } else if(event.code == ABS_MT_POSITION_Y || event.code == ABS_Y) { @@ -207,16 +209,26 @@ namespace maix::touchscreen // anti-clockwise 90 degree _x = _y_max - event.value - 1; event_move = true; + wait_pos_x = false; } } else if(event.type == EV_KEY) { if(event.code == BTN_TOUCH) { + if(event.value == 1) // some driver trigger press event before position + { + wait_pos_x = true; + wait_pos_x = true; + } _pressed = event.value == 1; event_press = true; } } + if(wait_pos_y || wait_pos_x) + { + continue; + } if(event_press) { break;