├── index.js ├── .gitignore ├── package.json ├── lib ├── constants.js └── board-io.js └── README.md /index.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = require('./lib/board-io') 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.iml 3 | .project 4 | .classpath 5 | .settings 6 | .idea 7 | node_modules 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "board-io", 3 | "version": "3.0.5", 4 | "description": "Provides a standard interface to boards capable of IO (e.g. Arduinos, Maestros, Raspberry Pis, etc) and their firmware", 5 | "repository": { 6 | "type": "git", 7 | "url": "git://github.com/achingbrain/board-io.git" 8 | }, 9 | "scripts": { 10 | "lint": "standard" 11 | }, 12 | "dependencies": { 13 | "check-types": "^1.2" 14 | }, 15 | "devDependencies": { 16 | "pre-commit": "^1.1.2", 17 | "standard": "^5.4.1" 18 | }, 19 | "keywords": [ 20 | "node", 21 | "firmata", 22 | "servo", 23 | "ssc", 24 | "johnny-five" 25 | ], 26 | "author": "Alex Potsides", 27 | "license": "BSD", 28 | "pre-commit": [ 29 | "lint" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /lib/constants.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The various modes pins support 3 | */ 4 | module.exports.MODES = Object.freeze({ 5 | INPUT: 0x00, 6 | OUTPUT: 0x01, 7 | ANALOG: 0x02, 8 | PWM: 0x03, 9 | SERVO: 0x04, 10 | SHIFT: 0x05, 11 | I2C: 0x06, 12 | ONEWIRE: 0x07, 13 | STEPPER: 0x08, 14 | IGNORE: 0x7F, 15 | UNKNOWN: 0x10 16 | }) 17 | 18 | /** 19 | * The various modes integrated circuits support 20 | */ 21 | module.exports.I2C_MODES = Object.freeze({ 22 | WRITE: 0x00, 23 | READ: 0x01, 24 | CONTINUOUS_READ: 0x02, 25 | STOP_READING: 0x03 26 | }) 27 | 28 | /** 29 | * Constants for stepper motors 30 | */ 31 | module.exports.STEPPER = Object.freeze({ 32 | TYPE: { 33 | DRIVER: 0x01, 34 | TWO_WIRE: 0x02, 35 | FOUR_WIRE: 0x04 36 | }, 37 | RUNSTATE: { 38 | STOP: 0x00, 39 | ACCEL: 0x01, 40 | DECEL: 0x02, 41 | RUN: 0x03 42 | }, 43 | DIRECTION: { 44 | CCW: 0x00, 45 | CW: 0x01 46 | } 47 | }) 48 | 49 | module.exports.SERIAL_MODES = { 50 | READ_CONTINUOUS: 0x00, 51 | STOP_READING: 0x01 52 | } 53 | 54 | // ids for hardware and software serial ports on the board 55 | module.exports.SERIAL_PORT_IDs = { 56 | HW_SERIAL0: 0x00, 57 | HW_SERIAL1: 0x01, 58 | HW_SERIAL2: 0x02, 59 | HW_SERIAL3: 0x03, 60 | SW_SERIAL0: 0x08, 61 | SW_SERIAL1: 0x09, 62 | SW_SERIAL2: 0x10, 63 | SW_SERIAL3: 0x11 64 | } 65 | 66 | // map to the pin resolution value in the capability query response 67 | module.exports.SERIAL_PIN_TYPES = { 68 | RES_RX0: 0x00, 69 | RES_TX0: 0x01, 70 | RES_RX1: 0x02, 71 | RES_TX1: 0x03, 72 | RES_RX2: 0x04, 73 | RES_TX2: 0x05, 74 | RES_RX3: 0x06, 75 | RES_TX3: 0x07 76 | } 77 | 78 | /** 79 | * Digital pin on value 80 | */ 81 | module.exports.HIGH = 0x01 82 | 83 | /** 84 | * Digital pin off value 85 | */ 86 | module.exports.LOW = 0x00 87 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # board-io 3 | 4 | An extendable implementation of Johnny Five's [IO Plugins](https://github.com/rwaldron/johnny-five/wiki/IO-Plugins). 5 | 6 | Implements all required and optional methods, along with the required constants - `MODE`, `HIGH`, `LOW`, etc. 7 | 8 | You should configure the relevant pins of your board in your constructor, then emit the ready event. 9 | 10 | E.g.: 11 | 12 | ```javascript 13 | var util = require('util'), 14 | BoardIO = require('board-io'); 15 | 16 | MyIO = function(path, callback) { 17 | // call super constructor 18 | BoardIO.call(this); 19 | 20 | // .. configure pins 21 | this._pins.push(..); 22 | 23 | // wait for an async method or use proccess.nextTick to 24 | // signal events 25 | process.nextTick(function() { 26 | // connect to hardware and emit "connect" event 27 | this.emit("connect"); 28 | 29 | // all done, emit ready event 30 | this.emit("ready"); 31 | 32 | // finally call the passed callback 33 | callback(); 34 | }.bind(this)); 35 | } 36 | util.inherits(IO, BoardIO); 37 | ``` 38 | 39 | Finally implement any of the IO Plugin methods of your choosing: 40 | 41 | ```javascript 42 | // implement digitalWrite 43 | MyIO.prototype.digitalWrite = function(pin, value) { 44 | .. 45 | }; 46 | ``` 47 | 48 | ## Logging 49 | 50 | By default BoardIO will print a message when every non-implemented method is invoked. To prevent this, set the `quiet` property of the super constructor args to true: 51 | 52 | ```javascript 53 | MyIO = function(path, callback) { 54 | // call super constructor 55 | BoardIO.call(this, { 56 | .. 57 | quiet: true 58 | }); 59 | 60 | .. 61 | } 62 | util.inherits(IO, BoardIO); 63 | ``` 64 | 65 | ## Changelog 66 | 67 | ### 3.0.5 68 | 69 | 1. Add serial methods and constants to match firmata 70 | 71 | ### 3.0.4 72 | 73 | 1. Actually just configurable 74 | 75 | ### 3.0.3 76 | 77 | 1. Make properties configurable and writable 78 | 79 | ### 3.0.2 80 | 81 | 1. Define pins and analogPins on initialisation 82 | 83 | ### 3.0.1 84 | 85 | 1. Adds new i2cXXX methods 86 | 2. Prints deprecation warning when calling old sendI2CXXX methods 87 | 88 | ### 3.0.0 - Initial release 89 | 90 | 1. All Firmata methods stubbed out 91 | -------------------------------------------------------------------------------- /lib/board-io.js: -------------------------------------------------------------------------------- 1 | var CONSTANTS = require('./constants') 2 | var EventEmitter = require('events').EventEmitter 3 | var util = require('util') 4 | var check = require('check-types') 5 | 6 | var log = console.info 7 | 8 | /** 9 | * Defines an interface to interact with attached IO boards - arduinos, servo controllers, etc 10 | * @param {String} port The name of the device we are connecting to 11 | * @param {function} callback A function to be invoked when the board is ready to interact with. 12 | */ 13 | function BoardIO (opts) { 14 | EventEmitter.call(this) 15 | 16 | opts = opts || {} 17 | 18 | // don't make any noise 19 | if (opts.quiet) { 20 | log = function () {} 21 | } 22 | 23 | // expose isReady property 24 | var isReady = false 25 | // these are the indexes of analog pins in the this.pins array 26 | var analogPins = [] 27 | 28 | // child classes will fill this array 29 | this._pins = [] 30 | 31 | this.once('ready', function () { 32 | isReady = true 33 | 34 | // make sure we have some pins 35 | check.verify.array(this._pins, 'this._pins should be an array!') 36 | check.verify.not.length(this._pins, 0, 'Please populate this._pins with pins!') 37 | 38 | this._pins.forEach(function (pin, index) { 39 | // make sure that the right properties have been set 40 | check.verify.object(pin, 'this._pins[' + index + '] should be an object!') 41 | check.verify.array(pin.supportedModes, 'this._pins[' + index + '].supportedModes should be an array!') 42 | check.verify.number(pin.mode, 'this._pins[' + index + '].mode should be a number!') 43 | check.verify.number(pin.report, 'this._pins[' + index + '].report should be a number!') 44 | check.verify.number(pin.analogChannel, 'this._pins[' + index + '].analogChannel should be a number!') 45 | 46 | // populate analog pins 47 | if (pin.supportedModes.indexOf(this.MODES.ANALOG) !== -1) { 48 | analogPins.push(index) 49 | } 50 | }, this) 51 | 52 | if (this._quiet) { 53 | log = function () {} 54 | } 55 | }) 56 | 57 | Object.defineProperties(this, { 58 | pins: { 59 | enumerable: true, 60 | configurable: true, 61 | get: function () { 62 | return this._pins 63 | } 64 | }, 65 | analogPins: { 66 | enumerable: true, 67 | configurable: true, 68 | get: function () { 69 | return analogPins 70 | } 71 | }, 72 | isReady: { 73 | enumerable: true, 74 | configurable: true, 75 | get: function () { 76 | return isReady 77 | } 78 | }, 79 | HIGH: { 80 | enumerable: true, 81 | value: CONSTANTS.HIGH 82 | }, 83 | LOW: { 84 | enumerable: true, 85 | value: CONSTANTS.LOW 86 | }, 87 | MODES: { 88 | enumerable: true, 89 | value: CONSTANTS.MODES 90 | }, 91 | I2C_MODES: { 92 | enumerable: true, 93 | value: CONSTANTS.I2C_MODES 94 | }, 95 | SERIAL_PIN_TYPES: { 96 | enumerable: true, 97 | value: CONSTANTS.SERIAL_PIN_TYPES 98 | }, 99 | SERIAL_PORT_IDs: { 100 | enumerable: true, 101 | value: CONSTANTS.SERIAL_PORT_IDs 102 | }, 103 | STEPPER: { 104 | enumerable: true, 105 | value: CONSTANTS.STEPPER 106 | } 107 | }) 108 | } 109 | 110 | // } extends EventEmmiter 111 | util.inherits(BoardIO, EventEmitter) 112 | 113 | /** 114 | * Asks the board to read analog data. 115 | * @param {number} pin The pin to read analog data 116 | * @param {function} callback A function to call when we have the analag data. 117 | */ 118 | BoardIO.prototype.analogRead = function (pin, callback) { 119 | log('BoardIO', 'analogRead of pin', pin) 120 | } 121 | 122 | /** 123 | * Asks the board to write an analog message. 124 | * @param {number} pin The pin to write analog data to. 125 | * @param {nubmer} value The data to write to the pin between 0 and 255. 126 | */ 127 | BoardIO.prototype.analogWrite = function (pin, value) { 128 | log('BoardIO', 'analogWrite', value, 'to pin', pin) 129 | } 130 | 131 | /** 132 | * Asks the board to move a servo 133 | * @param {number} pin The pin the servo is connected to 134 | * @param {number} value The degrees to move the servo to. 135 | */ 136 | BoardIO.prototype.servoWrite = function (pin, value) { 137 | log('BoardIO', 'servoWrite', value, 'to pin', pin) 138 | } 139 | 140 | /** 141 | * Asks the board to set the pin to a certain mode. 142 | * @param {number} pin The pin you want to change the mode of. 143 | * @param {number} mode The mode you want to set. Must be one of board.MODES 144 | */ 145 | BoardIO.prototype.pinMode = function (pin, mode) { 146 | var modeName = 'unknown' 147 | 148 | for (var key in this.MODES) { 149 | if (this.MODES[key] === mode) { 150 | modeName = key 151 | } 152 | } 153 | 154 | log('BoardIO', 'set pinMode of pin', pin, 'to mode', modeName) 155 | } 156 | 157 | /** 158 | * Asks the board to write a value to a digital pin 159 | * @param {number} pin The pin you want to write a value to. 160 | * @param {value} value The value you want to write. Must be board.HIGH or board.LOW 161 | */ 162 | BoardIO.prototype.digitalWrite = function (pin, value) { 163 | log('BoardIO', 'digitalWrite', value, 'to pin', pin) 164 | } 165 | 166 | /** 167 | * Asks the board to read digital data 168 | * @param {number} pin The pin to read data from 169 | * @param {function} callback The function to call when data has been received 170 | */ 171 | BoardIO.prototype.digitalRead = function (pin, callback) { 172 | log('BoardIO', 'digitalRead of pin', pin) 173 | } 174 | 175 | /** 176 | * Asks the board to tell us its capabilities 177 | * @param {function} callback A function to call when we receive the capabilities 178 | */ 179 | BoardIO.prototype.queryCapabilities = function (callback) { 180 | log('BoardIO', 'queryCapabilities') 181 | } 182 | 183 | /** 184 | * Asks the board to tell us its analog pin mapping 185 | * @param {function} callback A function to call when we receive the pin mappings. 186 | */ 187 | BoardIO.prototype.queryAnalogMapping = function (callback) { 188 | log('BoardIO', 'queryAnalogMapping') 189 | } 190 | 191 | /** 192 | * Asks the board to tell us the current state of a pin 193 | * @param {number} pin The pin we want to the know the state of 194 | * @param {function} callback A function to call when we receive the pin state. 195 | */ 196 | BoardIO.prototype.queryPinState = function (pin, callback) { 197 | log('BoardIO', 'queryPinState of pin', pin) 198 | } 199 | 200 | /** 201 | * Sends a I2C config request to the board with an optional 202 | * value in microseconds to delay an I2C Read. Must be called before 203 | * an I2C Read or Write 204 | * @param {number} delay in microseconds to set for I2C Read 205 | */ 206 | BoardIO.prototype.sendI2CConfig = function () { 207 | log('BoardIO', 'sendI2CConfig deprecated - use i2cConfig instead') 208 | } 209 | 210 | /** 211 | * Sends a I2C config request to the board with an optional 212 | * value in microseconds to delay an I2C Read. Must be called before 213 | * an I2C Read or Write 214 | * @param {number} delay in microseconds to set for I2C Read 215 | */ 216 | BoardIO.prototype.i2cConfig = function (delay) { 217 | log('BoardIO', 'i2cConfig with delay', delay) 218 | } 219 | 220 | /** 221 | * Asks the board to send an I2C request to a device 222 | * @param {number} slaveAddress The address of the I2C device 223 | * @param {Array} bytes The bytes to send to the device 224 | */ 225 | BoardIO.prototype.sendI2CWriteRequest = function () { 226 | log('BoardIO', 'sendI2CWriteRequest deprecated - use i2cWrite instead') 227 | } 228 | 229 | /** 230 | * Asks the board to send an I2C request to a device 231 | * @param {number} slaveAddress The address of the I2C device 232 | * @param {number} register The register on the I2C device to write to (optional) 233 | * @param {Array} bytes The bytes to send to the device 234 | */ 235 | BoardIO.prototype.i2cWrite = function () { 236 | if (arguments.length === 2) { 237 | log('BoardIO', 'i2cWrite to slave address', arguments[0], 'with bytes', arguments[1]) 238 | } else if (arguments.length === 3) { 239 | log('BoardIO', 'i2cWrite to slave address', arguments[0], 'register', arguments[1], 'with bytes', arguments[2]) 240 | } else { 241 | log('BoardIO', 'i2cWrite should be called with two or three arguments only') 242 | } 243 | } 244 | 245 | /** 246 | * Asks the board to send an I2C request to a device 247 | * @param {number} slaveAddress The address of the I2C device 248 | * @param {number} register The register on the I2C device to write to 249 | * @param {Array} bytes The bytes to send to the device 250 | */ 251 | BoardIO.prototype.i2cWriteReg = function (slaveAddress, register, bytes) { 252 | log('BoardIO', 'i2cWriteReg to slave address', slaveAddress, 'register', register, 'with bytes', bytes) 253 | } 254 | 255 | /** 256 | * Asks the board to request bytes from an I2C device 257 | * @param {number} slaveAddress The address of the I2C device 258 | * @param {number} numBytes The number of bytes to receive. 259 | * @param {function} callback A function to call when we have received the bytes. 260 | */ 261 | BoardIO.prototype.sendI2CReadRequest = function (slaveAddress, numBytes, callback) { 262 | log('BoardIO', 'sendI2CReadRequest deprecated - use i2cRead or i2cReadOnce instead') 263 | } 264 | 265 | /** 266 | * Asks the board to continuously request bytes from an I2C device 267 | * @param {number} slaveAddress The address of the I2C device 268 | * @param {number} numBytes The number of bytes to receive. 269 | * @param {function} callback A function to call when we have received the bytes. 270 | */ 271 | BoardIO.prototype.i2cRead = function () { 272 | if (arguments.length === 3) { 273 | log('BoardIO', 'i2cRead', arguments[1], 'bytes from address', arguments[0], 'handler', arguments[2]) 274 | } else if (arguments.length === 4) { 275 | log('BoardIO', 'i2cRead', arguments[2], 'bytes from register', arguments[1], 'at address', arguments[0], 'handler', arguments[3]) 276 | } else { 277 | log('BoardIO', 'i2cRead should be called with three or four arguments only') 278 | } 279 | } 280 | 281 | /** 282 | * Asks the board to request bytes from an I2C device 283 | * @param {number} slaveAddress The address of the I2C device 284 | * @param {number} register The register on the I2C device to read from (optional) 285 | * @param {number} numBytes The number of bytes to receive. 286 | * @param {function} callback A function to call when we have received the bytes. 287 | */ 288 | BoardIO.prototype.i2cReadOnce = function () { 289 | if (arguments.length === 3) { 290 | log('BoardIO', 'i2cReadOnce', arguments[1], 'bytes from address', arguments[0], 'handler', arguments[2]) 291 | } else if (arguments.length === 4) { 292 | log('BoardIO', 'i2cReadOnce', arguments[2], 'bytes from register', arguments[1], 'at address', arguments[0], 'handler', arguments[3]) 293 | } else { 294 | log('BoardIO', 'i2cReadOnce should be called with three or four arguments only') 295 | } 296 | } 297 | 298 | /** 299 | * Asks the Arduino to configure a hardware or serial port. 300 | * portId {number} The serial port to use (HW_SERIAL1, HW_SERIAL2, HW_SERIAL3, 301 | * SW_SERIAL0, SW_SERIAL1, SW_SERIAL2, SW_SERIAL3) 302 | * baud {number} The baud rate of the serial port 303 | * rxPin {number} [SW Serial only] The RX pin of the SoftwareSerial instance 304 | * txPin {number} [SW Serial only] The TX pin of the SoftwareSerial instance 305 | */ 306 | BoardIO.prototype.serialConfig = function (opts) { 307 | log('BoardIO', 'serialConfig with opts', opts) 308 | } 309 | 310 | /** 311 | * Writes an array of byted to the specified serial port 312 | * @param {number} portId The selected portId for lookup at CONSTANTS.SERIAL_PORT_IDs 313 | * @param {Array} inBytes The bytes to send to the device 314 | */ 315 | BoardIO.prototype.serialWrite = function (portId, inBytes) { 316 | log('BoardIO', 'serialWrite with portId', portId, 'and inBytes', inBytes) 317 | } 318 | 319 | /** 320 | * Creates an event emitter for data on a specified serial port 321 | * @param {number} portId The selected portId for lookup at CONSTANTS.SERIAL_PORT_IDs 322 | * @param {number} maxBytesToRead numBytes The maximum number of bytes to read per iteration (optional) 323 | * @param {Function} callback Function to call when we have received bytes 324 | */ 325 | BoardIO.prototype.serialRead = function (portId, maxBytesToRead, callback) { 326 | if (arguments.length === 2) { 327 | log('BoardIO', 'serialRead with portId', portId) 328 | } else { 329 | log('BoardIO', 'serialRead with portId', portId, 'max bytes', maxBytesToRead) 330 | } 331 | } 332 | 333 | /** 334 | * Stops reading data on a specified serial port. The port stays open. 335 | * @param {number} portId The selected portId for lookup at CONSTANTS.SERIAL_PORT_IDs 336 | */ 337 | BoardIO.prototype.serialStop = function (portId) { 338 | log('BoardIO', 'serialStop with portId', portId) 339 | } 340 | 341 | /** 342 | * Close the specified serial port. 343 | * @param {number} portId The selected portId for lookup at CONSTANTS.SERIAL_PORT_IDs 344 | */ 345 | BoardIO.prototype.serialClose = function (portId) { 346 | log('BoardIO', 'serialClose with portId', portId) 347 | } 348 | 349 | /** 350 | * Flush the specified serial port. 351 | * @param {number} portId The selected portId for lookup at CONSTANTS.SERIAL_PORT_IDs 352 | */ 353 | BoardIO.prototype.serialFlush = function (portId) { 354 | log('BoardIO', 'serialFlush with portId', portId) 355 | } 356 | 357 | /** 358 | * Specify which open serial port to read from (software serial only). 359 | * @param {number} portId The selected portId for lookup at CONSTANTS.SERIAL_PORT_IDs 360 | */ 361 | BoardIO.prototype.serialListen = function (portId) { 362 | log('BoardIO', 'serialListen with portId', portId) 363 | } 364 | 365 | /** 366 | * Set sampling interval in millis. Default is 19 ms 367 | * @param {number} interval The sampling interval in ms > 10 368 | */ 369 | BoardIO.prototype.setSamplingInterval = function (interval) { 370 | log('BoardIO', 'setSamplingInterval to', interval) 371 | } 372 | 373 | /** 374 | * Set reporting on pin 375 | * @param {number} pin The pin to turn on/off reporting 376 | * @param {number} value Binary value to turn reporting on/off 377 | */ 378 | BoardIO.prototype.reportAnalogPin = function (pin, value) { 379 | log('BoardIO', 'reportAnalogPin to pin', pin, 'with value', value) 380 | } 381 | 382 | /** 383 | * Set reporting on pin 384 | * @param {number} pin The pin to turn on/off reporting 385 | * @param {number} value Binary value to turn reporting on/off 386 | */ 387 | BoardIO.prototype.reportDigitalPin = function (pin, value) { 388 | log('BoardIO', 'reportDigitalPi to pin', pin, 'with value', value) 389 | } 390 | 391 | /** 392 | * 393 | * 394 | */ 395 | BoardIO.prototype.pulseIn = function (opts, callback) { 396 | log('BoardIO', 'pulseIn with opts', opts) 397 | } 398 | 399 | /** 400 | * Asks the board to configure a stepper motor with the given config to allow asynchronous control of the stepper 401 | * @param {number} deviceNum Device number for the stepper (range 0-5, expects steppers to be setup in order from 0 to 5) 402 | * @param {number} type One of this.STEPPER.TYPE.* 403 | * @param {number} stepsPerRev Number of steps motor takes to make one revolution 404 | * @param {number} dirOrMotor1Pin If using EasyDriver type stepper driver, this is direction pin, otherwise it is motor 1 pin 405 | * @param {number} stepOrMotor2Pin If using EasyDriver type stepper driver, this is step pin, otherwise it is motor 2 pin 406 | * @param {number} [motor3Pin] Only required if type == this.STEPPER.TYPE.FOUR_WIRE 407 | * @param {number} [motor4Pin] Only required if type == this.STEPPER.TYPE.FOUR_WIRE 408 | */ 409 | BoardIO.prototype.stepperConfig = function (deviceNum, type, stepsPerRev, dirOrMotor1Pin, stepOrMotor2Pin, motor3Pin, motor4Pin) { 410 | log('BoardIO', 'stepperConfig', deviceNum, type, stepsPerRev, dirOrMotor1Pin, stepOrMotor2Pin, motor3Pin, motor4Pin) 411 | } 412 | 413 | /** 414 | * Asks the board to move a stepper a number of steps at a specific speed 415 | * (and optionally with and acceleration and deceleration) 416 | * speed is in units of .01 rad/sec 417 | * accel and decel are in units of .01 rad/sec^2 418 | * TODO: verify the units of speed, accel, and decel 419 | * @param {number} deviceNum Device number for the stepper (range 0-5) 420 | * @param {number} direction One of this.STEPPER.DIRECTION.* 421 | * @param {number} steps Number of steps to make 422 | * @param {number} speed 423 | * @param {number|function} accel Acceleration or if accel and decel are not used, then it can be the callback 424 | * @param {number} [decel] 425 | * @param {function} [callback] 426 | */ 427 | BoardIO.prototype.stepperStep = function (deviceNum, direction, steps, speed, accel, decel, callback) { 428 | log('BoardIO', 'stepperStep', deviceNum, direction, steps, speed, accel, decel) 429 | } 430 | 431 | /** 432 | * Send SYSTEM_RESET to board 433 | */ 434 | BoardIO.prototype.reset = function () { 435 | log('BoardIO', 'reset') 436 | } 437 | 438 | /** 439 | * Configure the passed pin as the controller in a 1-wire bus. 440 | * Pass as enableParasiticPower true if you want the data pin to power the bus. 441 | * @param pin 442 | * @param enableParasiticPower 443 | */ 444 | BoardIO.prototype.sendOneWireConfig = function (pin, enableParasiticPower) { 445 | log('BoardIO', 'sendOneWireConfig', pin, 'with parasitic power', enableParasiticPower) 446 | } 447 | 448 | /** 449 | * Searches for 1-wire devices on the bus. The passed callback should accept 450 | * and error argument and an array of device identifiers. 451 | * @param pin 452 | * @param callback 453 | */ 454 | BoardIO.prototype.sendOneWireSearch = function (pin, callback) { 455 | log('BoardIO', 'sendOneWireSearch on pin', pin) 456 | } 457 | 458 | /** 459 | * Searches for 1-wire devices on the bus in an alarmed state. The passed callback 460 | * should accept and error argument and an array of device identifiers. 461 | * @param pin 462 | * @param callback 463 | */ 464 | BoardIO.prototype.sendOneWireAlarmsSearch = function (pin, callback) { 465 | log('BoardIO', 'sendOneWireAlarmsSearch on pin', pin) 466 | } 467 | 468 | /** 469 | * Reads data from a device on the bus and invokes the passed callback. 470 | * 471 | * N.b. ConfigurableFirmata will issue the 1-wire select command internally. 472 | * @param pin 473 | * @param device 474 | * @param numBytesToRead 475 | * @param callback 476 | */ 477 | BoardIO.prototype.sendOneWireRead = function (pin, device, numBytesToRead, callback) { 478 | log('BoardIO', 'sendOneWireRead', pin, device, numBytesToRead) 479 | } 480 | 481 | /** 482 | * Resets all devices on the bus. 483 | * @param pin 484 | */ 485 | BoardIO.prototype.sendOneWireReset = function (pin) { 486 | log('BoardIO', 'sendOneWireReset', pin) 487 | } 488 | 489 | /** 490 | * Writes data to the bus to be received by the passed device. The device 491 | * should be obtained from a previous call to sendOneWireSearch. 492 | * 493 | * N.b. ConfigurableFirmata will issue the 1-wire select command internally. 494 | * @param pin 495 | * @param device 496 | * @param data 497 | */ 498 | BoardIO.prototype.sendOneWireWrite = function (pin, device, data) { 499 | log('BoardIO', 'sendOneWireWrite', pin, device, data) 500 | } 501 | 502 | /** 503 | * Tells firmata to not do anything for the passed amount of ms. For when you 504 | * need to give a device attached to the bus time to do a calculation. 505 | * @param pin 506 | */ 507 | BoardIO.prototype.sendOneWireDelay = function (pin, delay) { 508 | log('BoardIO', 'sendOneWireDelay', pin, delay) 509 | } 510 | 511 | /** 512 | * Sends the passed data to the passed device on the bus, reads the specified 513 | * number of bytes and invokes the passed callback. 514 | * 515 | * N.b. ConfigurableFirmata will issue the 1-wire select command internally. 516 | * @param pin 517 | * @param device 518 | * @param data 519 | * @param numBytesToRead 520 | * @param callback 521 | */ 522 | BoardIO.prototype.sendOneWireWriteAndRead = function (pin, device, data, numBytesToRead, callback) { 523 | log('BoardIO', 'sendOneWireWriteAndRead', pin, device, data, numBytesToRead) 524 | } 525 | 526 | module.exports = BoardIO 527 | --------------------------------------------------------------------------------