Giter Site home page Giter Site logo

smart-leds's Introduction

Smart-leds

Use various addresable led like the ws2812 (neopixel) or apa102 (dotstar) in rust. As their protocol greatly differs and for some (like the ws2812) there are various methods, this crate doesn't implement any specific drivers by itself. It has to be coupled with a device driver that implements the smart-leds-trait, like the ws2812-spi, the ws2812-timer-delay or the apa102-spi drivers.

You can see some usage examples in the smart-leds-samples repo.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

smart-leds's People

Contributors

david-sawatzke avatar sajattack avatar cyril-marpaud avatar jounathaen avatar thezoq2 avatar rahix avatar

Stargazers

 avatar Alexander Kruzhkov avatar pujianquan avatar SpamixOfficial avatar  avatar Ada avatar cz avatar  avatar Baptiste Cluzel avatar Arne Christian Schmidt avatar  avatar Jeff Thorslund avatar ττ avatar  avatar Szczepan Cieślik avatar Billy Lindeman avatar Alek Miasnikov avatar Pavel Sadikov avatar Hashimoto Yoshiki avatar  avatar Samuel Pastva avatar YummyOreo avatar  avatar  avatar Piotr avatar Josué Figueroa avatar Adam Gausmann avatar Pradham K. avatar Scott Hyndman avatar Turbidsoul avatar tjallingt avatar NothingButYou avatar David Falkner avatar  avatar Hideaki Tai avatar Guillaume Revaillot avatar Kiran Shila avatar Ethan Zhang avatar Oasis-X avatar Blaž Rolih avatar Lucian Carata avatar  avatar Val Packett avatar Alexander Vysotsky avatar  avatar Lee Harrold avatar Alexander Krantz avatar  avatar Jordan Williams avatar Jay Sistar avatar Max avatar Igor Onyshchenko avatar Brian Vanderbusch avatar Jes Wolfe avatar Jean-Philippe Cugnet avatar Tim Docker avatar Jakob Klepp avatar Amy Keibler avatar Sergei Silnov avatar Mikey avatar Sightline avatar Antoine Petot avatar Stephen Onnen avatar Matt Westrik avatar Viktor Lazarev avatar Brian Dawn avatar Derrick Egersdörfer | CodeChap avatar Dylan Frankland avatar Daniel Pink avatar Yannick Bungers avatar Shahid Khan avatar Eric Clack avatar h h avatar Christoph Grabo avatar Nate Strandberg avatar Rust avatar  avatar  avatar Nils Van Zuijlen avatar Stephen Weeks avatar  avatar Iqbal Rifai avatar Ammar Faizi avatar Bradley Erickson avatar fudanchii avatar

Watchers

Jacob Rosenthal avatar James Cloos avatar  avatar  avatar  avatar  avatar

smart-leds's Issues

HSV to RGB conversion is wrong

Hi,

I think the HSV to RGB conversion is wrong. It also panics for hues above 190.

Testcode:

fn main() {
    for i in (0..=360).step_by(10) {
        let hsv_col = smart_leds::hsv::Hsv{hue: i, sat: 255, val: 255};
        println!("Hue: {} | {:?}", hsv_col.hue, smart_leds::hsv::hsv2rgb(hsv_col));
    }
}

Output:

