1
+ use crate :: etc_config:: EtcConfig ;
1
2
use anyhow:: { Error , Result } ;
2
3
use log:: info;
3
4
use rppal:: gpio:: { Gpio , Level , OutputPin } ;
@@ -21,12 +22,13 @@ pub enum LedState {
21
22
}
22
23
23
24
pub struct Led {
25
+ etc_config : EtcConfig ,
24
26
rx : mpsc:: Receiver < LedState > ,
25
27
}
26
28
27
29
impl Led {
28
- pub fn new ( rx : mpsc:: Receiver < LedState > ) -> Self {
29
- Self { rx }
30
+ pub fn new ( etc_config : EtcConfig , rx : mpsc:: Receiver < LedState > ) -> Self {
31
+ Self { etc_config , rx }
30
32
}
31
33
32
34
async fn process (
@@ -89,7 +91,7 @@ impl IntoSubsystem<Error> for Led {
89
91
90
92
subsys. start (
91
93
"InternalLed" ,
92
- InternalLed :: new ( internal_rx) . into_subsystem ( ) ,
94
+ InternalLed :: new ( self . etc_config . clone ( ) , internal_rx) . into_subsystem ( ) ,
93
95
) ;
94
96
95
97
tokio:: select! {
@@ -104,6 +106,7 @@ impl IntoSubsystem<Error> for Led {
104
106
}
105
107
106
108
struct InternalLed {
109
+ etc_config : EtcConfig ,
107
110
rx : mpsc:: Receiver < InternalLedState > ,
108
111
}
109
112
@@ -113,13 +116,9 @@ enum InternalLedState {
113
116
Off ,
114
117
}
115
118
116
- const GPIO_RED : u8 = 16 ;
117
- const GPIO_GREEN : u8 = 20 ;
118
- const GPIO_BLUE : u8 = 26 ;
119
-
120
119
impl InternalLed {
121
- pub fn new ( rx : mpsc:: Receiver < InternalLedState > ) -> Self {
122
- Self { rx }
120
+ pub fn new ( etc_config : EtcConfig , rx : mpsc:: Receiver < InternalLedState > ) -> Self {
121
+ Self { etc_config , rx }
123
122
}
124
123
125
124
async fn process (
@@ -151,9 +150,9 @@ impl InternalLed {
151
150
impl IntoSubsystem < Error > for InternalLed {
152
151
async fn run ( mut self , subsys : SubsystemHandle ) -> Result < ( ) > {
153
152
let gpio = Gpio :: new ( ) ?;
154
- let mut red_pin = gpio. get ( GPIO_RED ) ?. into_output_low ( ) ;
155
- let mut green_pin = gpio. get ( GPIO_GREEN ) ?. into_output_low ( ) ;
156
- let mut blue_pin = gpio. get ( GPIO_BLUE ) ?. into_output_low ( ) ;
153
+ let mut red_pin = gpio. get ( self . etc_config . gpio . red_led ) ?. into_output_low ( ) ;
154
+ let mut green_pin = gpio. get ( self . etc_config . gpio . green_led ) ?. into_output_low ( ) ;
155
+ let mut blue_pin = gpio. get ( self . etc_config . gpio . blue_led ) ?. into_output_low ( ) ;
157
156
158
157
tokio:: select! {
159
158
_ = subsys. on_shutdown_requested( ) => {
0 commit comments