I guess I understand what your are saying about reentrance...
I also conclude that the process is to complex and variable to be implemented without memory resources that are exposed to potential GC.
I though still expect/require a modification to existing setWatch() and clearWatch() functions in order to make it transparent for the application whether it is a built-in pin or or an extension-pin (a pin of any sort of portextender):
a) setWatch() has to:
invoke .setWatch() method on passed the extender pin and pass the callback and options object.
hold on to passed portextender pin object in the internal watch object (for any clearWatch() down the line).
b) clearWatch() has to:
invoke .clearWatch() method on the held-on portextender pin object(s - plural, when clearWatch is called without arguments).
With these two extensions it is possible to make any watch operation absolutely transparent - for the pin:
setWatch()
clearWatch() with watch ID / handle as argument
clearWatch() without argument
Should a)2. - holding on to passed portextender pin object in the internal watch object for any reasons - such as potential memory leak - not be possible, then this alternative is good enough:
setWatch has to:
ONLY return the passed portextender pin object reference as the watch ID (rather than just an integer number) and nothin else.
clearWatch has to:
detect that the passed-in watch ID is a portextender pin
invoke .clearWatch on the portextender pin
nothing else since there exists no internal watch info
The alternative does not support clearWatch() with no arguments, and - from my point of view - this is acceptable, because using clearWatch() with no arguments has anyway its challenges. Still transparent to the pin are:
setWatch()
clearWatch() with watch ID / handle as argument
With the alternative, Espruino has to store nothing about the watch. Non-built-in, portextender pins trigger the redirect of the argument(s) for both .setWatch() and .clearWatch().
For alternative it works also that the portextender object is passed rather than a pin. The portextender object has then to understand .setWatch() and .clearWatch, which could set interrupts for groups of pins. The implementations can even go that far, that .setWatch() can return any custom object deemed useful in the watch life cycle, as long as built-in clearWatch() can detect that passed in 'pin' object is not a built-in pin.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I guess I understand what your are saying about reentrance...
I also conclude that the process is to complex and variable to be implemented without memory resources that are exposed to potential GC.
I though still expect/require a modification to existing
setWatch()
andclearWatch()
functions in order to make it transparent for the application whether it is a built-in pin or or an extension-pin (a pin of any sort of portextender):.setWatch()
method on passed the extender pin and pass the callback and options object.clearWatch()
down the line)..clearWatch()
method on the held-on portextender pin object(s - plural, when clearWatch is called without arguments).With these two extensions it is possible to make any watch operation absolutely transparent - for the pin:
Should a)2. - holding on to passed portextender pin object in the internal watch object for any reasons - such as potential memory leak - not be possible, then this alternative is good enough:
.clearWatch
on the portextender pinThe alternative does not support
clearWatch() with no arguments
, and - from my point of view - this is acceptable, because using clearWatch() with no arguments has anyway its challenges. Still transparent to the pin are:With the alternative, Espruino has to store nothing about the watch. Non-built-in, portextender pins trigger the redirect of the argument(s) for both
.setWatch()
and.clearWatch()
.For alternative it works also that the portextender object is passed rather than a pin. The portextender object has then to understand
.setWatch()
and.clearWatch
, which could set interrupts for groups of pins. The implementations can even go that far, that.setWatch()
can return any custom object deemed useful in the watch life cycle, as long asbuilt-in clearWatch()
can detect that passed in 'pin' object is not a built-in pin.