summaryrefslogtreecommitdiffstats
path: root/pressure_control/firmware/valves.c
diff options
context:
space:
mode:
Diffstat (limited to 'pressure_control/firmware/valves.c')
-rw-r--r--pressure_control/firmware/valves.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/pressure_control/firmware/valves.c b/pressure_control/firmware/valves.c
index 75d4606..86ea85b 100644
--- a/pressure_control/firmware/valves.c
+++ b/pressure_control/firmware/valves.c
@@ -20,6 +20,7 @@
#include "valves.h"
#include "util.h"
+#include "main.h"
#include <avr/io.h>
@@ -34,6 +35,8 @@
static uint8_t current_global_state = 0xFF;
+static bool need_switch_to_idle;
+static jiffies_t switch_to_idle_time;
void valve0_switch(uint8_t state)
@@ -56,7 +59,6 @@ void valve1_switch(uint8_t state)
void valves_global_switch(uint8_t state)
{
-
if (state == current_global_state)
return;
current_global_state = state;
@@ -65,9 +67,6 @@ void valves_global_switch(uint8_t state)
case VALVES_IDLE:
valve0_switch(VALVE_STATE_12);
valve1_switch(VALVE_STATE_12);
- valve_wait_toggle();
- valve0_switch(VALVE_STATE_IDLE);
- valve1_switch(VALVE_STATE_IDLE);
break;
case VALVES_FLOW_IN:
valve1_switch(VALVE_STATE_12);
@@ -78,6 +77,18 @@ void valves_global_switch(uint8_t state)
valve1_switch(VALVE_STATE_14);
break;
}
+ switch_to_idle_time = get_jiffies() + msec_to_jiffies(VALVE_TOGGLE_MSEC);
+ need_switch_to_idle = 1;
+}
+
+void valves_work(void)
+{
+ if (need_switch_to_idle &&
+ time_after(get_jiffies(), switch_to_idle_time)) {
+ need_switch_to_idle = 0;
+ valve0_switch(VALVE_STATE_IDLE);
+ valve1_switch(VALVE_STATE_IDLE);
+ }
}
uint8_t valves_get_global_state(void)
@@ -101,7 +112,11 @@ void valves_shutdown(void)
void valves_emergency_state(void)
{
- valves_init();
+ valves_ddr_setup();
+ valves_global_switch(VALVES_IDLE);
+ valve_wait_toggle();
+ valve0_switch(VALVE_STATE_IDLE);
+ valve1_switch(VALVE_STATE_IDLE);
}
void valves_init(void)
bues.ch cgit interface