Commit Graph

102 Commits (d3d32cf278cbabe70e0ef95baf8137d5a63ca7b5)

Author SHA1 Message Date
nirenjan d3d32cf278 Block signals on child threads
This change adds logic to block signals on child threads. This is done
so that we can migrate signal handling to the main thread, even if we
add additional threads in the future.
2022-07-27 11:33:44 -07:00
nirenjan 41812e3c1e Add unit tests for mouse reverse scroll 2022-07-03 16:00:13 -07:00
nirenjan 95a10b5ac9 Add option to reverse mouse scroll direction
This change adds a ReverseScroll parameter to the configuration, which
if set, will change the direction of the scroll wheel of the virtual
mouse.

Github-Issue: #45
2022-06-14 09:36:13 -07:00
nirenjan 8c8f261c80 Disable use of PID file when running in foreground
When running in foreground, it is likely that it is running within
systemd. In this case, a stale PID file is likely to have a PID that
corresponds to a different process, which can still be kill'ed by the
root user. This results in a false positive that the process is still
running and causes the daemon to abort prematurely.

Fixes #42
2022-05-16 10:33:04 -07:00
nirenjan 6a8dff0a17 Fix mouse test linker failure on macOS 2022-04-28 02:18:13 -07:00
nirenjan 8f9ab9cefd Add tests for mouse configuration
This change adds a test suite for validating mouse configuration. This
only tests the logic for mouse thread enable/disable and mouse speed
calculations.
2022-04-28 01:54:09 -07:00
nirenjan 251ccfde0d Close command socket in test harness before terminating daemon 2022-04-08 22:59:37 -07:00
nirenjan 611bc9d965 Add mouse speed test cases 2022-04-08 17:30:34 -07:00
nirenjan 69426c62d8 Add tests for LED parser 2022-04-08 17:00:45 -07:00
nirenjan 527d4d5a1e Run daemon communication tests only on Linux
For some reason, the CI runs on Github Actions block the macOS runners,
and they take forever to run the tests. The tests are really needed only
on Linux, and the errno values that it uses are only verified to work on
Linux.
2022-04-08 00:26:44 -07:00
nirenjan c87c7caa68 Add test cases for clock configuration 2022-04-08 00:16:57 -07:00
nirenjan 0f7cd3fdb3 Add test cases for config get/set with wrong argc 2022-04-08 00:16:39 -07:00
nirenjan 33e940606c Add daemon communication test cases
This change adds an automated test harness that will spin up an instance
of the X52 daemon, connect to its command socket, send commands and
validate the responses. This first set of test cases simply validates
the basic configuration file handling. Subsequent commits will enhance
the tests to improve code coverage.
2022-04-07 23:24:24 -07:00
nirenjan f0ad185421 Fix formatted responses to include the trailing NUL 2022-04-02 08:23:55 -07:00
nirenjan 98822190ed Add a callback to apply one configuration item immediately
The configuration processing works as follows - the configuration
parameters are set in memory, and an apply function applies all the
changes directly to the device. While this works during startup and
reload, it adds a needless overhead when processing config set commands
from the command socket.

This change makes it such that a `config set` command would update the
configuration for that particular key, and then immediately call the
callback function for that key. This has the effect that individual
configuration changes are visible immediately, without having to reapply
every other configuration that hasn't changed.

This commit also removes the `config apply` command, since it is no
longer needed. The `config load` and `config reload` already handle
applying the configuration after reading it.
2022-02-11 13:30:17 -08:00
nirenjan cf6811d923 Check if mouse is enabled before reporting buttons
Prior to this change, the IO thread would always report a mouse button
event, even if the mouse was disabled in configuration, or the uinput
device was not created. This results in unexpected button/wheel events.

This change checks that the uinput device has been created and the mouse
has been enabled in the configuration before reporting a button or wheel
event.
2022-02-03 11:11:41 -08:00
nirenjan 5ab4784b21 Remove unnecessary code from x52d_config_save_file
This is a legacy from when there was a separate print_section function
2021-11-22 10:08:21 -08:00
nirenjan 385f1ca574 Fix typo in logging error handler 2021-11-22 10:06:23 -08:00
nirenjan 3896fa0d3e Update protocol documentation for logging command 2021-11-10 22:21:47 -08:00
nirenjan f6c6db6c61 Add command processing for logging configuration
This change adds the `logging show` and `logging set` commands to the
command processor module. This allows setting the log levels of the
individual modules via the socket.
2021-11-10 21:49:54 -08:00
nirenjan 2119e00647 Integrate pinelog module logging functionality 2021-11-10 09:29:27 -08:00
nirenjan 09740e0fe9 Update documentation to include communication protocol 2021-11-07 16:38:06 -08:00
nirenjan 7448334824 Add `config apply` command 2021-11-07 16:06:49 -08:00
nirenjan f2b0110380 Allow upto 1024 arguments
Prior to this change, it was possible for a malicious client to send a
buffer of 1024 NUL bytes, which would cause the parser to overflow the
argv array and eventually crash the program.

