Skip to content

Commit

Permalink
implement resume button for map view
Browse files Browse the repository at this point in the history
universal start/resume is not enough in some cases
  • Loading branch information
rand256 committed Oct 19, 2019
1 parent a26a98b commit a0291c4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 19 deletions.
60 changes: 41 additions & 19 deletions client/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<ons-fab ripple id="start_cleaning">
<ons-icon icon="fa-play"></ons-icon>
</ons-fab>
<ons-fab ripple id="resume_cleaning" style="display: none;">
<span class="resume_pause"><ons-icon icon="fa-pause"></ons-icon></span>
<span class="resume_play"><ons-icon icon="fa-play"></ons-icon></span>
</ons-fab>
<ons-fab ripple id="pause_cleaning" style="display: none;">
<ons-icon icon="fa-pause"></ons-icon>
</ons-fab>
Expand Down Expand Up @@ -161,6 +165,12 @@
document.getElementById("start_cleaning").style.display = 'none';
}
}
// resume available in paused and charger disconnected while in zoned cleaning states
if (res.state === 10 || (res.state === 2 && res.in_cleaning === 2)) {
document.getElementById("resume_cleaning").style.display = '';
} else {
document.getElementById("resume_cleaning").style.display = 'none';
}
// stop not available in paused and idle states, as well as many other states not related to cleaning, and in spot cleaning
if ([3,6,8,9,10,11,14,15,16].includes(res.state)) {
document.getElementById("stop_cleaning").style.display = 'none';
Expand All @@ -184,6 +194,7 @@
window.fn.reset_map_buttons = function() {
document.getElementById("start_cleaning").style.display = '';
document.getElementById("goto").style.display = '';
document.getElementById("resume_cleaning").style.display = 'none';
document.getElementById("pause_cleaning").style.display = 'none';
document.getElementById("spot_clean").style.display = 'none';
document.getElementById("stop_cleaning").style.display = 'none';
Expand All @@ -196,34 +207,29 @@
document.getElementById("start_cleaning").onclick = () => {
const zones = map.getLocations().zones;
const res = document.querySelector('.map-page-status').dataset;
if (+res.state === 10 || (+res.state === 2 && +res.in_cleaning === 2)) {
if (+res.in_returning === 1) {
put_command("drive_home","start_cleaning");
return;
}
if (+res.in_cleaning === 2 && zones.length) {
ons.notification.confirm("Zoned cleaning is on pause. Would you like to continue it or start a new one?",{buttonLabels: ["Continue", "Start new"]}).then(function (answer) {
if (answer === 0) {
put_command("start_cleaning");
} else {
zoned_cleanup(zones);
}
});
return;
}
put_command("start_cleaning");
return;
}
if (zones.length) {
zoned_cleanup(zones);
} else {
ons.notification.confirm("Can't start zoned cleaning: no zones specified. Do you want to run full cleaning instead?").then(function (answer) {
if (answer === 1) {
put_command("start_cleaning");
put_command("start_cleaning_only");
}
});
}
}
document.getElementById("resume_cleaning").onclick = () => {
const zones = map.getLocations().zones;
const res = document.querySelector('.map-page-status').dataset;
if (+res.state === 10 || (+res.state === 2 && +res.in_cleaning === 2)) {
if (+res.in_returning === 1) {
put_command("drive_home","resume_cleaning");
return;
}
put_command("start_cleaning","resume_cleaning");
return;
}
ons.notification.toast("Nothing to resume!", { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout });
}
document.getElementById("stop_cleaning").onclick = () => { put_command("stop_cleaning"); };
document.getElementById("pause_cleaning").onclick = () => { put_command("pause_cleaning"); };
document.getElementById("spot_clean").onclick = () => { put_command("spot_clean"); };
Expand Down Expand Up @@ -354,5 +360,21 @@
background-color: #ffffff;
color: #31313a;
}

.map-page-buttons .resume_pause {
position: absolute;
left: 0.55em;
width: 0.45em;
overflow-x: hidden;
}

.map-page-buttons .resume_play {
position: absolute;
left: 0.97em;
top: -0.02em;
width: 0.9em;
overflow-x: hidden;
transform: scale(0.86);
}
</style>
</ons-page>
10 changes: 10 additions & 0 deletions lib/webserver/WebServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,16 @@ const WebServer = function (options) {
});
});

this.app.put("/api/start_cleaning_only", function (req, res) {
self.vacuum.startCleaning((err, data) => {
if (err) {
res.status(500).send(err.toString());
} else {
res.json(data);
}
});
});

this.app.put("/api/pause_cleaning", function (req, res) {
self.vacuum.pauseCleaning(function (err, data) {
if (err) {
Expand Down

0 comments on commit a0291c4

Please sign in to comment.