Push dev work to master #2

Merged
sixteenmillimeter merged 416 commits from dev into master 2018-07-19 15:29:02 +00:00
4 changed files with 149 additions and 11 deletions
Showing only changes of commit 418d33c8f7 - Show all commits

View File

@ -4,3 +4,16 @@
Class representing the bluetooth interface
**Kind**: global class
<a name="Blootstrap+on"></a>
### blootstrap.on(eventName, callback)
Blootstrap.on() -
Binds functions to events that are triggered by BLE messages
**Kind**: instance method of [<code>Blootstrap</code>](#Blootstrap)
| Param | Type | Description |
| --- | --- | --- |
| eventName | <code>string</code> | Name of the event to to bind |
| callback | <code>function</code> | Invoked when the event is triggered |

View File

@ -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)
<a name="Intval+_declarePins"></a>
### intval._declarePins()
Intval._declarePins() -
(internal function) Declares all Gpio pins that will be used
**Kind**: instance method of [<code>Intval</code>](#Intval)
<a name="Intval+_undeclarePins"></a>
### intval._undeclarePins()
Intval._undeclarePins() -
(internal function) Undeclares all Gpio in event of uncaught error
that interupts the node process
**Kind**: instance method of [<code>Intval</code>](#Intval)
<a name="Intval+frame"></a>
### intval.frame(dir, time, delay)
Intval.frame() -
Begin a single frame with set variables or defaults
**Kind**: instance method of [<code>Intval</code>](#Intval)
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| dir | <code>boolean</code> | <code></code> | (optional) Direction of the frame |
| time | <code>integer</code> | <code></code> | (optional) Exposure time, 0 = minimum |
| delay | <code>delay</code> | <code></code> | (optional) Delay after frame before another can be started |

View File

@ -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)

View File

@ -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(() => {