Skip to content

Commit 62efa59

Browse files
committed
add start stop and reset functions
1 parent 0355bc4 commit 62efa59

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

example/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ import { AutodartsBoard } from 'autodarts-board'
88
board.onMessage((msg) => {
99
if (msg.type == 'motion_state') console.log(msg.data)
1010
})
11+
12+
// board.start()
13+
// board.stop()
14+
// board.reset()
1115
})()

src/Autodarts.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,38 @@ export class AutodartsBoard {
7474
onMessage(listener: (data: AutodartsWsMessage) => void) {
7575
this.eventEmitter.on('message', listener)
7676
}
77+
78+
private async fetch(path: string, init: RequestInit) {
79+
return await fetch(`http://${this.host}:${this.port}${path}`, init)
80+
}
81+
82+
/**
83+
* Start the cameras
84+
*/
85+
async start() {
86+
const res = await this.fetch('/api/start', {
87+
method: 'PUT',
88+
})
89+
return res.status == 200
90+
}
91+
92+
/**
93+
* Stop the cameras
94+
*/
95+
async stop() {
96+
const res = await this.fetch('/api/stop', {
97+
method: 'PUT',
98+
})
99+
return res.status == 200
100+
}
101+
102+
/**
103+
* Reset the board
104+
*/
105+
async reset() {
106+
const res = await this.fetch('/api/reset', {
107+
method: 'POST',
108+
})
109+
return res.status == 200
110+
}
77111
}

0 commit comments

Comments
 (0)