From 413a1e8070b71e2373aec5031a5bf7f6cf4d349c Mon Sep 17 00:00:00 2001 From: "Jack Gabriel C. Acodili" <112671361+acodili-jg@users.noreply.github.com> Date: Sun, 12 May 2024 21:46:52 +0800 Subject: [PATCH] Input hatch lock might be a dc motor --- diagram.json | 382 +++++++++++++++++++++++++++----------------------- src/sketch.rs | 115 +++++++++++---- src/state.rs | 1 + 3 files changed, 295 insertions(+), 203 deletions(-) diff --git a/diagram.json b/diagram.json index 5bc2e93..a6936d9 100644 --- a/diagram.json +++ b/diagram.json @@ -23,7 +23,7 @@ "type": "wokwi-pushbutton-6mm", "id": "start-btn", "top": 87.7, - "left": 170.1, + "left": 304.5, "rotate": 270, "attrs": { "color": "green", @@ -34,18 +34,28 @@ "type": "wokwi-pushbutton-6mm", "id": "stop-btn", "top": 87.7, - "left": 141.3, + "left": 275.7, "rotate": 270, "attrs": { "color": "red", "key": "Backspace" } }, + { + "type": "wokwi-led", + "id": "ready-led", + "top": 44.4, + "left": 243.8, + "attrs": { + "label": "rdy", + "color": "green" + } + }, { "type": "wokwi-led", "id": "blender-led", "top": 44.4, - "left": 301.4, + "left": 224.6, "attrs": { "label": "bdr", "color": "red" @@ -55,7 +65,7 @@ "type": "wokwi-led", "id": "heater-led", "top": 44.4, - "left": 282.2, + "left": 205.4, "attrs": { "label": "htr", "color": "orange" @@ -65,7 +75,7 @@ "type": "wokwi-led", "id": "mixer-led", "top": 44.4, - "left": 263, + "left": 186.2, "attrs": { "label": "mxr", "color": "white" @@ -73,19 +83,19 @@ }, { "type": "wokwi-led", - "id": "lower-drain-pump-led", + "id": "separator-hatch-enable-led", "top": 44.4, - "left": 224.6, + "left": 167, "attrs": { - "label": "ldp", - "color": "gray" + "label": "she", + "color": "yellow" } }, { "type": "wokwi-led", "id": "separator-hatch-direction-led", "top": 44.4, - "left": 205.4, + "left": 147.8, "attrs": { "label": "shd", "color": "yellow" @@ -93,51 +103,52 @@ }, { "type": "wokwi-led", - "id": "separator-hatch-enable-led", + "id": "input-hatch-lock-direction-led", "top": 44.4, - "left": 186.2, + "left": 128.6, "attrs": { - "label": "she", - "color": "yellow" + "label": "ild", + "color": "purple" } }, { "type": "wokwi-led", - "id": "ready-led", + "id": "input-hatch-lock-enable-led", "top": 44.4, "left": 109.4, "attrs": { - "label": "rdy", - "color": "green" + "label": "ile", + "color": "purple" } }, { "type": "wokwi-led", - "id": "upper-drain-pump-led", + "id": "water-pump-led", "top": 44.4, "left": 90.2, "attrs": { - "label": "udp", - "color": "gray" + "label": "wtr", + "color": "blue" } }, { "type": "wokwi-led", - "id": "water-pump-led", + "id": "lower-drain-pump-led", "top": 44.4, "left": 71, "attrs": { - "label": "wtr", - "color": "blue" + "label": "ldp", + "color": "gray" } }, { "type": "wokwi-led", - "id": "d12-led", + "id": "upper-drain-pump-led", "top": 44.4, "left": 51.8, "attrs": { - "color": "brown" + "label": "udp", + "color": "gray" } }, { @@ -149,16 +160,6 @@ "label": "test", "color": "brown" } - }, - { - "type": "wokwi-led", - "id": "led4", - "top": 44.4, - "left": 243.8, - "attrs": { - "label": "ihl", - "color": "purple" - } } ], "connections": [ @@ -172,119 +173,187 @@ ] ], [ - "bb1:tn.2", + "bb1:tn.3", "bb1:3t.a", "black", [ - "v0" + "v-0.1", + "h-8" ] ], [ - "bb1:tn.4", + "bb1:tn.5", "bb1:5t.a", "black", [ - "v0" + "v-0.1", + "h-8" ] ], [ - "bb1:7t.a", "bb1:tn.6", + "bb1:7t.a", "black", [ - "v0" + "v-0.1", + "h-8" ] ], [ + "bb1:tn.8", "bb1:9t.a", - "bb1:tn.7", "black", [ - "v0" + "v-0.1", + "h-8" ] ], [ - "bb1:25t.a", - "bb1:tn.21", + "bb1:tn.10", + "bb1:11t.a", "black", [ - "v0" + "v-0.1", + "h-8" ] ], [ - "bb1:27t.a", - "bb1:tn.22", + "bb1:tn.11", + "bb1:13t.a", "black", [ - "v0" + "v-0.1", + "h-8" + ] + ], + [ + "bb1:tn.13", + "bb1:15t.a", + "black", + [ + "v-0.1", + "h-8" + ] + ], + [ + "bb1:tn.15", + "bb1:17t.a", + "black", + [ + "v-0.1", + "h-8" + ] + ], + [ + "bb1:tn.16", + "bb1:19t.a", + "black", + [ + "v-0.1", + "h-8" + ] + ], + [ + "bb1:tn.18", + "bb1:21t.a", + "black", + [ + "v-0.1", + "h-8" + ] + ], + [ + "bb1:tn.20", + "bb1:23t.a", + "black", + [ + "v-0.1", + "h-8" + ] + ], + [ + "bb1:tn.21", + "bb1:25t.a", + "black", + [ + "v-0.1", + "h-8" ] ], [ - "bb1:29t.a", "bb1:tn.24", + "bb1:28t.a", "black", [ - "v0" + "v-0.1", + "h-8" + ] + ], + [ + "uno:0", + "bb1:27b.j", + "red", + [ + "v-28.8", + "h52.2" ] ], [ "uno:1", - "bb1:28t.a", - "orange", + "bb1:30b.j", + "green", [ - "v-19.2", - "h129", - "v-240", - "h-67.2" + "v-28.8", + "h71.5" ] ], [ "uno:2", - "bb1:26t.a", - "white", + "bb1:24t.a", + "green", [ "v-19.2", "h138.5", "v-240", - "h-86.4" + "h-105.6" ] ], [ "uno:3", - "bb1:24t.a", - "purple", + "bb1:22t.a", + "red", [ "v-19.2", "h148", "v-240", - "h-105.6" + "h-124.8" ] ], [ "uno:4", - "bb1:22t.a", - "gray", + "bb1:20t.a", + "orange", [ "v-19.2", "h157.5", "v-240", - "h-124.8" + "h-144" ] ], [ "uno:5", - "bb1:20t.a", - "gold", + "bb1:18t.a", + "white", [ "v-19.2", "h167", "v-240", - "h-144" + "h-163.2" ] ], [ "uno:6", - "bb1:18t.a", + "bb1:16t.a", "gold", [ "v-19.2", @@ -295,25 +364,30 @@ ], [ "uno:7", - "bb1:16b.j", - "green", + "bb1:14t.a", + "gold", [ - "v-19.2" + "v-19.2", + "h186", + "v-240", + "h-201.6" ] ], [ "uno:8", - "bb1:11b.j", - "red", + "bb1:12t.a", + "purple", [ "v-19.2", - "h-28.4" + "h202", + "v-240", + "h-220.8" ] ], [ "uno:9", "bb1:10t.a", - "green", + "purple", [ "v-19.2", "h212", @@ -324,7 +398,7 @@ [ "uno:10", "bb1:8t.a", - "gray", + "blue", [ "v-19.2", "h221.5", @@ -335,7 +409,7 @@ [ "uno:11", "bb1:6t.a", - "blue", + "gray", [ "v-19.2", "h231", @@ -346,12 +420,12 @@ [ "uno:12", "bb1:4t.a", - "brown", + "gray", [ "v-19.2", "h240.5", "v-240", - "h-297.6" + "h-259.2" ] ], [ @@ -405,59 +479,9 @@ "v-315.9" ] ], - [ - "bb1:tn.19", - "bb1:23t.a", - "black", - [ - "v0" - ] - ], - [ - "bb1:tn.10", - "bb1:13t.a", - "black", - [ - "v-0.1", - "h11.2" - ] - ], - [ - "bb1:tn.11", - "bb1:14t.a", - "black", - [ - "v0" - ] - ], - [ - "bb1:tn.14", - "bb1:17t.a", - "black", - [ - "v0" - ] - ], - [ - "bb1:tn.16", - "bb1:19t.a", - "black", - [ - "v-0.1", - "h-8" - ] - ], - [ - "bb1:tn.17", - "bb1:21t.a", - "black", - [ - "v0" - ] - ], [ "start-btn:1.l", - "bb1:14b.f", + "bb1:28b.f", "", [ "$bb" @@ -465,7 +489,7 @@ ], [ "start-btn:2.l", - "bb1:16b.f", + "bb1:30b.f", "", [ "$bb" @@ -473,7 +497,7 @@ ], [ "start-btn:1.r", - "bb1:14t.e", + "bb1:28t.e", "", [ "$bb" @@ -481,7 +505,7 @@ ], [ "start-btn:2.r", - "bb1:16t.e", + "bb1:30t.e", "", [ "$bb" @@ -489,7 +513,7 @@ ], [ "stop-btn:1.l", - "bb1:11b.f", + "bb1:25b.f", "", [ "$bb" @@ -497,7 +521,7 @@ ], [ "stop-btn:2.l", - "bb1:13b.f", + "bb1:27b.f", "", [ "$bb" @@ -505,7 +529,7 @@ ], [ "stop-btn:1.r", - "bb1:11t.e", + "bb1:25t.e", "", [ "$bb" @@ -513,7 +537,23 @@ ], [ "stop-btn:2.r", - "bb1:13t.e", + "bb1:27t.e", + "", + [ + "$bb" + ] + ], + [ + "ready-led:A", + "bb1:24t.e", + "", + [ + "$bb" + ] + ], + [ + "ready-led:C", + "bb1:23t.e", "", [ "$bb" @@ -521,7 +561,7 @@ ], [ "blender-led:A", - "bb1:30t.e", + "bb1:22t.e", "", [ "$bb" @@ -529,7 +569,7 @@ ], [ "blender-led:C", - "bb1:29t.e", + "bb1:21t.e", "", [ "$bb" @@ -537,7 +577,7 @@ ], [ "heater-led:A", - "bb1:28t.e", + "bb1:20t.e", "", [ "$bb" @@ -545,7 +585,7 @@ ], [ "heater-led:C", - "bb1:27t.e", + "bb1:19t.e", "", [ "$bb" @@ -553,7 +593,7 @@ ], [ "mixer-led:A", - "bb1:26t.e", + "bb1:18t.e", "", [ "$bb" @@ -561,23 +601,23 @@ ], [ "mixer-led:C", - "bb1:25t.e", + "bb1:17t.e", "", [ "$bb" ] ], [ - "lower-drain-pump-led:A", - "bb1:22t.e", + "separator-hatch-enable-led:A", + "bb1:16t.e", "", [ "$bb" ] ], [ - "lower-drain-pump-led:C", - "bb1:21t.e", + "separator-hatch-enable-led:C", + "bb1:15t.e", "", [ "$bb" @@ -585,7 +625,7 @@ ], [ "separator-hatch-direction-led:A", - "bb1:20t.e", + "bb1:14t.e", "", [ "$bb" @@ -593,30 +633,30 @@ ], [ "separator-hatch-direction-led:C", - "bb1:19t.e", + "bb1:13t.e", "", [ "$bb" ] ], [ - "separator-hatch-enable-led:A", - "bb1:18t.e", + "input-hatch-lock-direction-led:A", + "bb1:12t.e", "", [ "$bb" ] ], [ - "separator-hatch-enable-led:C", - "bb1:17t.e", + "input-hatch-lock-direction-led:C", + "bb1:11t.e", "", [ "$bb" ] ], [ - "ready-led:A", + "input-hatch-lock-enable-led:A", "bb1:10t.e", "", [ @@ -624,7 +664,7 @@ ] ], [ - "ready-led:C", + "input-hatch-lock-enable-led:C", "bb1:9t.e", "", [ @@ -632,7 +672,7 @@ ] ], [ - "upper-drain-pump-led:A", + "water-pump-led:A", "bb1:8t.e", "", [ @@ -640,7 +680,7 @@ ] ], [ - "upper-drain-pump-led:C", + "water-pump-led:C", "bb1:7t.e", "", [ @@ -648,7 +688,7 @@ ] ], [ - "water-pump-led:A", + "lower-drain-pump-led:A", "bb1:6t.e", "", [ @@ -656,7 +696,7 @@ ] ], [ - "water-pump-led:C", + "lower-drain-pump-led:C", "bb1:5t.e", "", [ @@ -664,7 +704,7 @@ ] ], [ - "d12-led:A", + "upper-drain-pump-led:A", "bb1:4t.e", "", [ @@ -672,29 +712,13 @@ ] ], [ - "d12-led:C", + "upper-drain-pump-led:C", "bb1:3t.e", "", [ "$bb" ] ], - [ - "led4:A", - "bb1:24t.e", - "", - [ - "$bb" - ] - ], - [ - "led4:C", - "bb1:23t.e", - "", - [ - "$bb" - ] - ], [ "d13-led:A", "bb1:2t.e", diff --git a/src/sketch.rs b/src/sketch.rs index 27e8e4d..dc1da43 100644 --- a/src/sketch.rs +++ b/src/sketch.rs @@ -1,7 +1,4 @@ -use arduino_hal::{ - hal::port::{PB0, PB1, PB2, PB3, PD0, PD1, PD2, PD3, PD4, PD5, PD6, PD7}, - port::mode::{Input, Output, PullUp}, -}; +use arduino_hal::port::mode::{Input, Output, PullUp}; use crate::{ duration, @@ -9,15 +6,78 @@ use crate::{ state::State, }; +macro_rules! pin_type { + (a0) => { + ::arduino_hal::hal::port::PC0 + }; + (a1) => { + ::arduino_hal::hal::port::PC1 + }; + (a2) => { + ::arduino_hal::hal::port::PC2 + }; + (a3) => { + ::arduino_hal::hal::port::PC3 + }; + (a4) => { + ::arduino_hal::hal::port::PC4 + }; + (a5) => { + ::arduino_hal::hal::port::PC5 + }; + (d0) => { + ::arduino_hal::hal::port::PD0 + }; + (d1) => { + ::arduino_hal::hal::port::PD1 + }; + (d2) => { + ::arduino_hal::hal::port::PD2 + }; + (d3) => { + ::arduino_hal::hal::port::PD3 + }; + (d4) => { + ::arduino_hal::hal::port::PD4 + }; + (d5) => { + ::arduino_hal::hal::port::PD5 + }; + (d6) => { + ::arduino_hal::hal::port::PD6 + }; + (d7) => { + ::arduino_hal::hal::port::PD7 + }; + (d8) => { + ::arduino_hal::hal::port::PB0 + }; + (d9) => { + ::arduino_hal::hal::port::PB1 + }; + (d10) => { + ::arduino_hal::hal::port::PB2 + }; + (d11) => { + ::arduino_hal::hal::port::PB3 + }; + (d12) => { + ::arduino_hal::hal::port::PB4 + }; + (d13) => { + ::arduino_hal::hal::port::PB5 + }; +} + macro_rules! decl_sketch { { - $($pin_field:ident : pin!( $mode:ty, $pin:ident : $pin_t:ty ) $({ $init:stmt })?),* $(,)? + $($pin_field:ident : pin!( $mode:ty, $pin:ident ) $({ $init:stmt })?),* $(,)? @ $($field:ident : $field_t:ty = $default:expr),* $(,)? } => { #[allow(dead_code, unused_variables)] pub struct Sketch { - $($pin_field : ::arduino_hal::port::Pin<$mode, $pin_t>,)* + $($pin_field : ::arduino_hal::port::Pin<$mode, pin_type!($pin)>,)* $($field : $field_t,)* } @@ -25,7 +85,7 @@ macro_rules! decl_sketch { #[allow(unused_mut, clippy::too_many_arguments)] #[must_use] pub fn new( - $(mut $pin_field : ::arduino_hal::port::Pin<$mode, $pin_t>,)* + $(mut $pin_field : ::arduino_hal::port::Pin<$mode, pin_type!($pin)>,)* ) -> Self { $($($init)?)* Sketch { @@ -47,18 +107,19 @@ macro_rules! decl_sketch { } decl_sketch! { - blender: pin!(Output, d0: PD0), - heater: pin!(Output, d1: PD1), - mixer: pin!(Output, d2: PD2), - input_hatch_lock: pin!(Output, d3: PD3), - lower_drain_pump: pin!(Output, d4: PD4) { lower_drain_pump.set_high() }, - separator_hatch_direction: pin!(Output, d5: PD5), - separator_hatch_enable: pin!(Output, d6: PD6), - start: pin!(Input, d7: PD7), - stop: pin!(Input, d8: PB0), - ready: pin!(Output, d9: PB1), - upper_drain_pump: pin!(Output, d10: PB2) { upper_drain_pump.set_high() }, - water_pump: pin!(Output, d11: PB3), + stop: pin!(Input, d0), + start: pin!(Input, d1), + ready: pin!(Output, d2), + blender: pin!(Output, d3), + heater: pin!(Output, d4), + mixer: pin!(Output, d5), + separator_hatch_enable: pin!(Output, d6), + separator_hatch_direction: pin!(Output, d7), + input_hatch_lock_direction: pin!(Output, d8), + input_hatch_lock_enable: pin!(Output, d9), + water_pump: pin!(Output, d10), + lower_drain_pump: pin!(Output, d11) { lower_drain_pump.set_high() }, + upper_drain_pump: pin!(Output, d12) { upper_drain_pump.set_high() }, @ state: State = State::default(), last_ms: Millis = millis(), @@ -98,22 +159,28 @@ impl Sketch { State::InitialIdling if self.start.is_high() => {} State::InitialIdling => { transition_to!(InitialLocking); - self.input_hatch_lock.set_high(); + self.input_hatch_lock_direction.set_low(); + self.input_hatch_lock_enable.set_high(); } State::InitialLocking if self.start.is_high() => { - transition_to!(InitialIdling); - self.input_hatch_lock.set_low(); + transition_to!(InitialUnlocking); + self.input_hatch_lock_direction.set_high(); } State::InitialLocking if delta_ms < duration::LOCKING => {} State::InitialLocking => { transition_to!(InitialSetupSeparatorOpening); - self.stopping = false; self.ready.set_low(); - self.separator_hatch_direction.set_low(); + self.input_hatch_lock_enable.set_low(); self.separator_hatch_enable.set_high(); } + State::InitialUnlocking if delta_ms < duration::LOCKING => {} + State::InitialUnlocking => { + transition_to!(InitialIdling); + self.input_hatch_lock_enable.set_low(); + } + State::InitialSetupSeparatorOpening if delta_ms < duration::SEPARATOR_TRANSITION => {} State::InitialSetupSeparatorOpening => { transition_to!(InitialSetupWaterPumping); diff --git a/src/state.rs b/src/state.rs index d285a0b..e0323ed 100644 --- a/src/state.rs +++ b/src/state.rs @@ -4,6 +4,7 @@ pub enum State { InitialDraining, InitialIdling, InitialLocking, + InitialUnlocking, InitialSetupSeparatorOpening, InitialSetupWaterPumping, InitialSetupSeparatorClosing,