Commit 3137b1c9 authored by Philippe Kalaf's avatar Philippe Kalaf

Rewrite temperature sensor drivers to be more efficient and enable both sensors

parent c5a1b903
......@@ -45,9 +45,7 @@ BrewControl::BrewControl( PinName brew_pin,
PinName pump_control_pin,
PinName pressure_sensor_pin,
PinName temp_sensor_pin,
#ifdef TEMP2
PinName temp2_sensor_pin,
#endif
PinName boiler_pwm_pin
) :
_brew_switch(brew_pin, 0),
......@@ -570,9 +568,5 @@ uint16_t BrewControl::get_last_pulse_count_side()
uint16_t BrewControl::get_last_pulse_count_top()
{
#ifdef TEMP2
return _temp2_sensor.get_last_pulse_count();
#else
return 0;
#endif
}
......@@ -27,17 +27,44 @@ const int LMT01::_pulse_temp_table[20][2] = {
{110, 2569}, {120, 2731}, {130, 2894}, {140, 3058}, {150, 3220}
};
LMT01::LMT01(PinName pin) : _interrupt(pin) { // create the InterruptIn on the pin specified to LMT01
LMT01::LMT01(PinName pin) : _interrupt(pin), _worker_thread(osPriorityNormal, 1024) { // create the InterruptIn on the pin specified to LMT01
_interrupt.mode(PullUp); // an internal pull up is used, otherwise disable here
_interrupt.fall(callback(this, &LMT01::increment)); // attach increment function of this counter instance
_pulse_timer.start();
_ticker.attach(callback(this, &LMT01::worker), 0.5);
_interrupt.fall(callback(this, &LMT01::_increment)); // attach increment function of this counter instance
// Start worker thread for counting pulses and calculating temp
_worker_thread.start(callback(this, &LMT01::_worker));
}
void LMT01::worker()
void LMT01::_worker()
{
// Find pulse/temp range from table
uint16_t i;
while(true)
{
_interrupt.enable_irq();
ThisThread::sleep_for(250);
_pulse_count = 0;
_last_pulse_count = 0;
// Let's skip the first potentially partial pulse train
while (_pulse_count != _last_pulse_count || _pulse_count == 0 || _last_pulse_count == 0)
{
_last_pulse_count = _pulse_count;
ThisThread::sleep_for(1);
}
// OK let's now count the next pulse train from the start
_pulse_count = 0;
_last_pulse_count = 0;
while (_pulse_count != _last_pulse_count || _pulse_count == 0 || _last_pulse_count == 0)
{
_last_pulse_count = _pulse_count;
ThisThread::sleep_for(1);
}
// Find pulse/temp range from table
for (i = 0; i < sizeof(_pulse_temp_table); i++)
if (_last_pulse_count < _pulse_temp_table[i][1])
break;
......@@ -51,23 +78,16 @@ void LMT01::worker()
) * 10 // at this point unit is 10^3 Celsius
)
+ _pulse_temp_table[i-1][0] * 1000;
_interrupt.disable_irq();
ThisThread::sleep_for(250);
}
}
void LMT01::increment()
void LMT01::_increment()
{
// Detect when pulses stop so we convert the reading and reset timer
// 10ms is long enough to indicate pulses have stopped
if (_pulse_timer.read_ms() > 10)
{
_pulse_timer.reset();
_last_pulse_count = _pulse_count;
_pulse_count = 0;
}
else
{
_pulse_timer.reset();
_pulse_count++;
}
}
// returns temperature in 10^3 Celsius
......
......@@ -30,7 +30,6 @@ public:
static const int _pulse_temp_table[20][2];
void increment();
int read_int();
float read();
uint16_t get_last_pulse_count();
......@@ -41,10 +40,10 @@ private:
volatile uint16_t _last_pulse_count;
// temperature in 10^3 Celsius
volatile int _temperature;
Timer _pulse_timer;
Ticker _ticker;
Thread _worker_thread;
void worker();
void _worker();
void _increment();
};
#endif// lmt01_h
......@@ -83,14 +83,9 @@ bool power_save;
// pump phasecontrol signal (PUMP_CTRL)
// pressure sensor (PRESSURE_IN)
// side temperature sensor (TEMP_IN)
// top temperature sensor (TEMP2_IN) - Not Implemented
// top temperature sensor (TEMP2_IN)
// boiler control ssr (BOILER_CTRL)
#ifdef TEMP2
BrewControl brew_control(p10, p15, p12, p13, p20, p25, p14, p26);
#else
BrewControl brew_control(p10, p15, p12, p13, p20, p25, p26);
#endif
// Menu structures
//
......
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