Rotation

Posted on
Page
of 2
/ 2
Next
  • Just out of curiosity, is there a way to rotate the screen 180° and keep it rotated until the watchface is unloaded (e.g. when the loader shall show up)?

    I'm tempted to add a feature to my watchface that if it's unlocked you would swipe up to roate the whole screen to show the time to another person and swipe it again to have the normal mode.

  • Yes - you can use g.setRotation(2) (you need to redraw after it).

    The screen won't automatically swap back when the next app loads (since it's set up so left-handed users can permanently keep their watch in that state), so you'll need to implement a handler for the Bangle.on('kill', ...) event to call g.setRotation(0) to put it back.

  • OK, will look into it, thanks a lot!

  • As there is no g.getRotation, how do I determine the current set rotation?

  • I don't think you can - I guess the question is why do you need to? Can't you keep track yourself?

  • Yes, I guess I could. I'll let this as is for now. Maybe I'll add a toggle for BJS1 later.
    https://github.com/espruino/BangleApps/p­ull/2369

    The screen won't automatically swap back when the next app loads (since it's set up so left-handed users can permanently keep their watch in that state), so you'll need to implement a handler for the Bangle.on('kill', ...) event to call g.setRotation(0) to put it back.

    Actually now that I tried it out on the watch I find it better to not reset this when exiting. It's a neat feature to change global orientation quickly :)

  • Why i need to 90° convenient rotation:

  • @Gordon could you do me a favor and revert this whole PR?

    Also I'm really wondering why the watchface is still loaded when the launcher is shown. How do I kill my
    Bangle.on("drag", e => {
    when user presses the button for the launcer?

    Not that familiar with git and I'm afraid I would break something. I now discovered the problem that I cannot use the launcher anymore. Did not notice that before. Will work on this eventually but for now I got no time :(
    @Serj will hopefully consider the 90° then :)

  • Revert this PR? https://github.com/espruino/BangleApps/p­ull/2369

    Also I'm really wondering why the watchface is still loaded when the launcher is shown

    You implemented the remove function, but presumably didn't actually manage to remove all of the stuff that the clock loaded in it? https://github.com/pebl-hank/BangleApps/­blob/383f18f92facbf8a4ea44bad2f8ea9ce0f7­63f6a/apps/hworldclock/app.js#L305-L313

    There's info on implementing/testing here: http://www.espruino.com/Bangle.js+Fast+L­oad

    Specifically handling stuff like drag is covered here: http://www.espruino.com/Bangle.js+Fast+L­oad#event-handlers

    Although really for drag you should be using setUI({mode:"custom",clock:true,drag:...­})

    Best bet is just to not have the remove function for now, and then the clock will unload 'normally' and will get rid of all the changes.

  • PS: I will do the revert. Never mind. Sorry for any inconvenience.
    https://github.com/espruino/BangleApps/p­ull/2374

  • I attached my current code.

    Current log shows:

    Uncaught ReferenceError: "onDrag" is not defined
     at line 1 col 285
    ...ngle.removeListener('drag',onDrag);Ba­ngle.removeListener('on...
                                  ^
    in function "a" called from line 2 col 168
    ...e;delete Bangle.uiRemove;a()}g.reset();if(c){if("­updown"==c)...
                                  ^
    in function called from line 1 col 31
    Bangle.uiRemove?(Bangle.setUI(),(__FILE_­_=a)||(a=".bootcde")...
                                  ^
    at line 1 col 115
    ..."Storage").read(a))):load(a)
                                  ^
    in function called from line 1 col 408
    ...))}c?Bangle.load(b.launcher):eval('E.­showMessage("No Launche...
                                  ^
    at line 1 col 525
    ...at:false,edge:"falling"});');
                                  ^
    in function called from system
    

    How do I resolve this?

    However, development is very difficult for me as I do not understand certain things. E.g. when I want to check the interaction between the watchface and the loader, the easiest would be to just upload my watchface to the storage. But when I do that via IDE, I get strange errors from the watchface that I don't get when it is uploaded to RAM:

    Uncaught Error: Module Font5x9Numeric7Seg not found
     at line 15 col 29 in hworldclock.app.js
    require("Font5x9Numeric7Seg").add(Graphi­cs);
                                ^
    

    1 Attachment

  • Regarding "onDrag" is not defined:

    Without diving deep into the code, I suspect you can solve the issue by wrapping Bangle.removeListener('drag',onDrag) in an if (onDrag) { ... } or if (onDrag!==undefined) { ... }. So that if onDrag isn't defined anymore for some reason it will not try to remove it.

    Regarding Module Font5x9Numeric7Seg not found:

    I think I remember require()ed fonts are inserted at the top of the app.js file on upload from the app loader, much like modules. I think you could look at the app.js file (via Web IDE) after you installed it via the app loader and see that code prepended. Then you could copy that code into your app code to be able to run it from the Web IDE without going via the app loader (again, I think).

  • I now changed it to

    Bangle.setUI({
      mode : "custom",clock:true,
      remove : function() {
        // Called to unload all of the clock app
    	if (typeof PosInterval === "undefined") {
    		console.log("PosInterval is undefined")
    	} else {
    		if (PosInterval) clearInterval(PosInterval);
    	}	
        PosInterval = undefined;
        if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds);
        drawTimeoutSeconds = undefined;
        if (drawTimeout) clearTimeout(drawTimeout);
        drawTimeout = undefined;	
    	if (typeof onDrag !== "undefined") Bangle.removeListener('drag',onDrag);
    	if (typeof onLock !== "undefined") Bangle.removeListener('onLock',onLock);
      }});
    

    Now, the loader shows up, but the Listener seems to be still in place.

  • There shouldn't be quotation marks around undefined.

    Try:
    if (typeof onDrag !== undefined) Bangle.removeListener('drag',onDrag);

  • Then I actually get

     build: apps/hworldclock/app.js#L317
    Invalid typeof comparison value
    
    
  • Searching the repository it seems to me that that logic works for other apps: https://github.com/espruino/BangleApps/s­earch?q=%21%3D%3Dundefined

    Does it work if you use != instead of !==?

    EDIT: Wait, drop the typeof like so:

    if (onDrag !== undefined) Bangle.removeListener('drag',onDrag);
    
  •     if (onDrag !== undefined) Bangle.removeListener('drag',onDrag);
    

    gives me

    Uncaught ReferenceError: "onDrag" is not defined
     at line 12 col 770 in hworldclock.app.js
    ...ut);drawTimeout=undefined;if(onDrag!=­=undefined)Bangle.removeListener('drag',­on...
                                                     ^
    
  • Ok, try initiating onDrag outside of initDragEvents() like so:

    //......
    
    let onDrag; // Initiate onDrag here. If you want to you could move the logic here as well but it shouldn't be neccesary, I think.
    
    function initDragEvents() {
    	
    if (BANGLEJS2) { 	
    	//Bangle.on("drag", e => {
    	onDrag = e => {  // Add logic to onDrag here as before. Notice I dropped the "let" on this line.
                //......
    
  • I actually removed the function as it was obsolete anyway - with the same result.
    See attached file.

    Thanks for your patience!


    1 Attachment

  • Ok, and now it works? 👍

  • No, it doesn't. I get no error with the attached code. But the Listener isn't deleted. So it's basically the same as with the first try. I can load the watchface but when the launcher is called, the rotation is still happening on swipe...

  • And if you go back to not using the if-statement now and just do as you did first like so:

    Bangle.removeListener('drag',onDrag);
    

    ?

  • Then I get

    Uncaught ReferenceError: "onDrag" is not defined
     at line 12 col 802 in hworldclock.app.js
    ...ngle.removeListener('drag',onDrag);Ba­ngle.removeListener('on...
                                  ^
    
  • hmm, try initiating onDrag above the Bangle.setUI( ... )-block maybe?

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Rotation

Posted by Avatar for Hank @Hank

Actions