示例#1
0
文件: paraOMP.c 项目: jotia1/COSC3500
int main(int argc, char **argv){
  if (argc != 3) {
    fprintf(stderr, "Usage: sim N0 dt");
    return -1;
  }
  const int N0 = atoi(argv[1]);
  double dt = strtod(argv[2], NULL);
	const int N1 = N0; /* grid size, must be odd */
	/* Watch out for Courant condition (x2 resolution, x4 more time steps */
	const double dx = 1./(N0-1), t_end = 0.5,
			a = 1-4 * dt/ (dx * dx), b = dt/(dx * dx);
	/* TODO probably want to malloc this?? */
	double t = 0., p_gauge, p[N0 * N1], p_new[N0 * N1], tmp[N0 * N1]; 
	int n = 0;
	setInitialPressure(p, N0, N0, N1);

	while (t < t_end) {
		updatePressure(p_new, p, N0, N1, a, b);
		p_gauge = getGauge(p_new, N0, N1);
		n++; t += dt;
		if (t < 0.1){
			printf("time step: %d, t=%e, p at gauge = %e\n", n, t, p_gauge);
		}
		/* TODO can just swap pointers here instead of copy */
		copyPressure(p, p_new, N0, N1);

	}
  return 0;

}
static void *handleTemperaturePressure (void *data)
{
	double temperature;
	double pressure;
	time_t sec;
	double sample = 1200; //trigger time (second) for trend 
	time_t initial = time (NULL) ;
	double delta ;

	for (;;){
		if(bmp085_Calibration(fd) > 0 ){
			temperature = bmp085_GetTemperature(bmp085_ReadUT(fd));
			sleep(1);
			pressure = bmp085_GetPressure(bmp085_ReadUP(fd));
			int press = round(pressure/100);
			int temp = round(temperature/10);
			updateTemp (temp) ;
			updatePressure (press) ;
			sleep(4) ; //Wait 4s to avoid concurrent access
  			sec = time (NULL);
  			delta = difftime(sec,  initial);
   			if (delta > sample ){
  				trend (press);
				initial = time(NULL);
				sleep (1);
			}
		}	
		sleep (2);
	}
	return 0;
}
示例#3
0
文件: pump.c 项目: Daven005/ESP8266
void ICACHE_FLASH_ATTR processPump(void) { // Every 100mS
	updatePressure();
	checkLevel();
	switch (pumpState()) {
	case MANUAL_OFF:
		easygpio_outputSet(PUMP, 0);
		pumpOnCount = 0;
		checkNotFlowing();
		break;
	case MANUAL_ON:
		if (secondsNotFlowing() > 30) {
			pumpState_OffManual();
			easygpio_outputSet(PUMP, 0);
			sounderAlarm(3); // No flow for 30S in Manual
		} else {
			easygpio_outputSet(PUMP, 1);
		}
		break;
	case AUTO_OFF:
		if (getCurrentPressure() < sysCfg.settings[SET_PUMP_ON]) {
			startCheckIsFlowing();
			pumpState_OnAuto();
			easygpio_outputSet(PUMP, 1);
		} else {
			easygpio_outputSet(PUMP, 0);
			pumpOnCount = 0;
			checkNotFlowing();
		}
		sounderClear();
		break;
	case AUTO_ON:
		if (getCurrentPressure() > sysCfg.settings[SET_PUMP_OFF]) {
			pumpState_OffAuto();
			easygpio_outputSet(PUMP, 0);
		} else {
			if (secondsNotFlowing() > sysCfg.settings[SET_NO_FLOW_AUTO_ERROR]) {
				publishAlarm(1, flowAverageReading()); // No flow for SET_NO_FLOW_AUTO_ERROR (10S) in Auto
				sounderAlarm(1);
				publishAlarm(6, secondsNotFlowing()); // No flow for SET_NO_FLOW_AUTO_ERROR (10S) in Auto
				pumpState_OffManual();
			} else {
				pumpOnCount++;
				if (pumpOnCount >= sysCfg.settings[SET_MAX_PUMP_ON_WARNING]
						&& getCurrentPressure() < sysCfg.settings[SET_LOW_PRESSURE_WARNING]) {
					publishError(3, getCurrentPressure()); // Low pressure and Pump On > SET_MAX_PUMP_ON_WARNING
				}
				if (pumpOnCount >= sysCfg.settings[SET_MAX_PUMP_ON_WARNING]) { // 1 minute
					publishError(1, sysCfg.settings[SET_MAX_PUMP_ON_WARNING]);
				} else if (pumpOnCount == sysCfg.settings[SET_MAX_PUMP_ON_ERROR]) { // 5 minutes
					publishAlarm(2, pumpOnCount); // Running for SET_MAX_PUMP_ON_ERROR (5 Minutes) in Auto
					sounderAlarm(2);
				} else if (pumpOnCount > sysCfg.settings[SET_MAX_PUMP_ON_ERROR]) {
					pumpOnCount = sysCfg.settings[SET_MAX_PUMP_ON_ERROR] + 1;
				}
			}
		}
		break;
	}
}
示例#4
0
void TempSensor::updateSensor()
{
    // The BMP180 sensor doesn't need to be read every time through the loop
    if (updateTempCounter > delayCount)
    {
        updateTemperature();
        updatePressure();
        updateAltitude();
        updateTempCounter = 0;
    }
    else
    {
        updateTempCounter++;
    }
}
示例#5
0
void BMP180::update() {
    // make sure we've calibrated
    if (! calibrate()) return;
    // make sure we have a valid temperature at least once per second
    if ((_sinceLastTemperature > temperatureInterval) &&
            (! _pressureRequested)) {
        updateTemperature();
    }
    // don't update pressure when we're waiting for a temperature request
    if (_temperatureRequested) return;
    // update the pressure at the requested interval
    if ((_sinceLastPressure > pressureInterval) || (_pressureRequested)) {
        updatePressure();
    }
}
示例#6
0
int main(int argc, char **argv){
	const int N0 = 51, N1 = N0; /* grid size, must be odd */
	/* Watch out for Courant condition (x2 resolution, x4 more time steps */
	const double dx = 1./(N0-1), dt = 1e-5, t_end = 0.5,
			a = 1-4 * dt/ (dx * dx), b = dt/(dx * dx);
	/* TODO probably want to malloc this?? */
	double t = 0., p_gauge, p[N0 * N1], p_new[N0 * N1], tmp[N0 * N1]; 
	int n = 0;
	setInitialPressure(p, N0, N0, N1);

	while (t < t_end) {
		updatePressure(p_new, p, N0, N1, a, b);
		p_gauge = getGauge(p_new, N0, N1);
		n++; t += dt;
		if (t < 0.1){
			printf("time step: %d, t=%e, p at gauge = %e\n", n, t, p_gauge);
		}
		/* TODO can just swap pointers here instead of copy */
		copyPressure(p, p_new, N0, N1);

	}

}
示例#7
0
void Bmp085::init(){
	uint8_t buf[2];
	I2C2Class::getInstance()->read(BMP085ADDR,AC1,buf,2);
	ac1 = (((int16_t)buf[0])<<8)|((int16_t)buf[1]);
	I2C2Class::getInstance()->read(BMP085ADDR,AC2,buf,2);
	ac2 = (((int16_t)buf[0])<<8)|((int16_t)buf[1]);
	I2C2Class::getInstance()->read(BMP085ADDR,AC3,buf,2);
	ac3 = (((int16_t)buf[0])<<8)|((int16_t)buf[1]);
	I2C2Class::getInstance()->read(BMP085ADDR,AC4,buf,2);
	ac4 = (((uint16_t)buf[0])<<8)|((int16_t)buf[1]);
	I2C2Class::getInstance()->read(BMP085ADDR,AC5,buf,2);
	ac5 = (((uint16_t)buf[0])<<8)|((uint16_t)buf[1]);
	I2C2Class::getInstance()->read(BMP085ADDR,AC6,buf,2);
	ac6 = (((uint16_t)buf[0])<<8)|((uint16_t)buf[1]);
	I2C2Class::getInstance()->read(BMP085ADDR,B1,buf,2);
	b1 = (((int16_t)buf[0])<<8)|((int16_t)buf[1]);
	I2C2Class::getInstance()->read(BMP085ADDR,B2,buf,2);
	b2 = (((int16_t)buf[0])<<8)|((int16_t)buf[1]);
	I2C2Class::getInstance()->read(BMP085ADDR,MB,buf,2);
	mb = (((int16_t)buf[0])<<8)|((int16_t)buf[1]);
	I2C2Class::getInstance()->read(BMP085ADDR,MC,buf,2);
	mc = (((int16_t)buf[0])<<8)|((int16_t)buf[1]);
	I2C2Class::getInstance()->read(BMP085ADDR,MD,buf,2);
	md = (((int16_t)buf[0])<<8)|((int16_t)buf[1]);
	
	for(int i=0;i<20;i++){
		startMeasureingTemp();
		vTaskDelay(10);
		updateTemp();
		
		startMeasureingPressure();
		vTaskDelay(10);
		updatePressure();
	}
	
	startMeasureingTemp();
}
static void *handlePressure (void *data)
{
  double angle ;
  int i, sum ;
  int pressure ;
  int pressures [8] ;

  for (i = 0 ; i < 8 ; ++i)
    pressures [i] = 0 ;

  angle = 0.0 ;

  for (;;)
  {
    sum = 0 ;
    for (i = 0 ; i < 24 ; ++i)
    {
      pressure = (int)rint ((sin (angle / 180.0 * M_PI) + 1.0) * 60.0 + 940) ;
      sum += pressure ;
      updatePressure (pressures, pressure) ;

      angle += 1.0 ;
      if (angle > 360.0)
 	angle = 0.0 ;

      usleep (100000) ;
    }

    for (i = 1 ; i < 8 ; ++i)
      pressures [i - 1] = pressures [i] ;

    pressures [7] = sum / 24 ;
  }

  return NULL ;
}