More work
This commit is contained in:
parent
b35dec2fdc
commit
6b90c9f76a
30 changed files with 710 additions and 109 deletions
58
HarmonyLinkTest_CPP/CMakeLists.txt
Normal file
58
HarmonyLinkTest_CPP/CMakeLists.txt
Normal file
|
@ -0,0 +1,58 @@
|
|||
# Copyright (c) 2024 Jordon Brooks
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
cmake_minimum_required(VERSION 3.22.1)
|
||||
project(HarmonyLinkTest)
|
||||
|
||||
# Specify the C++ standard
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
|
||||
# Automatically add all .cpp and .h/.hpp files in the src directory
|
||||
file(GLOB_RECURSE TEST_SOURCES "src/*.cpp")
|
||||
file(GLOB_RECURSE TEST_HEADERS "src/*.h" "src/*.hpp")
|
||||
|
||||
# Add executable for static library
|
||||
add_executable(HarmonyLinkTestStatic_CPP ${TEST_SOURCES} ${TEST_HEADERS})
|
||||
target_link_libraries(HarmonyLinkTestStatic_CPP PRIVATE LibHarmonyLinkStatic)
|
||||
target_compile_definitions(HarmonyLinkTestStatic_CPP PRIVATE HARMONYLINK_STATIC)
|
||||
|
||||
# Add executable for shared library
|
||||
add_executable(HarmonyLinkTestShared_CPP ${TEST_SOURCES} ${TEST_HEADERS})
|
||||
target_link_libraries(HarmonyLinkTestShared_CPP PRIVATE LibHarmonyLinkShared)
|
||||
target_compile_definitions(HarmonyLinkTestShared_CPP PRIVATE HARMONYLINK_SHARED)
|
||||
|
||||
# Set output directories for all build types
|
||||
foreach(TYPE IN ITEMS DEBUG RELEASE)
|
||||
string(TOUPPER ${TYPE} TYPE_UPPER)
|
||||
|
||||
# Static test executable properties
|
||||
set_target_properties(HarmonyLinkTestStatic_CPP PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/HarmonyLinkTestStatic_CPP"
|
||||
LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/lib/${TYPE}/HarmonyLinkTestStatic_CPP"
|
||||
ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkTestStatic_CPP"
|
||||
)
|
||||
|
||||
# Shared test executable properties
|
||||
set_target_properties(HarmonyLinkTestShared_CPP PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/HarmonyLinkTestShared_CPP"
|
||||
LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/lib/${TYPE}/HarmonyLinkTestShared_CPP"
|
||||
ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkTestShared_CPP"
|
||||
)
|
||||
endforeach()
|
||||
|
||||
# Copy the DLL to the executable directory after building the shared test executable
|
||||
add_custom_command(TARGET HarmonyLinkTestShared_CPP POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"$<TARGET_FILE:LibHarmonyLinkShared>"
|
||||
"$<TARGET_FILE_DIR:HarmonyLinkTestShared_CPP>")
|
170
HarmonyLinkTest_CPP/src/main.cpp
Normal file
170
HarmonyLinkTest_CPP/src/main.cpp
Normal file
|
@ -0,0 +1,170 @@
|
|||
// Copyright (c) 2024 Jordon Brooks
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
|
||||
#include "HarmonyLinkLib.h"
|
||||
|
||||
// Include necessary headers for platform-specific functionality
|
||||
#ifdef BUILD_WINDOWS
|
||||
#include <conio.h> // For _kbhit() and _getch()
|
||||
#include <windows.h> // For system("cls")
|
||||
#else
|
||||
#include <unistd.h> // For read()
|
||||
#include <termios.h> // For termios
|
||||
#include <stdio.h> // For getchar()
|
||||
#include <fcntl.h> // For F_GETFL, F_SETFL and O_NONBLOCK
|
||||
#endif
|
||||
|
||||
std::atomic<bool> quitFlag(false);
|
||||
|
||||
// Function to clear the screen cross-platform
|
||||
void clearScreen() {
|
||||
#ifdef BUILD_WINDOWS
|
||||
system("cls");
|
||||
#else
|
||||
std::cout << "\x1B[2J\x1B[H";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Function to check if 'q' or 'Q' is pressed in Windows
|
||||
void checkForQuit() {
|
||||
while (!quitFlag) {
|
||||
#ifdef BUILD_WINDOWS
|
||||
if (_kbhit()) {
|
||||
const char c = static_cast<char>(_getch());
|
||||
if (c == 'q' || c == 'Q') {
|
||||
quitFlag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
struct termios oldt, newt;
|
||||
int ch;
|
||||
int oldf;
|
||||
|
||||
tcgetattr(STDIN_FILENO, &oldt);
|
||||
newt = oldt;
|
||||
newt.c_lflag &= ~(ICANON | ECHO);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
|
||||
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
|
||||
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
|
||||
|
||||
ch = getchar();
|
||||
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
||||
fcntl(STDIN_FILENO, F_SETFL, oldf);
|
||||
|
||||
if (ch != EOF) {
|
||||
ungetc(ch, stdin);
|
||||
if (ch == 'q' || ch == 'Q') {
|
||||
quitFlag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// Checks for input every roughly 60 frames
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(16));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Hello, World!" << '\n';
|
||||
|
||||
std::thread inputThread(checkForQuit);
|
||||
|
||||
if (!LibHarmonyLink::HarmonyLink_Init())
|
||||
{
|
||||
printf("Failed to Initialize HarmonyLink!");
|
||||
}
|
||||
|
||||
printf("HarmonyLink Initialized!");
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||
|
||||
//const bool isWine = LibHarmonyLink::get_is_wine();
|
||||
//const char* test = isWine ? "is" : "isn't";
|
||||
|
||||
//const HarmonyLinkLib::FOSVerInfo* os_info = HarmonyLinkLib::get_os_version();
|
||||
|
||||
//const HarmonyLinkLib::FDevice* device_info = HarmonyLinkLib::get_device_info();
|
||||
|
||||
//const HarmonyLinkLib::FCPUInfo* cpu_info = HarmonyLinkLib::get_cpu_info();
|
||||
|
||||
// This loop is to test how stable & expensive these functions are
|
||||
while (!quitFlag)
|
||||
{
|
||||
// Clear the screen
|
||||
clearScreen();
|
||||
|
||||
//std::wcout << "This program " << test << " running under wine.\n";
|
||||
|
||||
//if (cpu_info)
|
||||
//{
|
||||
// cpu_info->print();
|
||||
//}
|
||||
|
||||
//if (os_info)
|
||||
//{
|
||||
// os_info->print();
|
||||
//}
|
||||
|
||||
//if (device_info)
|
||||
//{
|
||||
// wprintf(L"Is SteamDeck: %s\n", device_info->device == HarmonyLinkLib::EDevice::STEAM_DECK ? L"true" : L"false");
|
||||
//}
|
||||
|
||||
// we can't do this before the loop because we need updated values
|
||||
//if (const HarmonyLinkLib::FBattery* battery = HarmonyLinkLib::get_battery_status())
|
||||
//{
|
||||
// battery->print();
|
||||
// battery->free();
|
||||
//}
|
||||
|
||||
//const bool is_docked = HarmonyLinkLib::get_is_docked();
|
||||
|
||||
//const char* dock_check_string = is_docked ? "is" : "isn't";
|
||||
|
||||
//wprintf(L"Device %hs docked\n", dock_check_string);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
if (inputThread.joinable())
|
||||
{
|
||||
inputThread.join();
|
||||
}
|
||||
|
||||
//if (os_info)
|
||||
//{
|
||||
// os_info->free();
|
||||
//}
|
||||
|
||||
//if (device_info)
|
||||
//{
|
||||
// device_info->free();
|
||||
//}
|
||||
|
||||
//if (cpu_info)
|
||||
//{
|
||||
// cpu_info->free();
|
||||
//}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue