Rename WS28xx* to Ws28xx*
This commit is contained in:
parent
8791b64636
commit
2859a23b1e
@ -9,7 +9,7 @@ pub trait HardwareDev {
|
|||||||
fn write_all(&mut self, encoded_data: &[u8]) -> Result<(), String>;
|
fn write_all(&mut self, encoded_data: &[u8]) -> Result<(), String>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait WS28xxAdapter {
|
pub trait Ws28xxAdapter {
|
||||||
/// Returns a reference to the hardware device.
|
/// Returns a reference to the hardware device.
|
||||||
/// This function only needs to be implemented once in the generic adapter.
|
/// This function only needs to be implemented once in the generic adapter.
|
||||||
fn get_hw_dev(&mut self) -> &mut Box<dyn HardwareDev>;
|
fn get_hw_dev(&mut self) -> &mut Box<dyn HardwareDev>;
|
||||||
@ -18,7 +18,7 @@ pub trait WS28xxAdapter {
|
|||||||
/// is the number of LEDs you want to write to. *Note* that if you have performance critical
|
/// is the number of LEDs you want to write to. *Note* that if you have performance critical
|
||||||
/// applications (like you need a signal on the LEDS on a given time) it's a better idea
|
/// applications (like you need a signal on the LEDS on a given time) it's a better idea
|
||||||
/// to encode the data earlier by yourself using `crate::encoding`-module and calling
|
/// to encode the data earlier by yourself using `crate::encoding`-module and calling
|
||||||
/// `WS28xxAdapter::write_encoded_rgb`. Otherwise and if your device is slow the encoding
|
/// `Ws28xxAdapter::write_encoded_rgb`. Otherwise and if your device is slow the encoding
|
||||||
/// could cost a few microseconds to milliseconds - depending on your amount of data and machine.
|
/// could cost a few microseconds to milliseconds - depending on your amount of data and machine.
|
||||||
fn write_rgb(&mut self, rgb_data: &[(u8, u8, u8)]) -> Result<(), String> {
|
fn write_rgb(&mut self, rgb_data: &[(u8, u8, u8)]) -> Result<(), String> {
|
||||||
let encoded_data = encode_rgb_slice(rgb_data);
|
let encoded_data = encode_rgb_slice(rgb_data);
|
||||||
@ -47,13 +47,13 @@ pub trait WS28xxAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Platform agnostic (generic) adapter that connects your application via your specified
|
/// Platform agnostic (generic) adapter that connects your application via your specified
|
||||||
/// hardware interface to your WS28xx LEDs. *Handle this as something like an abstract class
|
/// hardware interface to your Ws28xx LEDs. *Handle this as something like an abstract class
|
||||||
/// for concrete implementations!* This works in `#[no-std]`-environments.
|
/// for concrete implementations!* This works in `#[no-std]`-environments.
|
||||||
pub struct WS28xxGenAdapter {
|
pub struct Ws28xxGenAdapter {
|
||||||
hw: Box<dyn HardwareDev>,
|
hw: Box<dyn HardwareDev>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WS28xxGenAdapter {
|
impl Ws28xxGenAdapter {
|
||||||
/// Constructor that stores the hardware device in the adapter.
|
/// Constructor that stores the hardware device in the adapter.
|
||||||
pub fn new(hw: Box<dyn HardwareDev>) -> Self {
|
pub fn new(hw: Box<dyn HardwareDev>) -> Self {
|
||||||
Self { hw }
|
Self { hw }
|
||||||
@ -61,7 +61,7 @@ impl WS28xxGenAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Implement the getter for the hardware device.
|
// Implement the getter for the hardware device.
|
||||||
impl WS28xxAdapter for WS28xxGenAdapter {
|
impl Ws28xxAdapter for Ws28xxGenAdapter {
|
||||||
fn get_hw_dev(&mut self) -> &mut Box<dyn HardwareDev> {
|
fn get_hw_dev(&mut self) -> &mut Box<dyn HardwareDev> {
|
||||||
&mut self.hw
|
&mut self.hw
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Adapter for SPI-dev on Linux-systems. This requires std.
|
//! Adapter for SPI-dev on Linux-systems. This requires std.
|
||||||
|
|
||||||
use crate::adapter_gen::{HardwareDev, WS28xxAdapter, WS28xxGenAdapter};
|
use crate::adapter_gen::{HardwareDev, Ws28xxAdapter, Ws28xxGenAdapter};
|
||||||
use crate::timings::PI_SPI_HZ;
|
use crate::timings::PI_SPI_HZ;
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use alloc::string::{String, ToString};
|
use alloc::string::{String, ToString};
|
||||||
@ -28,7 +28,7 @@ impl HardwareDev for SpiHwAdapterDev {
|
|||||||
impl SpiHwAdapterDev {
|
impl SpiHwAdapterDev {
|
||||||
/// Connects your application with the SPI-device of your device.
|
/// Connects your application with the SPI-device of your device.
|
||||||
/// This uses the `spidev`-crate. Returns a new adapter object
|
/// This uses the `spidev`-crate. Returns a new adapter object
|
||||||
/// for the WS28xx LEDs.
|
/// for the Ws28xx LEDs.
|
||||||
///
|
///
|
||||||
/// * `dev` - Device name. Probably "/dev/spidev0.0" if available.
|
/// * `dev` - Device name. Probably "/dev/spidev0.0" if available.
|
||||||
///
|
///
|
||||||
@ -46,17 +46,17 @@ impl SpiHwAdapterDev {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adapter that connects your application via SPI to your WS28xx LEDs.
|
/// Adapter that connects your application via SPI to your Ws28xx LEDs.
|
||||||
/// This requires an SPI device on your machine. This doesn't work
|
/// This requires an SPI device on your machine. This doesn't work
|
||||||
/// with `#[no-std]`.
|
/// with `#[no-std]`.
|
||||||
pub struct WS28xxSpiAdapter {
|
pub struct Ws28xxSpiAdapter {
|
||||||
gen: WS28xxGenAdapter,
|
gen: Ws28xxGenAdapter,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WS28xxSpiAdapter {
|
impl Ws28xxSpiAdapter {
|
||||||
/// Connects your application with the SPI-device of your device.
|
/// Connects your application with the SPI-device of your device.
|
||||||
/// This uses the `spidev`-crate. Returns a new adapter object
|
/// This uses the `spidev`-crate. Returns a new adapter object
|
||||||
/// for the WS28xx LEDs.
|
/// for the Ws28xx LEDs.
|
||||||
///
|
///
|
||||||
/// * `dev` - Device name. Probably "/dev/spidev0.0" if available.
|
/// * `dev` - Device name. Probably "/dev/spidev0.0" if available.
|
||||||
///
|
///
|
||||||
@ -64,12 +64,12 @@ impl WS28xxSpiAdapter {
|
|||||||
pub fn new(dev: &str) -> Result<Self, String> {
|
pub fn new(dev: &str) -> Result<Self, String> {
|
||||||
let spi = SpiHwAdapterDev::new(dev).map_err(|err| err.to_string())?;
|
let spi = SpiHwAdapterDev::new(dev).map_err(|err| err.to_string())?;
|
||||||
let spi = Box::from(spi);
|
let spi = Box::from(spi);
|
||||||
let gen = WS28xxGenAdapter::new(spi);
|
let gen = Ws28xxGenAdapter::new(spi);
|
||||||
Ok(Self { gen })
|
Ok(Self { gen })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WS28xxAdapter for WS28xxSpiAdapter {
|
impl Ws28xxAdapter for Ws28xxSpiAdapter {
|
||||||
fn get_hw_dev(&mut self) -> &mut Box<dyn HardwareDev> {
|
fn get_hw_dev(&mut self) -> &mut Box<dyn HardwareDev> {
|
||||||
// forward to generic adapter
|
// forward to generic adapter
|
||||||
// todo this is not the best code design because this requires
|
// todo this is not the best code design because this requires
|
||||||
|
@ -5,8 +5,8 @@ use std::ops::Add;
|
|||||||
use std::process;
|
use std::process;
|
||||||
use std::sync::mpsc::Receiver;
|
use std::sync::mpsc::Receiver;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use ws2818_rgb_led_spi_driver::adapter_gen::WS28xxAdapter;
|
use ws2818_rgb_led_spi_driver::adapter_gen::Ws28xxAdapter;
|
||||||
use ws2818_rgb_led_spi_driver::adapter_spi::WS28xxSpiAdapter;
|
use ws2818_rgb_led_spi_driver::adapter_spi::Ws28xxSpiAdapter;
|
||||||
|
|
||||||
/// Maximum number of lights allowed
|
/// Maximum number of lights allowed
|
||||||
const MAX_NUM_LIGHTS: u16 = 128;
|
const MAX_NUM_LIGHTS: u16 = 128;
|
||||||
@ -37,7 +37,7 @@ pub enum Message {
|
|||||||
|
|
||||||
#[allow(clippy::module_name_repetitions)]
|
#[allow(clippy::module_name_repetitions)]
|
||||||
pub struct LEDStrip {
|
pub struct LEDStrip {
|
||||||
pub adapter: Box<dyn WS28xxAdapter>,
|
pub adapter: Box<dyn Ws28xxAdapter>,
|
||||||
pub config: Config,
|
pub config: Config,
|
||||||
pub pattern: Box<dyn Pattern>,
|
pub pattern: Box<dyn Pattern>,
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ pub struct LEDStrip {
|
|||||||
impl LEDStrip {
|
impl LEDStrip {
|
||||||
pub fn new(config: Config) -> Self {
|
pub fn new(config: Config) -> Self {
|
||||||
let adapter = Box::new(
|
let adapter = Box::new(
|
||||||
WS28xxSpiAdapter::new("/dev/spidev0.0").expect("Cannot locate device /dev/spidev0.0!"),
|
Ws28xxSpiAdapter::new("/dev/spidev0.0").expect("Cannot locate device /dev/spidev0.0!"),
|
||||||
);
|
);
|
||||||
let pattern = Box::new(pattern::Solid::new(color::BLACK));
|
let pattern = Box::new(pattern::Solid::new(color::BLACK));
|
||||||
let num_lights = config.num_lights;
|
let num_lights = config.num_lights;
|
||||||
|
Loading…
Reference in New Issue
Block a user