Removing Touchscreen Handler #480
Replies: 10 comments
-
Posted at 2014-05-06 by DrAzzy I think it's just setting a watch, so if you figure out the watch number, you can clear it with clearWatch(). Unfortunately, as you can see in the module code, they don't keep record of the watches - that would be easy enough to change though http://www.espruino.com/modules/ADS7843.js |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-06 by Stev Hey. Yes, i guess changing the module code is they best way to go. I tried to figure out the watch id before. Cumbersome. Thanks. Stev |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-07 by @gfwilliams Yes - At the moment you're a bit stuck. Why do you want to remove it though? Can't the callback just return? I can't remember specifically about that module, but by repeatedly connecting and disconnecting you would probably be re-initialising the chip each time. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-07 by Stev I just was playing around. Now that the board seems to work, I'd like build some touch UI on top of it and that were my first steps last night, when I realized that calling the connect function again would result in adding watches, not deleting the former. Just wanted to get rid of the older ones and see where I would put the switching of "active" screen areas. You're probably right about the re-init, so I'll try to put the picking behind that one callback. I still seem to have to re-polish my JS skills. Right now I always end up with code copied into handlers when I just want to pass a reference to a function and I still have no idea on how to access/create "top-level"/global vars from within a handler. Is there a name/reference for the Espruino top level object (the one I get with "this" when in the shell)? Or maybe that's just the wrong pattern to communicate between handlers and set up a system. BTW: Also I see a growing number of "LCD = {}" entries when I look into the var with dump(). I can do multiple "delete LCD" to get rid of them, but neither do I know where the come from, nor how multiples of them can exist be created in the first place. So. Arrived at the JS level, at last :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-07 by @gfwilliams I'm surprised you can't get at global vars within a handler normally - stuff like setWatch/setInterval will set As far as callbacks, if you do:
Then you can redefine the touch function, either by just entering it again, or by typing Shame about the |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-07 by Stev Good to know about 'this' in the timers/handlers. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-07 by @gfwilliams Yes, it's probably an oversight really. In the browser you've got However, you can create a global variable just like:
It works even for objects too - so you've actually got to be careful about using |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-09 by Stev
Hm. That's exactly what's not working (and the problem I meant when mentioning not being clear when copying function code vs referencing functions). When I do this like in your example above, I can edit the touch function, but it will not have any effect, as the original one seems to be "submitted" and stays active. If I instead use a double reference like
, I can redefine doTouch effectively using edit(). That's where I stumbled and wondered if I somehow could delete the original callback. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-09 by @gfwilliams Ahh, that's interesting. I just checked and it seems that if you redefine the function with:
It should work (I didn't try this on the touchscreen, but I tried with setInterval, and something that looks a bit like the touchscreen handler). However if you try
And that doesn't work. I'll try and fix that (what edit does) in the next version though. Unfortunately I believe that |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-09 by Stev Funny. As I usually use the functional notation. Only since working with the touchscreen code I used the direct function declaration because the touchscreen examples were written that way :) Notation-wise it might make sense to differentiate them (named function vs function var with anonymous function), but I don't know what JSs spec actually says. I just remember that in a coding context/script, direct function declarations are parsed befor the actual script execution while the var = function(){} notation is a executed as part of the normal execution sequence (making the former being present/declared for code positioned before the function declaration, while the latter wouldn't). Also, in espruino, when I do a
i'll get
in both cases. And both objects can be combined with additional methods. Just was that thing that left me confuse about the copying vs. referencing idea for function(object)s and wanting to be able to delete that callback . Because once you screwed it... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-06 by Stev
Hi,
it might just be a bit late today, but how do I remove a callback for the Touchscreen that I have set in the connect method? I see that it creates a watch. Can that be referenced?
(i could reference another function from there, but i wonder if I ever get rid of that original connect handler)
Stev
Beta Was this translation helpful? Give feedback.
All reactions