Ich konnte das Vorhaben dank deiner Unterstützung umsetzen.
Hier der erste Wurf meines Javascripts, vl kanns ja jemand brauchen:
/* -------------------------------------------------------------------------------- */
/* global status variables */
var m_moveCommands = [];
var m_cleanCommands = [];
var m_forceNextCommand = false;
var m_timeout = 0;
/* -------------------------------------------------------------------------------- */
/* trigger point to go back to charging */
on({id: '0_userdata.0.Staubsauger.myCharge'}, function (obj) {
console.log('myCharge Start');
m_moveCommands = [];
m_cleanCommands = [];
setState('ecovacs-deebot.0.control.charge', "1");
});
/* -------------------------------------------------------------------------------- */
/* trigger point to start a cleaning */
on({id: '0_userdata.0.Staubsauger.mySpotArea'}, function (obj) {
console.log('mySpotArea Start');
/* clear old cleaning program */
m_moveCommands = [];
m_cleanCommands = [];
/* get the input information where to clean */
var cleanInput = getState('0_userdata.0.Staubsauger.mySpotArea').val.toString();
/* parse the input */
var cleanCommands = [];
if (cleanInput.includes(","))
{
cleanCommands = cleanInput.split(",");
}
else
{
cleanCommands[0] = cleanInput.toString();
}
/* add the move commands if needed */
/* Schlafzimmertüre */
if (cleanCommands.includes("2")) /* Schlafzimmer */
{
/* move to Schlafzimmertüre */
m_moveCommands[m_moveCommands.length] = "304,-1037";
}
/* Vorzimmertüre */
if (cleanCommands.includes("3") || /* Vorzimmer */
cleanCommands.includes("4") || /* WC */
cleanCommands.includes("6") || /* Badezimmer */
cleanCommands.includes("7")) /* Kammer */
{
/* move to Vorzimmertüre */
m_moveCommands[m_moveCommands.length] = "-2012,2126";
}
/* WC Türe */
if (cleanCommands.includes("4")) /* WC */
{
/* move to WC Türe */
m_moveCommands[m_moveCommands.length] = "-3368,1542";
}
/* Badezimmertüre */
if (cleanCommands.includes("6")) /* Badezimmer */
{
/* move to Badezimmer Türe */
m_moveCommands[m_moveCommands.length] = "-5203,1354";
}
/* Kammer Türe */
if (cleanCommands.includes("7")) /* Kammer */
{
/* move to Kammer Türe */
m_moveCommands[m_moveCommands.length] = "-5698,2844";
}
/* set the global clean commands variable */
m_cleanCommands = cleanCommands;
// force the continuation to start the next program step
m_forceNextCommand = true;
// print program
console.log("New Cleaning Programm:");
console.log(m_moveCommands);
console.log(m_cleanCommands);
});
/* -------------------------------------------------------------------------------- */
/* cyclicly check if the the next command shall be triggered */
schedule('* * * * * *', function () {
/* handle the timeout function */
/* wait a moment to become the program active */
if (0 < m_timeout)
{
if ("idle" != getState('ecovacs-deebot.0.info.cleanstatus').val)
{
m_timeout = 0;
return;
}
m_timeout = m_timeout - 1;
return;
}
/* find out if the robot is still busy or if we force the continuation */
if ("idle" != getState('ecovacs-deebot.0.info.cleanstatus').val &&
false == m_forceNextCommand)
{
// console.log("Busy detected.");
return;
}
m_forceNextCommand = false;
// console.log("Continue with next step if available.");
/* print program */
// console.log(m_moveCommands);
// console.log(m_cleanCommands);
/* execute next move command if needed */
if (0 != m_moveCommands.length)
{
/* get next move command parameter */
const s_move = m_moveCommands.shift();
console.log("goToPostion " + s_move);
/* start the move command */
setState("ecovacs-deebot.0.control.extended.goToPosition", s_move);
m_timeout = 10;
/* stop the execution of this loop */
return;
}
/* execute next clean command if needed */
if (0 != m_cleanCommands.length)
{
/* get next clean command parameter */
var s_clean = "";
for (var i = 0; i < m_cleanCommands.length; i++)
{
s_clean = s_clean + m_cleanCommands[i] + ",";
}
s_clean.substring(0, s_clean.length - 1);
/* remove the commands that will be processed */
m_cleanCommands = [];
console.log("spotArea " + s_clean);
/* start the move command */
setState("ecovacs-deebot.0.control.spotArea", s_clean);
/* stop the execution of this loop */
return;
}
});