improve WaitType blink_pattern selection (code readability)
This commit is contained in:
		@@ -62,6 +62,17 @@ enum WaitType {
 | 
			
		||||
    MqttConfig,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl WaitType {
 | 
			
		||||
    fn blink_pattern(&self) -> u32 {
 | 
			
		||||
        match self {
 | 
			
		||||
            WaitType::MissingConfig => 500_u32,
 | 
			
		||||
            WaitType::ConfigButton => 100_u32,
 | 
			
		||||
            WaitType::MqttConfig => 200_u32,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
 | 
			
		||||
/// Light State tracking data for mqtt
 | 
			
		||||
struct LightState {
 | 
			
		||||
@@ -917,15 +928,12 @@ fn update_plant_state(
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn wait_infinity(wait_type: WaitType, reboot_now: Arc<AtomicBool>) -> ! {
 | 
			
		||||
    let delay = match wait_type {
 | 
			
		||||
        WaitType::MissingConfig => 500_u32,
 | 
			
		||||
        WaitType::ConfigButton => 100_u32,
 | 
			
		||||
        WaitType::MqttConfig => 200_u32,
 | 
			
		||||
    };
 | 
			
		||||
    let delay = wait_type.blink_pattern();
 | 
			
		||||
 | 
			
		||||
    let mut led_count = 8;
 | 
			
		||||
    loop {
 | 
			
		||||
        if wait_type == WaitType::MissingConfig {
 | 
			
		||||
            led_count = led_count + 1;
 | 
			
		||||
            led_count += 1;
 | 
			
		||||
            if led_count > 8 {
 | 
			
		||||
                led_count = 1;
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user