Permalink
Browse files

From now on programs started manually can be stopped only manually an…

…d programs started from the app can be stopped only from the app.
  • Loading branch information...
1 parent e9ee268 commit 305229fedfacf6bff6c664c142a5c0241c1f2c07 @morkai committed Mar 4, 2012
@@ -165,6 +165,22 @@ Controller.prototype.stopZone = function(zoneId, done)
});
};
+/**
+ * @param {String} zoneId
+ * @param {Function} done
+ */
+Controller.prototype.resetZone = function(zoneId, done)
+{
+ var zone = this.zones[zoneId];
+
+ if (!zone)
+ {
+ return done();
+ }
+
+ zone.reset(done);
+};
+
/**
* @param {Object} data
* @param {Function} done
@@ -320,6 +336,10 @@ var messageHandlers = {
{
this.stopZone(req, res);
},
+ resetZone: function(req, res)
+ {
+ this.resetZone(req, res);
+ },
startProgram: function(req, res)
{
this.startProgram(req, res);
View
@@ -48,14 +48,29 @@ Zone.prototype.finalize = function(stopReason, done)
this.changeState('stopped', {stopReason: stopReason}, done);
};
+/**
+ * @param {Function} done
+ */
+Zone.prototype.reset = function(done)
+{
+ done();
+
+ this.connected();
+
+ if (this.doesNeedReset)
+ {
+ this.wasReset();
+ }
+};
+
/**
* @param {Object} data
* @param {Function} done
*/
Zone.prototype.startProgram = function(data, done)
{
var options = {
- manual: data.user ? true : false,
+ manual: data.user ? false : true,
program: data.program
};
@@ -473,7 +488,7 @@ Zone.prototype.programStopped = function()
* @param {Number} remainingTime
* @param {String} state
* @param {Number} stepIndex
- * @param {NumbeR} stepIteration
+ * @param {Number} stepIteration
*/
Zone.prototype.updateProgress = function(
remainingTime, state, stepIndex, stepIteration)
@@ -490,8 +505,6 @@ Zone.prototype.updateProgress = function(
Zone.prototype.startAssignedProgram = function()
{
- this.needsReset();
-
this.controller.sendMessage('startAssignedProgram', {
zoneId: this.zone._id
});
@@ -513,6 +526,11 @@ Zone.prototype.onInputChange = function(input, newValue, oldValue)
newValue
);
+ if (input === 'stopButton')
+ {
+ return newValue === 1 ? this.wasReset() : this.needsReset();
+ }
+
if (input === 'connected')
{
return newValue === 1 ? this.wasPlugIn() : this.needsPlugIn();
@@ -57,56 +57,39 @@ function onInputChange(input, newValue, oldValue)
*/
function handleStopButtonChange(zone, newValue, oldValue)
{
- // If somehow stop button is changed while the zone cart is not plugged in
- // to a power supply then the zone needs to be reset
- if (zone.doesNeedPlugIn)
- {
- return zone.needsReset();
- }
-
// If the stop button is released (newValue=0) right after
// connect (oldValue=-1) then the zone needs to be reset
if (newValue === 0 && oldValue === -1)
{
return zone.needsReset();
}
- // If the stop button is pressed (newValue=1) and the zone needs a reset
- // (doesNeedReset=true) then consider the zone to be reset
- if (zone.doesNeedReset && newValue === 1)
- {
- return zone.wasReset();
- }
+ var timers = zone.timers;
- if (!zone.doesNeedReset)
+ // If the stop button is released (newValue=0 and oldValue=1)
+ // then start the start assigned program timer
+ if (newValue === 0 && oldValue === 1)
{
- var timers = zone.timers;
+ clearTimeout(timers.startAssignedProgram);
- // If the stop button is released (newValue=0 and oldValue=1)
- // then start the start assigned program timer
- if (newValue === 0 && oldValue === 1)
+ timers.startAssignedProgram = setTimeout(function()
{
- clearTimeout(timers.startAssignedProgram);
-
- timers.startAssignedProgram = setTimeout(function()
- {
- delete timers.startAssignedProgram;
+ delete timers.startAssignedProgram;
- zone.startAssignedProgram();
- }, START_ASSIGNED_PROGRAM_TIMEOUT);
+ zone.startAssignedProgram();
+ }, START_ASSIGNED_PROGRAM_TIMEOUT);
- return;
- }
+ return;
+ }
- // If the stop button is pressed (newValue=1 and oldValue=0) and the start
- // assigned program timer is running then stop it
- if (newValue === 1 && oldValue === 0)
- {
- clearTimeout(timers.startAssignedProgram);
+ // If the stop button is pressed (newValue=1 and oldValue=0) and the start
+ // assigned program timer is running then stop it
+ if (newValue === 1 && oldValue === 0)
+ {
+ clearTimeout(timers.startAssignedProgram);
- delete timers.startAssignedProgram;
+ delete timers.startAssignedProgram;
- return;
- }
+ return;
}
}
@@ -35,14 +35,13 @@ function onInputChange(input, newValue, oldValue)
// reset and restore it to the connected state
if (input === 'stopButton' && newValue === 1)
{
- this.connected();
- this.wasReset();
+ return this.connected();
}
// If the zone cart was plugged off a power supply then switch to
// the connected state
if (input === 'connected' && newValue === 0)
{
- this.connected();
+ return this.connected();
}
}
@@ -35,14 +35,13 @@ function onInputChange(input, newValue, oldValue)
// reset and restore it to the connected state
if (input === 'stopButton' && newValue === 1)
{
- this.connected();
- this.wasReset();
+ return this.connected();
}
// If the zone cart was plugged off a power supply then switch to
// the connected state
if (input === 'connected' && newValue === 0)
{
- this.connected();
+ return this.connected();
}
}
@@ -17,6 +17,7 @@ exports.enter = function(oldState, options, done)
var zone = this;
zone.program = _.clone(options.program);
+ zone.program.manual = options.manual;
zone.program.remainingTime = zone.program.totalTime;
zone.program.running = true;
@@ -86,6 +87,13 @@ function onInputChange(input, newValue, oldValue)
*/
function handleStopButtonChange(zone, newValue, oldValue)
{
+ // Ignore the stop button input changes if the program was not started
+ // manually
+ if (!zone.program.manual)
+ {
+ return;
+ }
+
var timers = zone.timers;
// If the stop button is pressed (newValue=1)
@@ -33,14 +33,13 @@ function onInputChange(input, newValue, oldValue)
// reset and restore it to the connected state
if (input === 'stopButton' && newValue === 1)
{
- this.connected();
- this.wasReset();
+ return this.connected();
}
// If the zone cart was plugged off a power supply then switch to
// the connected state
if (input === 'connected' && newValue === 0)
{
- this.connected();
+ return this.connected();
}
}
View
@@ -149,7 +149,7 @@ ActiveZone.prototype.programStopped = function(user)
'Program [%s] on zone [%s] was stopped by a user%s.',
this.program.name,
this.zone.name,
- user ? (': ' + user.name) : 'manually'
+ user ? (': ' + user.name) : ' manually'
);
};
@@ -127,6 +127,22 @@ _.extend(ControllerProcess.prototype, {
});
},
+ /**
+ * @param {String} zoneId
+ * @param {Function} done
+ */
+ resetZone: function(zoneId, done)
+ {
+ var activeZone = this.zones[zoneId];
+
+ if (!activeZone)
+ {
+ return done();
+ }
+
+ this.sendMessage('resetZone', zoneId, done);
+ },
+
/**
* @param {Program} program
* @param {String} zoneId
View
@@ -81,6 +81,11 @@ Zone.methods.stop = function(done)
controllerProcesses.stopZone(this._id, done);
};
+Zone.methods.reset = function(done)
+{
+ controllerProcesses.resetZone(this._id, done);
+};
+
Zone.methods.startProgram = function(programId, user, done)
{
var zone = this;
@@ -125,6 +125,18 @@ exports.stopZone = function(zoneId, done)
});
};
+exports.resetZone = function(zoneId, done)
+{
+ var controllerId = zoneToControllerMap[zoneId];
+
+ if (!controllerId)
+ {
+ return done();
+ }
+
+ controllerProcesses[controllerId].resetZone(zoneId, done);
+};
+
exports.startProgram = function(program, zoneId, user, done)
{
var controllerId = zoneToControllerMap[zoneId];
View
@@ -140,6 +140,7 @@ app.post('/zones/:id', function(req, res, next)
var actionPrivileges = {
'startProgram': 'startStop',
'stopProgram': 'startStop',
+ 'reset': 'startStop',
'start': 'diag',
'stop': 'diag'
};
@@ -176,6 +177,10 @@ app.post('/zones/:id', function(req, res, next)
stopProgram(req, res, next, zone, user);
break;
+ case 'reset':
+ resetZone(res, next, zone);
+ break;
+
case 'start':
startZone(res, next, zone);
break;
@@ -595,6 +600,32 @@ function stopZone(res, next, zone)
});
}
+function resetZone(res, next, zone)
+{
+ zone.reset(function(err)
+ {
+ if (err)
+ {
+ console.debug(
+ 'Resetting zone <%s> failed: %s', zone.name, err.message || err
+ );
+
+ if (err instanceof Error)
+ {
+ next(err);
+ }
+ else
+ {
+ res.send(err, 400);
+ }
+ }
+ else
+ {
+ res.send(201);
+ }
+ });
+}
+
function emitNewZoneProgram(zoneId, programId)
{
var activeZone = controllerProcesses.getStartedZone(zoneId);
@@ -21,4 +21,4 @@ <h1>
podłączenie<br>
wózka
</p>
-<input class="startProgram action green" type="button" value="Start">
+<a class="startProgram action green">Start</a>
@@ -10,6 +10,7 @@ <h1>
ręczny<br>
reset
</p>
+<input class="resetZone action blue" type="button" value="Reset">
<p class="info">
Program <em><%- program.name %></em> uruchomiony
<% if (program.startUser) { %>
@@ -10,6 +10,7 @@ <h1>
ręczny<br>
reset
</p>
+<input class="resetZone action blue" type="button" value="Reset">
<p class="info">
Program <em><%- program.name %></em> uruchomiony
<% if (program.startUser) { %>
@@ -5,7 +5,7 @@ <h1>
<a class="programPreview" href="#programs/<%- program._id %>" data-programProperty="program"><%- program.name %></a>
</span>
</h1>
-<input class="stopProgram action red" type="button" value="Stop">
+<a class="stopProgram action red">Stop</a>
<div class="progressBar">
<p class="timeToEnd">&nbsp;</p>
<div class="progressValue">&nbsp;</div>
@@ -10,6 +10,7 @@ <h1>
ręczny<br>
reset
</p>
+<a class="resetZone action blue">Reset</a>
<p class="info">
Program <em><%- program.name %></em> uruchomiony
<% if (program.startUser) { %>
Oops, something went wrong.

0 comments on commit 305229f

Please sign in to comment.