Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature: Keep images on camera #99

Merged
merged 3 commits into from Apr 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -87,6 +87,14 @@ GPhoto.list(function (list) {
fs.writeFileSync(__dirname + '/picture.jpg', data);
});

// Take picture and keep image on camera
camera.takePicture({
download: true,
keep: true
}, function (er, data) {
fs.writeFileSync(__dirname + '/picture.jpg', data);
});

// Take picture without downloading immediately
camera.takePicture({download: false}, function (er, path) {
console.log(path);
Expand Down
5 changes: 5 additions & 0 deletions src/camera.cc
Expand Up @@ -82,6 +82,11 @@ NAN_METHOD(GPCamera::TakePicture) {
if (preVal->IsBoolean()) {
picture_req->preview = preVal->ToBoolean()->Value();
}

v8::Local<v8::Value> keepVal = options->Get(Nan::New("keep").ToLocalChecked());
if (keepVal->IsBoolean()) {
picture_req->keep = keepVal->ToBoolean()->Value();
}
} else {
REQ_FUN_ARG(0, cb);
picture_req = new take_picture_request();
Expand Down
1 change: 1 addition & 0 deletions src/camera.h
Expand Up @@ -70,6 +70,7 @@ class GPCamera : public Nan::ObjectWrap {
int ret;
bool download;
bool preview;
bool keep;
std::string path;
std::string target_path;
std::string socket_path;
Expand Down
2 changes: 1 addition & 1 deletion src/camera_helpers.cc
Expand Up @@ -377,7 +377,7 @@ void GPCamera::downloadPicture(take_picture_request *req) {
data = NULL;
}

if (retval == GP_OK) {
if (retval == GP_OK && !req->keep) {
retval = gp_camera_file_delete(req->camera, folder.str().c_str(),
name.c_str(), req->context);
}
Expand Down
13 changes: 12 additions & 1 deletion test/camera.test.coffee
Expand Up @@ -70,7 +70,18 @@ describe "node-gphoto2", ()->

it 'and download it to a buffer', (done)->
@timeout 10000
cameras[0].takePicture download:true, (er, data)->
cameras[0].takePicture download:true, keep:false, (er, data)->
try
should.not.exist er
data.should.be.an.instanceOf Buffer
checkJpegHeader data
done()
catch error
done error

it 'and keep it on camera', (done)->
@timeout 10000
cameras[0].takePicture download:true, keep:true, (er, data)->
try
should.not.exist er
data.should.be.an.instanceOf Buffer
Expand Down