download enose.c
Language: C
LOC: 69
Project Info
paparazzi
Server: Savannah NonGNU
Type: cvs
...zzi\paparazzi3\sw\airborne\
   3dmg.c
   3dmg.h
   actuators.c
   actuators.h
   adc.h
   adc_generic.c
   adc_generic.h
   ahrs.c
   ahrs.h
   ahrs_new.c
   ahrs_new.h
   anemotaxis.c
   anemotaxis.h
   ap_downlink.h
   autopilot.h
   bomb.c
   bomb.h
   cam.c
   cam.h
   cam_roll.c
   cam_roll.h
   chemo_detect.c
   chemo_detect.h
   chemotaxis.c
   chemotaxis.h
   commands.c
   commands.h
   control_grz.c
   control_grz.h
   datalink.c
   datalink.h
   dc.c
   dc.h
   discsurvey.c
   discsurvey.h
   downlink.c
   downlink.h
   dpicco.c
   dpicco.h
   enose.c
   enose.h
   estimator.c
   estimator.h
   fbw_downlink.h
   frames.h
   fw_h_ctl.c
   fw_h_ctl.h
   fw_v_ctl.c
   fw_v_ctl.h
   gps.c
   gps.h
   gps_ubx.c
   gps_ubx.h
   gyro.c
   gyro.h
   i2c.c
   i2c.h
   imu.c
   imu.h
   imu_v3.c
   imu_v3.h
   infrared.c
   infrared.h
   inter_mcu.c
   inter_mcu.h
   latlong.c
   latlong.h
   led.h
   link_imu.c
   link_imu.h
   link_mcu.c
   link_mcu.h
   main.c
   main_antenna.c
   main_ap.c
   main_ap.h
   main_demo1.c
   main_demo2.c
   main_demo3.c
   main_demo4.c
   main_demo5.c
   main_demo6.c
   main_fbw.c
   main_fbw.h
   main_grz.c
   main_imu.c
   main_motor_bench.c
   modem.h
   nav.c
   nav.h
   nav_line.c
   nav_line.h
   nav_survey_rectangle.c
   nav_survey_rectangle.h
   paparazzi.h
   point.c
   point.h
   ppm.h
   pprz_transport.c
   pprz_transport.h
   print.h
   radio_control.c
   radio_control.h
   rc_settings.c
   rc_settings.h
   setup_actuators.c
   spi.c
   spi.h
   srf08.c
   srf08.h
   sys_time.c
   sys_time.h
   test_adcs.c
   traffic_info.c
   traffic_info.h
   uart.h
   usb_serial.h
   wavecard.c
   wavecard.h
   xbee.c
   xbee.h

#include <string.h>

#include "enose.h"

#include "i2c.h"
#include "adc.h"
#include CONFIG


uint8_t enose_status;
uint8_t  enose_heat[ENOSE_NB_SENSOR];
uint16_t enose_val[ENOSE_NB_SENSOR];
uint16_t enose_PID_val;

#define ENOSE_SLAVE_ADDR 0xAE
#define ENOSE_PWM_ADDR   0x06
#define ENOSE_DATA_ADDR  0x00
#define ENOSE_HEAT_INIT 237

static uint8_t enose_conf_requested;
static volatile bool_t enose_i2c_done;
static struct adc_buf buf_PID;


void enose_init( void ) {
  uint8_t i;
  for (i=0; i< ENOSE_NB_SENSOR; i++) {
    enose_heat[i] = ENOSE_HEAT_INIT;
    enose_val[i] = 0;
  }
  enose_status = ENOSE_IDLE;
  enose_conf_requested = TRUE;
  enose_i2c_done = TRUE;

#ifdef ADC_CHANNEL_PID
  adc_buf_channel(ADC_CHANNEL_PID, &buf_PID, ADC_CHANNEL_PID_NB_SAMPLES);
#endif
}


void enose_set_heat(uint8_t no_sensor, uint8_t value) {
  enose_heat[no_sensor] = value;
  enose_conf_requested = TRUE;
}


void enose_periodic( void ) {
  enose_PID_val = buf_PID.sum / buf_PID.av_nb_sample;

  if (enose_i2c_done) {
    if (enose_conf_requested) {
      const uint8_t msg[] = { ENOSE_PWM_ADDR, enose_heat[0], enose_heat[1], enose_heat[2] };
      memcpy((void*)i2c_buf, msg, sizeof(msg));
      i2c_transmit(ENOSE_SLAVE_ADDR, sizeof(msg), &enose_i2c_done);
      enose_i2c_done = FALSE;
      enose_conf_requested = FALSE;
    }
    else if (enose_status == ENOSE_IDLE) {
      enose_status = ENOSE_MEASURING_WR;
      const uint8_t msg[] = { ENOSE_DATA_ADDR };  
      memcpy((void*)i2c_buf, msg, sizeof(msg));
      i2c_transmit(ENOSE_SLAVE_ADDR, sizeof(msg), &enose_i2c_done);
      enose_i2c_done = FALSE;
    }
    else if (enose_status == ENOSE_MEASURING_WR) {
      enose_status = ENOSE_MEASURING_RD;
      i2c_receive(ENOSE_SLAVE_ADDR, 6, &enose_i2c_done);
      enose_i2c_done = FALSE;
    }
    else if (enose_status == ENOSE_MEASURING_RD) {
      uint16_t val = (i2c_buf[0]<<8) | i2c_buf[1];
      if (val < 5000) 
	enose_val[0] = val;
      val = (i2c_buf[2]<<8) | i2c_buf[3];
      if (val < 5000) 
	enose_val[1] = val;
      val = (i2c_buf[4]<<8) | i2c_buf[5];
      if (val < 5000) 
	enose_val[2] = val;
      enose_status = ENOSE_IDLE;
    }
  }
}

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us