-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
940 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.