예제 #1
0
bool TouchScreen::read(uint16_t *x, uint16_t *y, uint16_t *pressure) {

	lastRawZ = readRawPressure();

	if (lastRawZ < minPressure) return false;
	// two consequent reads to double check coords and reduce errors
	lastRawX = readRawX();
	if (readRawX() != lastRawX) return false;

	lastRawY = readRawY();
	if (readRawY() != lastRawY) return false;

	if (lastRawX < calX1 || lastRawX > calX2 || lastRawY < calY1 || lastRawY > calY2)
			return false;

	lastRawX = (lastRawX - calX1) * TOUCH_WIDTH / (calX2 - calX1);
	lastRawY = (lastRawY - calY1) * TOUCH_HEIGHT / (calY2 - calY1);

	if (m_orientation == PORTRAIT) {
		*x = lastRawY;
		*y = TOUCH_WIDTH - lastRawX;
	} else {
		*x = lastRawX;
		*y = lastRawY;
	}

	*pressure = lastRawZ;

	return true;
}
예제 #2
0
int32_t MS5611::readPressure(bool compensation) {
    uint32_t D1 = readRawPressure();

    uint32_t D2 = readRawTemperature();
    int32_t dT = D2 - (uint32_t) fc[4] * 256;

    int64_t OFF = (int64_t) fc[1] * 65536 + (int64_t) fc[3] * dT / 128;
    int64_t SENS = (int64_t) fc[0] * 32768 + (int64_t) fc[2] * dT / 256;

    if (compensation) {
        int32_t TEMP = 2000 + ((int64_t) dT * fc[5]) / 8388608;

        OFF2 = 0;
        SENS2 = 0;

        if (TEMP < 2000) {
            OFF2 = 5 * ((TEMP - 2000) * (TEMP - 2000)) / 2;
            SENS2 = 5 * ((TEMP - 2000) * (TEMP - 2000)) / 4;
        }

        if (TEMP < -1500) {
            OFF2 = OFF2 + 7 * ((TEMP + 1500) * (TEMP + 1500));
            SENS2 = SENS2 + 11 * ((TEMP + 1500) * (TEMP + 1500)) / 2;
        }

        OFF = OFF - OFF2;
        SENS = SENS - SENS2;
    }

    uint32_t P = (D1 * SENS / 2097152 - OFF) / 32768;

    return P;
}
예제 #3
0
bool SensorReadBARO()
{
#if STACK_BARO
#ifdef BMP085
	if(SensorInitState.BARO_BRAND==BMP085) {
		if((getTickCount()>BaroDoTick)) {
			BaroDoTick = getTickCount() + 6;
			if(BaroDoState==0) {
				Sensor.rawBARO[1] = Sensor.BaroInfo.baroTemperature =  readRawTemperature();// - (28262-3534);
				TriggerRawPressure();
				Baro_Common();
				BaroDoTick = getTickCount() + 21;
				BaroDoState = 1;
				
				return false;
			}
			else {
				Sensor.rawBARO[0] = readRawPressure() - SensorInitState.BARO_BasePressure;
				Sensor.BaroInfo.baroPressure = readPressure();
				TriggerRawTemperature();
				BaroDoState = 0;
				
				return true;
			}
		}
		else
			return false;
	}
	else 
#endif
		static float temperature,pressure,BaroAlt;
		bool beUpdate;
		
		beUpdate = BMP280_GetData(&pressure, &temperature, &BaroAlt);;//TBM
		if(beUpdate) {
			Sensor.rawBARO[0] = Sensor.BaroInfo.baroPressure = pressure;
			Sensor.rawBARO[1] = Sensor.BaroInfo.baroTemperature = temperature;
			Baro_Common();
		}
		return beUpdate;
#else
	return false;
#endif
}
예제 #4
0
void SensorInitBARO()
{
#ifdef BMP085
	SensorInitState.BARO_Done = begin(BMP085_ULTRAHIGHRES);
	if(SensorInitState.BARO_Done)
		SensorInitState.BARO_BRAND = BMP085;
#endif
#ifdef BMP280
		SensorInitState.BARO_Done = Int_BMP280();
		if(SensorInitState.BARO_Done) {
			SensorInitState.BARO_BRAND = BMP280;
			printf("Baro Sensor - [BMP280]\n"); 
		}
		else 
			printf("Baro Sensor - [NA]\n"); 
#endif
		
	if(SensorInitState.BARO_Done) {
		switch (SensorInitState.BARO_BRAND) {
#ifdef BMP085
			case BMP085:
			TriggerRawPressure();
			DelayMsec(24);
			SensorInitState.BARO_BasePressure = readRawPressure();
			TriggerRawTemperature();
			BaroDoTick = getTickCount() + 15;
			BaroDoState = 0;
			Sensor.BaroInfo.baroPressureSum = 0;
			break;
#endif
#ifdef BMP280			
			case BMP280:
			{
				bool isBMP280TestPassed = BMP280SelfTest();
				printf("Baro Test Passed:%d\n",isBMP280TestPassed);
			}
			break;
			#endif	
		}
		printf("BARO connect - [OK]\n");
	}
	else
		printf("BARO connect - [FAIL]\n");
}
예제 #5
0
int32_t ZUNO_BMP180::readPressure(void) {

  int16_t UT = readRawTemperature();
  long    UP = readRawPressure();


  long X1 = UT - ac6;
  long X2 = mc;

  X1 *= ac5;
  X1 >>= 15;
  X2 <<= 11;
  X2 /= (X1 + md);
  //1) => B5 => B6 
  long B6 = (X1 + X2) - 4000;
  #if BMP180_DEBUG
  DEBUG_SERIAL.print("B6 = "); DEBUG_SERIAL.println(B6, DEC); ;
  #endif

  //2) X1
  // X1 = (B2*(B6*B6)/2^12)/2^11
  X2 = X1 = B6;
  X1 *= B6;
  X1 >>= 12;
  uint16_t koef1 = X1;
  X1 *= b2;
  X1 >>= 11;
  //3) 
  // X2 = ac2*b6/2^11
  X2 *= ac2;
  X2 >>= 11;
  // 4
  // B3 = ((4*ac1 + X1 + X2)*2^(oversampling) + 2) / 4
  long B3 = ac1;
  B3 <<= 2;
  B3 += X1 + X2;
  B3 <<= oversampling;
  B3 >>= 2;
  #if BMP180_DEBUG
  DEBUG_SERIAL.print("B3 = "); DEBUG_SERIAL.println(B3, DEC); ;
  #endif

  // 5)
  // X1 = AC3*B6/2^13
  X1 = ac3;
  X1 *= B6;
  X1 >>= 13;
  // 6)
  // X2 = (b1*b6*b6/2^12)/2^16
  X2 = b1;
  X2 *= koef1;
  X2 >>= 16;
  // 
  X1 += X2 + 2;
  X1 >>= 2;

  // B4....
  unsigned long B4 = X1;
  B4 += 32768;
  B4 *= ac4;
  B4 >>= 15;
  #if BMP180_DEBUG
  DEBUG_SERIAL.print("B4 = "); DEBUG_SERIAL.println(B4, DEC);
  #endif



  // B7
  unsigned long B7 = UP-B3; // B7
  B7 *= (50000 >> oversampling); 

  #if BMP180_DEBUG
  DEBUG_SERIAL.print("B7 = "); DEBUG_SERIAL.println(B7, DEC);
  #endif


  long p = (B7 & 0x80000000) ? (B7/B4) << 1 : (B7 << 1) / B4 ;
  
  #if BMP180_DEBUG
  DEBUG_SERIAL.print("p = "); DEBUG_SERIAL.println(p, DEC);
  #endif


  X1 = p >> 8;
  X1 *= X1;
  X1 *= 3038;
  X1 >>= 16;
  X2 = p;
  X2 *= -7357;
  X2 >>= 16;
  X1 += X2 + 3791;
  X1 >>= 4;

  p += X1; 

  return p;
}