summaryrefslogtreecommitdiffstats
path: root/pressure_control/firmware/valves.c
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2009-05-03 12:35:53 +0200
committerMichael Buesch <mb@bu3sch.de>2009-05-03 12:35:53 +0200
commitaa5604d118bc89e85c8230562080c034bfc9df17 (patch)
treeea99685ddc38ed4badad8fe6e17db162ffad6e01 /pressure_control/firmware/valves.c
parent44b0b0d80254064868c905b88826fda14010860c (diff)
downloadcnc-aa5604d118bc89e85c8230562080c034bfc9df17.tar.xz
cnc-aa5604d118bc89e85c8230562080c034bfc9df17.zip
pressure-control: Implement idle-release of valves through timer.
Signed-off-by: Michael Buesch <mb@bu3sch.de>
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