Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firmata.js typings #31

Open
troywweber7 opened this issue Sep 28, 2016 · 2 comments
Open

firmata.js typings #31

troywweber7 opened this issue Sep 28, 2016 · 2 comments

Comments

@troywweber7
Copy link

Hello! I am interested in finding a definition file for firmata.js (or in helping to generate one). The way I'm giving myself typescript support for firmata.js right now is INCREDIBLY HACKY. In fact, I know its the wrong way and I know all it is doing is keeping the compiler from complaining and helping provide me with some auto-completion. So I would really like some help in figuring out the right way to do this. Eventually I'd like to include a typings file in DefinitelyTyped so I can use $ typings search firmata and $ typings install --save --global dt~firmata.

What I have so far I use with

import { IBoard } from './interfaces/Firmata';

And the file Firmata.d.ts has this for its contents

/**
 * Created by troy on 9/19/16.
 */

// Most of these are generated by observing https://github.com/firmata/firmata.js/blob/master/lib/firmata.js

// TODO this can definitely be done better with a better understanding of prototypal inheritance

import SerialPort = require("serialport");

export interface IBoard
{
    // ==========
    // Properties
    // ==========
    MODES:{
        INPUT:number, OUTPUT:number, ANALOG:number, PWM:number, SERVO:number, SHIFT:number, I2C:number, ONEWIRE:number,
        STEPPER:number, SERIAL:number, PULLUP:number, IGNORE:number, PING_READ:number, UNKOWN:number
    },
    I2C_MODES:{ WRITE:number, READ:number, CONTINUOUS_READ:number, STOP_READING:number },
    STEPPER:{
        TYPE:{ DRIVER:number, TWO_WIRE:number, FOUR_WIRE:number },
        RUNSTATE:{ STOP:number, ACCEL:number, DECEL:number, RUN:number },
        DIRECTION:{ CCW:number, CW:number }
    },
    SERIAL_MODES:{ CONTINUOUS_READ:number, STOP_READING:number },
    SERIAL_PORT_IDs:{
        HW_SERIAL0:number, HW_SERIAL1:number, HW_SERIAL2:number, HW_SERIAL3:number,
        SW_SERIAL0:number, SW_SERIAL1:number,SW_SERIAL2:number, SW_SERIAL3:number, DEFAULT:number,
    },
    SERIAL_PIN_TYPES:{
        RES_RX0:number, RES_TX0:number, RES_RX1:number, RES_TX1:number,
        RES_RX2:number, RES_TX2:number, RES_RX3:number, RES_TX3:number,
    },
    HIGH:number,
    LOW:number,
    pins:[{
        mode:number,
        value:number,
        supportedModes:number[],
        analogChannel:number,
        state:number
    }],
    ports:number[],
    analogPins:number[],
    version:{},
    firmware:{
        name:string,
        version:{
            major:number,
            minor:number
        },
    },
    currentBuffer:number[],
    versionReceived:boolean,
    name:string,
    settings:IOptions,

    // TODO handle this more cleanly, currently a black box
    transport:SerialPort,

    // ====================
    // Constructor Function
    // ====================
    Board:(port:string|IPort, options?:IOptions, callback?:(err:any)=>void)=>IBoard,

    // =================
    // Prototype Methods
    // =================
    reportVersion:()=>void,
    queryFirmware:()=>void,
    analogRead:()=>void,
    analogWrite:()=>void,
    pwmWrite:()=>void,
    servoConfig:()=>void,
    servoWrite:()=>void,
    pinMode:(pin:number, mode:number)=>void,
    digitalWrite:(pin:number, val:number)=>void,
    digitalRead:(pin:number, callback:(val:number)=>void)=>void,
    queryCapabilities:()=>void,

    // TODO give these better definitions
    queryAnalogMapping:()=>void,
    queryPinState:()=>void,
    sendString:()=>void,
    sendI2CConfig:()=>void,
    i2cConfig:()=>void,
    sendI2CWriteRequest:()=>void,
    i2cWrite:()=>void,
    i2cWriteReg:()=>void,
    sendI2CReadRequest:()=>void,
    i2cRead:()=>void,
    i2cStop:()=>void,
    i2cReadOnce:()=>void,
    sendOneWireConfig:()=>void,
    sendOneWireSearch:()=>void,
    sendOneWireAlarmsSearch:()=>void,
    _sendOneWireSearch:()=>void,
    sendOneWireRead:()=>void,
    sendOneWireReset:()=>void,
    sendOneWireWrite:()=>void,
    sendOneWireDelay:()=>void,
    sendOneWireWriteAndRead:()=>void,
    _sendOneWireRequest:()=>void,

    setSamplingInterval:(interval:number)=>void,

    getSamplingInterval:()=>void,
    reportAnalogPin:()=>void,

    reportDigitalPin:(pin:number, value:number)=>void,

    pingRead:()=>void,

    stepperConfig:(deviceNum:number, type:number, stepsPerRev:number, dirOrMotor1Pin:number, stepOrMotor2Pin:number,
        motor3Pin?:number, motor4Pin?:number)=>void,
    // TODO define callback function better
    stepperStep:(deviceNum:number, direction:number, steps:number, speed:number, accel:number, decel:number,
        callback:Function)=>void,

    serialConfig:()=>void,
    serialWrite:()=>void,
    serialRead:()=>void,
    serialStop:()=>void,
    serialClose:()=>void,
    serialFlush:()=>void,
    serialListen:()=>void,
    sysexResponse:()=>void,
    sysexCommand:()=>void,
    reset:()=>void,

    // ==============
    // Static Methods (I think)
    // ==============
    isAcceptablePort:(port:IPort)=>boolean,
    requestPort:(callback:(err:any, port:IPort)=>any)=>void,
    encode:(data:number[])=>number[],
    decode:(data:number[])=>number[],


    // TODO define callback function better
    // TODO these need to be organized better
    on:(event:string, callback:Function)=>void,

    emit:(event:string)=>void,

    // ======
    // Custom (added by Joshua's firmata connector)
    // ======
    log:(message:any, ... optParams:any[])=>void,
    error:(message:any, ... optParams:any[])=>void,
    debug:(message:any, ... optParams:any[])=>void,
    info:(message:any, ... optParams:any[])=>void,
    warn:(message:any, ... optParams:any[])=>void,
}

interface IPort
{
    comName:string,
}

interface IOptions
{
    reportVersionTimeout?:number,
    samplingInterval?:number,
    serialPort?:{
        baudRate:number,
        bufferSize:number,
    }
}

As you can see, there are incomplete functions and I'm probably doing this the worst way possible, so any help is greatly appreciated.

@troywweber7
Copy link
Author

firmata.js is here, btw: https://github.com/firmata/firmata.js

@blakeembrey
Copy link
Member

Thanks. I'm not sure anyone will jump in directly to help you unless they're using it. If you have something that works, perhaps the best approach is to create a repo and add it to the registry and hope someone else finds it useful also to contribute?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants