-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcamera.js
More file actions
52 lines (45 loc) · 998 Bytes
/
Copy pathcamera.js
File metadata and controls
52 lines (45 loc) · 998 Bytes
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
const gphoto2 = require('gphoto2');
class Camera {
constructor() {
this.GPhoto = new gphoto2.GPhoto2();
this.GPhoto.setLogLevel(3);
}
initialize() {
return new Promise((resolve, reject) => {
this.GPhoto.list((list) => {
if (!list.length) {
reject('No camera found');
} else {
this.camera = list[0];
resolve();
}
});
});
}
configure(key, value) {
return new Promise((resolve, reject) => {
this.camera.setConfigValue(key, value, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}
takePicture(opts = { download: true }) {
return new Promise((resolve, reject) => {
this.camera.takePicture(opts, function(err, data) {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
get info() {
return this.camera.model;
}
}
module.exports = Camera;