Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void readBar(){
- int32_t b3,b6,x1,x2,x3;
- uint32_t b4,b7;
- switch(bar_state){
- case initTemp:
- bar_state=getTemp;
- writeTo(BAR_ADDRESS, 0xF4, 0x2E);
- bar_timers[temp]=millis();
- break;
- case getTemp:
- if(millis()>bar_timers[temp]+BAR_TEMPDELAY){
- bar_state=initPres;
- readFrom(BAR_ADDRESS, 0xF6, 2, bar_buff);
- bar_data[temp]=(bar_buff[0]<<8)|bar_buff[1];
- x1=((bar_data[temp]-(uint16_t)bar_calib[ac6])*(uint16_t)bar_calib[ac5])>>15;
- x2=((int32_t)bar_calib[mc]<<11)/(x1+bar_calib[md]);
- b5=x1+x2;
- bar_data[temp]=(b5+8)>>4;
- }
- break;
- case initPres:
- bar_state=getPres;
- writeTo(BAR_ADDRESS, 0xF4, 0x34+(BAR_SENSITIVITY<<6));
- bar_timers[pressure]=millis();
- break;
- case getPres:
- if(millis()>bar_timers[pressure]+BAR_PRESDELAY){
- if(millis()>bar_timers[temp]+1000)
- bar_state=initTemp;
- else
- bar_state=initPres;
- readFrom(BAR_ADDRESS, 0xF6, 3, bar_buff);
- bar_data[pressure]=((((uint32_t)bar_buff[0])<<16)|((uint32_t)bar_buff[1]<<8)|bar_buff[2])>>(8-BAR_SENSITIVITY);
- b6=b5-4000;
- x1=(bar_calib[b2]*(b6*b6)>>12)>>11;
- x2=(bar_calib[ac2]*b6)>>11;
- x3=x1+x2;
- b3=(((((int32_t)bar_calib[ac1])*4+x3)<<BAR_SENSITIVITY)+2)>>2;
- x1=(bar_calib[ac3]*b6)>>13;
- x2=(bar_calib[b1]*((b6*b6)>>12))>>16;
- x3=((x1+x2)+2)>>2;
- b4=((uint16_t)bar_calib[ac4]*(uint32_t)(x3+32768))>>15;
- b7=((uint32_t)(bar_data[pressure]-b3)*(50000>>BAR_SENSITIVITY));
- if(b7<0x80000000)
- bar_data[pressure]=(b7<<1)/b4;
- else
- bar_data[pressure]=(b7/b4)<<1;
- x1=(bar_data[pressure]>>8)*(bar_data[pressure]>>8);
- x1=(x1*3038)>>16;
- x2=(-7357*bar_data[pressure])>>16;
- bar_data[pressure]+=((x1+x2+3791)>>4);
- }
- break;
- default:
- Serial.println("Error in bar_state!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement