Skip to content

Commit

Permalink
Merge feat_get_camera_config
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Aug 18, 2018
2 parents d13e4e3 + ce36ef0 commit b19105c
Show file tree
Hide file tree
Showing 51 changed files with 1,087 additions and 424 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ cameraList.close();

Some example are available in the `examples` directory.

Checkout this project then run `npm run build` and run `node examples/camera.js`.
Checkout this project then run `npm run develop` and run `node examples/camera.js`.

## Contribute

Expand Down
4 changes: 2 additions & 2 deletions examples/abilities-list.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { checkCode } = require('../lib/driver');
const { checkCode } = require('../src/driver');

const { AbilitiesList, PortInfoList, GPhoto2Driver } = require('../src');
const ref = require('ref');
Expand All @@ -22,7 +22,7 @@ for (let i = 0; i < size; i++) {
checkCode(GPhoto2Driver.gp_list_get_name(list.pointer, i, name));
checkCode(GPhoto2Driver.gp_list_get_value(list.pointer, i, value));

console.log('name=>', name.deref());
console.log('path=>', name.deref());
console.log('value=>', value.deref());
}

Expand Down
29 changes: 29 additions & 0 deletions examples/camera-abilities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { Camera, closeQuietly, GPPortType, GPCameraDriverStatus, GPCameraFileOperation, GPCameraFolderOperation, GPDeviceType} = require('../src');

const camera = new Camera();

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

console.log('==> abilities.model', camera.getAbilities().model);
console.log('==> abilities.port', GPPortType[camera.getAbilities().port]);
console.log('==> abilities.status', GPCameraDriverStatus[camera.getAbilities().status]);
console.log('==> abilities.id', camera.getAbilities().id);
console.log('==> abilities.library', camera.getAbilities().library);
console.log('==> abilities.operation', camera.getAbilities().operation);
console.log('==> abilities.fileOperations', GPCameraFileOperation[camera.getAbilities().fileOperations]);
console.log('==> abilities.folderOperations', GPCameraFolderOperation[camera.getAbilities().folderOperations]);
console.log('==> abilities.usbVendor', camera.getAbilities().usbVendor);
console.log('==> abilities.usbProduct', camera.getAbilities().usbProduct);
console.log('==> abilities.usbClass', camera.getAbilities().usbClass);
console.log('==> abilities.usbSubclass', camera.getAbilities().usbSubclass);
console.log('==> abilities.deviceType', GPDeviceType[camera.getAbilities().deviceType]);
console.log('==> abilities.speed', camera.getAbilities().speed);

} catch (er) {
console.error(er.message);
} finally {
closeQuietly(camera);
}

4 changes: 2 additions & 2 deletions examples/camera-autoselect.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { Camera, closeQuietly } = require('../lib');
const { Camera, closeQuietly } = require('../src');
const path = require('path');
const camera = new Camera();

camera.initialize();

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

const cameraFile = camera.captureImage();

Expand Down
2 changes: 1 addition & 1 deletion examples/camera-info.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const SegfaultHandler = require('segfault-handler');
const path = require('path');
const { CameraList, closeQuietly } = require('../lib');
const { CameraList, closeQuietly } = require('../src');

SegfaultHandler.registerHandler('crash.log');

Expand Down
2 changes: 1 addition & 1 deletion examples/camera-list-autodetect.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const SegfaultHandler = require('segfault-handler');
const { CameraList, PortInfoList } = require('../lib');
const { CameraList, PortInfoList } = require('../src');

SegfaultHandler.registerHandler('crash.log');

Expand Down
2 changes: 1 addition & 1 deletion examples/camera-list-populate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const SegfaultHandler = require('segfault-handler');
const { CameraList, PortInfoList } = require('../lib');
const { CameraList, PortInfoList } = require('../src');

SegfaultHandler.registerHandler('crash.log');

Expand Down
17 changes: 6 additions & 11 deletions examples/camera-scenario-async.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Camera, closeQuietly, CameraWidgets } = require('../lib');
const { Camera, closeQuietly, CameraWidgets } = require('../src');
const path = require('path');

const camera = new Camera();
Expand All @@ -8,9 +8,9 @@ camera.initialize();

