Skip to content

Commit 4b9fae3

Browse files
committed
warpdrive 0.04: Remove buffer finding code (which fails if screen rotated) and make dependent on fw 2v21's Bangle.getOptions().lcdBufferPtr (fix #3818)
Also adds check for non-contiguous memory
1 parent 60d6742 commit 4b9fae3

File tree

3 files changed

+26
-67
lines changed

3 files changed

+26
-67
lines changed

apps/warpdrive/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
0.01: New app!
22
0.02: Minor code improvements
33
0.03: Minor code improvements
4+
0.04: Remove buffer finding code (which fails if screen rotated) and make dependent on fw 2v21's Bangle.getOptions().lcdBufferPtr (fix #3818)

apps/warpdrive/app.js

Lines changed: 24 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ void render(int* n, const unsigned char* m){
480480
);
481481
}
482482
}
483-
484483
`);
485484

486485
const nodeCount = 4;
@@ -490,9 +489,7 @@ const translation = new Uint32Array(10);
490489
let bgColor = 0;
491490
const BLACK = g.setColor.bind(g, 0);
492491
const WHITE = g.setColor.bind(g, 0xFFFF);
493-
let lcdBuffer = 0,
494-
start = 0;
495-
492+
let lcdBuffer = 0;
496493
let locked = false;
497494
let charging = false;
498495
let stopped = true;
@@ -522,65 +519,6 @@ function test(addr, y) {
522519
return !peek8(addr);
523520
}
524521

525-
function probe() {
526-
if (!start) {
527-
start = 0x20000000;
528-
if (test(Bangle.getOptions().lcdBufferPtr, 0))
529-
start = Bangle.getOptions().lcdBufferPtr; // FW=2v21
530-
else if (test(0x2002d3fe, 0)) // try to skip loading if possible
531-
start = 0x2002d3fe; // FW=2v20
532-
}
533-
const end = Math.min(start + 0x800, 0x20038000);
534-
535-
if (start >= end) {
536-
print("Could not find framebuffer");
537-
return;
538-
}
539-
540-
BLACK().fillRect(0, 0, 176, 0);
541-
// sampling every 64 bytes since a 176-pixel row is 66 bytes at 3bpp
542-
for (; start < end; start += 64) {
543-
if (peek8(start)) continue;
544-
WHITE().fillRect(0, 0, 176, 0);
545-
let b = peek8(start);
546-
BLACK().fillRect(0, 0, 176, 0);
547-
if (!b) continue;
548-
if (!peek8(start)) break;
549-
}
550-
551-
if (start >= end) {
552-
setTimeout(probe, 1);
553-
return;
554-
}
555-
556-
// find the beginning of the row
557-
while (test(start - 1, 0))
558-
start--;
559-
560-
/*
561-
let stride = (176 * 3 + 7) >> 3,
562-
padding = 0;
563-
for (let i = 0; i < 20; ++i, ++padding) {
564-
if (test(start + stride + padding, 1)) {
565-
break;
566-
}
567-
}
568-
569-
stride += padding;
570-
if (padding == 20) {
571-
print("Warning: Could not calculate padding");
572-
stride = 68;
573-
}
574-
*/
575-
let stride = 68;
576-
577-
lcdBuffer = start;
578-
print('Found lcdBuffer at ' + lcdBuffer.toString(16) + ' stride=' + stride);
579-
gfx.init(start, stride, E.getAddressOf(sintable, true));
580-
gfx.setCamera(0, 0, -300 << 8);
581-
setupInterval(true);
582-
}
583-
584522
function init() {
585523
bgColor = g.theme.bg & 0x8410;
586524
bgColor = ((bgColor >> 15) | (bgColor >> 9) | (bgColor >> 2));
@@ -612,7 +550,22 @@ function init() {
612550
c: i
613551
};
614552
}
615-
setTimeout(probe, 1);
553+
lcdBuffer = Bangle.getOptions().lcdBufferPtr;
554+
if (!lcdBuffer) {
555+
E.showMessage("Needs firmwave 2v21 or newer");
556+
return;
557+
}
558+
let stride = 68;
559+
//print('Found lcdBuffer at ' + lcdBuffer.toString(16) + ' stride=' + stride);
560+
var sintablePtr = E.getAddressOf(sintable, true);
561+
if (!sintablePtr) {
562+
lcdBuffer = 0;
563+
E.showMessage("Not enough memory");
564+
return;
565+
}
566+
gfx.init(lcdBuffer, stride, sintablePtr);
567+
gfx.setCamera(0, 0, -300 << 8);
568+
setupInterval(true);
616569
}
617570

618571
function updateNode(index) {
@@ -657,12 +610,17 @@ function drawNode(index) {
657610
translation[i++] = o.y * 256;
658611
translation[i++] = o.z * 256;
659612
translation[i++] = o.c;
660-
gfx.render(E.getAddressOf(translation, true));
613+
let translationPtr = E.getAddressOf(translation, true);
614+
if (!translationPtr) {
615+
lcdBuffer = 0;
616+
E.showMessage("Not enough memory");
617+
return;
618+
}
619+
gfx.render(translationPtr);
661620
}
662621

663622
function tick(locked) {
664623
g.reset();
665-
666624
if (lcdBuffer && !locked) {
667625
BLACK().drawRect(-1, -1, 0, 177); // dirty all the rows
668626
gfx.clear(bgColor);

apps/warpdrive/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "warpdrive",
33
"name": "warpdrive clock",
4-
"version": "0.03",
4+
"version": "0.04",
55
"description": "A watchface with an animated 3D scene.",
66
"readme": "README.md",
77
"icon": "app.png",

0 commit comments

Comments
 (0)