added led_state to LedButton
This commit is contained in:
parent
3bb23b50ff
commit
2cf404da0b
21
src/lib.rs
21
src/lib.rs
@ -26,13 +26,16 @@ pub enum PullConfig {
|
||||
/// Represents a button with built in led.
|
||||
pub struct LedButton<OP, IP> {
|
||||
/// the pin from mcu to LED
|
||||
pub led : StatefulLed<OP>,
|
||||
pub led : StatefulLed<OP>,
|
||||
|
||||
/// the pin from mcu to button
|
||||
pub button : StatefulButton<IP>,
|
||||
pub button : StatefulButton<IP>,
|
||||
|
||||
/// the state of the button, always initialised to NotPressed.
|
||||
pub state : ButtonState
|
||||
pub state : ButtonState,
|
||||
|
||||
/// the state of the led, always initialised to Off.
|
||||
pub led_state : LedState
|
||||
}
|
||||
|
||||
impl<OP: OutputPin, IP: InputPin> LedButton<OP, IP> {
|
||||
@ -64,17 +67,13 @@ impl<OP: OutputPin, IP: InputPin> LedButton<OP, IP> {
|
||||
///
|
||||
pub fn create(led_pin: OP, led_state: LedState, led_pullconf: PullConfig, button_pin: IP, button_config: ButtonConfig, fn_refresh: f32 ) -> Self {
|
||||
Self {
|
||||
led : StatefulLed::create(led_pin, led_pullconf, led_state),
|
||||
button : StatefulButton::create(button_pin, button_config, fn_refresh),
|
||||
state : ButtonState::NotPressed
|
||||
led : StatefulLed::create(led_pin, led_pullconf, led_state),
|
||||
button : StatefulButton::create(button_pin, button_config, fn_refresh),
|
||||
state : ButtonState::NotPressed,
|
||||
led_state : LedState::Off
|
||||
}
|
||||
}
|
||||
|
||||
/// get the current state of the LED.
|
||||
pub fn led_state(self) -> LedState {
|
||||
self.led.current_state
|
||||
}
|
||||
|
||||
/// set the LED to "On"-state.
|
||||
pub fn on(&mut self) {
|
||||
let _ = self.led.on();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user