runScenario({
autoFocus: true,
triggerCapture: true,
triggerCapture: false,
capture: true,
preview: true
preview: false
})
.catch((er) => {
console.error(er.message);
Expand Down Expand Up @@ -56,23 +56,18 @@ function runScenario({ autoFocus = false, preview = false, capture = false, trig
*
*/
function runAutofocus() {
const cfg = new CameraWidgets(camera);

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

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

return camera
.capturePreviewAsync(filePath)
Expand All @@ -85,7 +80,7 @@ function runPreview() {
*
*/
function runTriggerCapture() {
return camera.triggerCaptureAsync()
return camera.triggerCaptureAsync();
}

/**
Expand Down
53 changes: 31 additions & 22 deletions examples/camera-scenario.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Camera, closeQuietly, CameraWidgets } = require('../lib');
const { Camera, closeQuietly, CameraWidgets } = require('../src');
const path = require('path');

const camera = new Camera();
Expand All @@ -19,46 +19,55 @@ try {
closeQuietly(camera);
}


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

if (autoFocus) {
console.log('[GPDRIVER] Autofocus =============================');
runAutofocus();
try {
if (autoFocus) {
console.log('[GPDRIVER] Autofocus =============================');
runAutofocus();
}
} catch (er) {
console.warn('Autofocus fail', er.message);
}

if (preview) {
console.log('[GPDRIVER] Preview ===============================');
runPreview();
try {
if (preview) {
console.log('[GPDRIVER] Preview ===============================');
runPreview();
}
} catch (er) {
console.warn('Preview fail', er.message);
}

if (triggerCapture) {
console.log('[GPDRIVER] Trigger Capture =======================');
runTriggerCapture();
try {
if (triggerCapture) {
console.log('[GPDRIVER] Trigger Capture =======================');
runTriggerCapture();
}
} catch (er) {
console.warn('triggerCapture fail', er.message);
}

if (capture) {
console.log('[GPDRIVER] Capture ===============================');
runCapture();

runCapture();
try {
if (capture) {
console.log('[GPDRIVER] Capture ===============================');
runCapture();
}
} catch (er) {
console.warn('capture fail', er.message);
}

}

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

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

Expand Down
2 changes: 1 addition & 1 deletion examples/camera.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const SegfaultHandler = require('segfault-handler');
const path = require('path');
const { CameraList, closeQuietly } = require('../lib');
const { CameraList, closeQuietly } = require('../src');

SegfaultHandler.registerHandler('crash.log');

Expand Down
2 changes: 1 addition & 1 deletion examples/port-list.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { PortInfoList } = require('../lib');
const { PortInfoList } = require('../src');

const portList = new PortInfoList();

Expand Down
17 changes: 8 additions & 9 deletions examples/widgets.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
const path = require('path');
const { CameraList, closeQuietly } = require('../lib');

SegfaultHandler.registerHandler('crash.log');
const fs = require('fs');
const { CameraList, closeQuietly } = require('../src');

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

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

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

const cameraFile = camera.captureImage();

console.log(camera.toString());
console.log(camera.widgets.toString());

cameraFile.save(path.join(__dirname, 'capture.jpeg'));
// camera.widgets => Widget which inherit from Map class
const widgets = JSON.stringify(camera.widgets, null, 2);
fs.writeFileSync('../.tmp/widgets.json', widgets, { encoding: 'utf8' });

closeQuietly(cameraFile);
closeQuietly(camera);
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"tslint": "tslint --project tsconfig.json",
"test": "npm run tsc && npm run tslint && cross-env NODE_ENV=test nyc --reporter=html --reporter=text _mocha --recursive",
"tsc": "tsc --project tsconfig.json",
"develop": "tsc --project tsconfig.json -w",
"build": "tsc --project tsconfig.compile.json",
"prettier": "prettier '{src,test}/**/*.ts' --write"
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/AbilitiesList.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {checkCode, GPhoto2Driver} from "../driver";
import {PointerAbilityList, RefAbilitiesList} from "../driver/modules";
import {PointerAbilitiesList, RefAbilitiesList} from "../driver/modules";
import {Context} from "./Context";
import {List} from "./List";
import {PointerWrapper} from "./PointerWrapper";
import {PortInfoList} from "./PortInfoList";

export class AbilitiesList extends PointerWrapper<PointerAbilityList> {
export class AbilitiesList extends PointerWrapper<PointerAbilitiesList> {
constructor() {
super("gp_abilities_list", RefAbilitiesList);
}
Expand Down
Loading

0 comments on commit b19105c

Please sign in to comment.