Skip to content

Commit 3a00ce1

Browse files
committed
feat(io): joystick support
- Updated the docker image and the sight-gitlab references - Implemented `sight::io::joystick::interactor`, `sight::io::joystick::detail::event_loop` and a module `sight::modules::io::joystick`. #### sight::modules::io::joystick module Controls the global joystick `event_loop` instance. Basically, it starts it when `sight::modules::io::joystick::plugin::start()` is called and stops it on `sight::modules::io::joystick::plugin::stop()`. Once started, registered `interactor` will start receiving joystick events. There is a unit test (`sight::module::io::joystick::ut`) which demonstrates basic usage, the support of module unloading, etc.. #### sight::io::joystick::detail::event_loop class This is where the whole implementation is. It is a singleton that uses a timer to poll for SDL events on the main thread. When one is catch, it is simply forwarded to the registered `interactor` with specific callback functions. It implies that all callback functions are executed on the main thread, so you may have to protect the access if your service runs on a specific worker. The code of `instance()` could have been simpler, but, since we are dealing with posted tasks on the main thread, special care has been needed to let the instance die without making waiting tasks crash. #### sight::io::joystick::interactor interface This register / unregister automatically to the `event_loop` any class that inherits from it. Then, these callbacks will be available: ``` c++ void joystick_axis_motion_event(const axis_motion_event& _event); void joystick_axis_direction_event(const axis_direction_event& _event); void joystick_hat_motion_event(const hat_motion_event& _event); void joystick_ball_motion_event(const ball_motion_event& _event); void joystick_button_pressed_event(const button_event& _event); void joystick_button_released_event(const button_event& _event); void joystick_added_event(const joystick_event& _event); void joystick_removed_event(const joystick_event& _event); ``` All callbacks use "event" structures, which should provides all needed information (device name, index, guid, axis, buttons, ...). Indeed, almost all of what is available from SDL is forwarded. Additionally, it is possible to list all attached devices with `devices()` and to temporary stop receiving event with `block_events(bool)`. > `joystick_axis_direction_event` is derived from `joystick_axis_motion_event`, but instead of sending the axis values on every change, it converts it to "up" or "down", and is only trigered once, until the axis goes back to neutral.
1 parent 69aae54 commit 3a00ce1

21 files changed

+2066
-2
lines changed

.gitlab-ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ stages:
77

88
include:
99
- project: "sight/sight-gitlab"
10-
ref: cedfea7a6437cb7c31e6cac1ca58e6428e9cb2cc
10+
ref: a3ad77bb7cf077b97e1d56b7f3326ea57b061ca7
1111
file: "/.templates/deploy.yml"
1212
- project: "sight/sight-gitlab"
13-
ref: cedfea7a6437cb7c31e6cac1ca58e6428e9cb2cc
13+
ref: a3ad77bb7cf077b97e1d56b7f3326ea57b061ca7
1414
file: "/.templates/build.yml"
1515

1616
lint:ubuntu-24.04:

libs/io/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ add_subdirectory(opencv)
77
add_subdirectory(dimse)
88
add_subdirectory(session)
99
add_subdirectory(bitmap)
10+
add_subdirectory(joystick)

libs/io/joystick/CMakeLists.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
sight_add_target(
2+
io_joystick
3+
TYPE LIBRARY
4+
WARNINGS_AS_ERRORS ON
5+
OBJECT_LIBRARY ON
6+
)
7+
8+
# find_package(SDL2 CONFIG REQUIRED) done in Dependencies.cmake
9+
target_link_libraries(${TARGET_OBJECT_LIB} PRIVATE SDL2::SDL2)
10+
11+
target_link_libraries(${TARGET_OBJECT_LIB} PRIVATE core)
12+
13+
if(SIGHT_BUILD_TESTS)
14+
add_subdirectory(test)
15+
endif()

libs/io/joystick/Dependencies.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
find_package(SDL2 CONFIG REQUIRED)

0 commit comments

Comments
 (0)