Skip to content

Commit

Permalink
Merge fix/settings_widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Aug 27, 2018
2 parents 15ba902 + 0557e89 commit 25b48b9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
14 changes: 11 additions & 3 deletions examples/widgets.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs');
const { CameraList, closeQuietly } = require('../src');
const { CameraList, CameraWidgets, closeQuietly } = require('../src');
// If you launch this example not from library folder, change the previous line to:
// const { CameraList, closeQuietly } = require('@typedproject/gphoto2-driver');

Expand Down Expand Up @@ -27,11 +27,19 @@ if (cameraList.size) {
console.log('/actions/autofocusdrive', camera.widgets.get('/actions/autofocusdrive').value);
console.log('/settings/autofocus', camera.widgets.get('/settings/autofocus').value);

const lightmeter = camera.widgets.get('/status/flashopen');

setInterval(() => {
camera.widgets.refresh();
console.log('/status/flashopen (1) =>', new CameraWidgets(camera).get('/status/flashopen').value);
console.log('/status/flashopen (2) =>', lightmeter.value);
}, 1000);

// 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(camera);
// closeQuietly(camera);
}

cameraList.close();
// cameraList.close();
2 changes: 1 addition & 1 deletion src/components/CameraWidgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class CameraWidgets extends Map<string, Widget> implements ICloseable {

if (obj) {
Object.keys(obj).forEach(key => {
this.get(key).applyValue(obj[key], false);
this.get(key).setValue(obj[key], false);
});
}

Expand Down
7 changes: 3 additions & 4 deletions src/components/Widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class Widget implements IWidget {
* @param pointer
*/
set pointer(pointer: PointerCameraWidget) {
this.pointer = pointer;
this._pointer = pointer;
}

/**
Expand Down Expand Up @@ -150,7 +150,7 @@ export class Widget implements IWidget {
* @param value the value, may be null.
*/
set value(value: any) {
this.applyValue(value, true);
this.setValue(value, true);
}

get changed(): boolean {
Expand Down Expand Up @@ -263,14 +263,13 @@ export class Widget implements IWidget {
* If the settings are altered, they need to be applied to take effect.
*/
apply() {
this.cameraWidgets.checkNotClosed();
this.cameraWidgets.apply();
}

toJSON(): IWidget {
return ["path", "label", "type", "info", "value", "choices", "changed", "range", "readonly"].reduce((acc: any, key: string) => {
if (!(this[key] === "" || this[key] === undefined || this[key] === null)) {
acc[key] = this[key];
acc[key] = this[key] && this[key].toJSON ? this[key].toJSON() : this[key];
}

return acc;
Expand Down
8 changes: 8 additions & 0 deletions src/components/WidgetRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ export class WidgetRange {
this.step = step.deref();
}

public toJSON() {
return {
min: this.min,
max: this.max,
step: this.step
};
}

public toString() {
return "Range{" + this.min + ".." + this.max + ", step=" + this.step + "}";
}
Expand Down

0 comments on commit 25b48b9

Please sign in to comment.