<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -38,6 +38,8 @@
 #define EXTRUDER_HEATER_PIN       6
 #define EXTRUDER_FAN_PIN          5
 #define EXTRUDER_THERMISTOR_PIN   0
+#define VALVE_DIR_PIN             15
+#define VALVE_ENABLE_PIN          16  //NB: Conflicts with Max Z!!!!
 
 // how many steps do our motors have?
 #define X_MOTOR_STEPS 400
@@ -54,7 +56,8 @@
 #include &lt;ThermoplastExtruder_SNAP_v1.h&gt;
 #include &lt;CartesianBot_SNAP_v1.h&gt;
 
-ThermoplastExtruder extruder(EXTRUDER_MOTOR_DIR_PIN, EXTRUDER_MOTOR_SPEED_PIN, EXTRUDER_HEATER_PIN, EXTRUDER_FAN_PIN, EXTRUDER_THERMISTOR_PIN);
+ThermoplastExtruder extruder(EXTRUDER_MOTOR_DIR_PIN, EXTRUDER_MOTOR_SPEED_PIN, EXTRUDER_HEATER_PIN, 
+  EXTRUDER_FAN_PIN, EXTRUDER_THERMISTOR_PIN, VALVE_DIR_PIN, VALVE_ENABLE_PIN);
 
 CartesianBot bot = CartesianBot(
 	'x', X_MOTOR_STEPS, X_DIR_PIN, X_STEP_PIN, X_MIN_PIN, X_MAX_PIN, X_ENABLE_PIN,</diff>
      <filename>Single_Arduino_SNAP/Single_Arduino_SNAP.pde</filename>
    </modified>
    <modified>
      <diff>@@ -36,9 +36,13 @@ bool LinearAxis::atMin()
 	return digitalRead(this-&gt;min_pin);
 }
 
+/*
+ * NB!!!  Turned off by Adrian to free up pins
+*/
 bool LinearAxis::atMax()
 {
-	return digitalRead(this-&gt;max_pin);
+	return 0;
+	//return digitalRead(this-&gt;max_pin);
 }
 
 void LinearAxis::doStep()</diff>
      <filename>library/LinearAxis/LinearAxis.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -11,10 +11,14 @@
 	motor_pwm_pin and heater_pin must be PWM capable outputs.
 	thermistor_pin must be an analog input.
 */
-ThermoplastExtruder::ThermoplastExtruder(byte motor_dir_pin, byte motor_pwm_pin, byte heater_pin, byte cooler_pin, byte thermistor_pin)
+ThermoplastExtruder::ThermoplastExtruder(byte motor_dir_pin, byte motor_pwm_pin, 
+	byte heater_pin, byte cooler_pin, byte thermistor_pin, byte valve_dir_pin, 
+	byte valve_enable_pin)
 {
 	this-&gt;motor_dir_pin = motor_dir_pin;
 	this-&gt;motor_pwm_pin = motor_pwm_pin;
+	this-&gt;valve_dir_pin = valve_dir_pin;
+	this-&gt;valve_enable_pin = valve_enable_pin;	
 	this-&gt;heater_pin = heater_pin;
 	this-&gt;cooler_pin = cooler_pin;
 	this-&gt;thermistor_pin = thermistor_pin;
@@ -22,6 +26,8 @@ ThermoplastExtruder::ThermoplastExtruder(byte motor_dir_pin, byte motor_pwm_pin,
 	pinMode(this-&gt;motor_dir_pin, OUTPUT);
 	pinMode(this-&gt;motor_pwm_pin, OUTPUT);
 	pinMode(this-&gt;heater_pin, OUTPUT);
+	pinMode(this-&gt;valve_dir_pin, OUTPUT);
+	pinMode(this-&gt;valve_enable_pin, OUTPUT);
 
 	this-&gt;getTemperature();
 	this-&gt;setSpeed(0);
@@ -58,6 +64,17 @@ void ThermoplastExtruder::setDirection(bool dir)
 	digitalWrite(this-&gt;motor_dir_pin, this-&gt;motor_dir);
 }
 
+/*!
+  Pulse the valve to open or close it.  dir == true: open; dir == false: closed
+*/
+void ThermoplastExtruder::setValve(bool dir, byte pulse_time)
+{
+	digitalWrite(this-&gt;valve_dir_pin, dir);
+	digitalWrite(this-&gt;valve_enable_pin, 1);
+	delay(2*(int)pulse_time);
+	digitalWrite(this-&gt;valve_enable_pin, 0);
+}
+
 void ThermoplastExtruder::setTemperature(int temp)
 {
 	this-&gt;target_celsius = temp;</diff>
      <filename>library/ThermoplastExtruder/ThermoplastExtruder.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -26,7 +26,9 @@
 class ThermoplastExtruder
 {
 	public:
-		ThermoplastExtruder(byte motor_dir_pin, byte motor_pwm_pin, byte heater_pin, byte cooler_pin, byte thermistor_pin);
+		ThermoplastExtruder(byte motor_dir_pin, byte motor_pwm_pin, byte heater_pin, 
+		byte cooler_pin, byte thermistor_pin, byte valve_dir_pin, 
+		byte valve_enable_pin);
 
 		// various setters methods:
 		void setSpeed(byte speed);
@@ -38,6 +40,9 @@ class ThermoplastExtruder
 		int getTemperature();
 		int calculateTemperatureFromRaw(int raw);
 		void manageTemperature();
+		
+		// Open and close the valve
+		void setValve(bool dir, byte pulse_time);
 
 		//variables for easy access.
 		byte heater_low;		// Low heater, for when we're at our temp, 0-255
@@ -50,6 +55,8 @@ class ThermoplastExtruder
 		//pin numbers:
 		byte motor_pwm_pin;		// motor PWM pin
 		byte motor_dir_pin;		// motor direction pin
+		byte valve_enable_pin;	// valve enable pin
+		byte valve_dir_pin;		// valve direction pin		
 		byte heater_pin;		// heater PWM pin
 		byte thermistor_pin;	// thermistor analog input pin
 		byte cooler_pin;		// cooler fan PWM pin</diff>
      <filename>library/ThermoplastExtruder/ThermoplastExtruder.h</filename>
    </modified>
    <modified>
      <diff>@@ -45,6 +45,16 @@ void process_thermoplast_extruder_snap_commands_v1()
 			extruder.setDirection(0);
 			extruder.setSpeed(snap.getByte(1));
 		break;
+		
+		// Open the valve
+		case CMD_VALVEOPEN:
+			extruder.setValve(1, snap.getByte(1));
+		break;
+		
+		// Close the valve
+		case CMD_VALVECLOSE:
+			extruder.setValve(0, snap.getByte(1));
+		break;		
 
 		// dunno what this is supposed to do...
 		case CMD_SETPOS:</diff>
      <filename>library/ThermoplastExtruder_SNAP_v1/ThermoplastExtruder_SNAP_v1.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -71,6 +71,8 @@ int calculatePicTempForCelsius(int temperature);
 #define CMD_SETHEAT       9
 #define CMD_GETTEMP       10
 #define CMD_SETCOOLER     11
+#define CMD_VALVEOPEN  	  12
+#define CMD_VALVECLOSE    13
 #define CMD_PWMPERIOD     50
 #define CMD_PRESCALER     51 //apparently doesnt exist...
 #define CMD_SETVREF       52</diff>
      <filename>library/ThermoplastExtruder_SNAP_v1/ThermoplastExtruder_SNAP_v1.h</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b2f5e3304fd274f7158a49fb99edf0dcea63d259</id>
    </parent>
  </parents>
  <author>
    <name>adrian-bowyer</name>
    <email>adrian-bowyer@cb376a5e-1013-0410-a455-b6b1f9ac8223</email>
  </author>
  <url>http://github.com/alx/reprap-arduino-firmware/commit/8c3d8cf1e4ff619a7389384f1a7d304a8f7da3c0</url>
  <id>8c3d8cf1e4ff619a7389384f1a7d304a8f7da3c0</id>
  <committed-date>2008-04-30T11:06:30-07:00</committed-date>
  <authored-date>2008-04-30T11:06:30-07:00</authored-date>
  <message>Flow control valve code added.  The valve uses a latching solenoid
connected to the B output of the DC motor controller PCB.  This is driven
from pins 15 and 16 of the Arduino.

NB: the axis max sensors have been disabled to allow this.

git-svn-id: https://reprap.svn.sourceforge.net/svnroot/reprap/trunk/reprap/firmware/Arduino@1549 cb376a5e-1013-0410-a455-b6b1f9ac8223</message>
  <tree>54446da7230b086e797c5aae74bdad5372f0dbaa</tree>
  <committer>
    <name>adrian-bowyer</name>
    <email>adrian-bowyer@cb376a5e-1013-0410-a455-b6b1f9ac8223</email>
  </committer>
</commit>
