Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sui77 committed Sep 27, 2020
1 parent 42c6787 commit 204e146
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 82 deletions.
9 changes: 6 additions & 3 deletions public_html/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ h2 {
height: 180px
}

.thumbnail-box .thumbnail-text {
/*.thumbnail-box .thumbnail-text {
width: 88px;
float: left;
}
}*/

.thumbnail-outer {
margin: 10px;
Expand Down Expand Up @@ -147,4 +146,8 @@ i {

.js-abort {
display:none;
}

button.xsmall {
font-size:12px; height:25px; padding:3px;
}
27 changes: 22 additions & 5 deletions public_html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<script src="/js/jquery.ui.touch-punch.min.js"></script>
<script src="/js/odyniec-imgareaselect/jquery.imgareaselect.js"></script>
<script src="/js/jquery.toast.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-toast-plugin/1.3.2/jquery.toast.min.css" integrity="sha512-wJgJNTBBkLit7ymC6vvzM1EcSWeM9mmOu+1USHaRBbHkm6W9EgM0HY27+UtUaprntaYQJF75rc8gjxllKs5OIQ==" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-toast-plugin/1.3.2/jquery.toast.min.css" integrity="sha512-wJgJNTBBkLit7ymC6vvzM1EcSWeM9mmOu+1USHaRBbHkm6W9EgM0HY27+UtUaprntaYQJF75rc8gjxllKs5OIQ==" crossorigin="anonymous"/>

<script src="js/scann3r.js"></script>

Expand Down Expand Up @@ -49,17 +49,34 @@ <h1>About</h1>
</div>

<div class="container content" id="c-browse">
<div class="row" id="thumbs">
<div id="thumb-template" class="thumbnail-box">
<div class="thumbnail-outer">
<img class="thumbnail-image" src="/img/preview640x480.png">
<div class="row" id="thumbs" style="">
<div id="thumb-template" class="thumbnail-box" style="width:300px;height:430px">
<div class="thumbnail-outer" style="padding:0;border:solid 0px #0f0;">

<img style="width:280px; height:280px;margin-bottom:10px;" class="thumbnail-image" src="/img/preview640x480.png">
<div style="padding-left:10px;padding-right:10px;margin-top:-80px;color:#fff;background-color:#000;font-size:30px;position:absolute" class="thumbnail-text"></div>

<!--
<div class="thumbnail-text"></div>
<div class="thumbnail-icons">
<i class="trash feather-trash-2"></i>
<i class="cloud feather-upload-cloud"></i>
<a href="javascript:" class="resultZip"><i class="feather-download-cloud"></i></a>
<a href="javascript:" class="zip"><i class="zip feather-download"></i></a>
</div>
-->
<div class="row">
<div class="col-sm-5">
<a href="javascript:" class="t-delete"><button class="xsmall primary" style="margin:0;margin-bottom:5px;width:100%;text-align:left;"><i class="feather-trash-2"></i> Delete</button></a>
<a href="javascript:" class="t-download"><button class="xsmall primary" style="margin:0;margin-bottom:5px;width:100%;text-align:left;"><i class="feather-download"></i> Download ZIP</button></a>
<a href="javascript:" class="t-cloud-up"><button class="xsmall primary" style="margin:0;margin-bottom:5px;width:100%;text-align:left;"><i class="feather-upload-cloud"></i> Cloud Upload</button></a>
<a href="javascript:" class="t-cloud-down"><button class="xsmall tertiary" style="margin:0;margin-bottom:5px;width:100%;text-align:left;"><i class="feather-download-cloud"></i> Mesh</button></a>
</div>
<div class="col-sm-6">
<ul class="infolist"></ul>
</div>
</div>
</div>

</div>
Expand Down
62 changes: 42 additions & 20 deletions public_html/js/scann3r.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ var Scann3r = {
this.gallery.prepend(t1);
$('#dialog-finished').html(t2)
.dialog({
width: 250,
height: 330
width: 350,
height: 550
});
});

Expand Down Expand Up @@ -305,34 +305,42 @@ var Scann3r = {
}
}
}
}
,
},

