Skip to content

Commit

Permalink
add toggle on lightbulb
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Apr 1, 2023
1 parent 06ed399 commit bfd25a4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
16 changes: 16 additions & 0 deletions devs/lib/clientcmds.ts
Expand Up @@ -50,6 +50,22 @@ ds.Led.prototype.setAll = async function (r, g, b) {
await this.pixels.write(buf)
}

declare module "@devicescript/core" {
interface LightBulb {
/**
* Toggle light between off and full brightness
* @param lowerThreshold if specified, the light will be turned off if the current brightness is above this threshold
*/
toggle(lowerThreshold?: number): Promise<void>
}
}

ds.LightBulb.prototype.toggle = async function (lowerThreshold?: number) {
const value = await this.brightness.read()
const on = value > (lowerThreshold || 0)
await this.brightness.write(on ? 0 : 1)
}

class ClientRegister<T> implements ds.ClientRegister<T> {
private value: T

Expand Down
14 changes: 14 additions & 0 deletions packages/sampleprj/src/mainesp3.ts
@@ -0,0 +1,14 @@
import { pins, board } from "@dsboard/adafruit_qt_py_c3"
import { startLightBulb } from "@devicescript/servers"

const lightBulb = startLightBulb({
pin: pins.A0,
})

setInterval(async () => {
await lightBulb.toggle();
}, 500);




2 changes: 1 addition & 1 deletion vscode/package.json
Expand Up @@ -545,7 +545,7 @@
"command": "extension.devicescript.editor.configure",
"title": "DeviceScript: Configure...",
"category": "DeviceScript",
"icon": "$(settings-gear)"
"icon": "$(wand)"
},
{
"command": "extension.devicescript.terminal.show",
Expand Down

0 comments on commit bfd25a4

Please sign in to comment.