예제 #1
0
void baro_hca_read_event( void ) {
  pBaroRaw = 0;
  // Get raw altimeter from buffer
  pBaroRaw = ((uint16_t)baro_hca_i2c_trans.buf[0] << 8) | baro_hca_i2c_trans.buf[1];

  if (pBaroRaw == 0)
    baro_hca_valid = FALSE;
  else
    baro_hca_valid = TRUE;


  if (baro_hca_valid) {
    //Cut RAW Min and Max
    if (pBaroRaw < BARO_HCA_MIN_OUT)
      pBaroRaw = BARO_HCA_MIN_OUT;
    if (pBaroRaw > BARO_HCA_MAX_OUT)
      pBaroRaw = BARO_HCA_MAX_OUT;

  }
  baro_hca_i2c_trans.status = I2CTransDone;

  uint16_t foo = 0;
  float bar = 0;
#ifdef SENSOR_SYNC_SEND
  DOWNLINK_SEND_BARO_ETS(DefaultChannel, DefaultDevice, &pBaroRaw, &foo, &bar)
#else
    RunOnceEvery(10, DOWNLINK_SEND_BARO_ETS(DefaultChannel, DefaultDevice, &pBaroRaw, &foo, &bar));
#endif

}
예제 #2
0
void baro_ets_read_event(void)
{
  // Get raw altimeter from buffer
  baro_ets_adc = ((uint16_t)(baro_ets_i2c_trans.buf[1]) << 8) | (uint16_t)(baro_ets_i2c_trans.buf[0]);
  // Check if this is valid altimeter
  if (baro_ets_adc == 0) {
    baro_ets_valid = FALSE;
  } else {
    baro_ets_valid = TRUE;
  }

  // Continue only if a new altimeter value was received
  if (baro_ets_valid) {
    // Calculate offset average if not done already
    if (!baro_ets_offset_init) {
      --baro_ets_cnt;
      // Check if averaging completed
      if (baro_ets_cnt == 0) {
        // Calculate average
        baro_ets_offset = (uint16_t)(baro_ets_offset_tmp / BARO_ETS_OFFSET_NBSAMPLES_AVRG);
        // Limit offset
        if (baro_ets_offset < BARO_ETS_OFFSET_MIN) {
          baro_ets_offset = BARO_ETS_OFFSET_MIN;
        }
        if (baro_ets_offset > BARO_ETS_OFFSET_MAX) {
          baro_ets_offset = BARO_ETS_OFFSET_MAX;
        }
        baro_ets_offset_init = TRUE;
      }
      // Check if averaging needs to continue
      else if (baro_ets_cnt <= BARO_ETS_OFFSET_NBSAMPLES_AVRG) {
        baro_ets_offset_tmp += baro_ets_adc;
      }
    }
    // Convert raw to m/s
    if (baro_ets_offset_init) {
      baro_ets_altitude = ground_alt + BARO_ETS_ALT_SCALE * (float)(baro_ets_offset - baro_ets_adc);
      // New value available
      float pressure = BARO_ETS_SCALE * (float) baro_ets_adc + BARO_ETS_PRESSURE_OFFSET;
      AbiSendMsgBARO_ABS(BARO_ETS_SENDER_ID, pressure);
#ifdef BARO_ETS_SYNC_SEND
      DOWNLINK_SEND_BARO_ETS(DefaultChannel, DefaultDevice, &baro_ets_adc, &baro_ets_offset, &baro_ets_altitude);
#endif
    } else {
      baro_ets_altitude = 0.0;
    }
  } else {
    baro_ets_altitude = 0.0;
  }

  // Transaction has been read
  baro_ets_i2c_trans.status = I2CTransDone;
}
예제 #3
0
void baro_hca_read_event(void)
{
  pBaroRaw = 0;
  // Get raw altimeter from buffer
  pBaroRaw = ((uint16_t)baro_hca_i2c_trans.buf[0] << 8) | baro_hca_i2c_trans.buf[1];

  if (pBaroRaw == 0) {
    baro_hca_valid = FALSE;
  } else {
    baro_hca_valid = TRUE;
  }


  if (baro_hca_valid) {
    //Cut RAW Min and Max
    if (pBaroRaw < BARO_HCA_MIN_OUT) {
      pBaroRaw = BARO_HCA_MIN_OUT;
    }
    if (pBaroRaw > BARO_HCA_MAX_OUT) {
      pBaroRaw = BARO_HCA_MAX_OUT;
    }

    float pressure = BARO_HCA_SCALE * (float)pBaroRaw + BARO_HCA_PRESSURE_OFFSET;
    AbiSendMsgBARO_ABS(BARO_HCA_SENDER_ID, pressure);
  }
  baro_hca_i2c_trans.status = I2CTransDone;

  uint16_t foo = 0;
  float bar = 0;
#ifdef SENSOR_SYNC_SEND
  DOWNLINK_SEND_BARO_ETS(DefaultChannel, DefaultDevice, &pBaroRaw, &foo, &bar)
#else
  RunOnceEvery(10, DOWNLINK_SEND_BARO_ETS(DefaultChannel, DefaultDevice, &pBaroRaw, &foo, &bar));
#endif

}