Skip to content

Commit

Permalink
another folder refactor
Browse files Browse the repository at this point in the history
- implements print_details()
- adds 1 example in typescript
- more WIP on rust example
- rename enums.rs to types.rs
- move all bindings to bindings folder
- rename lib folder to library (for gitignore reasons)
- add a new CI related to examples only
  • Loading branch information
2bndy5 committed Oct 16, 2024
1 parent a8fee94 commit 976f9e0
Show file tree
Hide file tree
Showing 99 changed files with 2,907 additions and 314 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# lint/build examples

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
lint-python:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
cache: "pip"
cache-dependency-path: "examples/python/requirements*.txt"
- name: Install workflow tools
run: >-
python -m pip install
-r examples/python/requirements.txt
-r examples/python/requirements-dev.txt
- run: ruff check
- run: ruff format
- run: mypy

build-node:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
- run: rustup update --no-self-update
- run: yarn install
- name: Build binding (debug)
run: yarn build:debug
- name: Lint examples
run: yarn examples-lint
- name: Compile examples
run: yarn examples-build

lint-rust:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup update --no-self-update
- uses: cargo-bins/cargo-binstall@main
- name: Install just
run: cargo binstall -y just
- run: just lint-examples
24 changes: 15 additions & 9 deletions .github/workflows/node-packaging.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
name: Node.js Builds
env:
DEBUG: napi:*
ARTIFACT_PATH: rf24-node/rf24.*.node
ARTIFACT_PATH: bindings/node/rf24.*.node
MACOSX_DEPLOYMENT_TARGET: '10.13'

on:
push:
branches: [main]
tags: ['v*']
paths:
- 'lib/src/**'
- 'rf24-node/**'
- 'library/src/**'
- 'bindings/node/**'
- '!**/*.md'
pull_request:
branches: [main]
paths:
- 'library/src/**'
- 'bindings/node/**'
- '!**/*.md'

jobs:
build:
strategy:
Expand Down Expand Up @@ -143,7 +149,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: generated-index
path: rf24-node/index.*
path: bindings/node/index.*

