Issue with touch interfacing

Posted on
  • I wanted to implement touch individually for these features. I posted this on the forum and they suggested I implement it in this manner.

    Bangle.on('touch', function(n,event) { 
    if(event.y<60){
    walking_subactivity();
    }  
    else if(event.y>=60 && event.y<120){
    jogging_subactivity();
      }
    else
      {
    cycling_subactivity();
      }
    });
    

    The issue now is that once I am on the working screen, if I click on the middle portion of the touch screen it takes me to the jogging screen. My main issue is that once I choose the walking option, the screen should remain there even if I click at some other part of the screen and do not jump to the jogging and cycling screen.

    I have written the function names in the if-else condition in order to make the code a bit more readable for the sake of this doubt.

    Thank you in advance.


    4 Attachments

    • Cycling (1).jpeg
    • Jogging (1).jpeg
    • Walking (1).jpeg
    • Screenshot 2022-06-19 152404.jpg
  • I believe you should remove the listener used for selecting mode once you've made the selection, in your example function(n, event). I don't know, but I suspect you might need to break function(n, event) out into a function with it's own name to make it work, maybe

    function selectOnTouch(n, event) { ... }
    ...
    Bangle.removeListener('touch', selectOnTouch);
    

    and then your code would be something like

    function selectOnTouch(n, event) { 
    if(event.y<60){
    walking_subactivity();
    Bangle.removeListener('touch', selectOnTouch);
    }  
    else if(event.y>=60 && event.y<120){
    jogging_subactivity();
    Bangle.removeListener('touch', selectOnTouch);
      }
    else
      {
    cycling_subactivity();
    Bangle.removeListener('touch', selectOnTouch);
      }
    });
    
    Bangle.on('touch', selectOnTouch); //start the listener for touch input here
    

    I'm not 100% on these things though - but I think that's basically how it works. This is relevant I think: http://www.espruino.com/Reference#l_Obje­ct_removeListener

    I hope I'm not leading you astray with this :P

  • @Ganblejs It works exactly as I want it to work. Thank you very much, I have been stuck on this for days and it finally works!!

  • Nice! I just recently learned about removing listeners myself - it was something of a revelation. :)

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

Issue with touch interfacing

Posted by Avatar for pranjal @pranjal

Actions