lancaster-university / codal-microbit-v2

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

`wasPressed()` for the `TouchButton` class #396

Closed microbit-carlos closed 7 months ago

microbit-carlos commented 10 months ago

Moved from:


@dpgeorge comment:

I think wasPressed() was only added to the NRF52Pin object, but not to the TouchButton() class?


@JohnVidler reply:

Yes, to align with NRF52Pin::isPressed

TouchButton objects are only used internally within NRF52Pins and the uBit object exposes all pins, edge connector or otherwise as Pin objects: https://github.com/lancaster-university/codal-microbit-v2/blob/master/model/MicroBitIO.h#L370 so every Pin gains the new method 🙂

microbit-carlos commented 10 months ago

TouchButton objects are only used internally within NRF52Pins and the uBit object exposes all pins, edge connector or otherwise as Pin objects

Yes, but the main way to use the touch logo is via uBit.logo which is a TouchButton: https://github.com/lancaster-university/codal-microbit-v2/blob/d54ce9b784ef1bba22c075b281bb877abf53ea18/model/MicroBit.h#L158

microbit-carlos commented 7 months ago

@dpgeorge from your comment in: https://github.com/lancaster-university/codal-microbit-v2/issues/251#issuecomment-1807953678

I think wasPressed() was only added to the NRF52Pin object, but not to the TouchButton() class?

I assume you meant wasTouched() as that's the method that was added to NRF52Pin and not TouchButton?

TouchButton should already contain a wasPressed() method, is that something you can use? (uBit.logo.wasPressed() already exists) Or do you need a wasTouched() method as well in TouchButton? (uBit.logo.wasTouched() doesn't exists right now) If you need a wasTouched() method would you be able to use the uBit.io.face.wasTouched()? (uBit.io.face is an NRF52Pin instance)

dpgeorge commented 7 months ago

I assume you meant wasTouched() as that's the method that was added to NRF52Pin and not TouchButton?

Yes, I meant to say wasTouched() was only added to the NRF52Pin object.

TouchButton should already contain a wasPressed() method, is that something you can use?

I tried using this but it doesn't seem to work, it always returns 0.

If you need a wasTouched() method would you be able to use the uBit.io.face.wasTouched()?

The code currently uses this (it uses uBit.io.logo.wasTouched()) and that seems to work. But I was under the impression this uses resistive touch and instead it's better to use TouchButton::wasPressed(). But maybe I'm wrong here. If it's correct (electrical behaviour wise) to use uBit.io.logo.wasTouched() then I'm happy to do that. That means all the touch objects use the same code, they all use NRF52Pin::wasTouched(). And that's how the code currently works, so there would be nothing to change if this is the correct way to do it.

microbit-carlos commented 7 months ago

Quick clarification for the previous messages, as it gets confusing: uBit.io.face is a reference to uBit.io.logo, so it's a NRF52Pin instance. On the other hand, uBit.logo is the instance of TouchButton.

Okay, so as we have the wasTouched() method available in uBit.io.logo and the touch type (capacitive vs resistive) can be independently configured, I believe we can do everything in MicroPython land via uBit.io.logo.

It does make sense to also add wasTouched() to TouchButton`, but rather than drag this around more, let's just go with what we have at hand.

I'll mark this as complete.