Commit b881a8cb authored by Philippe Kalaf's avatar Philippe Kalaf

Calculate average pressure during shots

parent 8546a603
......@@ -123,7 +123,7 @@ int BrewControl::get_shot_volume()
}
void BrewControl::boiler_pid_worker()
void BrewControl::_boiler_pid_worker()
{
// take temperature measurement
float latestTemp = get_current_temperature();
......@@ -153,7 +153,7 @@ void BrewControl::boiler_pid_worker()
void BrewControl::enable_boiler()
{
_enable_boiler = 1;
_boiler_pid_ticker.attach(callback(this, &BrewControl::boiler_pid_worker),
_boiler_pid_ticker.attach(callback(this, &BrewControl::_boiler_pid_worker),
PID_WORKER_PERIOD);
}
......@@ -252,9 +252,12 @@ uint8_t BrewControl::get_state()
return _state;
}
void BrewControl::brew_worker()
void BrewControl::_brew_worker()
{
_shot_clock = _shot_clock + BREW_WORKER_PERIOD;
if (_mode != MODE_PRE_INFUSE)
_pressure_sensor.start_count();
if (_mode == MODE_PRE_INFUSE)
{
......@@ -371,7 +374,7 @@ uint8_t BrewControl::start()
// Run worker at defined period
if(_mode != MODE_MANUAL)
_brew_ticker.attach(callback(this, &BrewControl::brew_worker),
_brew_ticker.attach(callback(this, &BrewControl::_brew_worker),
BREW_WORKER_PERIOD);
return _mode;
......@@ -385,7 +388,7 @@ void BrewControl::toggle_solenoid()
_brew_switch = 1;
}
void BrewControl::stop()
void BrewControl::_stop()
{
_state = STOPPED;
_brew_switch = 0;
......@@ -399,8 +402,9 @@ void BrewControl::soft_stop()
{
_pump_control.set_level(0);
_brew_ticker.detach();
_soft_stop_timer.attach(callback(this, &BrewControl::stop),
_soft_stop_timer.attach(callback(this, &BrewControl::_stop),
SOFT_STOP_TIME_S);
_average_pressure = _pressure_sensor.stop_count();
_state = SOFT_STOPPING;
}
......
......@@ -109,8 +109,6 @@ public:
uint8_t toggle();
/// Start brewing, this resets all live variables and based on set targets initiates the right brew mode, returns set mode
uint8_t start();
/// Stop brewing
void stop();
/// Stop brewing with reduced backflush
void soft_stop();
......@@ -163,6 +161,9 @@ private:
// Operating modes
uint8_t _state;
int _mode;
// The average pressure of previous shot
float _average_pressure;
// These are used for pre-infuse mode to go back to initial settings after
// pre-infuse is done
......@@ -175,9 +176,10 @@ private:
// Workers
Ticker _brew_ticker;
void brew_worker();
void _brew_worker();
Ticker _boiler_pid_ticker;
void boiler_pid_worker();
void _boiler_pid_worker();
void _stop();
};
#endif// brewcontrol_h
......@@ -40,5 +40,32 @@ int PressureSensor::read_pa()
// measurements show the 0.5V value at around 10300
int pressure_pascal = (_input.read_u16() - 10300);
pressure_pascal = (pressure_pascal * 25);
return pressure_pascal;
}
return pressure_pascal;
}
void PressureSensor::worker()
{
if(_read_count != -1)
{
_read_count++;
// keep calculating average
_average_pressure = ( _average_pressure * (_read_count-1)
+ read_pa() )
/_read_count;
}
}
void PressureSensor::start_count()
{
_read_count = 0;
_average_pressure = 0;
_ticker.attach(callback(this, &PressureSensor::worker), 0.1);
}
float PressureSensor::stop_count()
{
_read_count = -1;
_ticker.detach();
return _average_pressure / 100000;
}
......@@ -30,10 +30,17 @@ public:
int read_pa();
float read_bars();
void start_count();
float stop_count();
private:
AnalogIn _input;
int _read_count;
int _average_pressure;
Ticker _ticker;
void worker();
};
#endif// PressureSensor_h
\ No newline at end of file
#endif// PressureSensor_h
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment