Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ObnizSwitch<EventTypes>

The embedded switch on obniz Board.

Type parameters

  • EventTypes: string

Hierarchy

Index

Constructors

constructor

Properties

Obniz

Obniz: Obniz

obniz to be used

Optional onchange

When the switch state changes, this callback function will be called. If you press and release a switch, it callbacks twice ("push" and "none").

// Javascript Example
obniz.display.clear();
obniz.switch.onchange = function(state) {
  if (state === "push") {
    obniz.display.print("Pushing");
  } else {
    obniz.display.clear();
  }
}

state

current switch state

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

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

getWait

  • This determines the current status of the switch.

    // Javascript Example
    obniz.display.clear();
    var state = await obniz.switch.getWait();
    if (state === "push") {
      obniz.display.print("Now Pressed");
    }

    Returns Promise<ObnizSwitchState>

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

schemaBasePath

  • schemaBasePath(): string

stateWait

  • With this you wait until the switch status changes to state.

    // Javascript Example
    await obniz.switch.stateWait("push");
    console.log("switch pushed");
    
    await obniz.switch.stateWait("left");
    console.log("switch left");
    
    await obniz.switch.stateWait("right");
    console.log("switch right");
    
    await obniz.switch.stateWait("none");
    console.log("switch none");

    Parameters

    Returns Promise<void>

validate

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

    • commandUri: any
    • json: any

    Returns WSSchema.MultiResult

Generated using TypeDoc