tessel / t1-docs

API documentation for Tessel 1. Start reading below. (Unmaintained)
98 stars 19 forks source link

Pin API docs don't distinguish digital vs analog pin methods #66

Open EvanSimpson opened 9 years ago

EvanSimpson commented 9 years ago

The documentation lists methods like pin.input() without distinguishing that they only exist in digital pin objects and not analog pin objects.

For example, the following script

var tessel = require('tessel');

var gpio = tessel.port['GPIO'];

var pin = gpio.pin['A1'];

pin.input();

produces this error

/app/index.js:7: attempt to call method 'input' (a nil value)

Whereas

var tessel = require('tessel');

var gpio = tessel.port['GPIO'];

var pin = gpio.pin['G1'];

pin.input();

works as expected.

Quick check to see the differences in methods:

var tessel = require('tessel');

var gpio = tessel.port['GPIO'];

var pin1 = gpio.pin['G1'];
var pin2 = gpio.pin['A1'];

var getAllMethods = function(object) {
  return Object.getOwnPropertyNames(object).filter(function(property) {
      return typeof object[property] == 'function';
  });
}

console.log("Digital pin:", getAllMethods(pin1));
console.log("Analog pin:", getAllMethods(pin2));
Digital pin: [ input, rawWrite, readSync, read, pull, output, rawRead, high, once, writeSync, set, toggle, removeListener, pulse, removeAllListeners, mode, setOutput, rawDirection, low, write, pulseIn, readPulse, on, setInput, addListener, setMaxListeners, removeListener, removeAllListeners, on, once, listeners, emit ]
Analog pin: [ write, read, readSync ]
johnnyman727 commented 9 years ago

@EvanSimpson what do you think is the ideal way to handle this? Simply more descriptive error messages?