Skip to content

Commit

Permalink
properly detect some gen3 devices
Browse files Browse the repository at this point in the history
  • Loading branch information
rand256 committed Dec 2, 2020
1 parent 2b8e6df commit 7e8efbc
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 134 deletions.
10 changes: 5 additions & 5 deletions client/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
stopButton.setAttribute("disabled", "disabled");
Promise.resolve()
.then(res => {
if (fn.device.state === 6 && fn.device.ver !== 3) {
if (fn.device.state === 6 && !fn.device.features.v3) {
return fn.prequest("api/pause_cleaning", "PUT").then(res => new Promise(res => setTimeout(res,19e2)));
}
})
Expand All @@ -136,7 +136,7 @@
homeButton.setAttribute("disabled", "disabled");
Promise.resolve()
.then(res => {
if ([5,11,16,17,18].includes(fn.device.state) && fn.device.ver !== 3) {
if ([5,11,16,17,18].includes(fn.device.state) && !fn.device.features.v3) {
return fn.prequest("api/stop_cleaning", "PUT").then(res => new Promise(res => setTimeout(res,19e2)));
}
})
Expand Down Expand Up @@ -385,7 +385,7 @@
loadingBarHome.setAttribute("indeterminate", "indeterminate");
return Promise.resolve()
.then(res => {
if (fn.device.state === 6 && fn.device.ver !== 3) {
if (fn.device.state === 6 && !fn.device.features.v3) {
return fn.prequest("api/pause_cleaning", "PUT").then(res => new Promise(res => setTimeout(res,19e2)));
}
})
Expand Down Expand Up @@ -668,7 +668,7 @@
robotStateDetailsM2.textContent = ("00" + (res.clean_area / 1000000).toFixed(2)).slice(-6);
robotStateDetailsTime.textContent = fn.secondsToHms(res.clean_time);

fanspeedPresets = fn.device.ver !== 3 ? {
fanspeedPresets = !fn.device.features.v3 ? {
1: i18next.t('home.fanspeedPresets.whisper',"Whisper"),
38: i18next.t('home.fanspeedPresets.quiet',"Quiet"),
60: i18next.t('home.fanspeedPresets.balanced',"Balanced"),
Expand All @@ -680,7 +680,7 @@
103: i18next.t('home.fanspeedPresets.turbo',"Turbo"),
104: i18next.t('home.fanspeedPresets.max',"Max")
};
if (fn.device.model !== "rockrobo.vacuum.v1") {
if (!fn.device.features.nmop) {
fanspeedPresets[105] = i18next.t('home.fanspeedPresets.mop',"Mop");
}
fanspeedButton.innerHTML = "<ons-icon icon=\"fa-superpowers\"></ons-icon> " + (fanspeedPresets[res.fan_power] || `Custom ${res.fan_power}%`);
Expand Down
33 changes: 14 additions & 19 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,21 +224,18 @@
}

var fetchDevice = function(retry) {
return fn.prequest("api/current_status")
return fn.prequest("api/device_features")
.then(res => {
fn.device = {
model: res.model,
ver: res.msg_ver
};
}, err => {
fn.device = {
model: "unknown",
ver: 1
};
setTimeout(() => fetchDevice(true),5e3);
if (res.error) throw res.error;
fn.device = res;
})
.catch(err => {
if (retry) {
throw null;
throw "can't get device features: " + err;
}
return new Promise((resolve,reject) => {
setTimeout(() => fetchDevice(true).then(resolve).catch(e => reject(e)),5e3);
});
})
.then(res => {
let ploadImg = (name,file) => {
Expand All @@ -251,7 +248,6 @@
}
return Promise.all([ploadImg('robotImg',(fn.device.model === 'rockrobo.vacuum.v1' ? 'robot_v1.png' : 'robot.png')),ploadImg('chargerImg','charger.png')]);
})
.catch(e => {});
}

var waitForGlobals = fetchDevice()
Expand Down Expand Up @@ -281,20 +277,19 @@
})
})
.then(res => { window.fn.localize = locI18next.init(i18next,{selectorAttr: 'data-i18n', targetAttr: 'data-i18n-target' }); })
.catch(e => {
fn.localize = function() {};
console.error('loading interface configuration has failed', e);
});
</script>
<div>Loading...</div>
<div id="initial_loading_msg">Loading...</div>
<script type="module" crossorigin>
import { RRMapParser } from "./zone/js-modules/rr-map-parser.js";
import { VacuumMap } from "./zone/js-modules/vacuum-map.js"
window.fn.parseBinaryMap = function(gzippedMap) { return RRMapParser.PARSE(pako.inflate(gzippedMap)) || {}; };
window.fn.createVacuumMap = function(canvasElement) { return new VacuumMap(canvasElement); }

