From c96c9f0f8c5eb1c62614273027fdeaaa8d8d6b6e Mon Sep 17 00:00:00 2001 From: TheJackiMonster Date: Wed, 5 Apr 2023 22:14:51 +0200 Subject: [PATCH] Add examples for debug output Signed-off-by: TheJackiMonster --- CMakeLists.txt | 1 + examples/CMakeLists.txt | 3 ++ examples/debug_d3/CMakeLists.txt | 17 ++++++++ examples/debug_d3/src/debug.c | 64 +++++++++++++++++++++++++++++++ examples/debug_d4/CMakeLists.txt | 17 ++++++++ examples/debug_d4/src/debug.c | 66 ++++++++++++++++++++++++++++++++ interface_lib/CMakeLists.txt | 2 +- 7 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 examples/CMakeLists.txt create mode 100644 examples/debug_d3/CMakeLists.txt create mode 100644 examples/debug_d3/src/debug.c create mode 100644 examples/debug_d4/CMakeLists.txt create mode 100644 examples/debug_d4/src/debug.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 0904216..b1dfc02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ set(FUSION_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/modules/Fusion) set(FUSION_LIBRARY Fusion) add_subdirectory(interface_lib) +add_subdirectory(examples) add_executable(nrealAirLinuxDriver src/driver.c diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..a4714b4 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,3 @@ + +add_subdirectory(debug_d3) +add_subdirectory(debug_d4) diff --git a/examples/debug_d3/CMakeLists.txt b/examples/debug_d3/CMakeLists.txt new file mode 100644 index 0000000..237edbd --- /dev/null +++ b/examples/debug_d3/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.16) +project(nrealAirDebugD3) + +set(CMAKE_C_STANDARD 17) + +add_library( + nrealAirDebugD3 + src/debug.c +) + +target_include_directories(nrealAirDebugD3 + BEFORE PUBLIC ${NRA_INCLUDE_DIR} +) + +target_link_libraries(nrealAirDebugD3 + ${NRA_LIBRARY} +) diff --git a/examples/debug_d3/src/debug.c b/examples/debug_d3/src/debug.c new file mode 100644 index 0000000..c598c0a --- /dev/null +++ b/examples/debug_d3/src/debug.c @@ -0,0 +1,64 @@ +// +// Created by thejackimonster on 05.04.23. +// +// Copyright (c) 2023 thejackimonster. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#include "device3.h" + +#include + +void test3(uint64_t timestamp, + device3_event_type event, + const device3_ahrs_type* ahrs) { + device3_quat_type orientation; + device3_vec3_type euler; + + switch (event) { + case DEVICE3_EVENT_INIT: + printf("Initialized\n"); + break; + case DEVICE3_EVENT_UPDATE: + orientation = device3_get_orientation(ahrs); + euler = device3_get_euler(orientation); + printf("Pitch: %.2f; Roll: %.2f; Yaw: %.2f\n", euler.x, euler.y, euler.z); + break; + default: + break; + } +} + +int main(int argc, const char** argv) { + device3_type* dev3 = device3_open(test3); + + if (!dev3) { + return 1; + } + + while (dev3) { + if (device3_read(dev3, 0) < 0) { + break; + } + } + + device3_close(dev3); + return 0; +} diff --git a/examples/debug_d4/CMakeLists.txt b/examples/debug_d4/CMakeLists.txt new file mode 100644 index 0000000..fbb52b9 --- /dev/null +++ b/examples/debug_d4/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.16) +project(nrealAirDebugD4) + +set(CMAKE_C_STANDARD 17) + +add_library( + nrealAirDebugD4 + src/debug.c +) + +target_include_directories(nrealAirDebugD4 + BEFORE PUBLIC ${NRA_INCLUDE_DIR} +) + +target_link_libraries(nrealAirDebugD4 + ${NRA_LIBRARY} +) diff --git a/examples/debug_d4/src/debug.c b/examples/debug_d4/src/debug.c new file mode 100644 index 0000000..ea2bb59 --- /dev/null +++ b/examples/debug_d4/src/debug.c @@ -0,0 +1,66 @@ +// +// Created by thejackimonster on 05.04.23. +// +// Copyright (c) 2023 thejackimonster. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#include "device4.h" + +#include + +void test4(uint32_t timestamp, + device4_event_type event, + uint8_t brightness, + const char* msg) { + switch (event) { + case DEVICE4_EVENT_MESSAGE: + printf("Message: `%s`\n", msg); + break; + case DEVICE4_EVENT_BRIGHTNESS_SET: + printf("Set Brightness: %u\n", brightness); + break; + case DEVICE4_EVENT_BRIGHTNESS_UP: + printf("Increase Brightness: %u\n", brightness); + break; + case DEVICE4_EVENT_BRIGHTNESS_DOWN: + printf("Decrease Brightness: %u\n", brightness); + break; + default: + break; + } +} + +int main(int argc, const char** argv) { + device4_type* dev4 = device4_open(test4); + + if (!dev4) { + return 1; + } + + while (dev4) { + if (device4_read(dev4, 0) < 0) { + break; + } + } + + device4_close(dev4); + return 0; +} diff --git a/interface_lib/CMakeLists.txt b/interface_lib/CMakeLists.txt index 70bd0ba..7bfdef8 100644 --- a/interface_lib/CMakeLists.txt +++ b/interface_lib/CMakeLists.txt @@ -24,5 +24,5 @@ target_link_libraries(nrealAirLibrary ${LIBUSB1_LIBRARIES} ${FUSION_LIBRARY} m ) -set(NRA_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include PARENT_SCOPE) +set(NRA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE) set(NRA_LIBRARY nrealAirLibrary PARENT_SCOPE)