a quick update on the subject: I tried for a while getting the following to work but yet without success ( it seems I get the beginning right, but then my code happily produces 'instant pixel artifacts garbage' instead of sending part of the buffer for spi refresh )
The idea behind the 'flipP' ( fliPartial() ) & 'clearP()' ( clearPartial() ) is to be able to later build upon those in order to provide saving & restoring an ArrayBuffer ( g.buffer ) smaller than the entire screen as well as providing a way to quickly update or clear only part of the screen ( in normal & paletted mode )
If anyone's skilled & brave enough to defeat the troubles that lies below, I guess I'm not the only one who'd benefit for such kindness ;p
the non-working-quite-right versions ( rest of the code is as above )
exports.connectPaletted = function(palette, spi, dc, ce, rst, callback) {
// ( .. )
// flipP(): execute a partial refresh of the buffer to the screen - seems working for whatever fy & fheight if fx==0 & fwidth==LCD_WIDTH
g.flipP = function(fx, fy, fwidth ,fheight) {
ce.reset();
spi.write(0x2A,dc);
//spi.write(0,fx+1,0,fwidth+1);
//spi.write(0,fx+2,0,fwidth);
//spi.write(0,fx+1,0,fwidth); // the +1 is what actually does the trick
spi.write(0,fx+1,0,fwidth);
//spi.write(0,fx+1, 0,fx+fwidth); // COMBO THAT SEEMS TO PASS ( seemed to trick this out for fwidth == lcd_width ) ?!
spi.write(0x2B,dc);
//spi.write(0,fy,0,fy+fheight); // responsible for the glitches ? ( stuff 'rolling over' itself on the vertical axis )
//spi.write(0,fy+1,fheight+1);
//spi.write(0,fy,fheight); // COMBO THAT SEEMS TO PASS for fwidth == lcd_width, but was missing an arg ?!
//spi.write(0,fy,1,fheight);
spi.write(1,fy,0,fheight);
spi.write(0x2C,dc);
var lines = 16; // size of buffer to use for un-paletting
var a = new Uint16Array(fwidth*lines); // default
//for (var y=0;y<fheight;y+=lines) { // default - doesn't work for stuff not at top of screen
for (var y=fy;y<fy+fheight;y+=lines) { // A-way - seemed to work for fxwidth == lcd_width & stuff not at top of screen
//E.mapInPlace(new Uint8Array(g.buffer, y*fwidth*bits/8, a.length), a, palette, bits); // default - seems to work for whatever fheight & fy
// idea: (new Uint8Array(g.buffer, (y+(fx*y))*fwidth*bits/8, a.length), a, palette, bits);
E.mapInPlace(new Uint8Array(g.buffer, (y+(fx*y))*fwidth*bits/8, a.length), a, palette, bits); // seemed to work for whatever fheight & fy
spi.write(a.buffer);
}
ce.set();
};
// clearP(): execute a partial clear of the buffer to the screen - currently discovered as an error in the above 'flipP' code .. :|
g.clearP = function(fx, fy, fwidth ,fheight) {
ce.reset();
spi.write(0x2A,dc);
//spi.write(0,fx+1,0,fwidth+1);
//spi.write(0,fx+2,0,fwidth);
//spi.write(0,fx,0,fwidth);
spi.write(0,fx+1,0,fwidth); // the +1 is what actually does the trick
//spi.write(0,fx+1, 0,fx+fwidth); // COMBO THAT SEEMS TO PASS ( seemed to trick this out for fwidth == lcd_width ) ?!
spi.write(0x2B,dc);
//spi.write(0,fy,0,fy+fheight); // responsible for the glitches ? ( stuff 'rolling over' itself on the vertical axis )
//spi.write(0,fy+1,fheight+1);
//spi.write(0,fy,fheight); // COMBO THAT SEEMS TO PASS for fwidth == lcd_width, but was missing an arg ?!
spi.write(0,fy,0,fheight);
//spi.write(0,fy,1,fheight);
//spi.write(0,fy+1,0,fheight);
spi.write(0x2C,dc);
var lines = 16; // size of buffer to use for un-paletting
var a = new Uint16Array(fwidth*lines); // default
//for (var y=0;y<fheight;y+=lines) { // default - doesn't work for stuff not at top of screen
for (var y=fy;y<fy+fheight;y+=lines) { // default - seemed to work for fxwidth == lcd_width & stuff not at top of screen
E.mapInPlace(new Uint8Array(g.buffer, y*fwidth*bits/8, a.length), a, palette, bits); // default
// idea: (new Uint8Array(g.buffer, (y+(fx*y))*fwidth*bits/8, a.length), a, palette, bits);
//E.mapInPlace(new Uint8Array(g.buffer, (y+(fx*y))*fwidth*bits/8, a.length), a, palette, bits); // give vertical-space colored glitches
//E.mapInPlace(new Uint8Array(g.buffer, y*(fx+y)*fwidth*bits/8, a.length), a, palette, bits); // give vertical-space colored glitches
spi.write(a.buffer);
}
ce.set();
};
test code ( better tried with something already drawn on screen, like some polygons or a logo ..
var g = exports.connectPaletted(colorPalette, spi, screen_dc, screen_cs, screen_rst, function() {
//g.clear(); // NOPE, we DON'T ;)
g.setFont8x12();
// ( .. )
g.setColor(3);
g.drawString("Hello, world!", 2, 2);
g.setColor(2);
g.drawString("Hello, world 2!", 2, 16);
//g.flip(); // NOPE, we DON'T use this one either ..
// full changing both but nothing else
g.flipP(0, 0, LCD_WIDTH, 12); // seems to work fine
g.flipP(0, 16, LCD_WIDTH, 12); // seems to work fine
// trying to partially change both
setTimeout(function(){
g.setColor(8);
g.drawString("Karaki", 2, 2);
g.setColor(9);
g.drawString("Karaki2", 2, 16);
//g.flipP(0, 2, LCD_WIDTH, 4); // cut its top ?! :L
g.flipP(0, 0, LCD_WIDTH, 4); // what about its top ?
g.flipP(0, 16+2, LCD_WIDTH, 4); // doesn't work at all :L
console.log('color change 2 ( partial horizontal ) occured ?');
setTimeout(function(){
g.setColor(10);
g.drawString("Karaki", 2, 2);
g.setColor(11);
g.drawString("Karaki2", 2, 16);
g.flipP(0, 0, 50, 4); // so how is its beginning ?
g.flipP(0, 16+2, 50, 4); // & this one's ?
console.log('color change 3 ( partial vertical ) occured ?'); // -> getting garbage for both ..
}, 6000);
}, 2000);
I achieved 'horizontal color stripes' on the 1st item with 3 redrawns before messing with the code & not being able to fix my mess back to that moment I wished I saved it :/ ( gotta upload picture of this & other cases as well .. )
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
a quick update on the subject: I tried for a while getting the following to work but yet without success ( it seems I get the beginning right, but then my code happily produces 'instant pixel artifacts garbage' instead of sending part of the buffer for spi refresh )
The idea behind the 'flipP' ( fliPartial() ) & 'clearP()' ( clearPartial() ) is to be able to later build upon those in order to provide saving & restoring an ArrayBuffer ( g.buffer ) smaller than the entire screen as well as providing a way to quickly update or clear only part of the screen ( in normal & paletted mode )
If anyone's skilled & brave enough to defeat the troubles that lies below, I guess I'm not the only one who'd benefit for such kindness ;p
the non-working-quite-right versions ( rest of the code is as above )
test code ( better tried with something already drawn on screen, like some polygons or a logo ..
I achieved 'horizontal color stripes' on the 1st item with 3 redrawns before messing with the code & not being able to fix my mess back to that moment I wished I saved it :/ ( gotta upload picture of this & other cases as well .. )
this being said, I'm onto a little break ..