Skip to content

Commit

Permalink
Couple fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shellixyz committed Feb 2, 2019
1 parent 372f0e5 commit 8e12f12
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 113 deletions.
42 changes: 28 additions & 14 deletions src/main/blackbox/blackbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,19 @@ static const blackboxSimpleFieldDefinition_t blackboxSlowFields[] = {
{"wind", 0, SIGNED, PREDICT(0), ENCODING(UNSIGNED_VB)},
{"wind", 1, SIGNED, PREDICT(0), ENCODING(UNSIGNED_VB)},
{"wind", 2, SIGNED, PREDICT(0), ENCODING(UNSIGNED_VB)},
{"MPU temperature", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"IMUTemperature", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
#ifdef USE_BARO
{"baro temperature", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"baroTemperature", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
#endif
#ifdef USE_TEMPERATURE_SENSOR
{"temp0 temperature", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"temp1 temperature", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"temp2 temperature", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"temp3 temperature", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"temp4 temperature", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"temp5 temperature", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"temp6 temperature", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"temp7 temperature", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"sens0Temp", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"sens1Temp", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"sens2Temp", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"sens3Temp", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"sens4Temp", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"sens5Temp", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"sens6Temp", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
{"sens7Temp", -1, SIGNED, PREDICT(0), ENCODING(SIGNED_VB)},
#endif
};

Expand Down Expand Up @@ -465,9 +465,13 @@ typedef struct blackboxSlowState_s {
uint16_t powerSupplyImpedance;
uint16_t sagCompensatedVBat;
int16_t wind[XYZ_AXIS_COUNT];
int16_t mpuTemperature;
int16_t imuTemperature;
#ifdef USE_BARO
int16_t baroTemperature;
#endif
#ifdef USE_TEMPERATURE_SENSOR
int16_t tempSensorTemperature[MAX_TEMP_SENSORS];
#endif
} __attribute__((__packed__)) blackboxSlowState_t; // We pack this struct so that padding doesn't interfere with memcmp()

//From rc_controls.c
Expand Down Expand Up @@ -1055,10 +1059,15 @@ static void writeSlowFrame(void)

blackboxWriteSigned16VBArray(slowHistory.wind, XYZ_AXIS_COUNT);

blackboxWriteSignedVB(slowHistory.mpuTemperature);
blackboxWriteSignedVB(slowHistory.imuTemperature);

#ifdef USE_BARO
blackboxWriteSignedVB(slowHistory.baroTemperature);
#endif

#ifdef USE_TEMPERATURE_SENSOR
blackboxWriteSigned16VBArray(slowHistory.tempSensorTemperature, MAX_TEMP_SENSORS);
#endif

blackboxSlowFrameIterationTimer = 0;
}
Expand Down Expand Up @@ -1093,15 +1102,20 @@ static void loadSlowState(blackboxSlowState_t *slow)
}

bool valid_temp;
valid_temp = getMPUTemperature(&slow->mpuTemperature);
if (!valid_temp) slow->mpuTemperature = 0xFFFF;
valid_temp = getIMUTemperature(&slow->imuTemperature);
if (!valid_temp) slow->imuTemperature = 0xFFFF;

#ifdef USE_BARO
valid_temp = getBaroTemperature(&slow->baroTemperature);
if (!valid_temp) slow->baroTemperature = 0xFFFF;
#endif

#ifdef USE_TEMPERATURE_SENSOR
for (uint8_t index; index < MAX_TEMP_SENSORS; ++index) {
valid_temp = getSensorTemperature(index, slow->tempSensorTemperature + index);
if (!valid_temp) slow->tempSensorTemperature[index] = 0xFFFF;
}
#endif

}

Expand Down
2 changes: 1 addition & 1 deletion src/main/cms/cms_menu_osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ static const OSD_Entry menuOsdElemsEntries[] =
OSD_ELEMENT_ENTRY("WIND HOR", OSD_WIND_SPEED_HORIZONTAL),
OSD_ELEMENT_ENTRY("WIND VERT", OSD_WIND_SPEED_VERTICAL),

OSD_ELEMENT_ENTRY("MPU TEMP", OSD_MPU_TEMPERATURE),
OSD_ELEMENT_ENTRY("IMU TEMP", OSD_IMU_TEMPERATURE),
#ifdef USE_BARO
OSD_ELEMENT_ENTRY("BARO TEMP", OSD_BARO_TEMPERATURE),
#endif
Expand Down
17 changes: 7 additions & 10 deletions src/main/drivers/1-wire/ds2482.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,20 @@ bool ds2482_write_config(_1WireDev_t *_1WireDev, uint8_t config)
return busWrite(_1WireDev->busDev, DS2482_WRITE_CONFIG_CMD, DS2482_CONFIG_WRITE_BYTE(config));
}

bool ds2482_wait_for_bus(_1WireDev_t *_1WireDev)
bool ds2482_poll(_1WireDev_t *_1WireDev, bool wait_for_bus, uint8_t *status)
{
uint8_t status;
uint8_t status_temp;
do {
bool ack = busRead(_1WireDev->busDev, 0xFF, &status);
bool ack = busRead(_1WireDev->busDev, 0xFF, &status_temp);
if (!ack) return false;
} while (DS2482_1WIRE_BUSY(status));
} while (wait_for_bus && DS2482_1WIRE_BUSY(status_temp));
if (status) *status = status_temp;
return true;
}

bool ds2482_poll(_1WireDev_t *_1WireDev, bool wait_for_bus, uint8_t *status)
bool ds2482_wait_for_bus(_1WireDev_t *_1WireDev)
{
do {
bool ack = busRead(_1WireDev->busDev, 0xFF, status);
if (!ack) return false;
} while (wait_for_bus && DS2482_1WIRE_BUSY(*status));
return true;
return ds2482_poll(_1WireDev, true, NULL);
}

bool ds2482_1wire_reset(_1WireDev_t *_1WireDev)
Expand Down
19 changes: 13 additions & 6 deletions src/main/fc/fc_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1348,10 +1348,15 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
sbufWriteU16(dst, osdConfig()->alt_alarm);
sbufWriteU16(dst, osdConfig()->dist_alarm);
sbufWriteU16(dst, osdConfig()->neg_alt_alarm);
sbufWriteU16(dst, osdConfig()->mpu_temp_alarm_min);
sbufWriteU16(dst, osdConfig()->mpu_temp_alarm_max);
sbufWriteU16(dst, osdConfig()->imu_temp_alarm_min);
sbufWriteU16(dst, osdConfig()->imu_temp_alarm_max);
#ifdef USE_BARO
sbufWriteU16(dst, osdConfig()->baro_temp_alarm_min);
sbufWriteU16(dst, osdConfig()->baro_temp_alarm_max);
#else
sbufWriteU16(dst, 0);
sbufWriteU16(dst, 0);
#endif
break;

case MSP2_INAV_OSD_PREFERENCES:
Expand Down Expand Up @@ -1407,7 +1412,7 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
for (uint8_t index = 0; index < MAX_TEMP_SENSORS; ++index) {
int16_t temperature;
bool valid = getSensorTemperature(index, &temperature);
sbufWriteU16(dst, valid ? temperature : 0xFFFF);
sbufWriteU16(dst, valid ? temperature : -1000);
}
#endif
break;
Expand Down Expand Up @@ -2600,10 +2605,12 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
osdConfigMutable()->alt_alarm = sbufReadU16(src);
osdConfigMutable()->dist_alarm = sbufReadU16(src);
osdConfigMutable()->neg_alt_alarm = sbufReadU16(src);
osdConfigMutable()->mpu_temp_alarm_min = sbufReadU16(src);
osdConfigMutable()->mpu_temp_alarm_max = sbufReadU16(src);
osdConfigMutable()->imu_temp_alarm_min = sbufReadU16(src);
osdConfigMutable()->imu_temp_alarm_max = sbufReadU16(src);
#ifdef USE_BARO
osdConfigMutable()->baro_temp_alarm_min = sbufReadU16(src);
osdConfigMutable()->baro_temp_alarm_max = sbufReadU16(src);
#endif
} else
return MSP_RESULT_ERROR;
}
Expand Down Expand Up @@ -2655,7 +2662,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)

