Ejemplo n.º 1
0
void humid_sht_periodic(void)
{
  uint8_t error = 0, checksum;

  if (humid_sht_status == SHT_IDLE) {
    /* init humidity read */
    s_connectionreset();
    s_start_measure(HUMI);
    humid_sht_status = SHT_MEASURING_HUMID;
  } else if (humid_sht_status == SHT_MEASURING_HUMID) {
    /* get data */
    error += s_read_measure(&humidsht, &checksum);

    if (error != 0) {
      s_connectionreset();
      s_start_measure(HUMI);    //restart
      //LED_TOGGLE(2);
    } else {
      error += s_start_measure(TEMP);
      humid_sht_status = SHT_MEASURING_TEMP;
    }
  } else if (humid_sht_status == SHT_MEASURING_TEMP) {
    /* get data */
    error += s_read_measure(&tempsht, &checksum);

    if (error != 0) {
      s_connectionreset();
      s_start_measure(TEMP);    //restart
      //LED_TOGGLE(2);
    } else {
      calc_sht(humidsht, tempsht, &fhumidsht, &ftempsht);
      humid_sht_available = true;
      s_connectionreset();
      s_start_measure(HUMI);
      humid_sht_status = SHT_MEASURING_HUMID;
      DOWNLINK_SEND_SHT_STATUS(DefaultChannel, DefaultDevice, &humidsht, &tempsht, &fhumidsht, &ftempsht);
      humid_sht_available = false;

#if SHT_SDLOG
  if (pprzLogFile != -1) {
    if (!log_sht_started) {
      sdLogWriteLog(pprzLogFile, "SHT75: Humid(pct) Temp(degC) GPS_fix TOW(ms) Week Lat(1e7deg) Lon(1e7deg) HMSL(mm) gspeed(cm/s) course(1e7deg) climb(cm/s)\n");
      log_sht_started = true;
    }
    sdLogWriteLog(pprzLogFile, "sht75: %9.4f %9.4f    %d %d %d   %d %d %d   %d %d %d\n",
		  fhumidsht, ftempsht,
		  gps.fix, gps.tow, gps.week,
		  gps.lla_pos.lat, gps.lla_pos.lon, gps.hmsl,
		  gps.gspeed, gps.course, -gps.ned_vel.z);
  }
#endif

    }
  }
}
Ejemplo n.º 2
0
void humid_sht_periodic(void) {
  uint8_t error=0, checksum;

  if (humid_sht_status == SHT_IDLE) {
    /* init humidity read */
    s_connectionreset();
    s_start_measure(HUMI);
    humid_sht_status = SHT_MEASURING_HUMID;
  }
  else if (humid_sht_status == SHT_MEASURING_HUMID) {
    /* get data */
    error += s_read_measure(&humidsht, &checksum);

    if (error != 0) {
      s_connectionreset();
      s_start_measure(HUMI);    //restart
      LED_TOGGLE(2);
    }
    else {
      error += s_start_measure(TEMP);
      humid_sht_status = SHT_MEASURING_TEMP;
    }
  }
  else if (humid_sht_status == SHT_MEASURING_TEMP) {
    /* get data */
    error += s_read_measure(&tempsht, &checksum);

    if (error != 0) {
      s_connectionreset();
      s_start_measure(TEMP);    //restart
      LED_TOGGLE(2);
    }
    else {
      calc_sht(humidsht, tempsht, &fhumidsht, &ftempsht);
      humid_sht_available = TRUE;
      s_connectionreset();
      s_start_measure(HUMI);
      humid_sht_status = SHT_MEASURING_HUMID;
      DOWNLINK_SEND_SHT_STATUS(DefaultChannel, DefaultDevice, &humidsht, &tempsht, &fhumidsht, &ftempsht);
      humid_sht_available = FALSE;
    }
  }
}
Ejemplo n.º 3
0
void humid_sht_event( void ) {
  if (sht_trans.status == I2CTransSuccess) {
    switch (sht_status) {

    case SHT_TRIG_TEMP:
      sht_status = SHT_GET_TEMP;
      sht_trans.status = I2CTransDone;
      break;

    case SHT_READ_TEMP:
      /* read temperature */
      tempsht = (sht_trans.buf[0] << 8) | sht_trans.buf[1];
      tempsht &= 0xFFFC;
      if (humid_sht_crc(sht_trans.buf) == 0) {
        /* trigger humid measurement, no master hold */
        sht_trans.buf[0] = SHT_TRIGGER_HUMID;
        sht_status = SHT_TRIG_HUMID;
        I2CTransmit(SHT_I2C_DEV, sht_trans, SHT_SLAVE_ADDR, 1);
      }
      else {
        /* checksum error, restart */
        sht_status = SHT_IDLE;
        sht_trans.status == I2CTransDone;
      }
      break;

    case SHT_TRIG_HUMID:
      sht_status = SHT_GET_HUMID;
      sht_trans.status = I2CTransDone;
      break;

    case SHT_READ_HUMID:
      /* read humidity */
      humidsht = (sht_trans.buf[0] << 8) | sht_trans.buf[1];
      humidsht &= 0xFFFC;
      fhumidsht = -6. + 125. / 65536. * humidsht;
      ftempsht = -46.85 + 175.72 / 65536. * tempsht;

      sht_status = SHT_IDLE;
      sht_trans.status = I2CTransDone;

      if (humid_sht_crc(sht_trans.buf) == 0) {
        DOWNLINK_SEND_SHT_STATUS(DefaultChannel, &humidsht, &tempsht, &fhumidsht, &ftempsht);
      }
      break;

    case SHT_RESET:
      sht_status = SHT_SERIAL;
      sht_trans.status = I2CTransDone;
      break;

    case SHT_SERIAL1:
      /* read serial number part 1 */
      sht_serial[5] = sht_trans.buf[0];
      sht_serial[4] = sht_trans.buf[2];
      sht_serial[3] = sht_trans.buf[4];
      sht_serial[2] = sht_trans.buf[6];
      /* get serial number part 2 */
      sht_status = SHT_SERIAL2;
      sht_trans.buf[0] = 0xFC;
      sht_trans.buf[1] = 0xC9;
      I2CTransceive(SHT_I2C_DEV, sht_trans, SHT_SLAVE_ADDR, 2, 6);
      break;

    case SHT_SERIAL2:
      /* read serial number part 2 */
      sht_serial[1] = sht_trans.buf[0];
      sht_serial[0] = sht_trans.buf[1];
      sht_serial[7] = sht_trans.buf[3];
      sht_serial[6] = sht_trans.buf[4];
      sht_serial1=sht_serial[7]<<24|sht_serial[6]<<16|sht_serial[5]<<8|sht_serial[4];
      sht_serial2=sht_serial[3]<<24|sht_serial[2]<<16|sht_serial[1]<<8|sht_serial[0];
      DOWNLINK_SEND_SHT_SERIAL(DefaultChannel, &sht_serial1, &sht_serial2);
      sht_status = SHT_IDLE;
      sht_trans.status = I2CTransDone;
      break;

    default:
      sht_trans.status = I2CTransDone;
      break;
    }
  }
}