From 427335c5264794d980623f0aa308d6e0b3ff0042 Mon Sep 17 00:00:00 2001 From: Michael Buesch Date: Fri, 29 May 2009 17:55:31 +0200 Subject: pressure-control: Fix APIs for multiple sensors Signed-off-by: Michael Buesch --- pressure_control/firmware/main.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'pressure_control/firmware/main.c') diff --git a/pressure_control/firmware/main.c b/pressure_control/firmware/main.c index 01933ce..ec2335d 100644 --- a/pressure_control/firmware/main.c +++ b/pressure_control/firmware/main.c @@ -1,7 +1,7 @@ /* * Pneumatic pressure controller. * - * Copyright (C) 2008 Michael Buesch + * Copyright (C) 2008-2009 Michael Buesch * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,6 +43,11 @@ struct pressure_state state; /* The 1000Hz jiffies counter */ static jiffies_t jiffies_counter; +DEFINE_VALVE(xy_control_valves, D, 6, 7, 4, 5); +DEFINE_VALVE(z_control_valves, C, 2, 3, 4, 5); +static DEFINE_SENSOR(xy_control_sensor, 0, 245, 4400, 10000); +static DEFINE_SENSOR(z_control_sensor, (1<= 0); - cur_state = valves_get_global_state(); + cur_state = valves_get_global_state(&xy_control_valves); if (abs_offset > cfg.hysteresis) { /* Adjust the pressure */ report_change = (cur_state == VALVES_IDLE); if (is_too_big) - valves_global_switch(VALVES_FLOW_OUT); + valves_global_switch(&xy_control_valves, VALVES_FLOW_OUT); else - valves_global_switch(VALVES_FLOW_IN); + valves_global_switch(&xy_control_valves, VALVES_FLOW_IN); } else if (abs_offset > cfg.hysteresis / 4) { /* If we're idle, stay idle. * If we're increasing or decreasing pressure, @@ -167,15 +172,16 @@ static void check_pressure(void) * The pressure is OK. Make sure the valves are * all idle. */ report_change = (cur_state != VALVES_IDLE); - valves_global_switch(VALVES_IDLE); + valves_global_switch(&xy_control_valves, VALVES_IDLE); } if (state.mbar < 800) { /* If the pressure in the reservoir is low, * the feedforward of the pneumatic valve for * flow-out might not work correctly. So force poke * the valves again until we reach a good pressure. */ - __valves_global_switch(valves_get_global_state()); - valves_disarm_auto_idle(); + __valves_global_switch(&xy_control_valves, + valves_get_global_state(&xy_control_valves)); + valves_disarm_auto_idle(&xy_control_valves); } } if (abs((int32_t)state.mbar - (int32_t)state.reported_mbar) >= 100) @@ -220,7 +226,7 @@ int main(void) wdt_disable(); if (mcucsr & (1 << BORF)) { /* If we have a brownout, try to enter valve emergency state. */ - valves_emergency_state(); + valves_emergency_state(&xy_control_valves); mdelay(500); /* This wasn't a real brownout, if we're still alife. * Go on with initialization. */ @@ -236,8 +242,8 @@ int main(void) if (!(mcucsr & (1 << PORF)) && (mcucsr & (1 << WDRF))) print("WATCHDOG RESET!\n"); - valves_init(); - sensor_init(); + valves_init(&xy_control_valves); + sensor_init(&xy_control_sensor); eeprom_load_config(); system_timer_init(); @@ -246,7 +252,7 @@ int main(void) print("Monitoring...\n"); remote_work(); remote_notify_restart(); - sensor_trigger_read(); + sensor_trigger_read(&xy_control_sensor); while (1) { static jiffies_t next_sensor_trigger; static bool need_sensor_trigger; @@ -269,10 +275,10 @@ int main(void) /* It's time for triggering another * sensor measurement. */ need_sensor_trigger = 0; - sensor_trigger_read(); + sensor_trigger_read(&xy_control_sensor); } remote_work(); - valves_work(); + valves_work(&xy_control_valves); wdt_reset(); } } -- cgit v1.2.3