Skip to content

Commit

Permalink
Configurable device name #212
Browse files Browse the repository at this point in the history
  • Loading branch information
sbs20 committed May 17, 2021
1 parent 7958da0 commit 338fcc3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 27 deletions.
75 changes: 49 additions & 26 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,17 @@ module.exports = {
*/
afterDevices(devices) {
// Override the defaults for plustek scanners
const device = devices.filter(d => d.id.startsWith('plustek'))[0];
if (device) {
device.features['--mode'].default = 'Color';
device.features['--resolution'].default = 150;
device.features['--resolution'].options = [75, 150, 300, 600];
device.features['--brightness'].default = 0;
device.features['--contrast'].default = 5;
device.features['-x'].default = 215;
device.features['-y'].default = 297;
}
devices
.filter(d => d.id.includes('plustek'))
.forEach(device => {
device.features['--mode'].default = 'Color';
device.features['--resolution'].default = 150;
device.features['--resolution'].options = [75, 150, 300, 600];
device.features['--brightness'].default = 0;
device.features['--contrast'].default = 5;
device.features['-x'].default = 215;
device.features['-y'].default = 297;
});
}
};
```
Expand All @@ -90,13 +91,14 @@ options.
*/
afterDevices(devices) {
// Override the defaults for plustek scanners
const device = devices.filter(d => d.id.startsWith('plustek'))[0];
if (device) {
device.features['--resolution'].default = 150;
device.features['--resolution'].options = [75, 150, 300, 600];
device.features['-x'].default = 215;
device.features['-y'].default = 297;
}
devices
.filter(d => d.id.includes('plustek'))
.forEach(device => {
device.features['--resolution'].default = 150;
device.features['--resolution'].options = [75, 150, 300, 600];
device.features['-x'].default = 215;
device.features['-y'].default = 297;
});
}
```

Expand All @@ -108,15 +110,36 @@ the cropping logic because scanservjs incorrectly trusts the SANE output.

```javascript
afterDevices(devices) {
const device = devices.filter(d => d.id.includes('brother'))[0];
if (device) {
device.features['-l'].limits = [0, 215];
device.features['-t'].limits = [0, 297];
device.features['-x'].default = 215;
device.features['-x'].limits = [0, 215];
device.features['-y'].default = 297;
device.features['-y'].limits = [0, 297];
}
devices
.filter(d => d.id.includes('brother'))
.forEach(device => {
device.features['-l'].limits = [0, 215];
device.features['-t'].limits = [0, 297];
device.features['-x'].default = 215;
device.features['-x'].limits = [0, 215];
device.features['-y'].default = 297;
device.features['-y'].limits = [0, 297];
});
}
```

### Friendly device name

If you have many scanners available then you may wish to give devices friendly
names as per [#212](https://github.com/sbs20/scanservjs/issues/212).
`{ScanDevice}` objects have a `name` attribute which defaults to the `id` but
can be anything you want it to be. You just need to override it.

```javascript
afterDevices(devices) {
const deviceNames = {
'plustek:libusb:001:003': 'Downstairs Canon Flatbed',
'test:device:unreal': 'Upstairs Canon MFD'
};

devices
.filter(d => d.id in deviceNames)
.forEach(d => d.name = deviceNames[d.id]);
}
```

Expand Down
1 change: 1 addition & 0 deletions server/src/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Adapter {
* @returns {ScanDevice}
*/
static decorate(device) {
device.name = device.id;
for (const key in device.features) {
const feature = device.features[key];
feature.parameters = feature.parameters.replace(/^auto\|/, '');
Expand Down
1 change: 1 addition & 0 deletions server/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
/**
* @typedef {Object} ScanDevice
* @property {string} id
* @property {string} name
* @property {string} version
* @property {Object.<string, ScanDeviceFeature>} features
*/
Expand Down
2 changes: 1 addition & 1 deletion webui/src/components/Scan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<v-col cols="12" md="3" class="mb-10 mb-md-0">
<v-select v-if="context.devices.length > 0"
:label="$t('scan.device')" v-model="device"
:items="context.devices" return-object item-text="id" @change="clear"></v-select>
:items="context.devices" return-object item-text="name" @change="clear"></v-select>

<v-select v-if="'--source' in device.features"
:label="$t('scan.source')" v-model="request.params.source"
Expand Down

0 comments on commit 338fcc3

Please sign in to comment.