diff --git a/build/templates/class.js b/build/templates/class.js new file mode 100644 index 0000000..d1e838c --- /dev/null +++ b/build/templates/class.js @@ -0,0 +1,78 @@ +/** + * Class template + * @module j5e/XXX + * @requires module:j5e/event + * @requires module:j5e/fn + */ + +import { Emitter } from "j5e/event"; +import { normalizeParams, getProvider } from "j5e/fn"; + +/** + * Class representing XXX + * @classdesc The XXX class allows for control of XXX + * @async + * @extends Emitter + * @fires Switch#XXX + * @fires Switch#XXX + */ +class XXX extends Emitter { + + #state = { + someStateProp: true + }; + + /** + * Instantiate XXX + * @param {object} options - A pin number, pin identifier or a complete IO options object (See {@tutorial C-INSTANTIATING} + * @property {boolean} XXX - True if XXX + * @example + * Use an XXX + * import XXX from "j5e/XXX"; + * + * const myxxx = await new XXX(12); + * + */ + constructor(options) { + return (async() => { + options = normalizeParams(options); + super(); + + const Provider = await getProvider(options, "builtin/digital"); + this.io = new Provider({ + pin: options.pin, + mode: Provider.Input, + onReadable: () => { + this.emit(this.isOpen ? "open" : "close"); + } + }); + + Object.defineProperties(this, { + XXX: { + get: () => { + return Boolean(this.io.XXX); + } + } + }); + + return this; + })(); + + } + + /** + * doSomething + * @return {XXX} + * @example + * import XXX from "j5e/XXX"; + * + * const myXXX = await new XXX(12); + * myXXX.doSomething(); + */ + doSomething() { + return this; + } + +} + +export default XXX; diff --git a/docs/js/lunr-data.js b/docs/js/lunr-data.js index a20f36c..4c14149 100644 --- a/docs/js/lunr-data.js +++ b/docs/js/lunr-data.js @@ -133,6 +133,36 @@ window.lunrData = { "onc", "time" ], + "module-j5e_relay-Relay.html": [ + "allow", + "class", + "control", + "j5e/relay~relay", + "lt;async>", + "module:j5e/relay~relay", + "relay" + ], + "module-j5e_relay-Relay.html#close": [ + "circuit", + "close", + "function", + "module:j5e/relay~relay#clos", + "relay" + ], + "module-j5e_relay-Relay.html#open": [ + "circuit", + "function", + "module:j5e/relay~relay#open", + "open", + "relay" + ], + "module-j5e_relay-Relay.html#toggle": [ + "circuit", + "function", + "module:j5e/relay~relay#toggl", + "relay", + "toggl" + ], "module-j5e_switch-Switch.html": [ "allow", "class", @@ -753,6 +783,12 @@ window.lunrData = { "pwm", "vari" ], + "module-j5e_relay.html": [ + "j5e/relay", + "modul", + "module:j5e/relay", + "relay" + ], "module-j5e_rgb.html": [ "control", "j5e/rgb", @@ -805,7 +841,7 @@ window.lunrData = { "xs" ] }, - "length": 71 + "length": 76 }, "tokenStore": { "root": { @@ -1239,6 +1275,18 @@ window.lunrData = { "ref": "module-j5e_event.Emitter.html#once", "tf": 110 }, + "module-j5e_relay-Relay.html#close": { + "ref": "module-j5e_relay-Relay.html#close", + "tf": 110 + }, + "module-j5e_relay-Relay.html#open": { + "ref": "module-j5e_relay-Relay.html#open", + "tf": 110 + }, + "module-j5e_relay-Relay.html#toggle": { + "ref": "module-j5e_relay-Relay.html#toggle", + "tf": 110 + }, "module-j5e_animation-Animation.html#enqueue": { "ref": "module-j5e_animation-Animation.html#enqueue", "tf": 110 @@ -1754,6 +1802,77 @@ window.lunrData = { }, "/": { "docs": {}, + "r": { + "docs": {}, + "e": { + "docs": {}, + "l": { + "docs": {}, + "a": { + "docs": {}, + "y": { + "docs": { + "module-j5e_relay.html": { + "ref": "module-j5e_relay.html", + "tf": 600 + } + }, + "~": { + "docs": {}, + "r": { + "docs": {}, + "e": { + "docs": {}, + "l": { + "docs": {}, + "a": { + "docs": {}, + "y": { + "docs": { + "module-j5e_relay-Relay.html": { + "ref": "module-j5e_relay-Relay.html", + "tf": 50 + } + } + } + } + } + } + } + } + } + } + } + }, + "g": { + "docs": {}, + "b": { + "docs": { + "module-j5e_rgb.html": { + "ref": "module-j5e_rgb.html", + "tf": 600 + } + }, + "~": { + "docs": {}, + "r": { + "docs": {}, + "g": { + "docs": {}, + "b": { + "docs": { + "module-j5e_rgb-RGB.html": { + "ref": "module-j5e_rgb-RGB.html", + "tf": 50 + } + } + } + } + } + } + } + } + }, "s": { "docs": {}, "w": { @@ -2012,37 +2131,6 @@ window.lunrData = { } } }, - "r": { - "docs": {}, - "g": { - "docs": {}, - "b": { - "docs": { - "module-j5e_rgb.html": { - "ref": "module-j5e_rgb.html", - "tf": 600 - } - }, - "~": { - "docs": {}, - "r": { - "docs": {}, - "g": { - "docs": {}, - "b": { - "docs": { - "module-j5e_rgb-RGB.html": { - "ref": "module-j5e_rgb-RGB.html", - "tf": 50 - } - } - } - } - } - } - } - } - }, "e": { "docs": {}, "a": { @@ -2173,6 +2261,36 @@ window.lunrData = { } } }, + "l": { + "docs": {}, + "a": { + "docs": {}, + "y": { + "docs": { + "module-j5e_relay-Relay.html": { + "ref": "module-j5e_relay-Relay.html", + "tf": 520 + }, + "module-j5e_relay-Relay.html#close": { + "ref": "module-j5e_relay-Relay.html#close", + "tf": 66.66666666666666 + }, + "module-j5e_relay-Relay.html#open": { + "ref": "module-j5e_relay-Relay.html#open", + "tf": 66.66666666666666 + }, + "module-j5e_relay-Relay.html#toggle": { + "ref": "module-j5e_relay-Relay.html#toggle", + "tf": 66.66666666666666 + }, + "module-j5e_relay.html": { + "ref": "module-j5e_relay.html", + "tf": 50 + } + } + } + } + }, "s": { "docs": {}, "u": { @@ -3543,6 +3661,10 @@ window.lunrData = { "docs": {}, "l": { "docs": { + "module-j5e_relay-Relay.html#toggle": { + "ref": "module-j5e_relay-Relay.html#toggle", + "tf": 716.6666666666666 + }, "module-j5e_led-LED.html#toggle": { "ref": "module-j5e_led-LED.html#toggle", "tf": 712.5 @@ -3663,6 +3785,10 @@ window.lunrData = { "docs": {}, "l": { "docs": { + "module-j5e_relay-Relay.html": { + "ref": "module-j5e_relay-Relay.html", + "tf": 10 + }, "module-j5e_switch-Switch.html": { "ref": "module-j5e_switch-Switch.html", "tf": 8.333333333333332 @@ -3829,6 +3955,10 @@ window.lunrData = { "ref": "module-j5e_event.Emitter.html", "tf": 116.25 }, + "module-j5e_relay-Relay.html": { + "ref": "module-j5e_relay-Relay.html", + "tf": 120 + }, "module-j5e_switch-Switch.html": { "ref": "module-j5e_switch-Switch.html", "tf": 118.33333333333333 @@ -3871,6 +4001,17 @@ window.lunrData = { }, "o": { "docs": {}, + "s": { + "docs": {}, + "e": { + "docs": { + "module-j5e_relay-Relay.html#close": { + "ref": "module-j5e_relay-Relay.html#close", + "tf": 716.6666666666666 + } + } + } + }, "c": { "docs": {}, "k": { @@ -3950,6 +4091,37 @@ window.lunrData = { } } }, + "i": { + "docs": {}, + "r": { + "docs": {}, + "c": { + "docs": {}, + "u": { + "docs": {}, + "i": { + "docs": {}, + "t": { + "docs": { + "module-j5e_relay-Relay.html#close": { + "ref": "module-j5e_relay-Relay.html#close", + "tf": 16.666666666666664 + }, + "module-j5e_relay-Relay.html#open": { + "ref": "module-j5e_relay-Relay.html#open", + "tf": 16.666666666666664 + }, + "module-j5e_relay-Relay.html#toggle": { + "ref": "module-j5e_relay-Relay.html#toggle", + "tf": 16.666666666666664 + } + } + } + } + } + } + } + }, "u": { "docs": {}, "r": { @@ -4297,6 +4469,10 @@ window.lunrData = { "docs": {}, "t": { "docs": { + "module-j5e_relay-Relay.html": { + "ref": "module-j5e_relay-Relay.html", + "tf": 50 + }, "module-j5e_switch-Switch.html": { "ref": "module-j5e_switch-Switch.html", "tf": 50 @@ -4741,6 +4917,10 @@ window.lunrData = { "undefined": { "tf": 10 }, + "module-j5e_relay-Relay.html": { + "ref": "module-j5e_relay-Relay.html", + "tf": 10 + }, "module-j5e_switch-Switch.html": { "ref": "module-j5e_switch-Switch.html", "tf": 8.333333333333332 @@ -5014,6 +5194,17 @@ window.lunrData = { }, "p": { "docs": {}, + "e": { + "docs": {}, + "n": { + "docs": { + "module-j5e_relay-Relay.html#open": { + "ref": "module-j5e_relay-Relay.html#open", + "tf": 716.6666666666666 + } + } + } + }, "t": { "docs": { "module-j5e_servo-Servo.html#sweep": { @@ -5139,6 +5330,10 @@ window.lunrData = { "ref": "module-j5e_led.html", "tf": 110 }, + "module-j5e_relay.html": { + "ref": "module-j5e_relay.html", + "tf": 110 + }, "module-j5e_rgb.html": { "ref": "module-j5e_rgb.html", "tf": 120 @@ -5302,98 +5497,390 @@ window.lunrData = { } } }, - "s": { + "r": { "docs": {}, - "w": { - "docs": {}, - "i": { - "docs": {}, - "t": { - "docs": {}, - "c": { - "docs": {}, - "h": { - "docs": { - "module-j5e_switch.html": { - "ref": "module-j5e_switch.html", - "tf": 1300 - } - }, - "~": { - "docs": {}, - "s": { - "docs": {}, - "w": { - "docs": {}, - "i": { - "docs": {}, - "t": { - "docs": {}, - "c": { - "docs": {}, - "h": { - "docs": { - "module-j5e_switch-Switch.html": { - "ref": "module-j5e_switch-Switch.html", - "tf": 1300 - } - } - } - } - } - } - } - } - } - } - } - } - } - }, "e": { "docs": {}, - "r": { + "l": { "docs": {}, - "v": { + "a": { "docs": {}, - "o": { + "y": { "docs": { - "module-j5e_servo.html": { - "ref": "module-j5e_servo.html", + "module-j5e_relay.html": { + "ref": "module-j5e_relay.html", "tf": 1300 } }, "~": { "docs": {}, - "s": { + "r": { "docs": {}, "e": { "docs": {}, - "r": { + "l": { "docs": {}, - "v": { + "a": { "docs": {}, - "o": { + "y": { "docs": { - "module-j5e_servo-Servo.html": { - "ref": "module-j5e_servo-Servo.html", + "module-j5e_relay-Relay.html": { + "ref": "module-j5e_relay-Relay.html", "tf": 1300 } }, "#": { "docs": {}, - "t": { - "docs": {}, - "o": { - "docs": { - "module-j5e_servo-Servo.html#to": { - "ref": "module-j5e_servo-Servo.html#to", - "tf": 1300 - } - } - } - }, - "s": { + "c": { + "docs": {}, + "l": { + "docs": {}, + "o": { + "docs": {}, + "s": { + "docs": { + "module-j5e_relay-Relay.html#close": { + "ref": "module-j5e_relay-Relay.html#close", + "tf": 1150 + } + } + } + } + } + }, + "o": { + "docs": {}, + "p": { + "docs": {}, + "e": { + "docs": {}, + "n": { + "docs": { + "module-j5e_relay-Relay.html#open": { + "ref": "module-j5e_relay-Relay.html#open", + "tf": 1150 + } + } + } + } + } + }, + "t": { + "docs": {}, + "o": { + "docs": {}, + "g": { + "docs": {}, + "g": { + "docs": {}, + "l": { + "docs": { + "module-j5e_relay-Relay.html#toggle": { + "ref": "module-j5e_relay-Relay.html#toggle", + "tf": 1150 + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + }, + "g": { + "docs": {}, + "b": { + "docs": { + "module-j5e_rgb.html": { + "ref": "module-j5e_rgb.html", + "tf": 1300 + } + }, + "~": { + "docs": {}, + "r": { + "docs": {}, + "g": { + "docs": {}, + "b": { + "docs": { + "module-j5e_rgb-RGB.html": { + "ref": "module-j5e_rgb-RGB.html", + "tf": 1300 + } + }, + "#": { + "docs": {}, + "c": { + "docs": {}, + "o": { + "docs": {}, + "l": { + "docs": {}, + "o": { + "docs": {}, + "r": { + "docs": { + "module-j5e_rgb-RGB.html#color": { + "ref": "module-j5e_rgb-RGB.html#color", + "tf": 1150 + } + } + } + } + } + } + }, + "o": { + "docs": {}, + "n": { + "docs": { + "module-j5e_rgb-RGB.html#on": { + "ref": "module-j5e_rgb-RGB.html#on", + "tf": 1300 + } + } + }, + "f": { + "docs": {}, + "f": { + "docs": { + "module-j5e_rgb-RGB.html#off": { + "ref": "module-j5e_rgb-RGB.html#off", + "tf": 1300 + } + } + } + } + }, + "t": { + "docs": {}, + "o": { + "docs": {}, + "g": { + "docs": {}, + "g": { + "docs": {}, + "l": { + "docs": { + "module-j5e_rgb-RGB.html#toggle": { + "ref": "module-j5e_rgb-RGB.html#toggle", + "tf": 1150 + } + } + } + } + } + } + }, + "b": { + "docs": {}, + "l": { + "docs": {}, + "i": { + "docs": {}, + "n": { + "docs": {}, + "k": { + "docs": { + "module-j5e_rgb-RGB.html#blink": { + "ref": "module-j5e_rgb-RGB.html#blink", + "tf": 1150 + } + } + } + } + } + } + }, + "f": { + "docs": {}, + "a": { + "docs": {}, + "d": { + "docs": { + "module-j5e_rgb-RGB.html#fade": { + "ref": "module-j5e_rgb-RGB.html#fade", + "tf": 1150 + } + }, + "e": { + "docs": {}, + "i": { + "docs": {}, + "n": { + "docs": { + "module-j5e_rgb-RGB.html#fadeIn": { + "ref": "module-j5e_rgb-RGB.html#fadeIn", + "tf": 1150 + } + } + } + } + } + } + } + }, + "p": { + "docs": {}, + "u": { + "docs": {}, + "l": { + "docs": {}, + "s": { + "docs": { + "module-j5e_rgb-RGB.html#pulse": { + "ref": "module-j5e_rgb-RGB.html#pulse", + "tf": 1150 + } + } + } + } + } + }, + "a": { + "docs": {}, + "n": { + "docs": {}, + "i": { + "docs": {}, + "m": { + "docs": { + "module-j5e_rgb-RGB.html#animate": { + "ref": "module-j5e_rgb-RGB.html#animate", + "tf": 1150 + } + } + } + } + } + }, + "s": { + "docs": {}, + "t": { + "docs": {}, + "o": { + "docs": {}, + "p": { + "docs": { + "module-j5e_rgb-RGB.html#stop": { + "ref": "module-j5e_rgb-RGB.html#stop", + "tf": 1150 + } + } + } + } + } + } + } + } + } + } + } + } + } + }, + "s": { + "docs": {}, + "w": { + "docs": {}, + "i": { + "docs": {}, + "t": { + "docs": {}, + "c": { + "docs": {}, + "h": { + "docs": { + "module-j5e_switch.html": { + "ref": "module-j5e_switch.html", + "tf": 1300 + } + }, + "~": { + "docs": {}, + "s": { + "docs": {}, + "w": { + "docs": {}, + "i": { + "docs": {}, + "t": { + "docs": {}, + "c": { + "docs": {}, + "h": { + "docs": { + "module-j5e_switch-Switch.html": { + "ref": "module-j5e_switch-Switch.html", + "tf": 1300 + } + } + } + } + } + } + } + } + } + } + } + } + } + }, + "e": { + "docs": {}, + "r": { + "docs": {}, + "v": { + "docs": {}, + "o": { + "docs": { + "module-j5e_servo.html": { + "ref": "module-j5e_servo.html", + "tf": 1300 + } + }, + "~": { + "docs": {}, + "s": { + "docs": {}, + "e": { + "docs": {}, + "r": { + "docs": {}, + "v": { + "docs": {}, + "o": { + "docs": { + "module-j5e_servo-Servo.html": { + "ref": "module-j5e_servo-Servo.html", + "tf": 1300 + } + }, + "#": { + "docs": {}, + "t": { + "docs": {}, + "o": { + "docs": { + "module-j5e_servo-Servo.html#to": { + "ref": "module-j5e_servo-Servo.html#to", + "tf": 1300 + } + } + } + }, + "s": { "docs": {}, "t": { "docs": {}, @@ -6106,201 +6593,6 @@ window.lunrData = { } } }, - "r": { - "docs": {}, - "g": { - "docs": {}, - "b": { - "docs": { - "module-j5e_rgb.html": { - "ref": "module-j5e_rgb.html", - "tf": 1300 - } - }, - "~": { - "docs": {}, - "r": { - "docs": {}, - "g": { - "docs": {}, - "b": { - "docs": { - "module-j5e_rgb-RGB.html": { - "ref": "module-j5e_rgb-RGB.html", - "tf": 1300 - } - }, - "#": { - "docs": {}, - "c": { - "docs": {}, - "o": { - "docs": {}, - "l": { - "docs": {}, - "o": { - "docs": {}, - "r": { - "docs": { - "module-j5e_rgb-RGB.html#color": { - "ref": "module-j5e_rgb-RGB.html#color", - "tf": 1150 - } - } - } - } - } - } - }, - "o": { - "docs": {}, - "n": { - "docs": { - "module-j5e_rgb-RGB.html#on": { - "ref": "module-j5e_rgb-RGB.html#on", - "tf": 1300 - } - } - }, - "f": { - "docs": {}, - "f": { - "docs": { - "module-j5e_rgb-RGB.html#off": { - "ref": "module-j5e_rgb-RGB.html#off", - "tf": 1300 - } - } - } - } - }, - "t": { - "docs": {}, - "o": { - "docs": {}, - "g": { - "docs": {}, - "g": { - "docs": {}, - "l": { - "docs": { - "module-j5e_rgb-RGB.html#toggle": { - "ref": "module-j5e_rgb-RGB.html#toggle", - "tf": 1150 - } - } - } - } - } - } - }, - "b": { - "docs": {}, - "l": { - "docs": {}, - "i": { - "docs": {}, - "n": { - "docs": {}, - "k": { - "docs": { - "module-j5e_rgb-RGB.html#blink": { - "ref": "module-j5e_rgb-RGB.html#blink", - "tf": 1150 - } - } - } - } - } - } - }, - "f": { - "docs": {}, - "a": { - "docs": {}, - "d": { - "docs": { - "module-j5e_rgb-RGB.html#fade": { - "ref": "module-j5e_rgb-RGB.html#fade", - "tf": 1150 - } - }, - "e": { - "docs": {}, - "i": { - "docs": {}, - "n": { - "docs": { - "module-j5e_rgb-RGB.html#fadeIn": { - "ref": "module-j5e_rgb-RGB.html#fadeIn", - "tf": 1150 - } - } - } - } - } - } - } - }, - "p": { - "docs": {}, - "u": { - "docs": {}, - "l": { - "docs": {}, - "s": { - "docs": { - "module-j5e_rgb-RGB.html#pulse": { - "ref": "module-j5e_rgb-RGB.html#pulse", - "tf": 1150 - } - } - } - } - } - }, - "a": { - "docs": {}, - "n": { - "docs": {}, - "i": { - "docs": {}, - "m": { - "docs": { - "module-j5e_rgb-RGB.html#animate": { - "ref": "module-j5e_rgb-RGB.html#animate", - "tf": 1150 - } - } - } - } - } - }, - "s": { - "docs": {}, - "t": { - "docs": {}, - "o": { - "docs": {}, - "p": { - "docs": { - "module-j5e_rgb-RGB.html#stop": { - "ref": "module-j5e_rgb-RGB.html#stop", - "tf": 1150 - } - } - } - } - } - } - } - } - } - } - } - } - } - }, "f": { "docs": {}, "n": { @@ -7156,7 +7448,7 @@ window.lunrData = { } } }, - "length": 649 + "length": 675 }, "corpusTokens": [ "0", @@ -7185,9 +7477,11 @@ window.lunrData = { "ccw", "center", "centerpoint", + "circuit", "class", "clearinterv", "clockwis", + "close", "code", "color", "complex", @@ -7267,6 +7561,8 @@ window.lunrData = { "j5e/fn~tim", "j5e/l", "j5e/led~l", + "j5e/relay", + "j5e/relay~relay", "j5e/rgb", "j5e/rgb~rgb", "j5e/sensor", @@ -7330,6 +7626,11 @@ window.lunrData = { "module:j5e/led~led#puls", "module:j5e/led~led#stop", "module:j5e/led~led#toggl", + "module:j5e/relay", + "module:j5e/relay~relay", + "module:j5e/relay~relay#clos", + "module:j5e/relay~relay#open", + "module:j5e/relay~relay#toggl", "module:j5e/rgb", "module:j5e/rgb~rgb", "module:j5e/rgb~rgb#anim", @@ -7375,6 +7676,7 @@ window.lunrData = { "on", "on/off", "onc", + "open", "opt", "option", "out", @@ -7397,6 +7699,7 @@ window.lunrData = { "read", "readm", "red", + "relay", "remov", "removelisten", "represent", @@ -7580,6 +7883,47 @@ window.lunrData = { "summary": "", "description": "Create an event listener that will only fire one time." }, + "module-j5e_relay-Relay.html": { + "id": "module-j5e_relay-Relay.html", + "kind": "class", + "title": "<async> j5e/relay~Relay", + "longname": "module:j5e/relay~Relay", + "name": "Relay", + "tags": "module:j5e/relay~Relay", + "summary": "", + "description": "The Relay class allows for control of a relay", + "body": "" + }, + "module-j5e_relay-Relay.html#close": { + "id": "module-j5e_relay-Relay.html#close", + "kind": "function", + "title": "close() → {Relay}", + "longname": "module:j5e/relay~Relay#close", + "name": "close", + "tags": "module:j5e/relay~Relay#close close", + "summary": "", + "description": "Close the relay circuit" + }, + "module-j5e_relay-Relay.html#open": { + "id": "module-j5e_relay-Relay.html#open", + "kind": "function", + "title": "open() → {Relay}", + "longname": "module:j5e/relay~Relay#open", + "name": "open", + "tags": "module:j5e/relay~Relay#open open", + "summary": "", + "description": "Open the relay circuit" + }, + "module-j5e_relay-Relay.html#toggle": { + "id": "module-j5e_relay-Relay.html#toggle", + "kind": "function", + "title": "toggle() → {Relay}", + "longname": "module:j5e/relay~Relay#toggle", + "name": "toggle", + "tags": "module:j5e/relay~Relay#toggle toggle", + "summary": "", + "description": "Toggle the relay circuit" + }, "module-j5e_switch-Switch.html": { "id": "module-j5e_switch-Switch.html", "kind": "class", @@ -8142,6 +8486,17 @@ window.lunrData = { "description": "Class library for managing LED's (Light Emitting Diodes). They can be connected to a digital IO (On/Off), or to a PWM IO (varying brightness).", "body": "" }, + "module-j5e_relay.html": { + "id": "module-j5e_relay.html", + "kind": "module", + "title": "j5e/relay", + "longname": "module:j5e/relay", + "name": "j5e/relay", + "tags": "module:j5e/relay", + "summary": "", + "description": "Relay", + "body": "" + }, "module-j5e_rgb.html": { "id": "module-j5e_rgb.html", "kind": "module", diff --git a/docs/js/lunr-data.json b/docs/js/lunr-data.json index 8a6ec25..c93c8a0 100644 --- a/docs/js/lunr-data.json +++ b/docs/js/lunr-data.json @@ -133,6 +133,36 @@ "onc", "time" ], + "module-j5e_relay-Relay.html": [ + "allow", + "class", + "control", + "j5e/relay~relay", + "lt;async>", + "module:j5e/relay~relay", + "relay" + ], + "module-j5e_relay-Relay.html#close": [ + "circuit", + "close", + "function", + "module:j5e/relay~relay#clos", + "relay" + ], + "module-j5e_relay-Relay.html#open": [ + "circuit", + "function", + "module:j5e/relay~relay#open", + "open", + "relay" + ], + "module-j5e_relay-Relay.html#toggle": [ + "circuit", + "function", + "module:j5e/relay~relay#toggl", + "relay", + "toggl" + ], "module-j5e_switch-Switch.html": [ "allow", "class", @@ -753,6 +783,12 @@ "pwm", "vari" ], + "module-j5e_relay.html": [ + "j5e/relay", + "modul", + "module:j5e/relay", + "relay" + ], "module-j5e_rgb.html": [ "control", "j5e/rgb", @@ -805,7 +841,7 @@ "xs" ] }, - "length": 71 + "length": 76 }, "tokenStore": { "root": { @@ -1239,6 +1275,18 @@ "ref": "module-j5e_event.Emitter.html#once", "tf": 110 }, + "module-j5e_relay-Relay.html#close": { + "ref": "module-j5e_relay-Relay.html#close", + "tf": 110 + }, + "module-j5e_relay-Relay.html#open": { + "ref": "module-j5e_relay-Relay.html#open", + "tf": 110 + }, + "module-j5e_relay-Relay.html#toggle": { + "ref": "module-j5e_relay-Relay.html#toggle", + "tf": 110 + }, "module-j5e_animation-Animation.html#enqueue": { "ref": "module-j5e_animation-Animation.html#enqueue", "tf": 110 @@ -1754,6 +1802,77 @@ }, "/": { "docs": {}, + "r": { + "docs": {}, + "e": { + "docs": {}, + "l": { + "docs": {}, + "a": { + "docs": {}, + "y": { + "docs": { + "module-j5e_relay.html": { + "ref": "module-j5e_relay.html", + "tf": 600 + } + }, + "~": { + "docs": {}, + "r": { + "docs": {}, + "e": { + "docs": {}, + "l": { + "docs": {}, + "a": { + "docs": {}, + "y": { + "docs": { + "module-j5e_relay-Relay.html": { + "ref": "module-j5e_relay-Relay.html", + "tf": 50 + } + } + } + } + } + } + } + } + } + } + } + }, + "g": { + "docs": {}, + "b": { + "docs": { + "module-j5e_rgb.html": { + "ref": "module-j5e_rgb.html", + "tf": 600 + } + }, + "~": { + "docs": {}, + "r": { + "docs": {}, + "g": { + "docs": {}, + "b": { + "docs": { + "module-j5e_rgb-RGB.html": { + "ref": "module-j5e_rgb-RGB.html", + "tf": 50 + } + } + } + } + } + } + } + } + }, "s": { "docs": {}, "w": { @@ -2012,37 +2131,6 @@ } } }, - "r": { - "docs": {}, - "g": { - "docs": {}, - "b": { - "docs": { - "module-j5e_rgb.html": { - "ref": "module-j5e_rgb.html", - "tf": 600 - } - }, - "~": { - "docs": {}, - "r": { - "docs": {}, - "g": { - "docs": {}, - "b": { - "docs": { - "module-j5e_rgb-RGB.html": { - "ref": "module-j5e_rgb-RGB.html", - "tf": 50 - } - } - } - } - } - } - } - } - }, "e": { "docs": {}, "a": { @@ -2173,6 +2261,36 @@ } } }, + "l": { + "docs": {}, + "a": { + "docs": {}, + "y": { + "docs": { + "module-j5e_relay-Relay.html": { + "ref": "module-j5e_relay-Relay.html", + "tf": 520 + }, + "module-j5e_relay-Relay.html#close": { + "ref": "module-j5e_relay-Relay.html#close", + "tf": 66.66666666666666 + }, + "module-j5e_relay-Relay.html#open": { + "ref": "module-j5e_relay-Relay.html#open", + "tf": 66.66666666666666 + }, + "module-j5e_relay-Relay.html#toggle": { + "ref": "module-j5e_relay-Relay.html#toggle", + "tf": 66.66666666666666 + }, + "module-j5e_relay.html": { + "ref": "module-j5e_relay.html", + "tf": 50 + } + } + } + } + }, "s": { "docs": {}, "u": { @@ -3543,6 +3661,10 @@ "docs": {}, "l": { "docs": { + "module-j5e_relay-Relay.html#toggle": { + "ref": "module-j5e_relay-Relay.html#toggle", + "tf": 716.6666666666666 + }, "module-j5e_led-LED.html#toggle": { "ref": "module-j5e_led-LED.html#toggle", "tf": 712.5 @@ -3663,6 +3785,10 @@ "docs": {}, "l": { "docs": { + "module-j5e_relay-Relay.html": { + "ref": "module-j5e_relay-Relay.html", + "tf": 10 + }, "module-j5e_switch-Switch.html": { "ref": "module-j5e_switch-Switch.html", "tf": 8.333333333333332 @@ -3829,6 +3955,10 @@ "ref": "module-j5e_event.Emitter.html", "tf": 116.25 }, + "module-j5e_relay-Relay.html": { + "ref": "module-j5e_relay-Relay.html", + "tf": 120 + }, "module-j5e_switch-Switch.html": { "ref": "module-j5e_switch-Switch.html", "tf": 118.33333333333333 @@ -3871,6 +4001,17 @@ }, "o": { "docs": {}, + "s": { + "docs": {}, + "e": { + "docs": { + "module-j5e_relay-Relay.html#close": { + "ref": "module-j5e_relay-Relay.html#close", + "tf": 716.6666666666666 + } + } + } + }, "c": { "docs": {}, "k": { @@ -3950,6 +4091,37 @@ } } }, + "i": { + "docs": {}, + "r": { + "docs": {}, + "c": { + "docs": {}, + "u": { + "docs": {}, + "i": { + "docs": {}, + "t": { + "docs": { + "module-j5e_relay-Relay.html#close": { + "ref": "module-j5e_relay-Relay.html#close", + "tf": 16.666666666666664 + }, + "module-j5e_relay-Relay.html#open": { + "ref": "module-j5e_relay-Relay.html#open", + "tf": 16.666666666666664 + }, + "module-j5e_relay-Relay.html#toggle": { + "ref": "module-j5e_relay-Relay.html#toggle", + "tf": 16.666666666666664 + } + } + } + } + } + } + } + }, "u": { "docs": {}, "r": { @@ -4297,6 +4469,10 @@ "docs": {}, "t": { "docs": { + "module-j5e_relay-Relay.html": { + "ref": "module-j5e_relay-Relay.html", + "tf": 50 + }, "module-j5e_switch-Switch.html": { "ref": "module-j5e_switch-Switch.html", "tf": 50 @@ -4741,6 +4917,10 @@ "undefined": { "tf": 10 }, + "module-j5e_relay-Relay.html": { + "ref": "module-j5e_relay-Relay.html", + "tf": 10 + }, "module-j5e_switch-Switch.html": { "ref": "module-j5e_switch-Switch.html", "tf": 8.333333333333332 @@ -5014,6 +5194,17 @@ }, "p": { "docs": {}, + "e": { + "docs": {}, + "n": { + "docs": { + "module-j5e_relay-Relay.html#open": { + "ref": "module-j5e_relay-Relay.html#open", + "tf": 716.6666666666666 + } + } + } + }, "t": { "docs": { "module-j5e_servo-Servo.html#sweep": { @@ -5139,6 +5330,10 @@ "ref": "module-j5e_led.html", "tf": 110 }, + "module-j5e_relay.html": { + "ref": "module-j5e_relay.html", + "tf": 110 + }, "module-j5e_rgb.html": { "ref": "module-j5e_rgb.html", "tf": 120 @@ -5302,98 +5497,390 @@ } } }, - "s": { + "r": { "docs": {}, - "w": { - "docs": {}, - "i": { - "docs": {}, - "t": { - "docs": {}, - "c": { - "docs": {}, - "h": { - "docs": { - "module-j5e_switch.html": { - "ref": "module-j5e_switch.html", - "tf": 1300 - } - }, - "~": { - "docs": {}, - "s": { - "docs": {}, - "w": { - "docs": {}, - "i": { - "docs": {}, - "t": { - "docs": {}, - "c": { - "docs": {}, - "h": { - "docs": { - "module-j5e_switch-Switch.html": { - "ref": "module-j5e_switch-Switch.html", - "tf": 1300 - } - } - } - } - } - } - } - } - } - } - } - } - } - }, "e": { "docs": {}, - "r": { + "l": { "docs": {}, - "v": { + "a": { "docs": {}, - "o": { + "y": { "docs": { - "module-j5e_servo.html": { - "ref": "module-j5e_servo.html", + "module-j5e_relay.html": { + "ref": "module-j5e_relay.html", "tf": 1300 } }, "~": { "docs": {}, - "s": { + "r": { "docs": {}, "e": { "docs": {}, - "r": { + "l": { "docs": {}, - "v": { + "a": { "docs": {}, - "o": { + "y": { "docs": { - "module-j5e_servo-Servo.html": { - "ref": "module-j5e_servo-Servo.html", + "module-j5e_relay-Relay.html": { + "ref": "module-j5e_relay-Relay.html", "tf": 1300 } }, "#": { "docs": {}, - "t": { - "docs": {}, - "o": { - "docs": { - "module-j5e_servo-Servo.html#to": { - "ref": "module-j5e_servo-Servo.html#to", - "tf": 1300 - } - } - } - }, - "s": { + "c": { + "docs": {}, + "l": { + "docs": {}, + "o": { + "docs": {}, + "s": { + "docs": { + "module-j5e_relay-Relay.html#close": { + "ref": "module-j5e_relay-Relay.html#close", + "tf": 1150 + } + } + } + } + } + }, + "o": { + "docs": {}, + "p": { + "docs": {}, + "e": { + "docs": {}, + "n": { + "docs": { + "module-j5e_relay-Relay.html#open": { + "ref": "module-j5e_relay-Relay.html#open", + "tf": 1150 + } + } + } + } + } + }, + "t": { + "docs": {}, + "o": { + "docs": {}, + "g": { + "docs": {}, + "g": { + "docs": {}, + "l": { + "docs": { + "module-j5e_relay-Relay.html#toggle": { + "ref": "module-j5e_relay-Relay.html#toggle", + "tf": 1150 + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + }, + "g": { + "docs": {}, + "b": { + "docs": { + "module-j5e_rgb.html": { + "ref": "module-j5e_rgb.html", + "tf": 1300 + } + }, + "~": { + "docs": {}, + "r": { + "docs": {}, + "g": { + "docs": {}, + "b": { + "docs": { + "module-j5e_rgb-RGB.html": { + "ref": "module-j5e_rgb-RGB.html", + "tf": 1300 + } + }, + "#": { + "docs": {}, + "c": { + "docs": {}, + "o": { + "docs": {}, + "l": { + "docs": {}, + "o": { + "docs": {}, + "r": { + "docs": { + "module-j5e_rgb-RGB.html#color": { + "ref": "module-j5e_rgb-RGB.html#color", + "tf": 1150 + } + } + } + } + } + } + }, + "o": { + "docs": {}, + "n": { + "docs": { + "module-j5e_rgb-RGB.html#on": { + "ref": "module-j5e_rgb-RGB.html#on", + "tf": 1300 + } + } + }, + "f": { + "docs": {}, + "f": { + "docs": { + "module-j5e_rgb-RGB.html#off": { + "ref": "module-j5e_rgb-RGB.html#off", + "tf": 1300 + } + } + } + } + }, + "t": { + "docs": {}, + "o": { + "docs": {}, + "g": { + "docs": {}, + "g": { + "docs": {}, + "l": { + "docs": { + "module-j5e_rgb-RGB.html#toggle": { + "ref": "module-j5e_rgb-RGB.html#toggle", + "tf": 1150 + } + } + } + } + } + } + }, + "b": { + "docs": {}, + "l": { + "docs": {}, + "i": { + "docs": {}, + "n": { + "docs": {}, + "k": { + "docs": { + "module-j5e_rgb-RGB.html#blink": { + "ref": "module-j5e_rgb-RGB.html#blink", + "tf": 1150 + } + } + } + } + } + } + }, + "f": { + "docs": {}, + "a": { + "docs": {}, + "d": { + "docs": { + "module-j5e_rgb-RGB.html#fade": { + "ref": "module-j5e_rgb-RGB.html#fade", + "tf": 1150 + } + }, + "e": { + "docs": {}, + "i": { + "docs": {}, + "n": { + "docs": { + "module-j5e_rgb-RGB.html#fadeIn": { + "ref": "module-j5e_rgb-RGB.html#fadeIn", + "tf": 1150 + } + } + } + } + } + } + } + }, + "p": { + "docs": {}, + "u": { + "docs": {}, + "l": { + "docs": {}, + "s": { + "docs": { + "module-j5e_rgb-RGB.html#pulse": { + "ref": "module-j5e_rgb-RGB.html#pulse", + "tf": 1150 + } + } + } + } + } + }, + "a": { + "docs": {}, + "n": { + "docs": {}, + "i": { + "docs": {}, + "m": { + "docs": { + "module-j5e_rgb-RGB.html#animate": { + "ref": "module-j5e_rgb-RGB.html#animate", + "tf": 1150 + } + } + } + } + } + }, + "s": { + "docs": {}, + "t": { + "docs": {}, + "o": { + "docs": {}, + "p": { + "docs": { + "module-j5e_rgb-RGB.html#stop": { + "ref": "module-j5e_rgb-RGB.html#stop", + "tf": 1150 + } + } + } + } + } + } + } + } + } + } + } + } + } + }, + "s": { + "docs": {}, + "w": { + "docs": {}, + "i": { + "docs": {}, + "t": { + "docs": {}, + "c": { + "docs": {}, + "h": { + "docs": { + "module-j5e_switch.html": { + "ref": "module-j5e_switch.html", + "tf": 1300 + } + }, + "~": { + "docs": {}, + "s": { + "docs": {}, + "w": { + "docs": {}, + "i": { + "docs": {}, + "t": { + "docs": {}, + "c": { + "docs": {}, + "h": { + "docs": { + "module-j5e_switch-Switch.html": { + "ref": "module-j5e_switch-Switch.html", + "tf": 1300 + } + } + } + } + } + } + } + } + } + } + } + } + } + }, + "e": { + "docs": {}, + "r": { + "docs": {}, + "v": { + "docs": {}, + "o": { + "docs": { + "module-j5e_servo.html": { + "ref": "module-j5e_servo.html", + "tf": 1300 + } + }, + "~": { + "docs": {}, + "s": { + "docs": {}, + "e": { + "docs": {}, + "r": { + "docs": {}, + "v": { + "docs": {}, + "o": { + "docs": { + "module-j5e_servo-Servo.html": { + "ref": "module-j5e_servo-Servo.html", + "tf": 1300 + } + }, + "#": { + "docs": {}, + "t": { + "docs": {}, + "o": { + "docs": { + "module-j5e_servo-Servo.html#to": { + "ref": "module-j5e_servo-Servo.html#to", + "tf": 1300 + } + } + } + }, + "s": { "docs": {}, "t": { "docs": {}, @@ -6106,201 +6593,6 @@ } } }, - "r": { - "docs": {}, - "g": { - "docs": {}, - "b": { - "docs": { - "module-j5e_rgb.html": { - "ref": "module-j5e_rgb.html", - "tf": 1300 - } - }, - "~": { - "docs": {}, - "r": { - "docs": {}, - "g": { - "docs": {}, - "b": { - "docs": { - "module-j5e_rgb-RGB.html": { - "ref": "module-j5e_rgb-RGB.html", - "tf": 1300 - } - }, - "#": { - "docs": {}, - "c": { - "docs": {}, - "o": { - "docs": {}, - "l": { - "docs": {}, - "o": { - "docs": {}, - "r": { - "docs": { - "module-j5e_rgb-RGB.html#color": { - "ref": "module-j5e_rgb-RGB.html#color", - "tf": 1150 - } - } - } - } - } - } - }, - "o": { - "docs": {}, - "n": { - "docs": { - "module-j5e_rgb-RGB.html#on": { - "ref": "module-j5e_rgb-RGB.html#on", - "tf": 1300 - } - } - }, - "f": { - "docs": {}, - "f": { - "docs": { - "module-j5e_rgb-RGB.html#off": { - "ref": "module-j5e_rgb-RGB.html#off", - "tf": 1300 - } - } - } - } - }, - "t": { - "docs": {}, - "o": { - "docs": {}, - "g": { - "docs": {}, - "g": { - "docs": {}, - "l": { - "docs": { - "module-j5e_rgb-RGB.html#toggle": { - "ref": "module-j5e_rgb-RGB.html#toggle", - "tf": 1150 - } - } - } - } - } - } - }, - "b": { - "docs": {}, - "l": { - "docs": {}, - "i": { - "docs": {}, - "n": { - "docs": {}, - "k": { - "docs": { - "module-j5e_rgb-RGB.html#blink": { - "ref": "module-j5e_rgb-RGB.html#blink", - "tf": 1150 - } - } - } - } - } - } - }, - "f": { - "docs": {}, - "a": { - "docs": {}, - "d": { - "docs": { - "module-j5e_rgb-RGB.html#fade": { - "ref": "module-j5e_rgb-RGB.html#fade", - "tf": 1150 - } - }, - "e": { - "docs": {}, - "i": { - "docs": {}, - "n": { - "docs": { - "module-j5e_rgb-RGB.html#fadeIn": { - "ref": "module-j5e_rgb-RGB.html#fadeIn", - "tf": 1150 - } - } - } - } - } - } - } - }, - "p": { - "docs": {}, - "u": { - "docs": {}, - "l": { - "docs": {}, - "s": { - "docs": { - "module-j5e_rgb-RGB.html#pulse": { - "ref": "module-j5e_rgb-RGB.html#pulse", - "tf": 1150 - } - } - } - } - } - }, - "a": { - "docs": {}, - "n": { - "docs": {}, - "i": { - "docs": {}, - "m": { - "docs": { - "module-j5e_rgb-RGB.html#animate": { - "ref": "module-j5e_rgb-RGB.html#animate", - "tf": 1150 - } - } - } - } - } - }, - "s": { - "docs": {}, - "t": { - "docs": {}, - "o": { - "docs": {}, - "p": { - "docs": { - "module-j5e_rgb-RGB.html#stop": { - "ref": "module-j5e_rgb-RGB.html#stop", - "tf": 1150 - } - } - } - } - } - } - } - } - } - } - } - } - } - }, "f": { "docs": {}, "n": { @@ -7156,7 +7448,7 @@ } } }, - "length": 649 + "length": 675 }, "corpusTokens": [ "0", @@ -7185,9 +7477,11 @@ "ccw", "center", "centerpoint", + "circuit", "class", "clearinterv", "clockwis", + "close", "code", "color", "complex", @@ -7267,6 +7561,8 @@ "j5e/fn~tim", "j5e/l", "j5e/led~l", + "j5e/relay", + "j5e/relay~relay", "j5e/rgb", "j5e/rgb~rgb", "j5e/sensor", @@ -7330,6 +7626,11 @@ "module:j5e/led~led#puls", "module:j5e/led~led#stop", "module:j5e/led~led#toggl", + "module:j5e/relay", + "module:j5e/relay~relay", + "module:j5e/relay~relay#clos", + "module:j5e/relay~relay#open", + "module:j5e/relay~relay#toggl", "module:j5e/rgb", "module:j5e/rgb~rgb", "module:j5e/rgb~rgb#anim", @@ -7375,6 +7676,7 @@ "on", "on/off", "onc", + "open", "opt", "option", "out", @@ -7397,6 +7699,7 @@ "read", "readm", "red", + "relay", "remov", "removelisten", "represent", @@ -7580,6 +7883,47 @@ "summary": "", "description": "Create an event listener that will only fire one time." }, + "module-j5e_relay-Relay.html": { + "id": "module-j5e_relay-Relay.html", + "kind": "class", + "title": "<async> j5e/relay~Relay", + "longname": "module:j5e/relay~Relay", + "name": "Relay", + "tags": "module:j5e/relay~Relay", + "summary": "", + "description": "The Relay class allows for control of a relay", + "body": "" + }, + "module-j5e_relay-Relay.html#close": { + "id": "module-j5e_relay-Relay.html#close", + "kind": "function", + "title": "close() → {Relay}", + "longname": "module:j5e/relay~Relay#close", + "name": "close", + "tags": "module:j5e/relay~Relay#close close", + "summary": "", + "description": "Close the relay circuit" + }, + "module-j5e_relay-Relay.html#open": { + "id": "module-j5e_relay-Relay.html#open", + "kind": "function", + "title": "open() → {Relay}", + "longname": "module:j5e/relay~Relay#open", + "name": "open", + "tags": "module:j5e/relay~Relay#open open", + "summary": "", + "description": "Open the relay circuit" + }, + "module-j5e_relay-Relay.html#toggle": { + "id": "module-j5e_relay-Relay.html#toggle", + "kind": "function", + "title": "toggle() → {Relay}", + "longname": "module:j5e/relay~Relay#toggle", + "name": "toggle", + "tags": "module:j5e/relay~Relay#toggle toggle", + "summary": "", + "description": "Toggle the relay circuit" + }, "module-j5e_switch-Switch.html": { "id": "module-j5e_switch-Switch.html", "kind": "class", @@ -8142,6 +8486,17 @@ "description": "Class library for managing LED's (Light Emitting Diodes). They can be connected to a digital IO (On/Off), or to a PWM IO (varying brightness).", "body": "" }, + "module-j5e_relay.html": { + "id": "module-j5e_relay.html", + "kind": "module", + "title": "j5e/relay", + "longname": "module:j5e/relay", + "name": "j5e/relay", + "tags": "module:j5e/relay", + "summary": "", + "description": "Relay", + "body": "" + }, "module-j5e_rgb.html": { "id": "module-j5e_rgb.html", "kind": "module", diff --git a/docs/list_module.html b/docs/list_module.html index ac90b09..abca609 100644 --- a/docs/list_module.html +++ b/docs/list_module.html @@ -135,6 +135,14 @@

j5e/led

+
+
+
+
+
+
+

j5e/relay

+
diff --git a/docs/module-j5e_relay-Relay.html b/docs/module-j5e_relay-Relay.html new file mode 100644 index 0000000..1d49d16 --- /dev/null +++ b/docs/module-j5e_relay-Relay.html @@ -0,0 +1,430 @@ + + + + + + <async> j5e/relay~Relay + + + + + + + + + + + + + + +
+
+
+ +
+
+
+

new <async> Relay( options )

+
+
+
+
Description
The Relay class allows for control of a relay
+
+
Parameters
+ + + + + + + + + + + + + + + +
NameTypeDescription
optionsobject + A pin number, pin identifier or a complete options object (See Instantiating a Device + + + + + + + + + + + + + + + +
NameTypeDescription
typestring + "NO" (Normally Open) or "NC" (Normally Closed) +
+
+
+
+
Properties
+ + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
isOnboolean + True if switch is on +
typeboolean + True if switch is on +
+
+
Examples

Use a Relay

+
+
import Relay from "j5e/relay";
+			
+			const relay = await new Relay(12);
+
+
Details
+ + + + + + + + + + + + + + + + +
+ + +
+ + + + +
+
+
+
+
+

Methods

+
+
+
+

close() → {Relay}

+
+
+
+
Description
Close the relay circuit
+
Returns
+
+ +
+
+
+
+
+
Examples
+
import Relay from "j5e/relay"
+			
+			const relay = await new Relay(12);
+			
+			// Turn it on
+			relay.close();
+			
+			// Wait 5 seeconds and turn it off
+			system.setTimeout(function() {
+			  relay.open();
+			}, 5000);
+
+
Details
+ + + + + + + + + + + + + + + + +
+ + +
+ + + + +
+
+
+
+
+

open() → {Relay}

+
+
+
+
Description
Open the relay circuit
+
Returns
+
+ +
+
+
+
+
+
Examples
+
import Relay from "j5e/relay"
+			
+			const relay = await new Relay(12);
+			
+			// Turn it on
+			relay.close();
+			
+			// Wait 5 seeconds and turn it off
+			system.setTimeout(function() {
+			  relay.open();
+			}, 5000);
+
+
Details
+ + + + + + + + + + + + + + + + +
+ + +
+ + + + +
+
+
+
+
+

toggle() → {Relay}

+
+
+
+
Description
Toggle the relay circuit
+
Returns
+
+ +
+
+
+
+
+
Examples
+
import Relay from "j5e/relay"
+			
+			const relay = await new Relay(12);
+			
+			// Turn it on
+			relay.toggle();
+			
+			// Wait 5 seeconds and turn it off
+			system.setTimeout(function() {
+			  relay.toggle();
+			}, 5000);
+
+
Details
+ + + + + + + + + + + + + + + + +
+ + +
+ + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
Documentation generated by JSDoc 3.6.4 using the FooDoc template.
+
+ + + + + + + + + + + +Fork me on GitHub + \ No newline at end of file diff --git a/docs/module-j5e_relay.html b/docs/module-j5e_relay.html new file mode 100644 index 0000000..4c4f3d8 --- /dev/null +++ b/docs/module-j5e_relay.html @@ -0,0 +1,198 @@ + + + + + + j5e/relay + + + + + + + + + + + + + + +
+
+
+ +
+
+
+
+
+
Description
Relay
+
Requires
+
+ +
+
+
+
+
+
Details
+ + + + + + + + + + + + + + + + +
+ + +
+ + + + +
+
+
+
+ +
+
+
+ +
+
+
+
+ +
Documentation generated by JSDoc 3.6.4 using the FooDoc template.
+
+ + + + + + + + + + + +Fork me on GitHub + \ No newline at end of file diff --git a/docs/relay_index.js.html b/docs/relay_index.js.html new file mode 100644 index 0000000..0a3feaf --- /dev/null +++ b/docs/relay_index.js.html @@ -0,0 +1,289 @@ + + + + + + + relay/index.js + + + + + + + + + + + + + + +
+
+
+
+
+
/**
+ * Relay
+ * @module j5e/relay
+ * @requires module:j5e/fn
+ */
+
+import { normalizeParams, getProvider } from "j5e/fn";
+
+/**
+ * Class representing a relay
+ * @classdesc The Relay class allows for control of a relay
+ * @async
+ */
+class Relay {
+
+  #state = {
+    isInverted: false,
+    isClosed: false,
+    value: null
+  }
+
+  /**
+   * Instantiate Relay
+   * @param {object} options - A pin number, pin identifier or a complete options object (See {@tutorial C-INSTANTIATING}
+   * @param {string} options.type - "NO" (Normally Open) or "NC" (Normally Closed)
+   * @property {boolean} isOn - True if switch is on
+   * @property {boolean} type - True if switch is on
+   * @example
+   * <caption>Use a Relay</caption>
+   * import Relay from "j5e/relay";
+   *
+   * const relay = await new Relay(12);
+   *
+   */
+  constructor(options) {
+    return (async() => {
+      options = normalizeParams(options);
+
+      const Provider = await getProvider(options, "builtin/digital");
+      this.io = new Provider({
+        pin: options.pin,
+        mode: Provider.Output
+      });
+
+      Object.defineProperties(this, {
+        value: {
+          get: () => {
+            return Number(this.isClosed);
+          }
+        },
+        isClosed: {
+          get: () => {
+            return this.#state.isClosed;
+          }
+        },
+        type: {
+          get: () => {
+            return this.#state.isInverted ? "NC" : "NO";
+          }
+        }
+      });
+
+      if (options.type === "NC") {
+        this.#state.isInverted = true;
+      }
+
+      return this;
+    })();
+
+  }
+
+  /**
+   * Close the relay circuit
+   * @return {Relay}
+   * @example
+   * import Relay from "j5e/relay"
+   *
+   * const relay = await new Relay(12);
+   *
+   * // Turn it on
+   * relay.close();
+   *
+   * // Wait 5 seeconds and turn it off
+   * system.setTimeout(function() {
+   *   relay.open();
+   * }, 5000);
+   */
+  close() {
+    this.io.write(
+      this.#state.isInverted ? 0 : 2 ** (this.io.resolution || 1) - 1
+    );
+    this.#state.isClosed = true;
+
+    return this;
+  }
+
+  /**
+   * Open the relay circuit
+   * @return {Relay}
+   * @example
+   * import Relay from "j5e/relay"
+   *
+   * const relay = await new Relay(12);
+   *
+   * // Turn it on
+   * relay.close();
+   *
+   * // Wait 5 seeconds and turn it off
+   * system.setTimeout(function() {
+   *   relay.open();
+   * }, 5000);
+   */
+  open() {
+
+    this.io.write(
+      this.#state.isInverted ? 2 ** (this.io.resolution || 1) - 1 : 0
+    );
+    this.#state.isClosed = false;
+
+    return this;
+  }
+
+  /**
+   * Toggle the relay circuit
+   * @return {Relay}
+   * @example
+   * import Relay from "j5e/relay"
+   *
+   * const relay = await new Relay(12);
+   *
+   * // Turn it on
+   * relay.toggle();
+   *
+   * // Wait 5 seeconds and turn it off
+   * system.setTimeout(function() {
+   *   relay.toggle();
+   * }, 5000);
+   */
+  toggle() {
+
+    if (this.#state.isClosed) {
+      this.open();
+    } else {
+      this.close();
+    }
+
+    return this;
+  }
+
+}
+
+export default Relay;
+
+
+
+
+
+
+ +
Documentation generated by JSDoc 3.6.4 using the FooDoc template.
+
+ + + + + + + + + + + +Fork me on GitHub + + \ No newline at end of file diff --git a/examples/relay-blink/main.js b/examples/relay-blink/main.js new file mode 100644 index 0000000..d56ff47 --- /dev/null +++ b/examples/relay-blink/main.js @@ -0,0 +1,8 @@ +import Relay from "j5e/relay"; +import { timer } from "j5e/fn"; + +const relay = await new Relay(14); + +timer.setInterval(function() { + relay.toggle(); +}, 1000); \ No newline at end of file diff --git a/examples/relay-blink/manifest.json b/examples/relay-blink/manifest.json new file mode 100644 index 0000000..560d8e8 --- /dev/null +++ b/examples/relay-blink/manifest.json @@ -0,0 +1,9 @@ +{ + "include": [ + "$(MODDABLE)/modules/io/manifest.json", + "$(j5e)/lib/relay/manifest.json" + ], + "modules": { + "*": "./main" + } +} \ No newline at end of file diff --git a/lib/relay/index.js b/lib/relay/index.js new file mode 100644 index 0000000..08535aa --- /dev/null +++ b/lib/relay/index.js @@ -0,0 +1,152 @@ +/** + * Relay + * @module j5e/relay + * @requires module:j5e/fn + */ + +import { normalizeParams, getProvider } from "j5e/fn"; + +/** + * Class representing a relay + * @classdesc The Relay class allows for control of a relay + * @async + */ +class Relay { + + #state = { + isInverted: false, + isClosed: false, + value: null + } + + /** + * Instantiate Relay + * @param {object} options - A pin number, pin identifier or a complete options object (See {@tutorial C-INSTANTIATING} + * @param {string} options.type - "NO" (Normally Open) or "NC" (Normally Closed) + * @property {boolean} isOn - True if switch is on + * @property {boolean} type - True if switch is on + * @example + * Use a Relay + * import Relay from "j5e/relay"; + * + * const relay = await new Relay(12); + * + */ + constructor(options) { + return (async() => { + options = normalizeParams(options); + + const Provider = await getProvider(options, "builtin/digital"); + this.io = new Provider({ + pin: options.pin, + mode: Provider.Output + }); + + Object.defineProperties(this, { + value: { + get: () => { + return Number(this.isClosed); + } + }, + isClosed: { + get: () => { + return this.#state.isClosed; + } + }, + type: { + get: () => { + return this.#state.isInverted ? "NC" : "NO"; + } + } + }); + + if (options.type === "NC") { + this.#state.isInverted = true; + } + + return this; + })(); + + } + + /** + * Close the relay circuit + * @return {Relay} + * @example + * import Relay from "j5e/relay" + * + * const relay = await new Relay(12); + * + * // Turn it on + * relay.close(); + * + * // Wait 5 seeconds and turn it off + * system.setTimeout(function() { + * relay.open(); + * }, 5000); + */ + close() { + this.io.write( + this.#state.isInverted ? 0 : 2 ** (this.io.resolution || 1) - 1 + ); + this.#state.isClosed = true; + + return this; + } + + /** + * Open the relay circuit + * @return {Relay} + * @example + * import Relay from "j5e/relay" + * + * const relay = await new Relay(12); + * + * // Turn it on + * relay.close(); + * + * // Wait 5 seeconds and turn it off + * system.setTimeout(function() { + * relay.open(); + * }, 5000); + */ + open() { + + this.io.write( + this.#state.isInverted ? 2 ** (this.io.resolution || 1) - 1 : 0 + ); + this.#state.isClosed = false; + + return this; + } + + /** + * Toggle the relay circuit + * @return {Relay} + * @example + * import Relay from "j5e/relay" + * + * const relay = await new Relay(12); + * + * // Turn it on + * relay.toggle(); + * + * // Wait 5 seeconds and turn it off + * system.setTimeout(function() { + * relay.toggle(); + * }, 5000); + */ + toggle() { + + if (this.#state.isClosed) { + this.open(); + } else { + this.close(); + } + + return this; + } + +} + +export default Relay; diff --git a/lib/relay/manifest.json b/lib/relay/manifest.json new file mode 100644 index 0000000..59163d6 --- /dev/null +++ b/lib/relay/manifest.json @@ -0,0 +1,18 @@ +{ + "include": [], + "modules": { + "*": [], + "j5e/fn": "$(j5e)/lib/fn/*", + "j5e/relay": "$(j5e)/lib/relay/*" + }, + "preload": [ + "j5e/fn", + "j5e/relay" + ], + "platforms": { + "esp": {}, + "...": { + "error": "Experimental TC53 IO modules unsupported" + } + } +} \ No newline at end of file diff --git a/manifest.json b/manifest.json index 09c1f9f..b2217a1 100644 --- a/manifest.json +++ b/manifest.json @@ -8,6 +8,7 @@ "j5e/event": "$(j5e)/lib/event/*", "j5e/fn": "$(j5e)/lib/fn/*", "j5e/led": "$(j5e)/lib/led/*", + "j5e/relay": "$(j5e)/lib/relay/*", "j5e/rgb": "$(j5e)/lib/rgb/*", "j5e/sensor": "$(j5e)/lib/sensor/*", "j5e/servo": "$(j5e)/lib/servo/*", diff --git a/package.json b/package.json index 2f7e64c..46ef833 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "j5e", - "version": "0.4.7", + "version": "0.5.0", "description": "j5e is a device framework built for ECMA TC-53's IO pattern", "main": "index.js", "exports": { @@ -11,6 +11,7 @@ "./event": "./lib/event/index.js", "./fn": "./lib/fn/index.js", "./led": "./lib/led/index.js", + "./relay": "./lib/relay/index.js", "./rgb": "./lib/rgb/index.js", "./sensor": "./lib/sensor/index.js", "./servo": "./lib/servo/index.js", diff --git a/test/relay.js b/test/relay.js new file mode 100644 index 0000000..1aa96a4 --- /dev/null +++ b/test/relay.js @@ -0,0 +1,312 @@ +import assert from "assert"; +import sinon from "sinon"; +import { Digital } from "@dtex/mock-io"; +import Relay from "j5e/relay"; +import { resolveAny } from "dns"; + +describe("Relay", function() { + + describe("Instantiation", function() { + + it("should return a valid Relay instance", async function() { + + const relay = await new Relay({ + pin: 12, + io: Digital + }); + + assert.equal(relay instanceof Relay, true); + assert.equal(relay.type, "NO"); + + }); + + describe("Options", function() { + + describe("type", async function() { + + it("should return a valid, inverted Relay instance", async function() { + + const relay = await new Relay({ + pin: 12, + io: Digital, + type: "NC" + }); + + assert.equal(relay instanceof Relay, true); + assert.equal(relay.type, "NC"); + + }); + + }); + }); + + }); + + describe("Properties", function() { + + describe("value", function() { + + it("should respond with 0 when Normally Open and open", async function() { + + const relay = await new Relay({ + pin: 12, + io: Digital + }); + + assert.equal(relay.value, 0); + + }); + + it("should respond with 1 when Normally Open and closed", async function() { + + const relay = await new Relay({ + pin: 12, + io: Digital + }); + + relay.close(); + assert.equal(relay.value, 1); + + }); + + it("should respond with 0 when Normally Closed and open", async function() { + + const relay = await new Relay({ + pin: 12, + io: Digital, + type: "NC" + }); + + assert.equal(relay.value, 0); + + }); + + it("should respond with 1 when Normally Closed and closed", async function() { + + const relay = await new Relay({ + pin: 12, + io: Digital, + type: "NC" + }); + + relay.close(); + assert.equal(relay.value, 1); + + }); + + }); + + describe("isClosed", function() { + + it("should respond with false when Normally Open and open", async function() { + + const relay = await new Relay({ + pin: 12, + io: Digital + }); + + assert.equal(relay.isClosed, false); + + }); + + it("should respond with true when Normally Open and closed", async function() { + + const relay = await new Relay({ + pin: 12, + io: Digital + }); + + relay.close(); + assert.equal(relay.isClosed, true); + + }); + + it("should respond with false when Normally Closed and open", async function() { + + const relay = await new Relay({ + pin: 12, + io: Digital, + type: "NC" + }); + + assert.equal(relay.isClosed, false); + + }); + + it("should respond with true when Normally Closed and closed", async function() { + + const relay = await new Relay({ + pin: 12, + io: Digital, + type: "NC" + }); + + relay.close(); + assert.equal(relay.isClosed, true); + + }); + + }); + + describe("type", function() { + + it("should respond with \"NO\" when Normally Open", async function() { + + const relay = await new Relay({ + pin: 12, + io: Digital + }); + + assert.equal(relay.type, "NO"); + + }); + + it("should respond with \"NC\" when Normally Closed", async function() { + + const relay = await new Relay({ + pin: 12, + io: Digital, + type: "NC" + }); + + assert.equal(relay.type, "NC"); + + }); + + }); + + }); + + describe("Methods", function() { + + describe("close", function() { + + it("should write HIGH to IO", async function() { + const relay = await new Relay({ + pin: 12, + io: Digital + }); + + const writeSpy = sinon.spy(relay.io, "write"); + + relay.close(); + assert.equal(writeSpy.callCount, 1); + assert.equal(writeSpy.lastCall.args[0], 1); + + writeSpy.restore(); + + }); + + it("should write LOW to IO when normally closed", async function() { + const relay = await new Relay({ + pin: 12, + io: Digital, + type: "NC" + }); + + const writeSpy = sinon.spy(relay.io, "write"); + + relay.close(); + assert.equal(writeSpy.callCount, 1); + assert.equal(writeSpy.lastCall.args[0], 0); + + writeSpy.restore(); + + }); + + }); + + describe("open", function() { + + it("should write LOW to IO", async function() { + const relay = await new Relay({ + pin: 12, + io: Digital + }); + + const writeSpy = sinon.spy(relay.io, "write"); + + relay.open(); + assert.equal(writeSpy.callCount, 1); + assert.equal(writeSpy.lastCall.args[0], 0); + + writeSpy.restore(); + + }); + + it("should write HIGH to IO when normally closed", async function() { + const relay = await new Relay({ + pin: 12, + io: Digital, + type: "NC" + }); + + const writeSpy = sinon.spy(relay.io, "write"); + + relay.open(); + assert.equal(writeSpy.callCount, 1); + assert.equal(writeSpy.lastCall.args[0], 1); + + writeSpy.restore(); + + }); + + }); + + describe("toggle", function() { + + it("should toggle with LOW = open and HIGH = closed", async function() { + const relay = await new Relay({ + pin: 12, + io: Digital + }); + + const writeSpy = sinon.spy(relay.io, "write"); + + relay.open(); + relay.toggle(); + relay.toggle(); + relay.toggle(); + relay.toggle(); + assert.equal(writeSpy.callCount, 5); + assert.equal(writeSpy.getCall(0).args[0], 0); + assert.equal(writeSpy.getCall(1).args[0], 1); + assert.equal(writeSpy.getCall(2).args[0], 0); + assert.equal(writeSpy.getCall(3).args[0], 1); + assert.equal(writeSpy.getCall(4).args[0], 0); + + writeSpy.restore(); + + }); + + it("should toggle with HIGH = open and LOW = closed when Normally Closed", async function() { + const relay = await new Relay({ + pin: 12, + io: Digital, + type: "NC" + }); + + const writeSpy = sinon.spy(relay.io, "write"); + + relay.open(); + relay.toggle(); + relay.toggle(); + relay.toggle(); + relay.toggle(); + assert.equal(writeSpy.callCount, 5); + assert.equal(writeSpy.getCall(0).args[0], 1); + assert.equal(writeSpy.getCall(1).args[0], 0); + assert.equal(writeSpy.getCall(2).args[0], 1); + assert.equal(writeSpy.getCall(3).args[0], 0); + assert.equal(writeSpy.getCall(4).args[0], 1); + + writeSpy.restore(); + + }); + + + }); + + }); + +});