This change makes the length of the argv array the same as the length of
the recv buffer, which means that even an input of all 0 bytes would not
cause any issues. The client would just get a bunch of ERR responses in
return.
2021-11-07 15:07:10 -08:00
nirenjan e82f9032eb Add 'config get' command to retrieve configuration
The command allows the client to retrieve individual parameters from the
configuration. This follows a similar syntax to the 'config set'
command, with the client supplying the section and key, and if there is
a matching entry in the configuration, it will return the corresponding
value.
2021-11-07 07:52:11 -08:00
nirenjan 2fe7b8af43 Cleanup response protocol
This change removes the unnecessary response length field from the
output buffer. It was added to check for possible issues in the
communication between client and server, but is not needed anymore. This
also makes the communication protocol standardized between client and
server.
2021-11-07 05:47:31 -08:00
nirenjan 20abe8974c Fix x52d_send_command prototype
Prior to this change, the recv call was using the same buflen as that of
the send, which meant that the response would be truncated at by the
client, while the server was sending the entire message. This was
evident by running a Python client which manually called recv with the
maximum buffer size.

This change updates the prototype to take both a bufin (length of the
input buffer), and a bufout (length of the output buffer) argument,
instead of a single buflen. With this change, commands work as expected
in x52ctl.
2021-11-07 05:40:08 -08:00
nirenjan 116b9e2c0c Add config set command to daemon command processor
This change allows setting the configuration from the socket. It behaves
similar to the override, and requires the client to send the section,
key and value, and responds with an OK or error value.
2021-11-05 15:27:24 -07:00
nirenjan 7b8c71dd35 Add command parsing and response logic
This change adds the generic command parsing logic, as well as the
response for the following commands:

* config load <file>
* config reload
* config save
* config dump <file>
2021-11-05 15:10:20 -07:00
nirenjan eb98804607 Make x52ctl send commands as individual args
This change makes the protocol more strict, in that the buffer sent to
the daemon must be a series of NUL separated arguments. This makes it a
little easier to handle the strings, especially those that may have
embedded whitespace.
2021-11-04 22:37:43 -07:00
nirenjan d8a5a2c3b8 Add daemon command handler loop
This change adds the logic to read a packet from the socket, accept
connections from clients, and close connections from clients that have
hung up. This commit does not yet have support for parsing and handling
the commands, and simply echoes the request back to the client.
2021-11-04 18:32:18 -07:00
nirenjan 5a78492140 Make X52 daemon listen on a Unix socket
This change makes X52 daemon listen on a Unix socket. This is in
preparation for changes that will read from the socket and allow clients
to communicate with and control the daemon.
2021-11-04 13:48:18 -07:00
nirenjan abc74d6e37 Fix linking with libintl on macOS 2021-11-04 11:05:52 -07:00
nirenjan 931f945133 Add x52ctl daemon communication program 2021-11-04 10:50:10 -07:00
nirenjan 18c0c72c74 Add client communication library
This change adds a library to connect to the X52 daemon and send
commands and receive responses. The library is a thin wrapper around the
POSIX sockets API. While a client could implement the functions
themselves, the library makes it a little bit easier, as well as
allowing for third-party clients to connect to and communicate with the
daemon.
2021-11-04 10:48:59 -07:00
nirenjan 293ba0a99d Remove duplicate check for default PID file 2021-11-03 11:44:24 -07:00
nirenjan 6c3efa44f5 Simplify configuration dumping
Prior to this change, there was a lot of duplicated code within the dump
routines, which would call out to a common `print_section` routine that
had global state. This causes problems from a multi-threaded perspective
in that multiple calls to `x52d_config_save_file` were not MT-safe.

In addition, the dump logic was written such that it could only be used
in the config dump. It is desired that we add functionality to return
the formatted config value as a string in a different part of the code
as well.

