Skip to content

Commit

Permalink
Merge feat_trigger_capture
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Jun 24, 2018
2 parents 53c418d + 544a8dd commit 47c4d0c
Show file tree
Hide file tree
Showing 20 changed files with 940 additions and 153 deletions.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

[![Build Status](https://travis-ci.org/TypedProject/ts-gphoto2-driver.svg?branch=master)](https://travis-ci.org/TypedProject/ts-gphoto2-driver)
[![Coverage Status](https://coveralls.io/repos/github/TypedProject/ts-gphoto2-driver/badge.svg?branch=master)](https://coveralls.io/github/TypedProject/ts-gphoto2-driver?branch=master)
![npm](https://img.shields.io/npm/dm/ts-gphoto2-driver.svg)
[![Package Quality](http://npm.packagequality.com/shield/ts-gphoto2-driver.png)](http://packagequality.com/#?package=ts-gphoto2-driver)
[![npm version](https://badge.fury.io/js/ts-gphoto2-driver.svg)](https://badge.fury.io/js/ts-gphoto2-driver)
![npm](https://img.shields.io/npm/dm/%40typedproject%2Fgphoto2-driver.svg)
[![npm version](https://badge.fury.io/js/%40typedproject%2Fgphoto2-driver.svg)](https://badge.fury.io/js/%40typedproject%2Fgphoto2-driver)
[![Dependencies](https://david-dm.org/romakita/ts-gphoto2-driver.svg)](https://david-dm.org/romakita/ts-gphoto2-driver#info=dependencies)
[![img](https://david-dm.org/romakita/ts-gphoto2-driver/dev-status.svg)](https://david-dm.org/romakita/ts-gphoto2-driver/#info=devDependencies)
[![img](https://david-dm.org/romakita/ts-gphoto2-driver/peer-status.svg)](https://david-dm.org/romakita/ts-gphoto2-driver/#info=peerDependenciess)
Expand All @@ -14,7 +13,16 @@

> This project is under Alpha version.
A Node.js wrapper for libgphoto2 writter in TypeScript. Useful for remote controlling of DSLRs and other digital cameras supported by gphoto2.
A Node.js wrapper for libgphoto2 written in TypeScript. Useful for remote controlling of DSLRs and other digital cameras supported by gphoto2.

## Features

- Camera autodetection,
- Take a picture/movie capture,
- Take a preview (not a live preview mode),
- Retrieve camera list,
- Select camera,
- Display info about your camera (summary, about, manual).

## Prerequisite

Expand Down Expand Up @@ -62,6 +70,9 @@ if (cameraList.size) {
cameraList.close();
```

## Examples

Some example

## Contributors
Please read [contributing guidelines here](./CONTRIBUTING.md).
Expand Down
12 changes: 7 additions & 5 deletions examples/camera-autoselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ const camera = new Camera();

camera.initialize();

console.log('Camera =>', camera);
if (!camera.isClosed()) {
console.log('Camera =>', camera);

const cameraFile = camera.captureImage();
const cameraFile = camera.captureImage();

// cameraFile.save(path.join(__dirname, 'capture.jpg'));
cameraFile.save(path.join(__dirname, '../.tmp/capture.jpeg'));

closeQuietly(cameraFile);
closeQuietly(camera);
closeQuietly(cameraFile);
closeQuietly(camera);
}
27 changes: 27 additions & 0 deletions examples/camera-info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const SegfaultHandler = require('segfault-handler');
const path = require('path');
const { CameraList, closeQuietly } = require('../src');

SegfaultHandler.registerHandler('crash.log');

const cameraList = new CameraList().load();

console.log('Nb camera', cameraList.size);

if (cameraList.size) {
const camera = cameraList.getCamera(0);
console.log('Camera summary =>', camera.getSummary());
console.log('----------------------------------------');
console.log('Camera about =>', camera.getAbout());

console.log('----------------------------------------');
try {
console.log('Camera manual =>', camera.getManual());
} catch (er) {
console.warn('Camera manual =>', er.message);
}

closeQuietly(camera);
}

cameraList.close();
7 changes: 4 additions & 3 deletions examples/camera-list-autodetect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { CameraList } = require('../src');
SegfaultHandler.registerHandler('crash.log');

const cameraList = new CameraList();
const portList = new PortInfoList().load();

// Auto-detect
cameraList.autodetect();
Expand All @@ -14,10 +15,10 @@ cameraList.toArray().forEach((cameraInfo, index) => {
console.log(`[Cam.${index}] model =>`, cameraInfo.model);
console.log(`[Cam.${index}] port =>`, cameraInfo.port);

// cameraList.getPortInfo(index);
const portInfo = portList.findByPath(cameraInfo.port);

/* console.log(`[Cam.portInfo.${index}] name =>`, cameraInfo.portInfo.name);
console.log(`[Cam.portInfo.${index}] path =>`, cameraInfo.portInfo.path);*/
console.log(`[Cam.${index}] portInfo =>`, portInfo.name);
console.log(`[Cam.${index}] portInfo =>`, portInfo.path);
});

cameraList.close();
102 changes: 102 additions & 0 deletions examples/camera-scenario-async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
const { Camera, closeQuietly, CameraWidgets } = require('../src');
const path = require('path');

const camera = new Camera();

console.log('[GPDRIVER] Camera init');
camera.initialize();

runScenario({
autoFocus: true,
triggerCapture: true,
capture: true,
preview: true
})
.catch((er) => {
console.error(er.message);
return Promise.resolve();
})
.then(() => {
closeQuietly(camera);
});


function runScenario({ autoFocus = false, preview = false, capture = false, triggerCapture = false }) {
console.log('[GPDRIVER] Camera Loaded');

return Promise
.resolve()
.then(() => {
if (autoFocus) {
console.log('[GPDRIVER] Autofocus =============================');
return runAutofocus();
}
})
.then(() => {
if (preview) {
console.log('[GPDRIVER] Preview ===============================');
return runPreview();
}
})
.then(() => {
if (triggerCapture) {
console.log('[GPDRIVER] Trigger Capture =======================');
return runTriggerCapture();
}
})
.then(() => {
if (capture) {
console.log('[GPDRIVER] Capture ===============================');
return runCapture();
}
});
}

/**
*
*/
function runAutofocus() {
const cfg = new CameraWidgets(camera);

try {
cfg.setValue('/actions/autofocusdrive', true);
cfg.apply();
} catch (er) {
console.warn(er);
} finally {
closeQuietly(cfg);
}
}

/**
*
*/
function runPreview() {
const filePath = path.join(__dirname, '../.tmp/capture.jpg');

return camera
.capturePreviewAsync(filePath)
.then(() => {
console.log('File saved on', filePath);
});
}

/**
*
*/
function runTriggerCapture() {
return camera.triggerCaptureAsync()
}

/**
*
*/
function runCapture() {
const filePath = path.join(__dirname, '../.tmp/capture.jpg');

return camera
.captureImageAsync(filePath)
.then(() => {
console.log('File saved on', filePath);
});
}
120 changes: 70 additions & 50 deletions examples/camera-scenario.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,89 @@
const { Camera, closeQuietly, CameraWidgets } = require('../src');
const path = require('path');
const autoFocus = false;
const preview = false;
const capture = true;
const camera = new Camera();

const camera = new Camera();

try {
console.log('[GPDRIVER] Camera init');
camera.initialize();

console.log('Camera Loaded');
console.log('=========');
if (autoFocus) {
console.log('Auto focus');
const cfg = new CameraWidgets(camera);
runScenario({
autoFocus: true,
triggerCapture: true,
capture: true,
preview: true
});
} catch (er) {
console.error(er.message);
} finally {
closeQuietly(camera);
}


process.on('exit', () => {
closeQuietly(cfg);
});
function runScenario({ autoFocus = false, preview = false, capture = false, triggerCapture = false }) {
console.log('[GPDRIVER] Camera Loaded');

try {
cfg.setValue('/actions/autofocusdrive', true);
cfg.apply();
} finally {
closeQuietly(cfg);
}
if (autoFocus) {
console.log('[GPDRIVER] Autofocus =============================');
runAutofocus();
}
console.log('=========');

if (preview) {
console.log('Preview');
const cameraFile = camera.capturePreview();

if (cameraFile) {
console.log('PreviewFile');
try {
cameraFile.save(path.join(__dirname, 'preview.jpg'));
}
catch (er) {
console.error(er);
}
finally {
closeQuietly(cameraFile);
}
}


camera.deinitialize();
camera.initialize();
console.log('[GPDRIVER] Preview ===============================');
runPreview();
}

if (triggerCapture) {
console.log('[GPDRIVER] Trigger Capture =======================');
runTriggerCapture();
}
console.log('=========');

if (capture) {
console.log('Capture');
const cf2 = camera.captureImage();

try {
// console.log('==>', path.join(__dirname, 'capture.jpg'));
cf2.save(path.join(__dirname, 'capture.jpg'));
} finally {
closeQuietly(cf2);
}
console.log('[GPDRIVER] Capture ===============================');
runCapture();

runCapture();
}
}

/**
*
*/
function runAutofocus() {
const cfg = new CameraWidgets(camera);

} finally {
closeQuietly(camera);
try {
cfg.setValue('/actions/autofocusdrive', true);
cfg.apply();
} catch (er) {
console.warn(er);
} finally {
closeQuietly(cfg);
}
}

/**
*
*/
function runPreview() {
const filePath = path.join(__dirname, '../.tmp/preview.jpg');
camera.capturePreview(filePath);
console.log('File saved on', filePath);
}

/**
*
*/
function runTriggerCapture() {
camera.triggerCapture();
}

/**
*
*/
function runCapture() {
const filePath = path.join(__dirname, '../.tmp/capture.jpg');

camera.captureImage(filePath);
console.log('File saved on', filePath);
}
14 changes: 9 additions & 5 deletions examples/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ console.log('Nb camera', cameraList.size);

if (cameraList.size) {
const camera = cameraList.getCamera(0);
console.log('Camera =>', camera);

const cameraFile = camera.captureImage();

cameraFile.save(path.join(__dirname, 'capture.jpeg'));
if (!camera.isClosed()) {
console.log('Camera =>', camera);

closeQuietly(cameraFile);
closeQuietly(camera);
const cameraFile = camera.captureImage();

cameraFile.save(path.join(__dirname, '../.tmp/capture.jpeg'));

closeQuietly(cameraFile);
closeQuietly(camera);
}
}

cameraList.close();
Loading

0 comments on commit 47c4d0c

Please sign in to comment.