Skip to content

Commit

Permalink
Fix the bug when detect multi display
Browse files Browse the repository at this point in the history
  • Loading branch information
ycsos committed Sep 15, 2020
1 parent 5e0d44c commit 61136a9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
.idea/
cmake-build-debug/
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.17)
cmake_minimum_required(VERSION 3.13)
project(LG_ultrafine_brightness)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS -g)

set(libusb_1_FIND_REQUIRED TRUE)
include(${PROJECT_SOURCE_DIR}/cmake/Findlibusb-1.0.cmake)
Expand Down
14 changes: 14 additions & 0 deletions UltrafineDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,21 @@ UltrafineDisplay::UltrafineDisplay(libusb_device *lg_usb) {
}
}

UltrafineDisplay::UltrafineDisplay(const UltrafineDisplay &a) {
strcpy(DisplayType, a.DisplayType);
product_id = a.product_id;
vendor_id = a.vendor_id;
lg_dev = a.lg_dev;
lg_handle = a.lg_handle;
lg_iface = 1;
libusb_success = 0;
brightness_step = 5;
}

UltrafineDisplay::~UltrafineDisplay(){
}

void UltrafineDisplay::LG_Close(){
if (libusb_success == LIBUSB_SUCCESS){
libusb_release_interface(lg_handle, lg_iface);
libusb_attach_kernel_driver(lg_handle, lg_iface);
Expand Down
2 changes: 2 additions & 0 deletions UltrafineDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ extern unordered_map<uint16_t, char *> support_device;
class UltrafineDisplay {
public:
UltrafineDisplay(libusb_device * lg_usb);
UltrafineDisplay(const UltrafineDisplay &a);
~UltrafineDisplay();
uint16_t get_brightness();
void set_brightness(uint16_t val);
uint8_t get_brightness_level();
void set_brightness_level(uint8_t);
char * getDisplayName();
void interactive();
void LG_Close();
private:
char DisplayType[128];
uint16_t product_id;
Expand Down
5 changes: 4 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static int get_lg_ultrafine_usb_devices(libusb_device **devs, int usb_cnt, libus
int r = libusb_get_device_descriptor(devs[i], &desc);
auto lg_search = support_device.find(desc.idProduct);
if (lg_search != support_device.end()) {
*lg_devs[k++] = devs[i];
(*lg_devs)[k++] = devs[i];
}
}

Expand Down Expand Up @@ -99,6 +99,9 @@ int main() {
int chooseDisplay = atoi(&c);
clear();
Display_pool[chooseDisplay].interactive();
for(auto &a : Display_pool){
a.LG_Close();
}
}

endwin();
Expand Down

0 comments on commit 61136a9

Please sign in to comment.