-
Thanks @fanoush, shows how well I know Javascript! Much appreciated, I hope I can now fight it to a standstill.
-
Thanks, @Gordon. i'm afraid I'm still struggling: another line in my program contains:
if (dest==2 && y>1 && y<5) {...
which gives the same error. I've tried adding parentheses as in your suggestion, eventually ending up with abominations like
if (((dest==2)==true) && (((y>1)==true) && ((y<5))==true)) {...
but all these variants gave the same error. Frustratingly, just including the offending line in a simple test program works perfectly so the problem must be due to something elsewhere in the code. I will try to sort it out.
I'm afraid I've been doing exactly what you and @fanoush warn against, sticking "compiled" on the entire draw loop. This runs at 5 frames per second versus about 1.5 for raw or vanilla. So while I don't want ignore your advice , I'm loathe to give up the extra speed - it will be interesting to see what JIT delivers when I can get that working.
My use of the watch is entirely focused on interesting watch faces - I have very few other apps installed so RAM usage and startup speed aren't really issues. I would like to contribute something to the community, however, so when I have this face working properly I hope to publish it.
-
-
-
Thanks @fanoush.
The error from "compiled" stops it working and the code is just uploaded as source.
I have other problems with "jit": it seems not to like '&&' both on the line in question and elsewhere in my code:
JIT SyntaxError: Got && expected EOF at line 3 col 28 g.setBgColor((bngl && E.getBattery()<10)?63488:(g.th... ^
The following test gives me the same error:
function test() { "jit"; print((true && false)?'y':'n'); } test();
I do have many maths options in a loop: I'm making a version of https://www.youtube.com/watch?v=IA4UsV04bnM
and am rotating 128 lines - there's a couple of screenshots below. I've tried to optimise the code anyway by precomputing the rotated lines, using Int8Arrays and Float32Arrays etc. What's left in the loop is therefore pretty simple arithmetic, indexing into the arrays and comparisons but quite a lot of them. Without compiling I get roughly 1 loop per sec, with I get between two and three per sec so a really good improvement. -
I'm trying to compile a watch face that includes the following code to change the background colour as a simple low battery warning:
g.setBgColor((bngl && E.getBattery()<10)?63488:(g.theme.bg))
When compiled this gives:
WARNING: Function marked with "compiled" uploaded in source form
[ COMPILER MESSAGE ] : Error: Infer(unforced) kept changing stuffIf the line is commented out the warning doesn't appear and the compiled version runs.
What causes the error and is there a way around it? Thanks in advance.
-
Thanks a lot, @fanoush, just what I wanted.
-
-
Thanks, Gordon, that's good to know. It hadn't occurred to me to set transparency before drawing the image - saves faffing around afterwards and much appreciated!
I'm actually using a custom font with symbols so vectors and polylines would be difficult but I'm happy with this approach now. many thanks.
-
Many thanks, @Ganblejs, I'll take a look at that.
-
Thanks for your reply. I know you can rotate the whole display or individual text items by 90/180/270 degrees but I want to rotate the hours by 30 degrees (or even 15 for a 24 hour clock) and possibly to rotate a smaller amount if I update it every second or minute. This is why I'm using drawImage() - if there's anything else I can't find it so I'd be really grateful for a pointer!
-
I'm trying to make a circular watch face with the numbers angled towards the centre. To do this I draw each number in turn into an array buffer and save them as individual images so they can subsequently be drawn with appropriate rotation.
The images are created using drawString with the "solid" parameter set to 0, which I hoped means empty pixels would remain transparent. They are saved with asImage("object") but the resulting image has no transparency information and the rotated numbers appear on an opaque background. To clear that I have add a "transparent" field and replace the buffer with a copy stored in a Uint8array.
This works but it seems a really clunky process. Is there a better way to rotate text characters with a transparent background? Thanks.
-
-
Well, my first version only drew five lines which does fit on a Bangle 2 - I increased it to 100 just to see if I could make it break on the emulator (and I couldn't). So far as I can tell the graphics system happily ignores coordinates outside the visible bounds, but anyway my problem occurs when trying to draw within the visible area.
The attached image shows the device (black image) breaking partway through the final line, whereas the emulator (white) completes the last line.
-
I want to draw lines of varying width and attach my test app. This runs fine in the emulator up to at least 100 iterations (see line 34), although it is slow. On my watch , however, it breaks while drawing the fourth line and the console shows:
0 1 2 3 Execution Interrupted at line 1 col 237 ...0,y0);e2=err;x2=x0;if(2*e2>=-dx){for(e2+=dy,y2=y0;e2<ed*wd&&(y1!=y2... ^ in function "drawLineWidth" called from line 3 col 38 drawLineWidth(i*20,0,i*20+100,175,i); ^
Process.memory() shows usage pretty steady at about 250 with 11750 free so if there is a memory leak I'm not seeing it.
Any ideas how I can fix this? Thanks.
-
-
I did read that and definitely loaded to widget_utils without the .js, just tried it again and got the same result. I also tried loading wear_detect into storage and got the same "exports not defined" error although it works fine when loaded from the site.
Sorry to be making heavy weather of this...is there something else I need to do to get my watch to look for a local copy? Thanks.
-
Thanks for the quick reply - it sounds good but I can't get the module to work. Uploading the module to storage gave Uncaught ReferenceError: "exports" is not defined at line 4 col 8 in widget_utils followed by Module widget_utils not found when I ran it (and also when I changed the IDE search path ).
But if I try require("wear_detect").isWorn().then(worn => {
console.log(worn ? "is worn" : "not worn");
}); it works correctly.I must be missing something!
-
I'm working on a watch face that fills the whole screen including the widget area. I don't miss widgets because I find them too small to read at a glance, but I have added a second screen that briefly shows battery and step count (in a large font!) when I tap the watch face. I'm wondering if it's possible to include widgets just on that second screen.
I've tried to do this by running Bangle.loadWidgets() and saving a copy of WIDGETS when the app is loaded, immediately before g.clear(). When the second screen is displayed I restore WIDGETS and run Bangle.drawWidgets(). After a timeout I set WIDGETS=[] before the original display is redrawn. This all works but I get an error message:
Uncaught Error: Cannot read property 'width' of undefined
at line 1 col 65 in widlock.wid.js
WIDGETS["lock"].width=Bangle.isLocked()?16:0;Bangle.drawWidg...
in function called from systemThe restored copy of WIDGETS does contain ["lock"].width and anyway I get the same message if I run loadWidgets() again instead of restore plus drawWidgets(). The error doesn't seem to stop the watch running but I'd like to get rid of it. Is there a better way to toggle the widget display on/off?
Thanks for any help.
Thanks, both. The comparisons are working in line with @fanoush's guidance and I'd already bound calls to Math.xxx, I will bind g.xxx as well - I will get there eventually!