Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PeripheralIO<EventTypes>

General purpose IO This is available on each io (for obniz Board series, it's io0 to io11)

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

drive

  • This allows you to change output drive method. By default, it is set as push-pull 5v.

    // Javascript Example
    obniz.io0.output(true); // output push-pull 5v
    
    obniz.io1.drive("3v");
    obniz.io1.output(true); // output push-pull 3v
    
    obniz.io2.pull("5v");
    obniz.io2.drive("open-drain");
    obniz.io2.output(true); // output open-drain with 5v pull-up

    Parameters

    Returns void

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(): void
  • This ends output/input on ioX.

    This function is effective only when using ioX.output() or ioX.input(). This won't be called when AD/UART/etc are used. Pull-up down also will not affected.

    // Javascript Example
    obniz.io0.output(true)
    obniz.io0.end();

    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

input

  • input(callback: (value: boolean) => void): boolean
  • Make ioX to input mode. Callback function will be called when io changes its input value.

    Parameters

    • callback: (value: boolean) => void
        • (value: boolean): void
        • Parameters

          • value: boolean

          Returns void

    Returns boolean

inputWait

  • inputWait(): Promise<boolean>
  • Make ioX to input mode.

    And this will return the current input value. It pauses the process until the value is returned.

    // Javascript Example
    var value = await obniz.io0.inputWait();
    console.log(value);

    Returns Promise<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

output

  • output(value: boolean | 0 | 1): void
  • Make ioX to output mode and put out 1 or 0.

    // Javascript Example
    obniz.io1.output(true); // io1 is 5v
    obniz.io2.output(1); //  io2 is 5v
    obniz.io3.drive("3v");
    obniz.io3.output(1); // io3 is around 3v.

    Parameters

    • value: boolean | 0 | 1

      output value

    Returns void

pull

  • This enables/disables internal weak pull up/down resistors.

    // Javascript Example
    obniz.io0.pull("3v");
    obniz.io0.drive("open-drain"); // output open-drain
    obniz.io0.output(false);

    Parameters

    Returns void

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

validate

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

    • commandUri: any
    • json: any

    Returns WSSchema.MultiResult

Generated using TypeDoc