This change brings in the shared state into a stack variable, and
changes the dump functions to return a const char *, thereby allowing
for greater reuse, as well as getting rid of the shared state. However,
there is still a little bit of shared state in the `int_dumper` routine.
This can be ignored for now, but we should possibly figure out how to
get rid of the shared state altogether.
2021-11-02 23:25:55 -07:00
nirenjan d9eed14e0d Include default location of x52d.conf in documentation
This change adds the default location of x52d.conf in the release builds
to the public documentation.
2021-10-06 23:44:16 -07:00
nirenjan fec67b5994 Revert "Enable verbose logging in systemd service"
This reverts commit 53957d0813. It was
supposed to be a temporary commit, but it was forgotten about. Reverting
this will restore the old behavior of only logging INFO and higher
priority logs.

Fixes #38.
2021-10-05 22:38:34 -07:00
nirenjan 4d2736e03c Indicate profiles are not yet supported.
See discussion in #37.

[skip ci]
2021-09-19 16:39:49 -07:00
nirenjan e8abbd0374 Allow for a greater range in mouse speeds
Prior to this change, the virtual mouse update was restricted to
updating once every `mouse_delay` microseconds, and the allowed values
were a small fixed set. Some users reported that even at the highest
speed, the speed was slower than they were used to (with a high DPI
mouse).

This change modifies the speed calculation algorithm as follows. It
keeps the slowest speed to refresh the mouse every 70 ms. As the speed
increases, the refresh rate drops by 5 ms for every increment in speed,
until the refresh rate caps at once every 10 ms. Beyond that, a
multiplicative factor begins to take effect, with each speed increase
adding 0.25 to the factor. That is, speed 13 would multiply the axis
components by 1.25 _and_ refresh every 10 ms. Speed 14 would bump the
factor to 1.50, speed 15 to 1.75, and so on, until the factor tops out
at 6.0.
2021-09-19 16:39:49 -07:00
nirenjan d8fc859e44 Change mouse speed parameters
Prior to this change, the mouse delays were between 50 ms to 250 ms,
with a difference of 50 ms between steps. Unfortunately, this was too
slow at lower speeds, therefore, the delays have been changed to vary
from 30 ms to 70 ms with a difference of 10 ms between steps. This gives
a much smoother mouse response.
2021-09-15 09:25:26 -07:00
nirenjan 4365e86f2a Fix logging indicating mouse speed range 2021-09-15 09:17:15 -07:00
nirenjan 16e53b897f Use $(localstatedir)/run instead of $(runstatedir)
`runstatedir` is only available in Autoconf 2.70, but unless the
distribution is a bleeding edge system, it most likely uses Autoconf
2.69. That said, several major distributions have backported runstatedir
support to the older versions, hiding the issue. See #35.

This change replaces all references to runstatedir to use
$localstatedir/run instead, which is what is recommended by the autoconf
manual.

This also updates the build instructions to add --localstatedir and
--sysconfdir. This is because the lack of the options would have them
default to `$(prefix)/var` and `$(prefix)/etc` respectively, and with
prefix set to `/usr`, these would be the bogus directories `/usr/var`
and `/usr/etc`.
2021-09-15 09:06:31 -07:00
nirenjan 8deb6a1513 Merge device acquisition and update threads 2021-09-15 00:17:20 -07:00
nirenjan c56f715155 Fix use of libx52io return codes
Prior to this change, we were treating ERROR_NO_DEVICE as if the hidapi
library itself would return such a code. However, that is not the case,
and we should be treating any error condition as a critical issue and
treat it as if the device was disconnected. The worst case scenario is
that it would have to re-enumerate the HID device list and reopen the
joystick.
2021-09-15 00:06:43 -07:00
nirenjan 025a06351a Apply mouse button events immediately
Prior to this change, the button change events were only happening on
periodic intervals corresponding to the change in the mouse REL_X and
REL_Y values. However, this has the issue that it tends to miss a few
events, especially those related to the scroll wheel.

This change reports button and wheel events immediately when receiving
the report, but it leaves the motion to be updated by the thread.
2021-09-14 23:35:05 -07:00
nirenjan 53957d0813 Enable verbose logging in systemd service 2021-09-14 17:34:20 -07:00
nirenjan 2a8ca8424e Reset reports on thread create and device disconnection
This ensures that if the device gets disconnected while the axis is held
outside of the default position, the axis will get reset.
2021-09-14 17:34:07 -07:00
nirenjan 7f29f5f5fe Add mouse update thread
This change adds a thread to translate thumbstick events to a virtual
mouse.
2021-09-14 17:08:01 -07:00