translator, wb_editors
4539
правок
Matveevrj (обсуждение | вклад) |
Matveevrj (обсуждение | вклад) |
||
Строка 82: | Строка 82: | ||
If you need several such motion detectors, then in order not to copy the code, you can wrap the creation of the rule and variables in a function: | If you need several such motion detectors, then in order not to copy the code, you can wrap the creation of the rule and variables in a function: | ||
<syntaxhighlight lang="ecmascript"> | <syntaxhighlight lang="ecmascript"> | ||
function makeMotionDetector(name, timeout_ms, detector_control, relay_control) { | function makeMotionDetector(name, timeout_ms, detector_control, relay_control) { | ||
Строка 90: | Строка 89: | ||
then: function(newValue, devName, cellName) { | then: function(newValue, devName, cellName) { | ||
if (!newValue) { | if (!newValue) { | ||
dev["wb-gpio" | dev["wb-gpio/relay_control"] = true; | ||
if (motion_timer_id) { | if (motion_timer_id) { | ||
clearTimeout(motion_timer_id); | clearTimeout(motion_timer_id); | ||
} | } | ||
motion_timer_id = setTimeout(function() { | |||
motion_timer_id = setTimeout(function() { | dev["wb-gpio/relay_control"] = false; | ||
dev["wb-gpio" | |||
motion_timer_id = null; | motion_timer_id = null; | ||
}, timeout_ms); | }, timeout_ms); | ||
Строка 105: | Строка 102: | ||
}); | }); | ||
} | } | ||
makeMotionDetector("motion_detector_1", 20000, "EXT1_DR1", "EXT2_R3A1"); | makeMotionDetector("motion_detector_1", 20000, "EXT1_DR1", "EXT2_R3A1"); |