Refactor arduino library as a class, using Typescript now.
This commit is contained in:
parent
fce259d29b
commit
c276525d3a
|
@ -1,82 +1,23 @@
|
||||||
## Classes
|
|
||||||
|
|
||||||
<dl>
|
|
||||||
<dt><a href="#Arduino">Arduino</a></dt>
|
|
||||||
<dd><p>Class representing the arduino communication features</p>
|
|
||||||
</dd>
|
|
||||||
</dl>
|
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
<dl>
|
<dl>
|
||||||
<dt><a href="#delay">delay(ms)</a> ⇒ <code>Promise</code></dt>
|
<dt><a href="#delay">delay(ms)</a> ⇒ <code>Promise</code></dt>
|
||||||
<dd><p>Pause the process for X milliseconds in async/await functions</p>
|
<dd><p>Pause the process for X milliseconds in async/await functions</p>
|
||||||
</dd>
|
</dd>
|
||||||
|
<dt><a href="#send">send(device, cmd)</a> ⇒ <code>Promise</code></dt>
|
||||||
|
<dd><p>Send a command to an Arduino using async/await</p>
|
||||||
|
</dd>
|
||||||
|
<dt><a href="#write">write(device, str)</a> ⇒ <code>Promise</code></dt>
|
||||||
|
<dd><p>Send a string to an Arduino using async/await</p>
|
||||||
|
</dd>
|
||||||
|
<dt><a href="#open">open(device)</a> ⇒ <code>Promise</code></dt>
|
||||||
|
<dd><p>Connect to an Arduino using async/await</p>
|
||||||
|
</dd>
|
||||||
|
<dt><a href="#close">close(device)</a> ⇒ <code>Promise</code></dt>
|
||||||
|
<dd><p>Close a connection to an Arduino using async/await</p>
|
||||||
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
<a name="Arduino"></a>
|
|
||||||
|
|
||||||
## Arduino
|
|
||||||
Class representing the arduino communication features
|
|
||||||
|
|
||||||
**Kind**: global class
|
|
||||||
|
|
||||||
* [Arduino](#Arduino)
|
|
||||||
* [.sendAsync(device, cmd)](#Arduino+sendAsync) ⇒ <code>Promise</code>
|
|
||||||
* [.writeAsync(device, str)](#Arduino+writeAsync) ⇒ <code>Promise</code>
|
|
||||||
* [.openArduino(device)](#Arduino+openArduino) ⇒ <code>Promise</code>
|
|
||||||
* [.closeArduino(device)](#Arduino+closeArduino) ⇒ <code>Promise</code>
|
|
||||||
|
|
||||||
<a name="Arduino+sendAsync"></a>
|
|
||||||
|
|
||||||
### arduino.sendAsync(device, cmd) ⇒ <code>Promise</code>
|
|
||||||
Send a command to an Arduino using async/await
|
|
||||||
|
|
||||||
**Kind**: instance method of [<code>Arduino</code>](#Arduino)
|
|
||||||
**Returns**: <code>Promise</code> - Resolves after sending
|
|
||||||
|
|
||||||
| Param | Type | Description |
|
|
||||||
| --- | --- | --- |
|
|
||||||
| device | <code>string</code> | Arduino identifier |
|
|
||||||
| cmd | <code>string</code> | Single character command to send |
|
|
||||||
|
|
||||||
<a name="Arduino+writeAsync"></a>
|
|
||||||
|
|
||||||
### arduino.writeAsync(device, str) ⇒ <code>Promise</code>
|
|
||||||
Send a string to an Arduino using async/await
|
|
||||||
|
|
||||||
**Kind**: instance method of [<code>Arduino</code>](#Arduino)
|
|
||||||
**Returns**: <code>Promise</code> - Resolves after sending
|
|
||||||
|
|
||||||
| Param | Type | Description |
|
|
||||||
| --- | --- | --- |
|
|
||||||
| device | <code>string</code> | Arduino identifier |
|
|
||||||
| str | <code>string</code> | String to send |
|
|
||||||
|
|
||||||
<a name="Arduino+openArduino"></a>
|
|
||||||
|
|
||||||
### arduino.openArduino(device) ⇒ <code>Promise</code>
|
|
||||||
Connect to an Arduino using async/await
|
|
||||||
|
|
||||||
**Kind**: instance method of [<code>Arduino</code>](#Arduino)
|
|
||||||
**Returns**: <code>Promise</code> - Resolves after opening
|
|
||||||
|
|
||||||
| Param | Type | Description |
|
|
||||||
| --- | --- | --- |
|
|
||||||
| device | <code>string</code> | Arduino identifier |
|
|
||||||
|
|
||||||
<a name="Arduino+closeArduino"></a>
|
|
||||||
|
|
||||||
### arduino.closeArduino(device) ⇒ <code>Promise</code>
|
|
||||||
Close a connection to an Arduino using async/await
|
|
||||||
|
|
||||||
**Kind**: instance method of [<code>Arduino</code>](#Arduino)
|
|
||||||
**Returns**: <code>Promise</code> - Resolves after closing
|
|
||||||
|
|
||||||
| Param | Type | Description |
|
|
||||||
| --- | --- | --- |
|
|
||||||
| device | <code>string</code> | Arduino identifier |
|
|
||||||
|
|
||||||
<a name="delay"></a>
|
<a name="delay"></a>
|
||||||
|
|
||||||
## delay(ms) ⇒ <code>Promise</code>
|
## delay(ms) ⇒ <code>Promise</code>
|
||||||
|
@ -89,3 +30,53 @@ Pause the process for X milliseconds in async/await functions
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| ms | <code>integer</code> | milliseconds |
|
| ms | <code>integer</code> | milliseconds |
|
||||||
|
|
||||||
|
<a name="send"></a>
|
||||||
|
|
||||||
|
## send(device, cmd) ⇒ <code>Promise</code>
|
||||||
|
Send a command to an Arduino using async/await
|
||||||
|
|
||||||
|
**Kind**: global function
|
||||||
|
**Returns**: <code>Promise</code> - Resolves after sending
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| device | <code>string</code> | Arduino identifier |
|
||||||
|
| cmd | <code>string</code> | Single character command to send |
|
||||||
|
|
||||||
|
<a name="write"></a>
|
||||||
|
|
||||||
|
## write(device, str) ⇒ <code>Promise</code>
|
||||||
|
Send a string to an Arduino using async/await
|
||||||
|
|
||||||
|
**Kind**: global function
|
||||||
|
**Returns**: <code>Promise</code> - Resolves after sending
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| device | <code>string</code> | Arduino identifier |
|
||||||
|
| str | <code>string</code> | String to send |
|
||||||
|
|
||||||
|
<a name="open"></a>
|
||||||
|
|
||||||
|
## open(device) ⇒ <code>Promise</code>
|
||||||
|
Connect to an Arduino using async/await
|
||||||
|
|
||||||
|
**Kind**: global function
|
||||||
|
**Returns**: <code>Promise</code> - Resolves after opening
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| device | <code>string</code> | Arduino identifier |
|
||||||
|
|
||||||
|
<a name="close"></a>
|
||||||
|
|
||||||
|
## close(device) ⇒ <code>Promise</code>
|
||||||
|
Close a connection to an Arduino using async/await
|
||||||
|
|
||||||
|
**Kind**: global function
|
||||||
|
**Returns**: <code>Promise</code> - Resolves after closing
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| device | <code>string</code> | Arduino identifier |
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const SerialPort = require('serialport');
|
const SerialPort = require('serialport');
|
||||||
const Readline = SerialPort.parsers.Readline;
|
const Readline = SerialPort.parsers.Readline;
|
||||||
const exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
|
const delay = require("delay");
|
||||||
const parser = new Readline('');
|
const parser = new Readline('');
|
||||||
const newlineRe = new RegExp('\n', 'g');
|
const newlineRe = new RegExp('\n', 'g');
|
||||||
const returnRe = new RegExp('\r', 'g');
|
const returnRe = new RegExp('\r', 'g');
|
||||||
|
@ -18,18 +20,6 @@ const KNOWN = [
|
||||||
'/dev/ttyACM0',
|
'/dev/ttyACM0',
|
||||||
'COM3'
|
'COM3'
|
||||||
];
|
];
|
||||||
/**
|
|
||||||
* Pause the process for X milliseconds in async/await functions
|
|
||||||
*
|
|
||||||
* @param {integer} ms milliseconds
|
|
||||||
*
|
|
||||||
* @returns {Promise} Resolves after wait
|
|
||||||
**/
|
|
||||||
async function delay(ms) {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
return setTimeout(resolve, ms);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Class representing the arduino communication features
|
* Class representing the arduino communication features
|
||||||
**/
|
**/
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const SerialPort = require('serialport');
|
const SerialPort = require('serialport');
|
||||||
const Readline = SerialPort.parsers.Readline;
|
const Readline = SerialPort.parsers.Readline;
|
||||||
const exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
|
const delay = require("delay");
|
||||||
const parser = new Readline('');
|
const parser = new Readline('');
|
||||||
const newlineRe = new RegExp('\n', 'g');
|
const newlineRe = new RegExp('\n', 'g');
|
||||||
const returnRe = new RegExp('\r', 'g');
|
const returnRe = new RegExp('\r', 'g');
|
||||||
|
@ -18,18 +20,6 @@ const KNOWN = [
|
||||||
'/dev/ttyACM0',
|
'/dev/ttyACM0',
|
||||||
'COM3'
|
'COM3'
|
||||||
];
|
];
|
||||||
/**
|
|
||||||
* Pause the process for X milliseconds in async/await functions
|
|
||||||
*
|
|
||||||
* @param {integer} ms milliseconds
|
|
||||||
*
|
|
||||||
* @returns {Promise} Resolves after wait
|
|
||||||
**/
|
|
||||||
async function delay(ms) {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
return setTimeout(resolve, ms);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Class representing the arduino communication features
|
* Class representing the arduino communication features
|
||||||
**/
|
**/
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const SerialPort = require('serialport');
|
const SerialPort = require('serialport');
|
||||||
const Readline = SerialPort.parsers.Readline;
|
const Readline = SerialPort.parsers.Readline;
|
||||||
const exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
|
const delay = require("delay");
|
||||||
const parser = new Readline('');
|
const parser = new Readline('');
|
||||||
const newlineRe = new RegExp('\n', 'g');
|
const newlineRe = new RegExp('\n', 'g');
|
||||||
const returnRe = new RegExp('\r', 'g');
|
const returnRe = new RegExp('\r', 'g');
|
||||||
|
@ -18,18 +20,6 @@ const KNOWN = [
|
||||||
'/dev/ttyACM0',
|
'/dev/ttyACM0',
|
||||||
'COM3'
|
'COM3'
|
||||||
];
|
];
|
||||||
/**
|
|
||||||
* Pause the process for X milliseconds in async/await functions
|
|
||||||
*
|
|
||||||
* @param {integer} ms milliseconds
|
|
||||||
*
|
|
||||||
* @returns {Promise} Resolves after wait
|
|
||||||
**/
|
|
||||||
async function delay(ms) {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
return setTimeout(resolve, ms);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Class representing the arduino communication features
|
* Class representing the arduino communication features
|
||||||
**/
|
**/
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,6 +4,8 @@ const SerialPort = require('serialport')
|
||||||
const Readline = SerialPort.parsers.Readline
|
const Readline = SerialPort.parsers.Readline
|
||||||
const exec = require('child_process').exec
|
const exec = require('child_process').exec
|
||||||
|
|
||||||
|
import delay = require('delay');
|
||||||
|
|
||||||
const parser : any = new Readline('')
|
const parser : any = new Readline('')
|
||||||
const newlineRe : RegExp = new RegExp('\n', 'g')
|
const newlineRe : RegExp = new RegExp('\n', 'g')
|
||||||
const returnRe : RegExp = new RegExp('\r', 'g')
|
const returnRe : RegExp = new RegExp('\r', 'g')
|
||||||
|
@ -23,35 +25,22 @@ const KNOWN : string[] = [
|
||||||
'COM3'
|
'COM3'
|
||||||
]
|
]
|
||||||
|
|
||||||
/**
|
|
||||||
* Pause the process for X milliseconds in async/await functions
|
|
||||||
*
|
|
||||||
* @param {integer} ms milliseconds
|
|
||||||
*
|
|
||||||
* @returns {Promise} Resolves after wait
|
|
||||||
**/
|
|
||||||
async function delay (ms : number) {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
return setTimeout(resolve, ms)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class representing the arduino communication features
|
* Class representing the arduino communication features
|
||||||
**/
|
**/
|
||||||
|
|
||||||
class Arduino {
|
class Arduino {
|
||||||
|
|
||||||
path : any = {}
|
private path : any = {}
|
||||||
known : string[] = KNOWN
|
private known : string[] = KNOWN
|
||||||
alias : any = {}
|
private alias : any = {}
|
||||||
serial : any = { connect : {}, projector : {}, camera : {}, light : {} }
|
private serial : any = { connect : {}, projector : {}, camera : {}, light : {} }
|
||||||
baud : number = 57600
|
private baud : number = 57600
|
||||||
queue : any = {}
|
private queue : any = {}
|
||||||
timer : number = 0
|
private timer : number = 0
|
||||||
lock : boolean = false
|
private lock : boolean = false
|
||||||
locks : any = {}
|
private locks : any = {}
|
||||||
confirmExec : any
|
private confirmExec : any
|
||||||
|
|
||||||
constructor () {
|
constructor () {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue