diff --git a/components/endpoints/class.command.js b/components/endpoints/class.command.js index 5aca593..f39f4e4 100644 --- a/components/endpoints/class.command.js +++ b/components/endpoints/class.command.js @@ -188,13 +188,18 @@ module.exports = class Command { * @param {Array} [params] Parameter array * @param {Function} [cb] Callback */ - trigger(params, cb = () => { }) { + trigger(params, cb) { if (!cb && params instanceof Function) { cb = params; params = []; } + if (!params && !cb) { + params = []; + cb = () => { }; + } + let worker = this.#privates.get("handler"); let iface = interfaces.get(this.interface); diff --git a/components/scenes/makro-types.js b/components/scenes/makro-types.js index 1175eb9..6db6c82 100644 --- a/components/scenes/makro-types.js +++ b/components/scenes/makro-types.js @@ -27,7 +27,14 @@ module.exports = { "component": "endpoints", "item": endpoint, "method": "trigger", - "args": [command] + "args": [command, () => { + + //console.log("Command executed adasdasdfasdfasdfasfdadsfasdf", err || success) + // how should this be catched? + // reject the makro execution if one command fails? + // or ignore it simple, and continue? + + }] }); resolve(_id); diff --git a/helper/map.js b/helper/map.js new file mode 100644 index 0000000..7b6324e --- /dev/null +++ b/helper/map.js @@ -0,0 +1,28 @@ +/** + * @function map + * Maps a range to another range + * + * @param {Number} value + * @param {Number} low1 + * @param {Number} high1 + * @param {Number} low2 + * @param {Number} high2 + * + * @example + * ```js + * // convert hex to mb + * console.log(map(255, 0, 255, 0, 1024)); // 1024 + * ``` + * + * @example + * ```js + * console.log(map(128, 0, 255, 0, 1024)); // 512 + * ``` + * + * @returns {Number} Convert input number + */ +function map(value, low1, high1, low2, high2) { + return low2 + (high2 - low2) * (value - low1) / (high1 - low1); +} + +module.exports = map; \ No newline at end of file diff --git a/system/component/class.item.js b/system/component/class.item.js index 3367abe..65b9258 100644 --- a/system/component/class.item.js +++ b/system/component/class.item.js @@ -22,7 +22,7 @@ module.exports = class Item { } }); - let labels = new Labels(...obj.labels); + let labels = new Labels(...obj.labels || []); Object.defineProperty(this, "labels", { get() {