Example #1
0
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;
	}
}
Example #2
0
float getCurrentAltitude()
{
	CoEnterMutexSection(PressureAtSeaLevelMutex);
	float p0 = pressureAtSeaLevel;
	CoLeaveMutexSection(PressureAtSeaLevelMutex);

	float p = getCurrentPressure()/100;
	float temp = Pow((p0/p),(1/5.257))-1;
	float t = getTemperature()/10;
	temp = temp * (t+273.15);
	return temp/0.0065;
}
Example #3
0
float calculateCurrentPressureAtSeaLevel(float currentAltitude)
{
	float t = getTemperature()/10;
	float p = getCurrentPressure()/100;
	float temp = 1-((0.0065*currentAltitude)/(t+(0.0065*currentAltitude)+273.15));
	temp = Pow(temp,-5.257);
	temp = p*temp;

	CoEnterMutexSection(PressureAtSeaLevelMutex);
	pressureAtSeaLevel = temp;
	CoLeaveMutexSection(PressureAtSeaLevelMutex);

	return temp;
}