Skip to content

Commit

Permalink
API Refactoring (#21)
Browse files Browse the repository at this point in the history
* Make API more idiomatic and don't query devices if not needed

This introduces a rust-y API with two main objects:

- `Device` represents a device that has not been opened yet
- `DeviceHandle` is a device that has been opened and which has methods
  to get/set its state.

Also, all serde-related stuff has been moved to `main.rs` since it's not
needed for the library itself. This opens the possibility to reduce the
dependencies of the library even more in the future.

* Use more descriptive `device_type_from_product_id` function name

* Increase clippy warning level and fix warnings

* Enforce and add documentation of all public library members

* Move serial number filtering to `main.rs`

* build: Mark binary-only dependencies as optional

* Expose device info of `Device`

* Rework device serial number filtering code

* Add `Litra` object to encapsulate the hidapi context

* Use more efficient `find()` instead of `filter().next()`

* build: Mark `cli` as default feature for easy binary building

For library usage, you can skip the unneeded dependencies by specifing
`litra` as dependency in your `Cargo.toml` like this:

    [dependencies]
    litra = { version = "<version>", default-features = false }

* refactor: Rename "enabled" to "on"

* Move range checks into `lib.rs` and improve library error handling

* Streamline error handling in `main.rs`

* build: Bump versions in `Cargo.lock`

* Remove unnecessary import in `lib.rs`

* ci: Remove `Cargo.lock` from pre-commit GitHub Actions workflow

This should not be done in checks for PRs. Instead, this is better being
taken care of by dependabot or something similar.

* Add error handling for brightness calculation errors to `main.rs`
  • Loading branch information
Holzhaus authored Feb 20, 2024
1 parent 45196c8 commit 3da7a5e
Show file tree
Hide file tree
Showing 5 changed files with 517 additions and 334 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ jobs:
with:
fetch-depth: 2

- name: Generate Cargo.lock
uses: actions-rs/cargo@v1
with:
command: generate-lockfile

- name: Set up Python
uses: actions/setup-python@v5

Expand Down
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ keywords = ["logitech", "litra", "glow", "beam", "light"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.5.0", features = ["derive"] }
hidapi = "2.6.0"
serde = { version = "1.0.196", features = ["derive"] }
serde_json = "1.0.113"
clap = { version = "4.5.0", features = ["derive"], optional = true }
serde = { version = "1.0.196", features = ["derive"], optional = true }
serde_json = { version = "1.0.113", optional = true }

[features]
default = ["cli"]
cli = ["dep:clap", "dep:serde", "dep:serde_json"]

[[bin]]
name = "litra"
required-features = ["cli"]
Loading

0 comments on commit 3da7a5e

Please sign in to comment.