Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuring pin as non-touch after being in touch mode leads to crash #73

Closed
dpgeorge opened this issue Jan 13, 2016 · 7 comments
Closed
Assignees

Comments

@dpgeorge
Copy link
Contributor

When calling pin.isTouched the pin automagically goes into touch mode and creates a MicroBitButton instance. It registers itself with the system ticker using addSystemComponent. Then if you call pin.getDigitalValue it deletes the MicroBitButton instance but does not seem to unregister itself with the system ticker. As such the system hangs.

Example code to reproduce:

void app_main() {
    while (1) {
        printf("digital mode\r\n");
        for (int i = 0; i < 20 * 10; ++i) {
            if (uBit.io.P0.getDigitalValue()) {
                uBit.display.print('D');
            } else {
                uBit.display.clear();
            }
            uBit.sleep(50);
        }
        printf("touch mode\r\n");
        for (int i = 0; i < 20 * 10; ++i) {
            if (uBit.io.P0.isTouched()) {
                uBit.display.print('T');
            } else {
                uBit.display.clear();
            }
            uBit.sleep(50);
        }
    }
}                                                                                                     

It works the first time round, but on the second loop it hangs.

@finneyj
Copy link
Contributor

finneyj commented Jan 13, 2016

thanks @dpgeorge.

@jamesadevine - can you please fix this one up? we should deregister in the appropriate destructor...

@dpgeorge
Copy link
Contributor Author

Destructors are evil: #72 :)

@finneyj
Copy link
Contributor

finneyj commented Jan 13, 2016

:-)

Well, let's face it, C++ is evil... But when in leagues with the devil, his minions should be turned to do our bidding. :-)

@jamesadevine
Copy link
Contributor

@finneyj @dpgeorge will be fixed momentarily...

@dpgeorge as an aside printf pulls in 1k of stuff, so uBit.serial.printf() should be used instead where possible.

(I assume you were aware though? In which case ignore me!)

@dpgeorge
Copy link
Contributor Author

@dpgeorge as an aside printf pulls in 1k of stuff, so uBit.serial.printf() should be used instead where possible.

Ok, thanks for the tip! It was just for debugging purposes in this case. MicroPython has its own internal printf implementation that we use (but I wouldn't be surprised if there were some stray native printf's in there somewhere...).

jamesadevine added a commit that referenced this issue Jan 13, 2016
The destructor for MicroBitButton didn't take into account the fact that
an instance can be destructed after registering a callback. This would then
result in a HardFault if an instance was destructed.

A clear repro case was registering a Touch input on a pin (abstracted as a button)
and swapping to a DigitalIn.
@dpgeorge
Copy link
Contributor Author

Thanks @jamesadevine!

@jamesadevine
Copy link
Contributor

@dpgeorge I'm revising the patch a little bit - will update in a short while! :)

jamesadevine added a commit that referenced this issue Jan 13, 2016
issue #73 highlighted an issue whereby the destruction of an instance
registered as an idle or system component, would result in a hardfault.

This was due to not deregistering idle or system callbacks.

This patch has been applied to all components currently in use by the
idle or system callbacks.
jamesadevine added a commit that referenced this issue Jan 13, 2016
Formatting corrections and further fixes for #73
jamesadevine added a commit that referenced this issue Jan 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants