summaryrefslogtreecommitdiffstats
path: root/pressure_control/firmware
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2008-10-23 19:37:14 +0200
committerMichael Buesch <mb@bu3sch.de>2008-10-23 19:37:14 +0200
commit55e576638e744b34021de662f0e8f4d9f5bbf6fd (patch)
tree4f64674ff5ed84510d25b9abda23b8daf0dc91ca /pressure_control/firmware
parent89b80bc2ae9a06f029beea7f62bae11b274de3e9 (diff)
downloadcnc-55e576638e744b34021de662f0e8f4d9f5bbf6fd.tar.xz
cnc-55e576638e744b34021de662f0e8f4d9f5bbf6fd.zip
pressure_control: Add manual valve switching.
Signed-off-by: Michael Buesch <mb@bu3sch.de>
Diffstat (limited to 'pressure_control/firmware')
-rw-r--r--pressure_control/firmware/Makefile2
-rw-r--r--pressure_control/firmware/remote.c29
-rw-r--r--pressure_control/firmware/remote.h2
-rw-r--r--pressure_control/firmware/valves.c10
-rw-r--r--pressure_control/firmware/valves.h12
5 files changed, 44 insertions, 11 deletions
diff --git a/pressure_control/firmware/Makefile b/pressure_control/firmware/Makefile
index a725d24..f59f2b4 100644
--- a/pressure_control/firmware/Makefile
+++ b/pressure_control/firmware/Makefile
@@ -34,7 +34,7 @@ valves.o: util.h valves.h
sensor.o: util.h sensor.h
-remote.o: util.h remote.h calibration.h main.h
+remote.o: util.h remote.h calibration.h main.h valves.h
%.s: %.c
$(CC) $(CFLAGS) -S $*.c
diff --git a/pressure_control/firmware/remote.c b/pressure_control/firmware/remote.c
index 78f0255..97f72df 100644
--- a/pressure_control/firmware/remote.c
+++ b/pressure_control/firmware/remote.c
@@ -22,6 +22,7 @@
#include "util.h"
#include "calibration.h"
#include "main.h"
+#include "valves.h"
#include <string.h>
@@ -170,14 +171,40 @@ static void handle_received_message(void)
}
case MSG_SET_CONFIG_FLAGS: {
struct pressure_config conf;
+ bool flag;
cli();
get_pressure_config(&conf);
- conf.autoadjust_enable = !!(rx_msg.config.flags & (1 << CFG_FLAG_AUTOADJUST_ENABLE));
+ flag = !!(rx_msg.config.flags & (1 << CFG_FLAG_AUTOADJUST_ENABLE));
+ if (conf.autoadjust_enable != flag) {
+ conf.autoadjust_enable = flag;
+ /* Make sure the values are idle. */
+ valves_global_switch(VALVES_IDLE);
+ }
set_pressure_config(&conf);
sei();
break;
}
+ case MSG_SET_VALVE: {
+ struct pressure_config conf;
+
+ get_pressure_config(&conf);
+ if (conf.autoadjust_enable) {
+ err = MSG_ERR_BUSY;
+ break;
+ }
+ if (rx_msg.valve.nr == 0) {
+ valve0_switch(rx_msg.valve.state == 0 ?
+ VALVE_STATE_12 : VALVE_STATE_14);
+ } else if (rx_msg.valve.nr == 1) {
+ valve1_switch(rx_msg.valve.state == 0 ?
+ VALVE_STATE_12 : VALVE_STATE_14);
+ } else
+ err = MSG_ERR_INVAL;
+ break;
+ }
+ case MSG_INVALID:
+ break;
default:
err = MSG_ERR_NOCMD;
break;
diff --git a/pressure_control/firmware/remote.h b/pressure_control/firmware/remote.h
index 5270407..ad67540 100644
--- a/pressure_control/firmware/remote.h
+++ b/pressure_control/firmware/remote.h
@@ -30,6 +30,8 @@ enum remote_message_error {
MSG_ERR_NONE = 0, /* No error */
MSG_ERR_CHKSUM, /* Checksum error */
MSG_ERR_NOCMD, /* Unknown command */
+ MSG_ERR_BUSY, /* Busy */
+ MSG_ERR_INVAL, /* Invalid argument */
};
enum remote_message_flags {
diff --git a/pressure_control/firmware/valves.c b/pressure_control/firmware/valves.c
index f77d8b2..70a2b6a 100644
--- a/pressure_control/firmware/valves.c
+++ b/pressure_control/firmware/valves.c
@@ -31,14 +31,8 @@
#define VALVE1_14 6 /* Pin for valve-1 position 14 */
#define VALVE1_12 7 /* Pin for valve-1 position 12 */
-/* State for one valve. */
-enum valve_state {
- VALVE_STATE_12,
- VALVE_STATE_14,
-};
-
-static void valve0_switch(uint8_t state)
+void valve0_switch(uint8_t state)
{
VALVE_PORT &= ~((1 << VALVE0_12) | (1 << VALVE0_14));
if (state == VALVE_STATE_12)
@@ -47,7 +41,7 @@ static void valve0_switch(uint8_t state)
VALVE_PORT |= (1 << VALVE0_14);
}
-static void valve1_switch(uint8_t state)
+void valve1_switch(uint8_t state)
{
VALVE_PORT &= ~((1 << VALVE1_12) | (1 << VALVE1_14));
if (state == VALVE_STATE_12)
diff --git a/pressure_control/firmware/valves.h b/pressure_control/firmware/valves.h
index 0f51a49..e7a5e74 100644
--- a/pressure_control/firmware/valves.h
+++ b/pressure_control/firmware/valves.h
@@ -4,13 +4,23 @@
#include <stdint.h>
+/* Global valves state */
enum valves_global_state {
VALVES_IDLE,
VALVES_FLOW_IN,
VALVES_FLOW_OUT,
};
+/* State for one valve. */
+enum valve_state {
+ VALVE_STATE_12,
+ VALVE_STATE_14,
+};
+
void valves_init(void);
-void valves_global_switch(uint8_t state);
+void valves_global_switch(uint8_t global_state);
+
+void valve0_switch(uint8_t state);
+void valve1_switch(uint8_t state);
#endif /* VALVES_H_ */
bues.ch cgit interface