mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +00:00
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:
parent
29005b578d
commit
469cc68b02
4 changed files with 26 additions and 12 deletions
|
@ -352,7 +352,7 @@ static void debug_print_pressures(struct plot_info *pi)
|
|||
int i;
|
||||
for (i = 0; i < pi->nr; i++) {
|
||||
struct plot_data *entry = pi->entry + i;
|
||||
printf("%5d |%9d | %9d |\n", i, SENSOR_PRESSURE(entry), INTERPOLATED_PRESSURE(entry));
|
||||
printf("%5d |%9d | %9d |\n", i, get_plot_sensor_pressure(entry), get_plot_interpolated_pressure(entry));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -388,7 +388,7 @@ void populate_pressure_information(struct dive *dive, struct divecomputer *dc, s
|
|||
first = last = -1;
|
||||
for (int i = 0; i < pi->nr; i++) {
|
||||
struct plot_data *entry = pi->entry + i;
|
||||
unsigned pressure = SENSOR_PRESSURE(entry, sensor);
|
||||
int pressure = get_plot_sensor_pressure(entry, sensor);
|
||||
|
||||
if (!pressure)
|
||||
continue;
|
||||
|
@ -417,7 +417,7 @@ void populate_pressure_information(struct dive *dive, struct divecomputer *dc, s
|
|||
|
||||
for (int i = first; i <= last; i++) {
|
||||
struct plot_data *entry = pi->entry + i;
|
||||
unsigned pressure = SENSOR_PRESSURE(entry, sensor);
|
||||
int pressure = get_plot_sensor_pressure(entry, sensor);
|
||||
int time = entry->sec;
|
||||
|
||||
while (ev && ev->time.seconds <= time) { // Find 1st gaschange event after
|
||||
|
|
|
@ -1309,8 +1309,8 @@ static void debug_print_profiledata(struct plot_info *pi)
|
|||
fprintf(f1, "id t1 gas gasint t2 t3 dil dilint t4 t5 setpoint sensor1 sensor2 sensor3 t6 po2 fo2\n");
|
||||
for (i = 0; i < pi->nr; i++) {
|
||||
entry = pi->entry + i;
|
||||
fprintf(f1, "%d gas=%8d %8d ; dil=%8d %8d ; o2_sp= %d %d %d %d PO2= %f\n", i, SENSOR_PRESSURE(entry),
|
||||
INTERPOLATED_PRESSURE(entry), O2CYLINDER_PRESSURE(entry), INTERPOLATED_O2CYLINDER_PRESSURE(entry),
|
||||
fprintf(f1, "%d gas=%8d %8d ; dil=%8d %8d ; o2_sp= %d %d %d %d PO2= %f\n", i, get_plot_sensor_pressure(entry),
|
||||
get_plot_interpolated_pressure(entry), O2CYLINDER_PRESSURE(entry), INTERPOLATED_O2CYLINDER_PRESSURE(entry),
|
||||
entry->o2pressure.mbar, entry->o2sensor[0].mbar, entry->o2sensor[1].mbar, entry->o2sensor[2].mbar, entry->pressures.o2);
|
||||
}
|
||||
fclose(f1);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1535,19 +1535,19 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
|
|||
if (gasChangeEntry + 1 <= plotInfo.entry + plotInfo.nr) {
|
||||
newGasEntry = gasChangeEntry + 1;
|
||||
qDebug() << "after gas change at " << newGasEntry->sec << ": sensor pressure" << newGasEntry->pressure[0] << "interpolated" << newGasEntry->pressure[1];
|
||||
if (SENSOR_PRESSURE(gasChangeEntry) == 0 || displayed_dive.cylinder[gasChangeEntry->sensor[0]].sample_start.mbar == 0) {
|
||||
if (get_plot_sensor_pressure(gasChangeEntry) == 0 || displayed_dive.cylinder[gasChangeEntry->sensor[0]].sample_start.mbar == 0) {
|
||||
// if we have no sensorpressure or if we have no pressure from samples we can assume that
|
||||
// we only have interpolated pressure (the pressure in the entry may be stored in the sensor
|
||||
// pressure field if this is the first or last entry for this tank... see details in gaspressures.c
|
||||
pressure_t pressure;
|
||||
pressure.mbar = INTERPOLATED_PRESSURE(gasChangeEntry) ? : SENSOR_PRESSURE(gasChangeEntry);
|
||||
pressure.mbar = get_plot_interpolated_pressure(gasChangeEntry) ? : get_plot_sensor_pressure(gasChangeEntry);
|
||||
QAction *adjustOldPressure = m.addAction(tr("Adjust pressure of cyl. %1 (currently interpolated as %2)")
|
||||
.arg(gasChangeEntry->sensor[0] + 1).arg(get_pressure_string(pressure)));
|
||||
}
|
||||
if (SENSOR_PRESSURE(newGasEntry) == 0 || displayed_dive.cylinder[newGasEntry->sensor[0]].sample_start.mbar == 0) {
|
||||
if (get_plot_sensor_pressure(newGasEntry) == 0 || displayed_dive.cylinder[newGasEntry->sensor[0]].sample_start.mbar == 0) {
|
||||
// we only have interpolated press -- see commend above
|
||||
pressure_t pressure;
|
||||
pressure.mbar = INTERPOLATED_PRESSURE(newGasEntry) ? : SENSOR_PRESSURE(newGasEntry);
|
||||
pressure.mbar = get_plot_interpolated_pressure(newGasEntry) ? : get_plot_sensor_pressure(newGasEntry);
|
||||
QAction *adjustOldPressure = m.addAction(tr("Adjust pressure of cyl. %1 (currently interpolated as %2)")
|
||||
.arg(newGasEntry->sensor[0] + 1).arg(get_pressure_string(pressure)));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue