Commit Graph

109 Commits

Author SHA1 Message Date
Peter Hutterer
f60f8a12ab tools: fix string parsing for LED colors 2017-03-31 15:07:01 +10:00
Peter Hutterer
fd348d456d tools: add missing LED_OFF switch case
And add the missing break
2017-03-31 15:07:01 +10:00
Peter Hutterer
0f73a97bc8 tools: move variable declaration up
We do C99, but not this :)
2017-03-31 15:07:01 +10:00
Peter Hutterer
7783f50110 tools: fix unused variable warnings 2017-03-31 15:07:01 +10:00
Ilia guterman
6c18b16a00 align ratbag-command usage documentation (#135) 2017-03-08 01:44:29 +02:00
Ilya Guterman
8e5ad717c4 ratbag-command: implement LED commands 2017-03-07 11:07:50 +10:00
Lyude
52d4e35192 Add the ability to enable or disable profiles
This is especially important for the mx780, so we can get rid of the
rude workaround we currently have in the driver for it.

Signed-off-by: Lyude <lyude@redhat.com>

Changes since v1:
- Just have profile enable/disable in ratbag-command
- Use bool instead of int
Changes since v2:
- Remove leftover function, whoops
- Fix leftover ints to bools
- Lots of style fixes
2016-11-16 09:45:01 +10:00
Lyude
01fcef9b9d Introduce new profile-oriented API
Almost all of the devices we've worked with here are the same: they have
some sort of profile on them, and if they don't (which is quite rare)
it's rather easy to simulate one in the driver. In fact basically all of
the device drivers in ratbag just update the profile and rewrite it on
calls to the write_resolution_dpi() and write_button() calls. This is
annoying since profile writes can take a good bit of time, and we're
wasting a lot of time with redundant profile writes that way.

During XDC this year, we came up with an idea that makes more sense: a
profile oriented API. Instead of having multiple entrypoints in the API
to writing and updating the profile we just cache all of the profile
changes until ratbag_device_commit_profiles() is called, at which point
we do a single set of writes for each profile and button that changed.

This has a lot of advantages:
- Where the profile is and is not written out to the device is now
  explicit.
- Changing attributes of each profile won't result in any sort of delay
  up until the library user commits the profiles, allowing us to avoid
  hanging the application every time a simple attribute is changed.
- We can cut down on workarounds in drivers to cater to the previous
  API.

Since this commit doesn't handle converting all of the device drivers
over to the new API, we also add a temporary wrapper for devices that
haven't yet been converted to this new API so that they're still usable.
Once all of the drivers have been converted to the new API, the wrapper
will be removed along with the internal driver API calls.

Signed-off-by: Lyude <thatslyude@gmail.com>

Changes since v1:
- has_changed→dirty
- Change namespace to LIBRATBAG_0.5.0
Changes since v2:
- Remove unneeded note about not setting dirty bit
- commit_profiles->commit
- Make FIXMEs more obvious
- Minor styling nitpicks
- Split up capability check fixes into seperate patch
2016-10-14 08:00:54 +10:00
Peter Hutterer
4054616190 Revamp the button macro code
The previous API was inconsistent and different to the rest of libratbag's
API. Replace with one where a macro is a separate struct, can be initialized
and then written to the device with a set_macro() call. The device copies the
contents, the macro is otherwise unmodified and can be re-used by the client
if need be.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-03-14 14:22:22 +10:00
Benjamin Tissoires
ff2d9713f7 Remove the default profile capability
We do not have any driver using it, and we are not sure this will even
be required. Before releasing a version with this, remove it. We
can always re-add this later if the need appears.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2016-02-10 15:22:25 +01:00
Palle Ravn
61dc211e04 Correct index check in ratbag-command
When initializing N profiles they are indexed 0 to N-1. However,
when setting the active profile to X the validation of X is a
check for X > N. Notice that N is invalid as the maximum index
is N-1.

Change the validation check of the new active profile to X >= N.

Signed-off-by: Palle Ravn <ravnzon@gmail.com>
2015-10-25 12:54:30 +01:00
Peter Hutterer
5b8f3c4744 Add snprintf_safe() and sprintf_safe helpers
Blows up when sprintf encounters an error, the result string is empty or the
result string is truncated.

Note: sprintf_safe only works on static buffers, it uses ARRAY_LENGTH.

Fixes #14

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-10-13 07:01:09 +10:00
Peter Hutterer
1abc7cdb69 Add strdup_safe() as a reliable strdup function
Handles NULL and guarantees a successful strdup

Fixes #14

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-10-13 07:00:16 +10:00
Peter Hutterer
a3aacd3a99 Drop the _by_index suffix
This is the default, if we need a _by_name or so later we can add it.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-16 00:55:12 +10:00
Peter Hutterer
2d922012fd tools: fix usage() indentation, add exit status
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 23:36:29 +10:00
Peter Hutterer
7ff92c4226 tools: add another "action" subcommand to set/get buttons
Like usage() already documented

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 23:36:29 +10:00
Peter Hutterer
1c84e74572 tools: Support macros
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 23:36:29 +10:00
Peter Hutterer
3b452df36c tools: do a cap check before trying to set buttons/macros/..
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 06:23:27 +10:00
Peter Hutterer
fa06db8398 tools: use strtol(), not strtod() to convert ints
oops.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 04:52:25 +10:00
Peter Hutterer
834daebdd8 tools: support the button commands
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 04:52:25 +10:00
Peter Hutterer
c5d79f5806 tools: support resolution's "rate get/set"
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 04:52:25 +10:00
Peter Hutterer
d6153ddb92 tools: change the usage() output to a manual one
A bit easier to explain when we have more flexibility.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 04:52:25 +10:00
Peter Hutterer
0a3269dbdb tools: improve profile active get/set/
Drop some unnecessary code, make the functions a bit smaller. Drop the printf
when we're activating the active profile.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 04:52:25 +10:00
Peter Hutterer
02b14046a3 tools: implement resolution active get/set
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 04:52:25 +10:00
Peter Hutterer
61d9c1006b tools: return the right error from device_from_arg
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 04:48:14 +10:00
Peter Hutterer
7df7ed325a tools: automatically print usage() on ERR_USAGE
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 04:48:14 +10:00
Peter Hutterer
839b31eb25 tools: categorize the return code
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 04:48:14 +10:00
Peter Hutterer
e7b421ae19 tools: fix resolution active get/set
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 04:48:14 +10:00
Peter Hutterer
6e56dec9ed tools: add an error message for a missing device path
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 04:48:14 +10:00
Peter Hutterer
fb941b5f75 tools: let ratbag_device_from_arg reduce the argc
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 04:48:14 +10:00
Peter Hutterer
aee827efa1 tools: drop active profile check in "profile active set"
Once we have the profile, we can call set_active and be done with it. No need
to check if another profile is currently active.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 04:48:14 +10:00
Peter Hutterer
f97a3142d1 tools: use the new flags for switch-etekcity and change-button
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 04:48:14 +10:00
Peter Hutterer
87881fd9d5 tools: change error messages into a more terse format
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-15 04:48:14 +10:00
Peter Hutterer
5e3ca7692e tools: auto-fill profile, resolution, device for each command
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 11:28:00 +10:00
Peter Hutterer
8af1530ea5 tools: make the top-level command list a subcommand itself
Allows us to reuse all the subcommand code, and factor out a bunch of helpers
later.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 11:28:00 +10:00
Peter Hutterer
26f82c7ecc tools: use the same error path in main()
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 11:28:00 +10:00
Peter Hutterer
f2bbd411fe tools: enable a plain dpi get/set
Works on the active profile, active resolution by default.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 11:28:00 +10:00
Peter Hutterer
9e02b26d74 tools: implement dpi get
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 11:28:00 +10:00
Peter Hutterer
b39a00d9e6 tools: update dpi set to work on the right resolution
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 11:28:00 +10:00
Peter Hutterer
ce4771456f tools: pre-load profile/resolution for the respective commands
So anything below either will have options->profile/resolution pre-set to the
right one.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 11:28:00 +10:00
Peter Hutterer
c504d8c029 tools: always open the device for all args
Except for "list", all commands need a device argument. Open it ahead of time
to reduce the boilerplate in each function.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 11:28:00 +10:00
Peter Hutterer
a0fb3a82f6 tools: implement dpi set, drop switch-dpi
Same code, except that we use a helper function to get the active profile.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 11:28:00 +10:00
Peter Hutterer
c89eb2f37b tools: improve the usage() output a bit
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 11:28:00 +10:00
Peter Hutterer
a838d6d1cd tools: add the stubs for the button/resolution command
Only stubs, and the usage() output isn't correct anymore. But we need to fix
this anyway, the combination of arguments will be too complex to handle them
in such a simple approach.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 11:28:00 +10:00
Peter Hutterer
6f93b0da69 tools: add another helper to open the device
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 11:28:00 +10:00
Peter Hutterer
59123945a7 tools: add profile active get|set commands
This replaces the switch-profile command

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 11:27:56 +10:00
Peter Hutterer
eb46a6581b tools: add a helper to get the device path
Doesn't do much, but it reduces some of the argc checking in the callers,
especially since we always expect the device as last argument

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 11:25:00 +10:00
Peter Hutterer
f99696e6d2 tools: use the parsed index instead of the argument
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 11:25:00 +10:00
Peter Hutterer
d0d5284132 tools: add ability to have subcommands in a ratbag_cmd
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 11:25:00 +10:00
Peter Hutterer
332a046cbb tools: stack the options into a struct passed to the functions
No functional changes, but this allows us to pass down profiles, resolutions,
etc.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-14 01:06:51 +10:00