class Measurement
{
private:
- static const size_t MAX_ELEMENTS = 100;
- static const unsigned long START_INTERVAL_MS = 5000;
+ static constexpr size_t MAX_ELEMENTS = 100;
+ static constexpr unsigned long START_INTERVAL_MS = 5000;
const PressureSensor &m_sensor;
unsigned long m_interval_ms;
typedef int pin;
const pin m_analog_pin;
- const float m_resistance; // in Ohms
+ const float m_resistance; // in Ohms
+ const float m_max_pressure;
static const float MIN_CURRENT = 4e-3; // in A
static const float MAX_CURRENT = 20e-3; // in A
static const float REFERENCE_VOLTAGE = 5; // in V
static const int CONVERSION_BIT_NUM = 10;
- float signal_to_pressure(int ad_signal);
+ float signal_to_pressure(int ad_signal) const;
public:
- const float m_max_pressure;
-
PressureSensor() = delete;
PressureSensor(pin analog_pin, float max_pressure = 10, float resistance = 240);
PressureSensor(const PressureSensor &other) = delete;
PressureSensor &operator=(const PressureSensor &other) = delete;
- float get_pressure();
+ float get_pressure() const;
};
#endif // PRESSURESENSOR_H
// And p = | ----------------------------------------- - MIN_CURRENT | * --------------
// \ m_resistance * (2^CONVERSION_BIT_NUM - 1) / I_R
-float PressureSensor::signal_to_pressure(int ad_signal)
+float PressureSensor::signal_to_pressure(int ad_signal) const
{
float signal_str;
float voltage;
return ((current - MIN_CURRENT) / (MAX_CURRENT - MIN_CURRENT) * m_max_pressure);
}
-float PressureSensor::get_pressure()
+float PressureSensor::get_pressure() const
{
return (signal_to_pressure(analogRead(m_analog_pin)));
}
#include "Measurement.h"
#include <avr/sleep.h>
-static const int PRESSURE_SENSOR1_PIN = A1;
-static const int PRESSURE_SENSOR2_PIN = A2;
-static const int PRESSURE_SENSOR3_PIN = A3;
+static constexpr int PRESSURE_SENSOR1_PIN = A1;
+static constexpr int PRESSURE_SENSOR2_PIN = A2;
+static constexpr int PRESSURE_SENSOR3_PIN = A3;
-static const int SWITCH_PIN = 2; // Only pins 2; 3 have external interrupts?
+static constexpr int SWITCH_PIN = 2; // Only pins 2; 3 have external interrupts?
-static const int GAS_VALVE_PIN = 9;
-static const int CELL_VALVE_PIN = 10;
-static const int PRESSURE_SENSOR_VALVE_PIN = 11;
-static const int VACUUM_VALVE_PIN = 12;
+static constexpr int GAS_VALVE_PIN = 9;
+static constexpr int CELL_VALVE_PIN = 10;
+static constexpr int PRESSURE_SENSOR_VALVE_PIN = 11;
+static constexpr int VACUUM_VALVE_PIN = 12;
-static const unsigned long CELL_BARELY_OPEN_EQUILIBRATION_MS = 10000;
-static const unsigned long EVACUATION_LONG_MS = 600000;
-static const unsigned long EVACUATION_MS = 60000;
+static constexpr unsigned long CELL_BARELY_OPEN_EQUILIBRATION_MS = 10000;
+static constexpr unsigned long EVACUATION_LONG_MS = 600000;
+static constexpr unsigned long EVACUATION_MS = 60000;
-static const unsigned int THREEWAY_TURNS_TO_FILL = 3;
+static constexpr unsigned int THREEWAY_TURNS_TO_FILL = 3;
-static const float MEASUREMENT_UPPER_LIMIT = 8;
-static const float MEASUREMENT_LOWER_LIMIT = 0.5;
+static constexpr float MEASUREMENT_UPPER_LIMIT = 8;
+static constexpr float MEASUREMENT_LOWER_LIMIT = 0.5;
void threeway_fill(Valve &threeway_valve, unsigned int count)
{