Fixed filling logic
This commit is contained in:
@@ -24,10 +24,12 @@ Api.addRoute('sensorData', {
|
||||
|
||||
|
||||
function reactToSensorData(nextSensorReading) {
|
||||
console.log("reacting to sensor");
|
||||
var controllerId = nextSensorReading.controllerId;
|
||||
var state = stateOrDefault(controllerId).state;
|
||||
var shouldStartPumping = (!state.in_valve || state.in_valve === 'closed') && ((parseInt(nextSensorReading.tankFull) === 0) && (state.out_valve === 'closed' || state.out_valve === 'closing'));
|
||||
console.log(nextSensorReading , state);
|
||||
var shouldStartPumping = (!state.in_valve || state.in_valve === 'closed' || state.in_valve === 'closing') && ((parseInt(nextSensorReading.tankFull) === 0) && (state.out_valve === 'closed' || state.out_valve === 'closing'));
|
||||
|
||||
var shouldStopPumping = (state.in_valve === 'open' || state.in_valve === 'opening') && (parseInt(nextSensorReading.tankFull) === 1 || state.out_valve === 'open' || state.out_valve === 'opening');
|
||||
|
||||
if (shouldStartPumping) {
|
||||
ControllerState.update({
|
||||
@@ -39,10 +41,7 @@ function reactToSensorData(nextSensorReading) {
|
||||
'set_by': 'server'
|
||||
}
|
||||
});
|
||||
}
|
||||
var shouldStopPumping = (state.in_valve === 'open' || state.in_valve === 'opening') && (parseInt(nextSensorReading.tankFull) === 1 || state.out_valve === 'open' || state.out_valve === 'opening');
|
||||
|
||||
if (shouldStopPumping) {
|
||||
} else if (shouldStopPumping) {
|
||||
ControllerState.update({
|
||||
controller_id: controllerId
|
||||
}, {
|
||||
@@ -102,3 +101,6 @@ function stateOrDefault(id) {
|
||||
});
|
||||
return stateEntry;
|
||||
}
|
||||
|
||||
Meteor.sharedFunctions = Meteor.sharedFunctions || {};
|
||||
Meteor.sharedFunctions.reactToSensorData = reactToSensorData;
|
||||
|
||||
Reference in New Issue
Block a user