case MSP2_INAV_SET_TEMP_SENSOR_CONFIG:
#ifdef USE_TEMPERATURE_SENSOR
if (dataSize >= sizeof(tempSensorConfig_t) * MAX_TEMP_SENSORS) {
if (dataSize == sizeof(tempSensorConfig_t) * MAX_TEMP_SENSORS) {
for (uint8_t index = 0; index < MAX_TEMP_SENSORS; ++index) {
tempSensorConfig_t *sensorConfig = tempSensorConfigMutable(index);
sensorConfig->type = sbufReadU8(src);
Expand Down
3 changes: 2 additions & 1 deletion src/main/fc/fc_msp_box.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ uint16_t packSensorStatus(void)
IS_ENABLED(sensors(SENSOR_GPS)) << 3 |
IS_ENABLED(sensors(SENSOR_RANGEFINDER)) << 4 |
IS_ENABLED(sensors(SENSOR_OPFLOW)) << 5 |
IS_ENABLED(sensors(SENSOR_PITOT)) << 6;
IS_ENABLED(sensors(SENSOR_PITOT)) << 6 |
IS_ENABLED(sensors(SENSOR_TEMP)) << 7;

// Hardware failure indication bit
if (!isHardwareHealthy()) {
Expand Down
26 changes: 18 additions & 8 deletions src/main/fc/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1592,14 +1592,24 @@ groups:
field: neg_alt_alarm
min: 0
max: 10000
- name: osd_mpu_temp_alarm_min
field: mpu_temp_alarm_min
min: -55
max: 125
- name: osd_mpu_temp_alarm_max
field: mpu_temp_alarm_max
min: -55
max: 125
- name: osd_imu_temp_alarm_min
field: imu_temp_alarm_min
min: -550
max: 1250
- name: osd_imu_temp_alarm_max
field: imu_temp_alarm_max
min: -550
max: 1250
- name: osd_baro_temp_alarm_min
field: baro_temp_alarm_min
condition: USE_BARO
min: -550
max: 1250
- name: osd_baro_temp_alarm_max
field: baro_temp_alarm_max
condition: USE_BARO
min: -550
max: 1250

- name: osd_artificial_horizon_reverse_roll
field: ahi_reverse_roll
Expand Down
16 changes: 9 additions & 7 deletions src/main/io/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2294,19 +2294,19 @@ static bool osdDrawSingleElement(uint8_t item)
break;
}

case OSD_MPU_TEMPERATURE:
case OSD_IMU_TEMPERATURE:
{
int16_t temperature;
const bool valid = getMPUTemperature(&temperature);
osdDisplayTemperature(elemPosX, elemPosY, "MPU", valid, temperature, osdConfig()->mpu_temp_alarm_min, osdConfig()->mpu_temp_alarm_max);
const bool valid = getIMUTemperature(&temperature);
osdDisplayTemperature(elemPosX, elemPosY, "IMU", valid, temperature, osdConfig()->imu_temp_alarm_min, osdConfig()->imu_temp_alarm_max);
return true;
}

case OSD_BARO_TEMPERATURE:
{
int16_t temperature;
const bool valid = getBaroTemperature(&temperature);
osdDisplayTemperature(elemPosX, elemPosY, "BARO", valid, temperature, osdConfig()->mpu_temp_alarm_min, osdConfig()->mpu_temp_alarm_max);
osdDisplayTemperature(elemPosX, elemPosY, "BARO", valid, temperature, osdConfig()->imu_temp_alarm_min, osdConfig()->imu_temp_alarm_max);
return true;
}

Expand Down Expand Up @@ -2640,7 +2640,7 @@ void pgResetFn_osdConfig(osdConfig_t *osdConfig)

osdConfig->item_pos[0][OSD_POWER] = OSD_POS(15, 1);

osdConfig->item_pos[0][OSD_MPU_TEMPERATURE] = OSD_POS(19, 2);
osdConfig->item_pos[0][OSD_IMU_TEMPERATURE] = OSD_POS(19, 2);
osdConfig->item_pos[0][OSD_BARO_TEMPERATURE] = OSD_POS(19, 3);
osdConfig->item_pos[0][OSD_TEMP_SENSOR_0_TEMPERATURE] = OSD_POS(19, 4);
osdConfig->item_pos[0][OSD_TEMP_SENSOR_1_TEMPERATURE] = OSD_POS(19, 5);
Expand Down Expand Up @@ -2669,10 +2669,12 @@ void pgResetFn_osdConfig(osdConfig_t *osdConfig)
osdConfig->alt_alarm = 100;
osdConfig->dist_alarm = 1000;
osdConfig->neg_alt_alarm = 5;
osdConfig->mpu_temp_alarm_min = -200;
osdConfig->mpu_temp_alarm_max = 600;
osdConfig->imu_temp_alarm_min = -200;
osdConfig->imu_temp_alarm_max = 600;
#ifdef USE_BARO
osdConfig->baro_temp_alarm_min = -200;
osdConfig->baro_temp_alarm_max = 600;
#endif

osdConfig->video_system = VIDEO_SYSTEM_AUTO;

Expand Down
6 changes: 3 additions & 3 deletions src/main/io/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ typedef enum {
OSD_MC_VEL_Z_PID_OUTPUTS,
OSD_MC_POS_XYZ_P_OUTPUTS,
OSD_3D_SPEED,
OSD_MPU_TEMPERATURE,
OSD_IMU_TEMPERATURE,
OSD_BARO_TEMPERATURE,
OSD_TEMP_SENSOR_0_TEMPERATURE,
OSD_TEMP_SENSOR_1_TEMPERATURE,
Expand Down Expand Up @@ -170,8 +170,8 @@ typedef struct osdConfig_s {
uint16_t alt_alarm; // positive altitude in m
uint16_t dist_alarm; // home distance in m
uint16_t neg_alt_alarm; // abs(negative altitude) in m
int16_t mpu_temp_alarm_min;
int16_t mpu_temp_alarm_max;
int16_t imu_temp_alarm_min;
int16_t imu_temp_alarm_max;
#ifdef USE_BARO
int16_t baro_temp_alarm_min;
int16_t baro_temp_alarm_max;
Expand Down
6 changes: 5 additions & 1 deletion src/main/rx/eleres.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,12 @@ static void telemetryRX(void)

presfil -= presfil/4;
presfil += baro.baroPressure;

int16_t temperature;
const bool temp_valid = sensors(SENSOR_BARO) ? getBaroTemperature(&temperature) : getIMUTemperature(&temperature);
if (!temp_valid) temperature = -1250; // If temperature not valid report -125°C
thempfil -= thempfil/8;
thempfil += DEGREES_TO_DECIDEGREES(getCurrentTemperature());
thempfil += temperature;

switch (telem_state++) {
case 0:
Expand Down
1 change: 1 addition & 0 deletions src/main/sensors/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ typedef enum {
SENSOR_OPFLOW = 1 << 6,
SENSOR_GPS = 1 << 7,
SENSOR_GPSMAG = 1 << 8,
SENSOR_TEMP = 1 << 9
} sensors_e;

extern uint8_t requestedSensors[SENSOR_INDEX_COUNT];
Expand Down
Loading

0 comments on commit 8e12f12

Please sign in to comment.