gallery: {
init: (sio) => {
this.sio = sio;
this.template = $('#thumb-template').clone();
$('#thumb-template').remove();
},
loadPage:
loadPage: function (page) {
let x = Scann3r.sio.emit('getProjects', 0, 100, (r) => {
for (let n in r) {
this.append(this.createThumb(r[n]));
}
});
},

function (page) {
let x = Scann3r.sio.emit('getProjects', 0, 100, (r) => {
for (let n in r) {
this.append(this.createThumb(r[n]));
}
});
}

,
createThumb: (data) => {
let humanReadableFilesize = (bytes) => {
if (bytes < 1024) {
return bytes + ' bytes';
} else if (bytes < 1024 * 1024) {
return (bytes / 1024).toFixed(1) + ' KB';
} else if (bytes < 1024 * 1024 * 1024) {
return (bytes / 1024 / 1024).toFixed(1) + ' MB';
} else {
return (bytes / 1024 / 1024 / 1024).toFixed(1) + ' GB';
}
};


let t = this.template.clone();
t.attr('id', 'foo');
t.addClass('thumb-' + data.id);
t.find('.thumbnail-image').attr('src', data.thumb);
t.find('.thumbnail-text').text('#' + data.id);
t.find('.zip').attr('href', '/' + data.id + '/images-' + data.id + '.zip');
t.find('.trash').click(function () {

t.find('.t-delete').click(() => {
if (confirm('Are you sure?')) {
Scann3r.sio.emit('delete', data.id, (err, r) => {
if (err) {
Expand All @@ -344,18 +352,32 @@ var Scann3r = {
}
});

t.find('.cloud').click(function () {
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>`);


t.find('.t-cloud-up').click(() => {
Scann3r.sio.emit('proxy', data.id, (err, r) => {
if (err) {

alert(err);
}
});
});


t.find('.thumbnail-image').attr('src', data.thumb);
t.find('.thumbnail-text').text('#' + data.id);
t.find('.t-download').attr('href', '/' + data.id + '/images-' + data.id + '.zip');


if (typeof data.resultZip != 'undefined') {
t.find('.resultZip').attr('href', '/' + data.id + '/' + data.resultZip);
t.find('.t-cloud-down').attr('href', '/' + data.id + '/' + data.resultZip);
} else {
t.find('.resultZip').hide();
t.find('.t-cloud-down').hide();
}
return t;
},
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ if (!fs.existsSync(configfile)) {
registry.set('turntable', new Stepper(config.data.turntable, gpio.turntableStep, gpio.turntableDir, gpio.turntableEnable));
registry.set('rotor', new Stepper(config.data.rotor, gpio.rotorStep, gpio.rotorDir, gpio.rotorEnable));
registry.set('camera', new Camera(registry));
registry.set('proxy', new Proxy(registry));
registry.set('webServer', new WebServer(registry));
registry.set('webSocket', new WebSocket(registry));
registry.set('notification', new Notification(registry));
registry.set('proxy', new Proxy(registry));

log.info('Ready!');
} catch(e) {
Expand Down
1 change: 1 addition & 0 deletions src/lib/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Project {
let id = await r.incrby('projectId', 1);
await r.lpush('projects', id);
await r.hset(`project:${id}`, 'id', id);
await r.hset(`project:${id}`, 'date', new Date().toISOString() );
let p = new Project(id, registry);
p.createFolder();
return p;
Expand Down
25 changes: 18 additions & 7 deletions src/lib/Scan.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const {exec} = require('child_process');
const Project = require('./Project.js');
const fs = require('fs').promises;

class Scan {

Expand All @@ -19,20 +20,20 @@ class Scan {
let config = this.registry.get('config');
this.config = config;
this.currentProgress = {
photo: '-',
photo: '',
text: '',
percent: 0
}

let rotorAngleFrom = config.get('rotorAngleRangeToScan.values')[0];
let rotorAngleTo = config.get('rotorAngleRangeToScan.values')[1];
this.rotorAngleFrom = config.get('rotorAngleRangeToScan.values')[0];
this.rotorAngleTo = config.get('rotorAngleRangeToScan.values')[1];
let rotorAnglesPerScan = config.get('rotorAnglesPerScan.value');
let imagesPerRevision = config.get('imagesPerRevision.value');

this.turntableRangeMax = config.get('turntable.range.max');

this.rotorStart = rotorAngleFrom;
this.rotorSteps = Math.floor((rotorAngleTo - rotorAngleFrom) / rotorAnglesPerScan);
this.rotorStart = this.rotorAngleFrom;
this.rotorSteps = Math.floor((this.rotorAngleTo - this.rotorAngleFrom) / rotorAnglesPerScan);
this.turntableSteps = Math.floor(this.turntableRangeMax / imagesPerRevision);

this.rotorCurrent = 0;
Expand All @@ -46,6 +47,12 @@ class Scan {

async start() {
this.project = await Project.create(this.registry);
this.project.set('rotorCount', this.rotorCount+1);
this.project.set('turntableCount', this.turntableCount+1);
this.project.set('crop', JSON.stringify(this.cropValues));
this.project.set('range', this.rotorAngleFrom + "° .. " + this.rotorAngleTo + "°");


this.progress({text: `Starting project #${this.project.id}.`});

this.progress({text: `Moving rotor and turntable to start position.`});
Expand Down Expand Up @@ -117,9 +124,13 @@ class Scan {
async zip() {
this.progress({text: `Creating ZIP file.`});
let filesToZip = this.project.getPath('cropped') + '*.jpg';
let zipFile = this.project.getPath() + 'images-' + this.project.id + '.zip';
let zipFile = this.project.getZipFileLocation();
let cmd = `/usr/bin/zip -j ${zipFile} ${filesToZip}`;
return this._exec(cmd);
await this._exec(cmd);
console.log(zipFile);
let stats = await fs.stat( zipFile);
let size = stats.size;
this.project.set('zipSize', size);
}

async crop(filename) {
Expand Down
9 changes: 2 additions & 7 deletions src/modules/Camera.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
const PiCamera = require('pi-camera');
const fs = require('fs');
const {exec} = require("child_process");
const log = require('../lib/Log.js').createLogger({name: 'Camera'});

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

var snapCount = 0;

class Camera {

onPreviewDone(img) {
Expand Down Expand Up @@ -72,7 +68,7 @@ class Camera {
let image = await this.camPreview.snapDataUrl();
this.onPreviewDone(image);
} catch (e) {
console.log('Could not snap preview', e);
log.error('Could not take preview picture ' + e.message);
}
this.snapping = false;
if (this.refresh) {
Expand All @@ -91,7 +87,7 @@ class Camera {
this.initCam();
await this.camProd.snap();
} catch (e) {
console.log('Could not snap image', e);
log.error('Could not take picture ' + e.message);
}
this.snapping = false;
}
Expand All @@ -107,7 +103,6 @@ class Camera {
this.snapPreview();
}
}

}

async stopPreview() {
Expand Down
31 changes: 24 additions & 7 deletions src/modules/Proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,38 @@ function sleep(ms) {
class Proxy {

onInfo(msg) {
// @todo abhängigkeiten nochmal irgendwie sauberer lösen
this.registry.get('webSocket').toast(msg);
}

onRegistered(msg) {
}


info(msg) {
this.onInfo(msg);
}

constructor(registry) {
log.info("Instanciating Proxy " + registry.get('config').get('version'));
this.io = registry.get('webSocket').io;
this.registry = registry;
this.files = {};
this.socket = null;
setInterval(() => this.maintenance(), 4000);
}

maintenance() {
console.log(Object.keys(this.files).length);
if ( this.socket != null && Object.keys(this.files).length == 0) {
this.socket.close();
this.socket = null;
this.files = {};
}
}

removeAllFiles() {

}

removeFile(uid) {

}

async addFile(project) {
Expand All @@ -62,7 +75,7 @@ class Proxy {
await this.connectToProxy();
this.socket.emit('register', uuid, size, (err, r) => {
if (!err) {
this.io.emit('proxy', r);
this.onRegistered(r);
this.files[uuid].status = STATUS_REGISTERED;
} else {
this.registry.get('notification').notify('error-' + uuid, 'Error', 'Proxy error: ' + err, 0, false);
Expand All @@ -83,7 +96,7 @@ class Proxy {
return;
}

this.socket = client.connect("ws://mc.sui.li:808", {
this.socket = client.connect(this.registry.get('config').get('proxy.url'), {
path: '/ws',
reconnection: false,
timeout: 2000,
Expand All @@ -100,9 +113,14 @@ class Proxy {

this.socket.on('disconnect', () => {
console.log('proxy disconnected');
this.files = {};
this.socket = null;
});

this.socket.on('expired',(uid) => {
delete this.files[uid];
});

this.socket.on('getData', async (uid, cb) => {
let me = this.files[uid];
let buffer = Buffer.alloc(BUFFER_SIZE);
Expand Down Expand Up @@ -154,7 +172,6 @@ class Proxy {
}
}

throw new Error('noooo');
}
}

Expand Down
Loading

0 comments on commit 204e146

Please sign in to comment.