Skip to content

Commit

Permalink
fix issue #3
Browse files Browse the repository at this point in the history
  • Loading branch information
sui77 committed Sep 29, 2020
1 parent 204e146 commit ad6e17a
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 44 deletions.
23 changes: 13 additions & 10 deletions public_html/js/scann3r.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
console.log(location.hash);

var Scann3r = {

sio: null,
Expand All @@ -12,6 +12,7 @@ var Scann3r = {
this.gallery.init();
this.gallery.loadPage(0);
this.toasts = [];
this.sio.emit('ready');
},

showWebsocketError() {
Expand Down Expand Up @@ -67,10 +68,6 @@ var Scann3r = {
hideAfter: false,
loader: false,
sticky: true,
afterShown: () => {
console.log('yup', $(this));

}
}

if (typeof this.toasts[data.id] != 'undefined') {
Expand All @@ -93,6 +90,10 @@ var Scann3r = {
});

this.sio.on('setSliderValue', (name, value) => {
if (! $('.slider[data-slider=' + name + ']').hasClass('ui-widget')) {
return; // not initialized yet
}

let key = (typeof value == 'object') ? 'values' : 'value';
$('.slider[data-slider=' + name + ']').slider(key, value);
});
Expand Down Expand Up @@ -352,11 +353,13 @@ var Scann3r = {
}
});

console.log(data);

t.find('.infolist').append(`<li>${data.rotorCount}x${data.turntableCount} Images</li>`);
t.find('.infolist').append(`<li>${humanReadableFilesize(data.zipSize)}</li>`);
t.find('.infolist').append(`<li>${data.range}</li>`);
if (data.complete) {
t.find('.infolist').append(`<li>${data.rotorCount}x${data.turntableCount} Images</li>`);
t.find('.infolist').append(`<li>${humanReadableFilesize(data.zipSize)}</li>`);
t.find('.infolist').append(`<li>${data.range}</li>`);
} else {
t.find('.infolist').append('<li>Aborted</li>');
}


t.find('.t-cloud-up').click(() => {
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ if (!fs.existsSync(configfile)) {
rotorStep: new Gpio(config.data.rotor.step, 'out'),
rotorDir: new Gpio(config.data.rotor.dir, 'out'),
rotorEnable: new Gpio(config.data.rotor.enable, 'out'),
}
};


registry.set('scanning', false);
registry.set('currentScan', null);
registry.set('config', config);
registry.set('redis', Redis.createClient(config.data.redis));
await config.loadDynamicValues();
Expand Down
2 changes: 0 additions & 2 deletions src/lib/Config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const _ = require('lodash');
const fs = require('fs');
const log = require('../lib/Log.js').createLogger({name: 'Config'});

class Config {

Expand All @@ -19,7 +18,6 @@ class Config {
}
}


let file = JSON.parse(fs.readFileSync('./package.json').toString());
this.data.version = file.version;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Log.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ module.exports = {
}
}
}
}
};
11 changes: 9 additions & 2 deletions src/lib/Scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Scan {
this.turntableCount = imagesPerRevision - 1;

this.cropValues = config.get('crop.values');

this.bAbort = false;
}


Expand All @@ -68,6 +70,7 @@ class Scan {
await this.deleteImages('cropped');
await this.deleteImages('original');
this.progress({photo: '', text: `Finished scanning project #${this.project.id}.`});
this.project.set('complete', 1);
} else {
this.progress({photo: '', text: `Scan failed #${this.project.id}.`});
}
Expand All @@ -76,14 +79,18 @@ class Scan {
}

checkAbort() {
if (this.registry.get('abort')) {
this.registry.set('abort', false);
if (this.bAbort) {
this.progress({photo: '', text: 'Scan aborted.'});
return true;
}
return false;
}

abort() {
this.progress({text: 'Aborting scan...'});
this.bAbort = true;
}

async next() {
if (this.checkAbort()) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Camera {
}

async startPreview() {
if (this.registry.get('scanning')) {
if (this.registry.get('currentScan') != null) {
return;
}
if (!this.refresh && !this.snapping) {
Expand Down
61 changes: 35 additions & 26 deletions src/modules/WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,25 @@ class WebSocket {
this.io.on('connection', async (socket) => {

log.info(`Client connected from ${socket.handshake.address}`);
if (this.registry.get('scanning')) {
socket.emit('disableControls');
}

this.registry.get('camera').startPreview();
socket.on('ready', () => {

for (let slider in this.sliderAction) {
let options = this.config.get(slider);
socket.emit('initSlider', slider, options);
}

console.log(this.config.get('version'));
socket.emit('info', 'info-version', this.config.get('version'));
socket.emit('imgArea', this.config.get('crop.values'));
socket.emit('invert', this.config.get('rotor.invert'));
this.registry.get('camera').startPreview();

for (let slider in this.sliderAction) {
let options = this.config.get(slider);
socket.emit('initSlider', slider, options);
}

if (this.registry.get('currentScan') != null) {
socket.emit('disableControls');
}

socket.emit('info', 'info-version', this.config.get('version'));
socket.emit('imgArea', this.config.get('crop.values'));
socket.emit('invert', this.config.get('rotor.invert'));
});

socket.on('disconnect', () => {
log.info(`Client disconnected from ${socket.handshake.address}`);
Expand Down Expand Up @@ -150,23 +154,28 @@ class WebSocket {
});

socket.on('start', async () => {
this.io.emit('disableControls');
this.registry.set('abort', false);
this.registry.set('scanning', true);
let scan = new Scan(this.registry, this.io);
scan.onProgress = (data) => {
this.io.emit('progress', data);
};
let project = await scan.start();
let projectData = await project.getAll();
this.io.emit('newProject', projectData);
this.io.emit('enableControls');
this.registry.set('scanning', false);
if (this.registry.get('currentScan') == null) {
this.io.emit('disableControls');
let scan = new Scan(this.registry, this.io);
this.registry.set('currentScan', scan);
scan.onProgress = (data) => {
this.io.emit('progress', data);
};
let project = await scan.start();
let projectData = await project.getAll();
this.io.emit('newProject', projectData);
this.io.emit('enableControls');
this.registry.set('currentScan', null);
} else {

}
});

socket.on('abort', async () => {
console.log('ABORT');
this.registry.set('abort', true);
let scan = this.registry.get('currentScan');
if (scan !== null) {
scan.abort();
}
});

socket.on('delete', async (id, cb) => {
Expand Down

0 comments on commit ad6e17a

Please sign in to comment.