-
Notifications
You must be signed in to change notification settings - Fork 0
/
releaseShutters.js
56 lines (45 loc) · 1.52 KB
/
releaseShutters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import ESPER from './lib/index.js'
// Check command line arguments and print usage if incorrect
if (process.argv.length < 3) {
console.log(`Usage: node ${process.argv[1]} <serial port name>`)
// Get list of trigger boxes
const devices = await ESPER.listPossibleTriggerBoxes()
if (devices.length < 1) {
console.error('No trigger boxes detected')
} else {
console.log('\nPossible trigger boxes:')
devices.forEach(device => console.log(` - "${device}"`))
}
// Do not continue
process.exit(1)
}
// Extract the comm port
const PORT_PATH = process.argv[2]
// Initialize trigger box object
console.log(`** Connecting to ${PORT_PATH} **`)
const triggerBox = new ESPER.TriggerBox(PORT_PATH)
triggerBox.on('ready', async () => {
// Print connection string
console.log('Connected to trigger box ' + triggerBox.boxId + ' in ' + triggerBox.mode + ' mode on port "' + PORT_PATH + '"')
try {
// Pause a bit before sending commands
await ESPER.waitForMilliseconds(1000)
// Enable link
console.log('Enabling link ...')
await triggerBox.enableLink(true)
// Focus and fire
console.log('Starting focus ...')
await triggerBox.startFocus(1000)
console.log('Releasing shutter ...')
await triggerBox.releaseShutter()
console.log('Releasing focus ...')
await triggerBox.stopFocus()
// Close the connection
console.log('Shutting down ...')
await triggerBox.close()
} catch (error) {
triggerBox.close()
console.error('Box command failed:')
console.error(error)
}
})