ons.ready(function () {
waitForGlobals.then(() => document.getElementById("appNavigator").pushPage('app-splitter.html'));
waitForGlobals.then(() => document.getElementById("appNavigator").pushPage('app-splitter.html')).catch(e => {
document.getElementById('initial_loading_msg').textContent = "Loading interface configuration has failed.";
console.error(e);
});

// todo: make it work without timeout hacks
switch (window.location.hash) {
Expand Down
5 changes: 2 additions & 3 deletions client/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
fn.prequest("api/map/latest", "GET", "arraybuffer")
.then(res => {
gzippedMapData = res;
return fn.device.ver === 3 ? fn.prequest("api/segment_names") : null;
return fn.device.features.rooms ? fn.prequest("api/segment_names") : null;
})
.then(res => {
var segmentNames = {};
Expand Down Expand Up @@ -375,7 +375,7 @@
document.getElementById("resume_cleaning").onclick = () => {
const res = document.querySelector('.map-page-status').dataset;
if ([2,10,12].includes(+res.state)) {
if (+res.in_returning === 1 || res.model === "rockrobo.vacuum.v1" && +res.in_cleaning === 0 && +res.state === 10) { // Gen1 is missing in_returning state
if (+res.in_returning === 1 || fn.device.features.nret && +res.in_cleaning === 0 && +res.state === 10) { // Gen1 is missing in_returning state
put_command("drive_home","resume_cleaning");
return;
} else if (+res.in_cleaning > 0) {
Expand Down Expand Up @@ -431,7 +431,6 @@
mapPageStatus.dataset['state'] = res['state'];
mapPageStatus.dataset['in_cleaning'] = res['in_cleaning'];
mapPageStatus.dataset['in_returning'] = res['in_returning'];
mapPageStatus.dataset['model'] = res['model'];
if (!fn.webifSettings.staticMapButtons) {
fn.reload_map_buttons(res);
}
Expand Down
4 changes: 2 additions & 2 deletions client/settings-persistent-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,14 @@
loadingBarSettingsPersistentData.setAttribute("indeterminate", "indeterminate");
Promise.all([
fn.prequest("api/current_status").then(res => {
if(fn.device.model === "roborock.vacuum.s5") {
if (!fn.device.features.npd) {
oldLabStatus = res.lab_status === 1;
document.querySelector('.persistent_data_form').classList.remove('hidden');
labModeSwitch.checked = oldLabStatus;
disableMapFunctions(!oldLabStatus);
if (oldLabStatus) {
mapRestoreTypeSelect.options[2].removeAttribute('disabled');
if (res.msg_ver === 3) {
if (fn.device.features.v3) {
mapRestoreTypeSelect.options[3].removeAttribute('disabled');
}
}
Expand Down
24 changes: 12 additions & 12 deletions client/settings-timers.html
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@
form.day.value = cron[2] || "";
form.hour.value = cron[1] || "";
form.minute.value = cron[0] || "";
if (cron[4] === "*" && fn.device.ver === 3 && !zoned) {
if (cron[4] === "*" && fn.device.features.v3 && !zoned) {
form.once.checked = true;
switchTimerOnce(form.once);
} else if (cron[4] !== "0,1,2,3,4,5,6") {
Expand Down Expand Up @@ -812,9 +812,9 @@
if (daySelection.length) {
daySelection = daySelection.sort().join(",");
} else {
daySelection = fn.device.ver === 3 && !zoned ? "0,1,2,3,4,5,6" : "*"; // in 2008 a single asterisk in days means "run once and delete" for native cleaning
daySelection = fn.device.features.v3 && !zoned ? "0,1,2,3,4,5,6" : "*"; // in 2008 a single asterisk in days means "run once and delete" for native cleaning
}
if (form.once.checked && fn.device.ver === 3) {
if (form.once.checked && fn.device.features.v3) {
daySelection = "*"; // that's it, clean and forget
}
// do not allow meaningless timers
Expand All @@ -827,12 +827,12 @@
// fanpower
var fanPower;
switch (form.fan_power_select.value) {
case "0": fanPower = fn.device.ver === 3 ? 101 : 1 ; break;
case "1": fanPower = fn.device.ver === 3 ? 101 : 38; break;
case "3": fanPower = fn.device.ver === 3 ? 103 : 75; break;
case "4": fanPower = fn.device.ver === 3 ? 104 : 100; break;
case "0": fanPower = fn.device.features.v3 ? 101 : 1 ; break;
case "1": fanPower = fn.device.features.v3 === 3 ? 101 : 38; break;
case "3": fanPower = fn.device.features.v3 === 3 ? 103 : 75; break;
case "4": fanPower = fn.device.features.v3 === 3 ? 104 : 100; break;
case "5": fanPower = 105; break;
default: fanPower = fn.device.ver === 3 ? 102 : 60; break;
default: fanPower = fn.device.features.v3 === 3 ? 102 : 60; break;
}
var iterations = +form.iterations_select.value;
// next promises
Expand Down Expand Up @@ -910,12 +910,12 @@
zoned = zoned ? true : false;
// show different headers for different modes and fw
editTimerDialog.querySelectorAll('.ztimer-item').forEach(item => item.style.display = (zoned ? '' : 'none'));
editTimerDialog.querySelectorAll('.ntimer-item').forEach(item => item.style.display = (!zoned && fn.device.ver === 3 ? '' : 'none'));
editTimerDialog.querySelectorAll('.ntimer-item').forEach(item => item.style.display = (!zoned && fn.device.features.v3 ? '' : 'none'));
editTimerDialog.querySelector('.edit-timer-desc').textContent = zoned ? i18next.t('settings.timers.timerZoneDesc',"Choose timer name and zone coordinates.") : i18next.t('settings.timers.timerDesc',"Choose timer settings.");
if (fn.device.ver === 3) {
editTimerDialog.querySelector('select > option[value="0"]').style.display = 'none';
if (fn.device.features.v3) {
editTimerDialog.querySelector('select > option[value="0"]').style.display = 'none'; // v3 devices doesn't have Whisper fanspeed
}
if (fn.device.model === "rockrobo.vacuum.v1") {
if (fn.device.features.nmop) {
editTimerDialog.querySelector('select > option[value="5"]').style.display = 'none';
}
clearTimerDialog(zoned);
Expand Down
6 changes: 3 additions & 3 deletions client/zones.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
let mapData, segmentNames = {};
fn.prequest("api/current_status")
.then ((res) => {
if (fn.device.ver !== 3) {
if (!fn.device.features.rooms) {
return Promise.reject(i18next.t('zones.noSegmentsSupport',"Your device's firmware doesn't support splitting the map into rooms."));
}
if (res['lab_status'] !== 1) {
Expand Down Expand Up @@ -356,10 +356,10 @@
}

ons.getScriptPage().onShow = function () {
if (fn.device.model === "rockrobo.vacuum.v1") {
if (fn.device.features.npd) {
document.getElementById("forbidden-markers-configuration-section").style.display = "none";
}
if (fn.device.ver !== 3) {
if (!fn.device.features.rooms) {
document.getElementById("rooms-configuration-section").style.display = "none";
}
loadingBarZones.setAttribute("indeterminate", "indeterminate");
Expand Down
13 changes: 0 additions & 13 deletions develop/run
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,6 @@ if [ ! -d "./develop/local" ]; then
echo "to suit your needs, then start this script again."
echo ""

echo "Initializing local (development) maps and paths ..."
# Create empty map files for initial run, to prevent errors.
# This should be revisited when the map testing logic is adapted.
if [ ! -f "./map" ]; then
echo "Creating empty map file"
touch ./map
fi

if [ ! -f "./log" ]; then
echo "Creating empty path log file"
touch ./log
fi

exit 1
fi

Expand Down
4 changes: 2 additions & 2 deletions lib/MapManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ MapManager.prototype.loadMap = function(name, callback) {
throw "required files at slot '"+name+"' missing";
}
systemOpts = this.configuration.get("system");
if (status['lab_status'] === 1 && status['msg_ver'] === 3 && ![1,2].includes(systemOpts.mapRestoreType)) { // for 2008+ fw
if (status['lab_status'] === 1 && this.vacuum.features.v3 && ![1,2].includes(systemOpts.mapRestoreType)) { // for 2008+ fw
fs.copyFileSync("/mnt/data/valetudo/maps/" + name + "/last_map", "/mnt/data/rockrobo/user_map" + (self.tempIdx+1));
if (fs.existsSync("/mnt/data/valetudo/maps/" + name + "/PersistData_1.data")) {
fs.copyFileSync("/mnt/data/valetudo/maps/" + name + "/PersistData_1.data", "/mnt/data/rockrobo/PersistData_" + (self.tempIdx+3) + ".data");
Expand Down Expand Up @@ -126,7 +126,7 @@ MapManager.prototype.loadMap = function(name, callback) {
this.configuration.set("system",Object.assign(systemOpts,{afterCleanDest: undefined}));
}
}
if (status['lab_status'] === 1 && status['msg_ver'] === 3 && ![1,2].includes(systemOpts.mapRestoreType)) {
if (status['lab_status'] === 1 && this.vacuum.features.v3 && ![1,2].includes(systemOpts.mapRestoreType)) {
self.vacuum.resetMap(function (err, data) {
if (err) {
return reject(err.toString());
Expand Down
Loading

0 comments on commit 7e8efbc

Please sign in to comment.