Skip to content

Commit 360faf9

Browse files
committed
bootscreen editor
1 parent 516cbdf commit 360faf9

File tree

9 files changed

+243
-66
lines changed

9 files changed

+243
-66
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ supported OS: Linux,Mac,Windows
88

99
* automatically clone repository from github if you don't have it
1010
* instant changing of Configuration*.h files
11-
* filter only changed options overall and for each section
12-
* show help for options
11+
* allow to filter only changed options overall and for each section
12+
* show help for all options
1313
* show help for G-codes
1414
* show allowed options/gcodes depends your configuration
1515
* reset configuration changes
16-
* switch between releases (available after reset)
16+
* switch between releases and update git repository from github
1717
* **uploading your old configuration over current**
1818
* **compiling and uploading firmware** via PlatformIO
1919
* **access to all serial ports** using console manager (Linux/Mac with auto ports changing detection)
20+
* simple 3D tool for positioning printer head in console manager
21+
* **snippets** allow edit upload BootScreen, calculate a step values for various stepper motors
2022
* quick navigate with a right sided navigation bar
2123
* creating an issue on [Marlin github](https://github.com/MarlinFirmware/Marlin) with your configuration
2224

@@ -28,7 +30,7 @@ in project used documentation from [MarlinDocumentation](https://github.com/Marl
2830
* [git](https://git-scm.com/downloads)
2931
* [PlatformIO](http://docs.platformio.org/en/latest/installation.html) (optional)
3032
## Using
31-
after run - choose a folder with Marlin repo or an empty folder for cloning
33+
After run appears a File dialog and asks to open any empty folder (then will be cloning for last version of marlin from github) or folder with the Marlin git repository
3234
# Installation NPM
3335
[![npm version](https://badge.fury.io/js/marlin-conf.svg)](https://badge.fury.io/js/marlin-conf)
3436

@@ -46,7 +48,7 @@ open terminal in an empty folder or in a folder with Marlin repository and type
4648
`mct` and confirm action
4749

4850
# Preview
49-
![image](https://cloud.githubusercontent.com/assets/3035266/26492336/2934c98c-421c-11e7-8aab-3ddab57525f3.png)
51+
![image](https://user-images.githubusercontent.com/3035266/26917440-f626e258-4c36-11e7-9d1c-3ae199a497ee.png)
5052

5153
## hints
5254
* In clean/unchanged configuration you can change current release version

app/server.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var express = require('express');
2+
var bodyParser = require('body-parser');
23
var path = require('path');
34
var opn = require('opn');
45
var mctool = require('./mc-tool');
@@ -28,6 +29,8 @@ if (serial_enabled)
2829

2930
app.use('/', express.static(path.join(__dirname,'..', 'static')));
3031
app.use('/libs', express.static(path.join(__dirname,'..', 'node_modules')));
32+
app.use(bodyParser.json());
33+
app.use(bodyParser.urlencoded({ extended: true }));
3134

3235
app.get('/tags', function (req, res) {
3336
git.Tags().then(data=>{
@@ -267,6 +270,16 @@ app.get('/bs/default', function (req, res) {
267270
.then(a=>res.send(a))
268271
.catch(e=>res.status(403).send(e))
269272
});
273+
app.post('/bs/custom', function (req, res) {
274+
var name='_Bootscreen.h';
275+
Promise
276+
.resolve(path.join(__dirname,'..','views',name))
277+
.then(file=>promisify(fs.readFile)(file,'utf8'))
278+
.then(text=>text.replace(/{{([\w.]+)}}/g,(m,r)=>r.split('.').reduce((p,o)=>(p=p&&p[o],p),req.body)))
279+
.then(file=>git.root().then(p=>promisify(fs.writeFile)(path.join(p,'Marlin',name),file)))
280+
.then(a=>res.end('writed'))
281+
.catch(e=>res.status(403).send(e))
282+
});
270283
app.get('/bs/custom', function (req, res) {
271284
git.root()
272285
.then(f=>path.join(f,'Marlin','_Bootscreen.h'))

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "marlin-conf",
3-
"version": "2.7.1",
3+
"version": "2.7.2",
44
"description": "configuration tool for Marlin project",
55
"main": "./index.js",
66
"scripts": {
@@ -51,6 +51,7 @@
5151
},
5252
"homepage": "https://github.com/akaJes/marlin-config#readme",
5353
"dependencies": {
54+
"body-parser": "^1.17.2",
5455
"bootstrap": "4.0.0-alpha.6",
5556
"cropper": "^3.0.0-rc.2",
5657
"express": "^4.15.2",

static/css/toggle.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
display: block; overflow: hidden; cursor: pointer;
2525
border: 1px solid #999999; border-radius: 20px;
2626
margin-bottom:0;
27+
text-align: left;
2728
}
2829
.onoffswitch-inner {
2930
display: block; width: 200%; margin-left: -100%;

static/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ <h4 class="modal-title" id="myModalLabel">Log</h4>
307307
</div>
308308
<div id="mct-alert" >
309309
<template class="_alert">
310-
<div class="alert alert-danger alert-dismissible fade show" role="alert">
310+
<div class="alert alert-danger alert-dismissible fade show" role="alert" data-dismiss="alert" >
311311
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
312312
<span aria-hidden="true">&times;</span>
313313
</button>
@@ -316,7 +316,7 @@ <h4 class="alert-heading">Oh snap!</h4>
316316
</div>
317317
</template>
318318
<template class="_info">
319-
<div class="alert alert-info alert-dismissible fade show" role="alert">
319+
<div class="alert alert-info alert-dismissible fade show" role="alert" data-dismiss="alert" >
320320
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
321321
<span aria-hidden="true">&times;</span>
322322
</button>

static/snippets.js

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ function readValues(inps){
2222
})
2323
return vals;
2424
}
25+
function setCanvasSize(canvas,width,height,scale){
26+
Object.assign(canvas,{width:width*scale,height:height*scale});
27+
var ctx = canvas.getContext("2d");
28+
ctx.setTransform(1, 0, 0, 1, 0, 0);
29+
ctx.scale(scale,scale);
30+
ctx.imageSmoothingEnabled = false;
31+
}
2532
function drawBootscreen(canvas,screen,size){
26-
Object.assign(canvas,{width:screen.width*size,height:screen.height*size});
27-
33+
setCanvasSize(canvas,screen.width,screen.height,size);
2834
function reader(screen){
2935
var bit=0x80>>(screen.pos%8);
3036
var pixel=!!(screen.data[parseInt(screen.pos/8)]&bit);
@@ -37,24 +43,58 @@ function drawBootscreen(canvas,screen,size){
3743
for (var x=0;screen.width>x;x++)
3844
if (reader(screen)){
3945
ctx.beginPath();
40-
ctx.rect(x*size,y*size,size,size)
46+
ctx.rect(x,y,1,1)
4147
ctx.fillStyle="black";
4248
ctx.fill();
4349
}
4450
}
4551
}
46-
function imgReader(file,img,canv){
47-
var destCtx = canv[0].getContext('2d');
48-
Object.assign(canv[0],{width:5*128,height:5*64});
49-
destCtx.scale(5, 5);
50-
destCtx.imageSmoothingEnabled = false;
52+
function createBootscreen(canvas,width,height){
53+
var inrow=Math.ceil(width/8);
54+
var buffer=new ArrayBuffer(inrow*height);
55+
var ar8=new Uint8Array(buffer);
56+
function writer(row,x,data){
57+
if (data)
58+
ar8[row+Math.floor(x/8)]|=0x80>>(x%8);
59+
}
60+
var ctx = canvas.getContext("2d");
61+
var data = ctx.getImageData(0, 0, width, height).data;
62+
var pixel = 0;
63+
for (var y=0;height>y;y++){
64+
for (var x=0;width>x;x++,pixel+=4)
65+
writer(y*Math.floor(width/8),x,data[pixel]==0);
66+
}
67+
var pos=0,lines='';
68+
for (var i=0;i<ar8.length;i++)
69+
lines+='0x'+('0'+ar8[pos++].toString(16)).slice(-2)+','+(pos%8?' ':'\n');
70+
return lines;
71+
}
72+
var resized; //global
73+
function imgReader(file,img,canv,inps){
74+
var scale=5;
75+
var canvas=canv[0];
76+
function setAspect(){
77+
var width=inps.eq(0).val(),height=inps.eq(1).val();
78+
img.cropper('setAspectRatio', width/height);
79+
}
80+
setCanvasSize(canvas,inps.eq(0).val(),inps.eq(1).val(),scale);
81+
inps.on('change',function(){
82+
var width=parseInt(inps.eq(0).val()),height=parseInt(inps.eq(1).val());
83+
if (canvas.width/scale != width || canvas.height/scale != height ){
84+
setCanvasSize(canvas,width,height,scale);
85+
setAspect();
86+
}else
87+
img.trigger('crop');
88+
})
5189
file.on('change', function (evt) {
5290
var tgt = evt.target || window.event.srcElement,
5391
files = tgt.files;
5492
// FileReader support
5593
if (FileReader && files && files.length) {
5694
var fr = new FileReader();
5795
fr.onload = function () {
96+
setCanvasSize(canvas,inps.eq(0).val(),inps.eq(1).val(),scale);
97+
setAspect();
5898
img.attr('src',fr.result);
5999
img.cropper('replace', fr.result);
60100
}
@@ -66,23 +106,19 @@ function imgReader(file,img,canv){
66106
zoomable: false,
67107
rotatable: false,
68108
scalable: false,
69-
aspectRatio: 2,
109+
aspectRatio: 1,
70110
minCropBoxWidth:10,
71111
maxCropBoxWidth:10,
72112
viewMode:1,
73113
};
74114
img.cropper(cropDefs);
75-
img.on('aspect',function(ev,aspect){
76-
cropDefs.aspectRatio = aspect;
77-
img.cropper('destroy').cropper(cropDefs);
78-
});
79115
img.on('crop',function(){
116+
var width=inps.eq(0).val(),height=inps.eq(1).val();
80117
var sel=img.cropper('getData');
81-
var canvas=cropImage(img,sel.x,sel.y,sel.width,sel.height,128,64);
82-
toBW(canvas);
83-
var ctx = canvas.getContext("2d");
84-
var destCtx = canv[0].getContext('2d');
85-
destCtx.drawImage(canvas, 0, 0);
118+
resized=cropImage(img,sel.x,sel.y,sel.width,sel.height,width,height);
119+
toBW(resized,parseInt(inps.eq(3).val()),inps.eq(4).prop('checked'));
120+
var destCtx = canvas.getContext('2d');
121+
destCtx.drawImage(resized, 0, 0);
86122
})
87123
}
88124
function cropImage(img,x,y,w,h,fw,fh){
@@ -92,14 +128,20 @@ function cropImage(img,x,y,w,h,fw,fh){
92128
var ctx=cv.getContext('2d');
93129
var aw=w/fw,ah=h/fh,a=Math.min(aw,ah);
94130
ctx.drawImage(img[0],x,y,w,h,0,0,Math.floor(w/a),Math.floor(h/a));
131+
// ctx.drawImage(img[0],x,y,w,h,0,0,fw,fh);
95132
return cv;
96133
}
97-
function toBW(canvas){
134+
function toBW(canvas,brightness,inverse){
98135
var ctx = canvas.getContext("2d");
99136
var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
100137
var data = imageData.data;
101138
for (var i = 0; i < data.length; i += 4) {
102-
var avg = (data[i] + data[i + 1] + data[i + 2]) / 3;
139+
//var avg = (data[i] + data[i + 1] + data[i + 2]) / 3;
140+
var lum = data[i] * 0.3 + data[i+1] * 0.59 + data[i+2] * 0.11;
141+
if (inverse)
142+
avg = (lum < brightness) ? 0 : 255;
143+
else
144+
avg = (lum < brightness) ? 255 : 0;
103145
data[i] = avg; // red
104146
data[i + 1] = avg; // green
105147
data[i + 2] = avg; // blue

views/_Bootscreen.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4+
*
5+
* Based on Sprinter and grbl.
6+
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
/**
24+
* Custom Bitmap for splashscreen
25+
*
26+
* This file was generated with marlin-config https://github.com/akaJes/marlin-config/
27+
*
28+
* You may use one of the following tools to generate the C++ bitmap array from
29+
* a black and white image:
30+
*
31+
* - http://www.marlinfw.org/tools/u8glib/converter.html
32+
* - http://www.digole.com/tools/PicturetoC_Hex_converter.php
33+
*/
34+
#include <avr/pgmspace.h>
35+
36+
#define CUSTOM_BOOTSCREEN_TIMEOUT {{timeout}}
37+
#define CUSTOM_BOOTSCREEN_BMPWIDTH {{width}}
38+
#define CUSTOM_BOOTSCREEN_BMPHEIGHT {{height}}
39+
40+
const unsigned char custom_start_bmp[{{bytes}}] PROGMEM = {
41+
{{data}}
42+
};

views/snippets/bs-0default.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<div style="text-align:center" class="bs-default">
33
<p>This is default boot screen with size <span></span></p>
44
<canvas></canvas>
5-
<p>Maximal allowed image can be placed on screen 128x64</p>
65
<script>
76
$(function(){
87
var base=$('.bs-default');
@@ -13,4 +12,4 @@
1312
drawBootscreen(base.find('canvas')[0],screen,10);
1413
})
1514
});
16-
</script>
15+
</script>

0 commit comments

Comments
 (0)