Hue: 0 | RGB { r: 251, g: 0, b: 0 }
Hue: 10 | RGB { r: 211, g: 39, b: 0 }
Hue: 20 | RGB { r: 171, g: 79, b: 0 }
Hue: 30 | RGB { r: 131, g: 119, b: 0 }
Hue: 40 | RGB { r: 91, g: 159, b: 0 }
Hue: 50 | RGB { r: 51, g: 199, b: 0 }
Hue: 60 | RGB { r: 11, g: 239, b: 0 }
Hue: 70 | RGB { r: 23, g: 0, b: 227 }
Hue: 80 | RGB { r: 63, g: 0, b: 187 }
Hue: 90 | RGB { r: 103, g: 0, b: 147 }
Hue: 100 | RGB { r: 143, g: 0, b: 107 }
Hue: 110 | RGB { r: 183, g: 0, b: 67 }
Hue: 120 | RGB { r: 223, g: 0, b: 27 }
Hue: 130 | RGB { r: 0, g: 243, b: 7 }
Hue: 140 | RGB { r: 0, g: 203, b: 47 }
Hue: 150 | RGB { r: 0, g: 163, b: 87 }
Hue: 160 | RGB { r: 0, g: 123, b: 127 }
Hue: 170 | RGB { r: 0, g: 83, b: 167 }
Hue: 180 | RGB { r: 0, g: 43, b: 207 }
Hue: 190 | RGB { r: 0, g: 3, b: 247 }
thread 'main' panicked at 'internal error: entered unreachable code', /home/jonathan/.cargo/registry/src/github.com-1ecc6299db9ec823/smart-leds-0.2.0/src/hsv.rs:56:14
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

Depending on how you interpret the hue type (degree as u16 or 360°/255) the values should be:
Degree:

Hue: 0   | RGB { r: 255, g: 0  , b:   0}
Hue: 30  | RGB { r: 255, g: 127, b:   0}
Hue: 60  | RGB { r: 255, g: 255, b:   0}
Hue: 90  | RGB { r: 127, g: 255, b:   0}
Hue: 120 | RGB { r:   0, g: 255, b:   0}
Hue: 150 | RGB { r:   0, g: 255, b: 127}
Hue: 180 | RGB { r:   0, g: 255, b: 255}
Hue: 210 | RGB { r:   0, g: 127, b: 255}
Hue: 240 | RGB { r:   0, g: 0  , b: 255}
Hue: 270 | RGB { r: 127, g: 0  , b: 255}
Hue: 300 | RGB { r: 255, g: 0  , b: 255}
Hue: 330 | RGB { r: 255, g: 0  , b: 127}

Fraction:

Hue:  0  | RGB { r: 255, g: 0  , b:   0}
Hue:  21 | RGB { r: 255, g: 128, b:   0}
Hue:  42 | RGB { r: 255, g: 255, b:   0}
Hue:  63 | RGB { r: 128, g: 255, b:   0}
Hue:  85 | RGB { r:   0, g: 255, b:   0}
Hue: 106 | RGB { r:   0, g: 255, b: 128}
Hue: 127 | RGB { r:   0, g: 255, b: 255}
Hue: 148 | RGB { r:   0, g: 128, b: 255}
Hue: 170 | RGB { r:   0, g: 0  , b: 255}
Hue: 191 | RGB { r: 128, g: 0  , b: 255}
Hue: 212 | RGB { r: 256, g: 0  , b: 255}
Hue: 233 | RGB { r: 256, g: 0  , b: 128}

Make named colors Deserialize

Hello :)
First of all, thank you for smart-leds, it's very convenient !

I'm using it in an embedded project that sends commands to an LED strip over Wifi/MQTT. I thus need to deserialize colors. You can check out the ugly From impl that allows me to do so for now.

Would it be possible to implement what's needed to "natively" deserialize named-colors directly from you crate, rather than having to implement that manually ?

Thank you, have a nice day !

[traits] Support RGBW as well as alternate orderings of channels

I have been tinkering with an sk6812 light strip (with about 500 lights) and also with ways to correctly address that.

The smart-leds-traits crate does provide for an RGBW type. However, the types like Gamma and Brightness specify an RGBW constraint.

In addition, sk6812 pulse ordering is R -> G -> B -> (W) instead of G -> R -> B for the ws2812.

In thinking about ways to support 4 channel, as well as different orderings. What we need is specialization :) . Since we don't have that, the only thing I can think of is to make traits that supply an iterator of iterators of values.

My thought is that we introduce a new trait called Channel which was just an iterator over ComponentType. So, effectively, we'd be supplying the "column" iterators, then the write/gamma/brightness functions would collect their set of iterators, and then poll each one, in order, as it is processing the colors.

One could also make a default implementation of the Color trait which produced a single iterator that just produces each ComponentType value, in order. So the existing implementations of write and friends don't have to change so much.

Thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.