lancaster-university / codal-microbit-v2

CODAL target for the micro:bit v2.x series of devices
MIT License
41 stars 50 forks source link

`NRF52Pin::wasTouched()` default mode is capacitative instead of the pin state #416

Closed microbit-carlos closed 3 months ago

microbit-carlos commented 3 months ago

From codal-nrf52/inc/NRF52Pin.h#L315 wasTouch has a default argument, so calling it without arguments defaults to capacitive mode:

 int wasTouched( TouchMode touchMode = TouchMode::Capacitative );

On the other hand isTouched() (codal-nrf52/inc/NRF52Pin.h#L277-L300) does not have a default value, so calling it with arguments uses the pin touch mode state instead:

int NRF52Pin::isTouched() {
    return isTouched(status & IO_STATUS_CAPACITATIVE_TOUCH ? TouchMode::Capacitative : TouchMode::Resistive);
}

int isTouched(TouchMode touchMode) { ... } 

MakeCode & MicroPython do not keep track of the configured pin state, and they offer a "set touch mode" function, which only needs to call isTouched() with the right argument. After that calling isTouched() without arguments uses the last set mode, so we should do the same for wasTouched().

microbit-carlos commented 3 months ago

@JohnVidler PR submitted: