Advertisement
otakus

Untitled

Nov 10th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1. void readBar(){
  2.   int32_t b3,b6,x1,x2,x3;
  3.   uint32_t b4,b7;
  4.  
  5.   switch(bar_state){
  6.     case initTemp:
  7.       bar_state=getTemp;
  8.       writeTo(BAR_ADDRESS, 0xF4, 0x2E);
  9.       bar_timers[temp]=millis();
  10.       break;
  11.     case getTemp:
  12.       if(millis()>bar_timers[temp]+BAR_TEMPDELAY){
  13.         bar_state=initPres;
  14.         readFrom(BAR_ADDRESS, 0xF6, 2, bar_buff);
  15.         bar_data[temp]=(bar_buff[0]<<8)|bar_buff[1];
  16.         x1=((bar_data[temp]-(uint16_t)bar_calib[ac6])*(uint16_t)bar_calib[ac5])>>15;
  17.         x2=((int32_t)bar_calib[mc]<<11)/(x1+bar_calib[md]);
  18.         b5=x1+x2;
  19.         bar_data[temp]=(b5+8)>>4;
  20.       }
  21.       break;
  22.     case initPres:
  23.       bar_state=getPres;
  24.       writeTo(BAR_ADDRESS, 0xF4, 0x34+(BAR_SENSITIVITY<<6));
  25.       bar_timers[pressure]=millis();
  26.       break;
  27.     case getPres:    
  28.       if(millis()>bar_timers[pressure]+BAR_PRESDELAY){
  29.         if(millis()>bar_timers[temp]+1000)
  30.           bar_state=initTemp;
  31.         else
  32.           bar_state=initPres;
  33.         readFrom(BAR_ADDRESS, 0xF6, 3, bar_buff);
  34.         bar_data[pressure]=((((uint32_t)bar_buff[0])<<16)|((uint32_t)bar_buff[1]<<8)|bar_buff[2])>>(8-BAR_SENSITIVITY);
  35.         b6=b5-4000;
  36.         x1=(bar_calib[b2]*(b6*b6)>>12)>>11;
  37.         x2=(bar_calib[ac2]*b6)>>11;
  38.         x3=x1+x2;
  39.         b3=(((((int32_t)bar_calib[ac1])*4+x3)<<BAR_SENSITIVITY)+2)>>2;
  40.         x1=(bar_calib[ac3]*b6)>>13;
  41.         x2=(bar_calib[b1]*((b6*b6)>>12))>>16;
  42.         x3=((x1+x2)+2)>>2;
  43.         b4=((uint16_t)bar_calib[ac4]*(uint32_t)(x3+32768))>>15;
  44.         b7=((uint32_t)(bar_data[pressure]-b3)*(50000>>BAR_SENSITIVITY));
  45.        
  46.         if(b7<0x80000000)
  47.           bar_data[pressure]=(b7<<1)/b4;
  48.         else
  49.           bar_data[pressure]=(b7/b4)<<1;
  50.         x1=(bar_data[pressure]>>8)*(bar_data[pressure]>>8);
  51.         x1=(x1*3038)>>16;
  52.         x2=(-7357*bar_data[pressure])>>16;
  53.         bar_data[pressure]+=((x1+x2+3791)>>4);
  54.       }
  55.       break;
  56.     default:
  57.       Serial.println("Error in bar_state!");
  58.   }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement