comparison rust/src/fridge.rs @ 635:4424a8b30f9c rust

config crate wants everything to be lower case
author Matt Johnston <matt@ucc.asn.au>
date Sun, 22 Sep 2019 22:06:46 +0800
parents a5721c02d3ee
children 43eb3cfdf769
comparison
equal deleted inserted replaced
634:a5721c02d3ee 635:4424a8b30f9c
59 type Msg = FridgeMsg; 59 type Msg = FridgeMsg;
60 fn receive(&mut self, 60 fn receive(&mut self,
61 ctx: &Context<Self::Msg>, 61 ctx: &Context<Self::Msg>,
62 r: Readings, 62 r: Readings,
63 _sender: Sender) { 63 _sender: Sender) {
64 self.temp_wort = r.get_temp(&self.config.WORT_NAME); 64 self.temp_wort = r.get_temp(&self.config.wort_name);
65 self.temp_fridge = r.get_temp(&self.config.FRIDGE_NAME); 65 self.temp_fridge = r.get_temp(&self.config.fridge_name);
66 66
67 if self.temp_wort.is_some() { 67 if self.temp_wort.is_some() {
68 self.wort_valid_time = Instant::now(); 68 self.wort_valid_time = Instant::now();
69 } 69 }
70 70
119 params: Params::defaults(), 119 params: Params::defaults(),
120 on: false, 120 on: false,
121 temp_wort: None, 121 temp_wort: None,
122 temp_fridge: None, 122 temp_fridge: None,
123 last_off_time: Instant::now(), 123 last_off_time: Instant::now(),
124 wort_valid_time: Instant::now() - Duration::new(config.FRIDGE_WORT_INVALID_TIME, 100), 124 wort_valid_time: Instant::now() - Duration::new(config.fridge_wort_invalid_time, 100),
125 integrator: StepIntegrator::new(Duration::new(1, 0)), 125 integrator: StepIntegrator::new(Duration::new(1, 0)),
126 control: Self::make_control(&config), 126 control: Self::make_control(&config),
127 }; 127 };
128 128
129 if nowait { 129 if nowait {
130 f.last_off_time -= Duration::new(config.FRIDGE_DELAY, 1); 130 f.last_off_time -= Duration::new(config.fridge_delay, 1);
131 } 131 }
132 132
133 f 133 f
134 } 134 }
135 135
136 #[cfg(target_os = "linux")] 136 #[cfg(target_os = "linux")]
137 fn make_control(config: &Config) -> FridgeControl { 137 fn make_control(config: &Config) -> FridgeControl {
138 let mut pin = Pin(config.FRIDGE_GPIO_PIN); 138 let mut pin = Pin(config.fridge_gpio_pin);
139 // XXX better error handling? 139 // XXX better error handling?
140 pin.export().expect("Exporting fridge gpio failed"); 140 pin.export().expect("Exporting fridge gpio failed");
141 pin.set_direction(Direction::Low).expect("Fridge gpio direction failed"); 141 pin.set_direction(Direction::Low).expect("Fridge gpio direction failed");
142 FridgeControl::Gpio(pin) 142 FridgeControl::Gpio(pin)
143 } 143 }
183 // Or elsewhere? 183 // Or elsewhere?
184 self.integrator.set_limit(Duration::new(self.params.overshoot_delay, 0)); 184 self.integrator.set_limit(Duration::new(self.params.overshoot_delay, 0));
185 185
186 // Safety to avoid bad things happening to the fridge motor (?) 186 // Safety to avoid bad things happening to the fridge motor (?)
187 // When it turns off don't start up again for at least FRIDGE_DELAY 187 // When it turns off don't start up again for at least FRIDGE_DELAY
188 if !self.on && off_time < Duration::new(self.config.FRIDGE_DELAY, 0) { 188 if !self.on && off_time < Duration::new(self.config.fridge_delay, 0) {
189 info!("fridge skipping, too early"); 189 info!("fridge skipping, too early");
190 return; 190 return;
191 } 191 }
192 192
193 if self.params.disabled { 193 if self.params.disabled {
200 200
201 // handle broken wort sensor 201 // handle broken wort sensor
202 if self.temp_wort.is_none() { 202 if self.temp_wort.is_none() {
203 let invalid_time = Instant::now() - self.wort_valid_time; 203 let invalid_time = Instant::now() - self.wort_valid_time;
204 warn!("Invalid wort sensor for {:?} secs", invalid_time); 204 warn!("Invalid wort sensor for {:?} secs", invalid_time);
205 if invalid_time < Duration::new(self.config.FRIDGE_WORT_INVALID_TIME, 0) { 205 if invalid_time < Duration::new(self.config.fridge_wort_invalid_time, 0) {
206 warn!("Has only been invalid for {:?}, waiting", invalid_time); 206 warn!("Has only been invalid for {:?}, waiting", invalid_time);
207 return; 207 return;
208 } 208 }
209 } 209 }
210 210