Skip to main content

Switch

caution

This service is rc and may change in the future.

A switch, which keeps its position.

import { Switch } from "@devicescript/core"

const sw = new Switch()

Registers

reading

Indicates whether the switch is currently active (on).

  • type: Register<boolean> (packing format u8)

  • read only

import { Switch } from "@devicescript/core"

const sw = new Switch()
// ...
const value = await sw.reading.read()
  • track incoming values
import { Switch } from "@devicescript/core"

const sw = new Switch()
// ...
sw.reading.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

variant

Describes the type of switch used.

  • type: Register<number> (packing format u8)

  • optional: this register may not be implemented

  • constant: the register value will not change (until the next reset)

  • read only

import { Switch } from "@devicescript/core"

const sw = new Switch()
// ...
const value = await sw.variant.read()
note

write and read will block until a server is bound to the client.

Events

on

Emitted when switch goes from off to on.

sw.on.subscribe(() => {

})

off

Emitted when switch goes from on to off.

sw.off.subscribe(() => {

})