soundanalogous / Breakout

Breakout is a javascript library and toolkit for connecting Arduino and other IOBoards to the web
www.breakoutjs.com
MIT License
180 stars 20 forks source link

Eliminate pin map dependency #68

Open soundanalogous opened 10 years ago

soundanalogous commented 10 years ago

In order to support host applications (StandardFirmata, AdvancedFirmata and ConfigurableFirmata are a "host applications") that don't use the capability query, each time a pin mode is set by the client, first check if the pin map contains a Pin object for that pin. If not, create an object for that pin and store it in the pin map. This way as long as clients specify pin modes, they should be able to use hosts that do not use capability queries.

May also need to first create a pin map with a range of pins set to a mode of DOUT (default). You wouldn't know what board is used in most cases so the range would have to be 0-64 or 0-128. This would support the case where a user expects the pins to be set to DOUT by default and therefore do not set a pin mode before attempting to use a pin.

soundanalogous commented 10 years ago

It may actually only require initializing all pins to digital on startup if the host doesn't issue a capability query on startup:

// call from checkForQueryResponse if _capabilityQueryResponseReceived === false
initPins: function () {
    for (var i = 0; i < 128; i++) {
        var pin = new Pin(i, Pin.DOUT);
        this._digitalPinMapping[i] = i;
        this.managePinListener(pin);
        this._ioPins[i] = pin;
    }
}

And then whenever a pin is used, make sure its type is properly set.