From ddf89cf6aade6bab62ea8540b64f94624c93c7b8 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Tue, 29 Aug 2017 08:23:52 -0400 Subject: [PATCH] Start intval logic in module --- lib/intval/index.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/intval/index.js b/lib/intval/index.js index 3b291fb..2d1f7dc 100644 --- a/lib/intval/index.js +++ b/lib/intval/index.js @@ -33,7 +33,11 @@ const PINS = { class Intval { constructor () { this._pin = {} - this._startFrame = 0 + this._state = { + dir : true, //forward + running : false, + startFrame : 0 + } this._declarePins() } _declarePins () { @@ -53,12 +57,25 @@ class Intval { this._pin.fwd.set(0) this._pin.bwd.set(1) } - _watchRelease (err, val) { + _watchMicro (err, val) { if (err) { - console.error(err); + console.error(err) } } + _watchRelease (err, val) { + if (err) { + console.error(err) + } + } + setDir (val = true) { + if (typeof val !== 'boolean') { + return console.warn('Direction must be represented as either true or false') + } + this._state.dir = val + } frame (dir = true, time = 0, delay = 0) { + this._state.running = true + this._pin.micro.watch(this._watchMicro) if (delay !== 0) { setTimeout(function () { if (dir) { @@ -76,8 +93,14 @@ class Intval { } } } + _stop () { + this._pin.fwd.set(0) + this._pin.bwd.set(0) + this._pin.micro.unwatch() + this._state.running = false + } status () { - return {} + return this._state } }