From 984a29c0692b46e143185133204a575897751f9c Mon Sep 17 00:00:00 2001 From: Sam Dai Date: Sun, 7 Jan 2024 19:54:21 -0800 Subject: [PATCH 1/4] set up module library structure --- CMakeLists.txt | 4 +++- src/CMakeLists.txt | 2 ++ src/main/CMakeLists.txt | 7 +++++++ src/main/diagnostics.cpp | 13 +++++++++++-- src/ui/CMakeLists.txt | 1 + src/ui/common/CMakeLists.txt | 2 ++ src/ui/common/commonUI.cpp | 13 +++++++++++++ src/ui/common/commonUI.h | 17 +++++++++++++++++ 8 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/CMakeLists.txt create mode 100644 src/ui/CMakeLists.txt create mode 100644 src/ui/common/CMakeLists.txt create mode 100644 src/ui/common/commonUI.cpp create mode 100644 src/ui/common/commonUI.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 36bb47d..3752709 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,9 @@ find_package(ryml REQUIRED) # further dependencies manually. # find_package( REQUIRED) -add_executable(diagnostics src/main/diagnostics.cpp) +# add_executable(diagnostics src/main/diagnostics.cpp) + +add_subdirectory(src) target_include_directories(diagnostics PUBLIC $ $) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..53cbaeb --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(main) +add_subdirectory(ui) diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt index e69de29..254dd83 100644 --- a/src/main/CMakeLists.txt +++ b/src/main/CMakeLists.txt @@ -0,0 +1,7 @@ +add_executable(diagnostics diagnostics.cpp) + +target_link_libraries(diagnostics PRIVATE UI) + +target_include_directories(diagnostics PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) diff --git a/src/main/diagnostics.cpp b/src/main/diagnostics.cpp index dafed14..54f228c 100644 --- a/src/main/diagnostics.cpp +++ b/src/main/diagnostics.cpp @@ -1,10 +1,19 @@ -#include +#include + +#include "commonUI.h" int main(int argc, char ** argv) { (void)argc; (void)argv; - printf("Welcome to UBC Sailbot diagnostics!\n"); + std::cout << "Welcome to UBC Sailbot Diagnostics! The C++ version" << std::endl; + + CommonUI myObj; + + int width = myObj.getTerminalWidthPub(); + + std::cout << "Terminal width is: " << width << std::endl; + return 0; } diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt new file mode 100644 index 0000000..e4717b2 --- /dev/null +++ b/src/ui/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(common) diff --git a/src/ui/common/CMakeLists.txt b/src/ui/common/CMakeLists.txt new file mode 100644 index 0000000..5e96001 --- /dev/null +++ b/src/ui/common/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(UI STATIC commonUI.cpp commonUI.h) +target_include_directories(UI PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/ui/common/commonUI.cpp b/src/ui/common/commonUI.cpp new file mode 100644 index 0000000..bf41791 --- /dev/null +++ b/src/ui/common/commonUI.cpp @@ -0,0 +1,13 @@ +#include "commonUI.h" + +#include +#include + +CommonUI::CommonUI() { terminal_width = getTerminalWidth(); } + +int CommonUI::getTerminalWidth() +{ + struct winsize size; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &size); + return size.ws_col; +} diff --git a/src/ui/common/commonUI.h b/src/ui/common/commonUI.h new file mode 100644 index 0000000..8fcfca8 --- /dev/null +++ b/src/ui/common/commonUI.h @@ -0,0 +1,17 @@ +#ifndef COMMON_UI_H_ +#define COMMON_UI_H_ + +/* Objects */ + +class CommonUI +{ +private: + int terminal_width; + static int getTerminalWidth(); + +public: + CommonUI(); + int getTerminalWidthPub() const { return terminal_width; } +}; + +#endif From b93493228371071cafb2349a92f9dd29be76c376 Mon Sep 17 00:00:00 2001 From: Sam Dai Date: Sun, 7 Jan 2024 19:54:48 -0800 Subject: [PATCH 2/4] set up module library structure --- CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3752709..b654802 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,11 +8,7 @@ endif() # find dependencies find_package(ament_cmake REQUIRED) find_package(ryml REQUIRED) -# uncomment the following section in order to fill in -# further dependencies manually. -# find_package( REQUIRED) -# add_executable(diagnostics src/main/diagnostics.cpp) add_subdirectory(src) target_include_directories(diagnostics PUBLIC From a4e253f5f3d23155854710fd8de1e6e23575f5d9 Mon Sep 17 00:00:00 2001 From: Sam Dai Date: Sun, 7 Jan 2024 21:07:36 -0800 Subject: [PATCH 3/4] removed test function and finalized CMake project structure --- src/main/CMakeLists.txt | 4 +++- src/ui/common/commonUI.h | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt index 254dd83..38c722f 100644 --- a/src/main/CMakeLists.txt +++ b/src/main/CMakeLists.txt @@ -1,6 +1,8 @@ add_executable(diagnostics diagnostics.cpp) -target_link_libraries(diagnostics PRIVATE UI) +target_link_libraries(diagnostics PRIVATE + UI +) target_include_directories(diagnostics PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/src/ui/common/commonUI.h b/src/ui/common/commonUI.h index 8fcfca8..f36dab3 100644 --- a/src/ui/common/commonUI.h +++ b/src/ui/common/commonUI.h @@ -11,7 +11,6 @@ class CommonUI public: CommonUI(); - int getTerminalWidthPub() const { return terminal_width; } }; #endif From 591608c05b3e90279977f684a90de2f867ce48a0 Mon Sep 17 00:00:00 2001 From: Sam Dai Date: Sun, 7 Jan 2024 21:12:01 -0800 Subject: [PATCH 4/4] fix error with no class memeber --- src/main/diagnostics.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/diagnostics.cpp b/src/main/diagnostics.cpp index 54f228c..3e18ac2 100644 --- a/src/main/diagnostics.cpp +++ b/src/main/diagnostics.cpp @@ -11,9 +11,5 @@ int main(int argc, char ** argv) CommonUI myObj; - int width = myObj.getTerminalWidthPub(); - - std::cout << "Terminal width is: " << width << std::endl; - return 0; }