GOB52 / gob_unifiedButton

Add software touch buttons for CoreS3 and Tough, and commonality with conventional buttons (M5.BtnX)
https://gob52.github.io/gob_unifiedButton/
MIT License
9 stars 0 forks source link

M5 Tough #1

Closed GrandeRipper closed 3 months ago

GrandeRipper commented 5 months ago

Hello, I would like to use the lib with an M5Tough. For this I had to change line 27 in UnifiedButton::begin(LovyanGFX* gfx, const appearance_t app) function as follows:

 _enable = /*M5.getBoard() == m5::board_t::board_M5StackCoreS3 &&*/ M5.Touch.isEnabled();

This displayed the buttons and they changed colour when I clicked on them. However, conditions such as "M5.BtnA.wasHold()" were never true. I found out that this is probably due to line 1207 - 1209 in M5Unified.cpp (version 0.1.14) => M5.update()

    BtnA.setRawState(ms, btn_bits & 1);
    BtnB.setRawState(ms, btn_bits & 2);
    BtnC.setRawState(ms, btn_bits & 4);

The lib works at least if I comment out these lines. An alternative solution seems to be the execution of unifiedButton.update() BEFORE M5.update()

Is there a better way to solve the problem? I am also not clear why running unifiedButton.update() BEFORE M5.update() seems to be a solution.

GrandeRipper commented 5 months ago

OK with unifiedButton.update() BEFORE M5.update() it doesn't really work either. Only isPressed() and pressedFor() are working wasClicked() doesn't work. probably because the corresponding variables are reset in M5.update(). I am a little confused how it can work with the CoreS3 at all... because the line 1207 - 1209 in M5Unified.cpp should also influence the behaviour.

GOB52 commented 5 months ago

Hi @GrandeRipper , Thanks for using my library.

As you guessed, it seems to be caused by overwriting values on the M5Unified side.
I have already discussed this issue with the M5Unified maintainer.

When the M5Unified side is updated, I would like to include M5Tough support in this library as well.

GOB52 commented 5 months ago

@GrandeRipper

M5Unified develop branch has been updated.

Could you try the following configuration?

lib_deps=https://github.com/m5stack/M5Unified.git#develop
GrandeRipper commented 5 months ago

Hi @GOB52 , i forgot to thank you for your work and your library. Sorry about that. With the develop version of M5Unified everything works as it should! (with customised UnifiedButton::begin) Thank you very much

GOB52 commented 5 months ago

Hi @GrandeRipper .

Thanks for trying. Are the following the only areas you have customized?

 _enable = /*M5.getBoard() == m5::board_t::board_M5StackCoreS3 &&*/ M5.Touch.isEnabled();
GrandeRipper commented 5 months ago

Hi @GOB52 i only customized that line:

_enable = /*M5.getBoard() == m5::board_t::board_M5StackCoreS3 &&*/ M5.Touch.isEnabled();
GOB52 commented 5 months ago

Thanks for the reply.

The next update would be the following code.

auto bd = M5.getBoard();
_enable = (bd ==  m5::board_t::board_M5StackCoreS3 || bd == m5::board_t::board_M5Tough)
               && M5.Touch.isEnabled();

The reason why "M5.Touch.isEnabled()" alone is not enough is that there are devices like Core2 that are touch capable and have touch buttons outside the screen..

I will start after the official update of M5Unified.

GrandeRipper commented 5 months ago

On a side note, it would be great if the buttons could be labelled differently during the execution of the programme.

GOB52 commented 5 months ago

Yes you can. See also https://github.com/GOB52/gob_unifiedButton/blob/master/examples/customButton/customButton_main.cpp

GOB52 commented 3 months ago

Hi @GrandeRipper

As M5Unified has been updated, gob_unifiedButton has also been updated and published 0.1.5.

If you have tried it and there are no problems, would you please close the issue?