diff --git a/lib/blootstrap/Readme.md b/lib/blootstrap/Readme.md
index 017bab5..e1b720a 100644
--- a/lib/blootstrap/Readme.md
+++ b/lib/blootstrap/Readme.md
@@ -4,3 +4,16 @@
Class representing the bluetooth interface
**Kind**: global class
+
+
+### blootstrap.on(eventName, callback)
+Blootstrap.on() -
+Binds functions to events that are triggered by BLE messages
+
+**Kind**: instance method of [Blootstrap
](#Blootstrap)
+
+| Param | Type | Description |
+| --- | --- | --- |
+| eventName | string
| Name of the event to to bind |
+| callback | function
| Invoked when the event is triggered |
+
diff --git a/lib/intval/Readme.md b/lib/intval/Readme.md
index 07e7198..176e2b7 100644
--- a/lib/intval/Readme.md
+++ b/lib/intval/Readme.md
@@ -4,3 +4,38 @@
Class representing the intval3 features
**Kind**: global class
+
+* [Intval](#Intval)
+ * [._declarePins()](#Intval+_declarePins)
+ * [._undeclarePins()](#Intval+_undeclarePins)
+ * [.frame(dir, time, delay)](#Intval+frame)
+
+
+
+### intval._declarePins()
+Intval._declarePins() -
+(internal function) Declares all Gpio pins that will be used
+
+**Kind**: instance method of [Intval
](#Intval)
+
+
+### intval._undeclarePins()
+Intval._undeclarePins() -
+(internal function) Undeclares all Gpio in event of uncaught error
+that interupts the node process
+
+**Kind**: instance method of [Intval
](#Intval)
+
+
+### intval.frame(dir, time, delay)
+Intval.frame() -
+Begin a single frame with set variables or defaults
+
+**Kind**: instance method of [Intval
](#Intval)
+
+| Param | Type | Default | Description |
+| --- | --- | --- | --- |
+| dir | boolean
|
| (optional) Direction of the frame |
+| time | integer
|
| (optional) Exposure time, 0 = minimum |
+| delay | delay
|
| (optional) Delay after frame before another can be started |
+
diff --git a/lib/intval/index.js b/lib/intval/index.js
index cbf2e44..5be37e6 100644
--- a/lib/intval/index.js
+++ b/lib/intval/index.js
@@ -30,6 +30,7 @@ const PINS = {
}
}
+/** Class representing the intval3 features */
class Intval {
constructor () {
this._pin = {}
@@ -38,23 +39,38 @@ class Intval {
frame : {
start : 0,
active : false,
+ time : 0,
+ delay : 0,
val : 0,
expected : 0
+ },
+ release : {
+ time: 0,
+ active : false
}
}
this._declarePins()
- process.on('SIGINT', () => {
- this._undeclarePins()
- })
+ process.on('SIGINT', this._undeclarePins)
}
+ /**
+ * Intval._declarePins() -
+ * (internal function) Declares all Gpio pins that will be used
+ *
+ */
_declarePins () {
- this._pin.fwd = Gpio(4, 'out')
- this._pin.bwd = Gpio(5, 'out')
- this._pin.micro = Gpio(6, 'in', 'rising')
- this._pin.release = Gpio(7, 'in', 'both')
+ this._pin.fwd = Gpio(13, 'out')
+ this._pin.bwd = Gpio(19, 'out')
+ this._pin.micro = Gpio(5, 'in', 'rising') //
+ this._pin.release = Gpio(6, 'in', 'both')
this._pin.release.watch(this._watchRelease)
}
+ /**
+ * Intval._undeclarePins() -
+ * (internal function) Undeclares all Gpio in event of uncaught error
+ * that interupts the node process
+ *
+ */
_undeclarePins () {
this._pin.fwd.unexport()
this._pin.bwd.unexport()
@@ -71,6 +87,9 @@ class Intval {
this._pin.bwd.set(1)
}
_watchMicro (err, val) {
+ /* Microswitch + 10K ohm resistor */
+ /* 1 = open */
+ /* 0 = closed */
if (err) {
console.error(err)
}
@@ -78,10 +97,29 @@ class Intval {
//determine when to stop
}
_watchRelease (err, val) {
+ const NOW = +new Date()
+ /* Button + 10K ohm resistor */
+ /* 1 = open */
+ /* 0 = closed */
if (err) {
- console.error(err)
+ return console.error(err)
}
console.log(`Release switch val: ${val}`)
+ if (val === 0) {
+ if (this._state.release.time === 0) {
+ this._state.release.time = NOW
+ this._state.release.active = true //maybe unncecessary
+ } else if (this._state.release.active) {
+ if (NOW - this._state.release.time > 100) {
+ this.frame()
+ } else if (NOW - this._state.release.time > 1000) {
+ this.sequence()
+ }
+ console.log(`Release closed for ${NOW - this._state.release.time}`)
+ this._state.release.time = 0
+ this._state.release.active = false
+ }
+ }
}
setDir (val = true) {
if (typeof val !== 'boolean') {
@@ -89,10 +127,38 @@ class Intval {
}
this._state.dir = val
}
- frame (dir = true, time = 0, delay = 0) {
+ /**
+ * Intval.frame() -
+ * Begin a single frame with set variables or defaults
+ *
+ * @param {boolean} dir (optional) Direction of the frame
+ * @param {integer} time (optional) Exposure time, 0 = minimum
+ * @param {delay} delay (optional) Delay after frame before another can be started
+ *
+ */
+ frame (dir = null, time = null, delay = null) { //may be overloaded, delay is suspect
+ if (dir === true || (dir === null && this._state.dir === true) ) {
+ dir = true
+ } else {
+ dir = false
+ }
+
+ if (time === null && this._state.time !== 0) {
+ time = this._state.time
+ } else {
+ time = 0
+ }
+
+ if (delay === null && this._state.delay !== 0) {
+ delay = this._state.delay
+ } else {
+ delay = 0
+ }
+
this._state.frame.start = +new Date()
this._state.frame.active = true
this._pin.micro.watch(this._watchMicro)
+
if (delay !== 0) {
setTimeout(function () {
if (dir) {
@@ -110,7 +176,10 @@ class Intval {
}
}
}
- _stop () {
+ sequence () {
+ console.log(`Started sequence`)
+ }
+ _stop () {
this._pin.fwd.set(0)
this._pin.bwd.set(0)
diff --git a/tests/gpio.js b/tests/gpio.js
index 56d4a76..ccdd1c5 100644
--- a/tests/gpio.js
+++ b/tests/gpio.js
@@ -6,11 +6,32 @@ const btn = Gpio(5, 'in', 'both')
console.log('Watching input on GPIO 05')
+let saveTime = 0
+let active = false
btn.watch((err, val) => {
+ const NOW = +new Date()
+ /* Button + 10K ohm resistor */
+ /* 1 = open */
+ /* 0 = closed */
if (err) {
return console.error(err)
}
- console.log(val)
+ console.log(`Release switch val: ${val}`)
+ if (val === 0) {
+ if (saveTime === 0) {
+ saveTime = NOW
+ active = true //maybe unncecessary
+ } else if (active) {
+ if (NOW - saveTime > 100) {
+ console.log('Started Frame')
+ } else if (NOW - saveTime > 1000) {
+ console.log('Started Sequence')
+ }
+ console.log(`Release closed for ${NOW - saveTime}`)
+ saveTime = 0
+ active = false
+ }
+ }
})
/*setInterval(() => {