Cleanup: replace pressure reading macros by inline functions

Replace the INTERPOLATED_PRESSURE and SENSOR_PRESSURE macros by
inline functions. Generate a common inline function that reads
a pressure value for a dynamic sensor.

Not all SENSOR_PRESSURE macros can be replaced, because the
macro is also used to set the value and C sadly doesn't know
the concept of "return reference from a function".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-07-05 23:14:07 +02:00 committed by Dirk Hohndel
parent 29005b578d
commit 469cc68b02
4 changed files with 26 additions and 12 deletions

View file

@ -98,12 +98,26 @@ int get_maxdepth(struct plot_info *pi);
#define SENSOR_PR 0
#define INTERPOLATED_PR 1
#define SENSOR_PRESSURE(_entry,_idx) (_entry)->pressure[_idx][SENSOR_PR]
#define INTERPOLATED_PRESSURE(_entry,_idx) (_entry)->pressure[_idx][INTERPOLATED_PR]
static inline int get_plot_pressure_data(const struct plot_data *entry, int sensor, int idx)
{
return entry->pressure[idx][sensor];
}
static inline int get_plot_sensor_pressure(const struct plot_data *entry, int idx)
{
return get_plot_pressure_data(entry, SENSOR_PR, idx);
}
static inline int get_plot_interpolated_pressure(const struct plot_data *entry, int idx)
{
return get_plot_pressure_data(entry, INTERPOLATED_PR, idx);
}
static inline int get_plot_pressure(const struct plot_data *entry, int idx)
{
int res = SENSOR_PRESSURE(entry, idx);
return res ? res : INTERPOLATED_PRESSURE(entry, idx);
int res = get_plot_sensor_pressure(entry, idx);
return res ? res : get_plot_interpolated_pressure(entry, idx);
}
#ifdef __cplusplus