universal-macOS:
name: Build universal macOS binary
Expand All @@ -163,12 +169,12 @@ jobs:
uses: actions/download-artifact@v4
with:
name: bindings-x86_64-apple-darwin
path: rf24-node/artifacts
path: bindings/node/artifacts
- name: Download macOS arm64 artifact
uses: actions/download-artifact@v4
with:
name: bindings-aarch64-apple-darwin
path: rf24-node/artifacts
path: bindings/node/artifacts
- name: Combine binaries
run: yarn universal
- name: Upload artifact
Expand Down Expand Up @@ -199,16 +205,16 @@ jobs:
uses: actions/download-artifact@v4
with:
pattern: binding-*
path: rf24-node/artifacts
path: bindings/node/artifacts
- name: Download generated index artifact
uses: actions/download-artifact@v4
with:
name: generated-index
path: rf24-node
path: bindings/node
- name: Move artifacts
run: yarn artifacts
- name: List packages
run: ls -R ./rf24-node/npm
run: ls -R ./bindings/node/npm
shell: bash
- name: Publish
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/python-packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on:
push:
branches: [main]
paths:
- rf24-py/**
- lib/src/**
- bindings/python/**
- library/src/**
- Cargo.toml
- pyproject.toml
- .github/workflows/python-packaging.yml
Expand All @@ -19,8 +19,8 @@ on:
pull_request:
branches: [main]
paths:
- rf24-py/**
- lib/src/**
- bindings/python/**
- library/src/**
- Cargo.toml
- pyproject.toml
- .github/workflows/python-packaging.yml
Expand Down
30 changes: 6 additions & 24 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ on:
push:
branches: [main]
paths:
- 'lib/**'
- '!lib/README.md'
- 'library/**'
- '!library/README.md'
- Cargo.toml
- .github/workflows/tests.yml
pull_request:
branches: [main]
paths:
- 'lib/**'
- '!lib/README.md'
- 'library/**'
- '!library/README.md'
- Cargo.toml
- .github/workflows/tests.yml

jobs:
lint-rust:
lint-lib:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -34,26 +34,8 @@ jobs:
key: cargo-lib-${{ hashFiles('lib/src/**', 'lib/Cargo.toml') }}
- run: just lint

lint-python:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
cache: 'pip'
cache-dependency-path: 'examples/python/requirements*.txt'
- name: Install workflow tools
run: >-
python -m pip install
-r examples/python/requirements.txt
-r examples/python/requirements-dev.txt
- run: ruff check
- run: ruff format
- run: mypy

test:
needs: [lint-rust]
needs: [lint-lib]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,4 @@ coverage.json
lcov.info

# supplemental docs build
docs/site/
docs/site/
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = ["lib", "examples/rust", "rf24-py", "rf24-node"]
default-members = ["lib"]
members = ["library", "examples/rust", "bindings/python", "bindings/node"]
default-members = ["library"]
resolver = "2"

[workspace.package]
Expand Down
5 changes: 5 additions & 0 deletions bindings/node/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-musl-gcc"
rustflags = ["-C", "target-feature=-crt-static", "-C", "link-arg=-Tdefmt.x"]
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static", "-C", "link-arg=-Tdefmt.x"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion rf24-node/Cargo.toml → bindings/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ napi-build = "2.0.1"

[target.'cfg(target_os = "linux")'.dependencies]
linux-embedded-hal = "0.4.0"
rf24-rs = { path = "../lib" }
rf24-rs = { path = "../../library", features = ["std"] }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion rf24-node/src/lib.rs → bindings/node/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod enums;
mod types;
#[cfg(target_os = "linux")]
mod radio;

Expand Down
13 changes: 10 additions & 3 deletions rf24-node/src/radio.rs → bindings/node/src/radio.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(target_os = "linux")]

use crate::enums::{
use crate::types::{
AvailablePipe, HardwareConfig, NodeCrcLength, NodeDataRate, NodeFifoState, NodePaLevel,
NodeStatusFlags, WriteConfig,
};
Expand All @@ -11,8 +11,8 @@ use linux_embedded_hal::{
};
use napi::{bindgen_prelude::Buffer, Error, Result, Status};

use rf24_rs::radio::{prelude::*, RF24};
use rf24_rs::StatusFlags;
use rf24::radio::{prelude::*, RF24};
use rf24::StatusFlags;

#[napi(js_name = "RF24")]
pub struct NodeRF24 {
Expand Down Expand Up @@ -477,4 +477,11 @@ impl NodeRF24 {
self.inner.get_status_flags(&mut flags);
NodeStatusFlags::from_inner(flags)
}

#[napi]
pub fn print_details(&mut self) -> Result<()> {
self.inner
.print_details()
.map_err(|e| Error::new(Status::GenericFailure, format!("{e:?}")))
}
}
44 changes: 22 additions & 22 deletions rf24-node/src/enums.rs → bindings/node/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(target_os = "linux")]
use rf24_rs::{CrcLength, DataRate, FifoState, PaLevel, StatusFlags};
use rf24::{CrcLength, DataRate, FifoState, PaLevel, StatusFlags};

/// Optional configuration parameters to fine tune instantiating the RF24 object.
/// Pass this object as third parameter to RF24 constructor.
Expand Down Expand Up @@ -117,37 +117,37 @@ pub enum NodePaLevel {
/// | nRF24L01 | Si24R1 with<br>LNA Enabled | Si24R1 with<br>LNA Disabled |
/// |:--------:|:--------------------------:|:---------------------------:|
/// | -18 dBm | -6 dBm | -12 dBm |
MIN,
Min,
/// | nRF24L01 | Si24R1 with<br>LNA Enabled | Si24R1 with<br>LNA Disabled |
/// |:--------:|:--------------------------:|:---------------------------:|
/// | -12 dBm | 0 dBm | -4 dBm |
LOW,
Low,
/// | nRF24L01 | Si24R1 with<br>LNA Enabled | Si24R1 with<br>LNA Disabled |
/// |:--------:|:--------------------------:|:---------------------------:|
/// | -6 dBm | 3 dBm | 1 dBm |
HIGH,
High,
/// | nRF24L01 | Si24R1 with<br>LNA Enabled | Si24R1 with<br>LNA Disabled |
/// |:--------:|:--------------------------:|:---------------------------:|
/// | 0 dBm | 7 dBm | 4 dBm |
MAX,
Max,
}

#[cfg(target_os = "linux")]
impl NodePaLevel {
pub fn into_inner(self) -> PaLevel {
match self {
NodePaLevel::MIN => PaLevel::MIN,
NodePaLevel::LOW => PaLevel::LOW,
NodePaLevel::HIGH => PaLevel::HIGH,
NodePaLevel::MAX => PaLevel::MAX,
NodePaLevel::Min => PaLevel::Min,
NodePaLevel::Low => PaLevel::Low,
NodePaLevel::High => PaLevel::High,
NodePaLevel::Max => PaLevel::Max,
}
}
pub fn from_inner(other: PaLevel) -> NodePaLevel {
match other {
PaLevel::MIN => NodePaLevel::MIN,
PaLevel::LOW => NodePaLevel::LOW,
PaLevel::HIGH => NodePaLevel::HIGH,
PaLevel::MAX => NodePaLevel::MAX,
PaLevel::Min => NodePaLevel::Min,
PaLevel::Low => NodePaLevel::Low,
PaLevel::High => NodePaLevel::High,
PaLevel::Max => NodePaLevel::Max,
}
}
}
Expand Down Expand Up @@ -189,27 +189,27 @@ impl NodeDataRate {
#[derive(Debug, PartialEq)]
pub enum NodeCrcLength {
/// represents no CRC checksum is used
DISABLED,
Disabled,
/// represents CRC 8 bit checksum is used
BIT8,
Bit8,
/// represents CRC 16 bit checksum is used
BIT16,
Bit16,
}

#[cfg(target_os = "linux")]
impl NodeCrcLength {
pub fn into_inner(self) -> CrcLength {
match self {
NodeCrcLength::DISABLED => CrcLength::DISABLED,
NodeCrcLength::BIT8 => CrcLength::BIT8,
NodeCrcLength::BIT16 => CrcLength::BIT16,
NodeCrcLength::Disabled => CrcLength::Disabled,
NodeCrcLength::Bit8 => CrcLength::Bit8,
NodeCrcLength::Bit16 => CrcLength::Bit16,
}
}
pub fn from_inner(other: CrcLength) -> NodeCrcLength {
match other {
CrcLength::DISABLED => NodeCrcLength::DISABLED,
CrcLength::BIT8 => NodeCrcLength::BIT8,
CrcLength::BIT16 => NodeCrcLength::BIT16,
CrcLength::Disabled => NodeCrcLength::Disabled,
CrcLength::Bit8 => NodeCrcLength::Bit8,
CrcLength::Bit16 => NodeCrcLength::Bit16,
}
}
}
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions rf24-py/Cargo.toml → bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ name = "rf24_py"
crate-type = ["cdylib"]

[dependencies]
pyo3 = "0.22.3"
pyo3 = {version = "0.22.4", features = ["extension-module"]}

[target.'cfg(target_os = "linux")'.dependencies]
linux-embedded-hal = "0.4.0"
rf24-rs = { path = "../lib" }
rf24-rs = { path = "../../library", features = ["std"]}
File renamed without changes.
12 changes: 6 additions & 6 deletions rf24-py/src/lib.rs → bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use pyo3::prelude::*;
// #[cfg(target_os = "linux")]
mod enums;
mod types;
mod radio;

#[cfg(target_os = "linux")]
Expand All @@ -17,10 +17,10 @@ fn bind_radio_impl(_m: &Bound<'_, PyModule>) -> PyResult<()> {
#[pymodule]
fn rf24_py(m: &Bound<'_, PyModule>) -> PyResult<()> {
bind_radio_impl(m)?;
m.add_class::<enums::PyCrcLength>()?;
m.add_class::<enums::PyDataRate>()?;
m.add_class::<enums::PyFifoState>()?;
m.add_class::<enums::PyPaLevel>()?;
m.add_class::<enums::PyStatusFlags>()?;
m.add_class::<types::PyCrcLength>()?;
m.add_class::<types::PyDataRate>()?;
m.add_class::<types::PyFifoState>()?;
m.add_class::<types::PyPaLevel>()?;
m.add_class::<types::PyStatusFlags>()?;
Ok(())
}
Loading

0 comments on commit 976f9e0

Please sign in to comment.