Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PeripheralSPI<EventTypes>

It is General Purpose SPI

Type parameters

  • EventTypes: string

Hierarchy

Index

Constructors

constructor

Properties

Obniz

Obniz: Obniz

obniz to be used

timeout

timeout: number = 30 * 1000

Rsponse waiting timeout in milliseconds

Static prefixed

prefixed: string | boolean

Methods

addListener

  • addListener(event: EventTypes, fn: ListenerFn, context?: any): this

emit

  • emit(event: EventTypes, ...args: Array<any>): boolean
  • Calls each of the listeners registered for a given event.

    Parameters

    • event: EventTypes
    • Rest ...args: Array<any>

    Returns boolean

end

  • end(reuse?: undefined | false | true): void
  • It ends spi

    // Javascript Example
    obniz.spi0.start({mode:"master", clk :0, mosi:1, miso:2, clock:1000000});
    obniz.spi0.write([0x12, 0x98]);
    obniz.spi0.end();

    Parameters

    • Optional reuse: undefined | false | true
      • True : getFreeSpi will not return this object
      • False : getFreeSpi will return this object

    Returns void

eventNames

  • eventNames(): Array<EventTypes>
  • Return an array listing the events for which the emitter has registered listeners.

    Returns Array<EventTypes>

fastValidate

  • fastValidate(commandUri: any, json: any): boolean
  • Parameters

    • commandUri: any
    • json: any

    Returns boolean

listenerCount

  • listenerCount(event: EventTypes): number
  • Return the number of listeners listening to a given event.

    Parameters

    • event: EventTypes

    Returns number

listeners

  • Return the listeners registered for a given event.

    Parameters

    • event: EventTypes

    Returns Array<ListenerFn>

notifyFromObniz

  • notifyFromObniz(json: any): void

off

  • off(event: EventTypes, fn?: EventEmitter.ListenerFn, context?: any, once?: undefined | false | true): this
  • Parameters

    • event: EventTypes
    • Optional fn: EventEmitter.ListenerFn
    • Optional context: any
    • Optional once: undefined | false | true

    Returns this

on

  • on(event: EventTypes, fn: ListenerFn, context?: any): this
  • Add a listener for a given event.

    Parameters

    • event: EventTypes
    • fn: ListenerFn
    • Optional context: any

    Returns this

once

  • once(event: EventTypes, fn: ListenerFn, context?: any): this
  • Add a one-time listener for a given event.

    Parameters

    • event: EventTypes
    • fn: ListenerFn
    • Optional context: any

    Returns this

removeAllListeners

removeListener

  • removeListener(event: EventTypes, fn?: EventEmitter.ListenerFn, context?: any, once?: undefined | false | true): this
  • Remove the listeners of a given event.

    Parameters

    • event: EventTypes
    • Optional fn: EventEmitter.ListenerFn
    • Optional context: any
    • Optional once: undefined | false | true

    Returns this

start

  • It starts spi. Now the mode is only "master".

    drive and pull are optional settings for io output. Default settings are drive:5v, pull:null. See more using obniz.io.drive() or pull().

    // Javascript Example
    obniz.spi0.start({mode:"master", clk :0, mosi:1, miso:2, frequency:1000000});
    var ret = await obniz.spi0.writeWait([0x12, 0x98]);
    console.log("received: "+ret);
    
    // drive and pull is optional
    obniz.spi0.start({mode:"master", clk :0, mosi:1, miso:2, frequency:1000000, drive: "5v", pull:null});

    Parameters

    Returns void

validate

  • validate(commandUri: any, json: any): WSSchema.MultiResult
  • Parameters

    • commandUri: any
    • json: any

    Returns WSSchema.MultiResult

write

  • write(data: number[]): void
  • It only sends data to spi and does not receive it.

    // Javascript Example
    obniz.spi0.start({mode:"master", clk :0, mosi:1, miso:2, frequency:1000000});
    obniz.spi0.write([0x12, 0x98]);

    Parameters

    • data: number[]

      Max length is 1024 bytes.

    Returns void

writeWait

  • writeWait(data: number[]): Promise<number[]>
  • It sends data to spi and wait until data are received. The received data length is the same as the sent data.

    // Javascript Example
    obniz.spi0.start({mode:"master", clk :0, mosi:1, miso:2, frequency:1000000});
    var ret = await obniz.spi0.writeWait([0x12, 0x98]);
    console.log("received: "+ret);

    Parameters

    • data: number[]

      Max length is 1024 bytes.

    Returns Promise<number[]>

    received data

Generated using TypeDoc