#include "helpers.h"
#include "PressureSensor.h"
#include "Valve.h"
-#include "CellValve.h"
#include "Measurement.h"
#include <avr/sleep.h>
static constexpr int PRESSURE_SENSOR_VALVE_PIN = 11;
static constexpr int VACUUM_VALVE_PIN = 12;
-static constexpr unsigned long CELL_BARELY_OPEN_EQUILIBRATION_MS = 10000;
+static constexpr unsigned long CELL_BARELY_OPEN_EQUILIBRATION_MS = 30000;
static constexpr unsigned long EVACUATION_LONG_MS = 600000;
static constexpr unsigned long EVACUATION_MS = 60000;
-static constexpr unsigned int THREEWAY_TURNS_TO_FILL = 3;
+static constexpr unsigned int THREEWAY_TURNS_TO_FILL = 1;
static constexpr float MEASUREMENT_UPPER_LIMIT = 8;
static constexpr float MEASUREMENT_LOWER_LIMIT = 0.5;
{
while (count > 0)
{
- threeway_valve.close();
+ threeway_valve.open_barely();
threeway_valve.open();
--count;
}
}
// The gas valve needs special treatment, because it is threeway.
-// Let's say open means cell-side and closed means gas-side
+// Let's say open means cell-side, closed means closed and barely open means
+// gas-side
void main_loop()
{
- PressureSensor sensor_1{PRESSURE_SENSOR1_PIN, 10};
+ PressureSensor sensor_1{PRESSURE_SENSOR1_PIN, 10, 242};
+ //PressureSensor sensor_2{PRESSURE_SENSOR2_PIN, 10, 241};
+ //PressureSensor sensor_3{PRESSURE_SENSOR3_PIN, 10, 241};
Measurement measurement{sensor_1};
- Valve vacuum_valve{VACUUM_VALVE_PIN, 760, 2400};
- CellValve cell_valve{CELL_VALVE_PIN, 760, 1600, 2400};
- Valve gas_threeway_valve{GAS_VALVE_PIN, 760, 2400};
+ Valve vacuum_valve{VACUUM_VALVE_PIN, 2295, 1494, 802};
+ Valve cell_valve{CELL_VALVE_PIN, 2000, 1535, 1276};
+ Valve gas_threeway_valve{GAS_VALVE_PIN, 1301, 1641, 2036};
vacuum_valve.close();
cell_valve.close();
- gas_threeway_valve.open();
+ gas_threeway_valve.close();
while (1)
{
if (!interrupt_happened && digitalRead(SWITCH_PIN) == HIGH)
cell_valve.open_barely();
delay(CELL_BARELY_OPEN_EQUILIBRATION_MS);
cell_valve.open();
- measurement.wait_for_equilibrium(0.01);
+ measurement.wait_for_equilibrium(0.05);
measurement.clear();
cell_valve.close();
}
cell_valve.open_barely();
delay(CELL_BARELY_OPEN_EQUILIBRATION_MS);
cell_valve.open();
- measurement.wait_for_equilibrium(0.01);
+ measurement.wait_for_equilibrium(0.05);
measurement.clear();
cell_valve.close();
}
}
vacuum_valve.open();
+ gas_threeway_valve.open();
cell_valve.open_barely();
delay(CELL_BARELY_OPEN_EQUILIBRATION_MS);
+ cell_valve.open();
+ delay(10000);
+ vacuum_valve.close();
signal_going_to_sleep();
sleep();
interrupt_happened = 0;
private:
const Servo m_servo;
const int m_usec_opened;
+ const int m_usec_barely_opened;
const int m_usec_closed;
int m_usec_current;
public:
Valve() = delete;
Valve(const Valve &other) = delete;
- Valve(pin control_pin, int usec_opened, int isec_closed);
+ Valve(pin control_pin, int usec_opened, int usec_barely_opened,
+ int isec_closed);
~Valve();
Valve &operator=(const Valve &other) = delete;
void open(float seconds = 5);
+ void open_barely(float seconds = 5);
void close(float seconds = 5);
void close_open_clean(unsigned int count = 3);
};
#include "Valve.h"
-Valve::Valve(pin control_pin, int usec_opened, int usec_closed)
+Valve::Valve(pin control_pin, int usec_opened, int usec_barely_opened,
+ int usec_closed)
: m_servo{}
, m_usec_opened{usec_opened}
+ , m_usec_barely_opened{usec_barely_opened}
, m_usec_closed{usec_closed}
, m_usec_current{usec_closed}
{
write_usec_timed(m_usec_opened, seconds);
}
+void Valve::open_barely(float seconds)
+{
+ write_usec_timed(m_usec_barely_opened, seconds);
+}
+
void Valve::close(float seconds)
{
write_usec_timed(m_usec_closed, seconds);