joncox123 / MotoButtons

Low cost, waterproof controller for motorcycle navigation, phone and media control
GNU General Public License v3.0
22 stars 4 forks source link

Suggestion #6

Closed Joergen57 closed 1 year ago

Joergen57 commented 1 year ago

Hi Jon, first of all thank you for the great project. This is exactly what I was looking for and that you implemented MyRoute-App support is really great. I love DIY projects and because of the very detailed instructions I was able to build the whole thing as a complete beginner. And thanks again for the troubleshooting, now it works. I would like to make two suggestions.

  1. it looks like the Motobuttons consumes almost no power, then it would not be bad to use a battery. The board seems to be prepared for this.
  2. at the moment the joystick is laid out so that the two switches are above. It would not be bad to be able to use the whole thing the other way around, or even sideways. So that the switches are sometimes below or (right / left) of joystick. You could do this by changing the cables from the joystick, but that is surely also possible by changing the software, right? Nothing important, just my first thoughts: A praxis test on the bike with the controller and MyRoute-App will follow.
joncox123 commented 1 year ago

Thanks for the suggestions. Battery power could be a possibility if current consumption is not too high. I'd have to measure this.

As for rotation of the button layout, I agree, this is something I had planned to do. I realized that you want the power cable running toward the front of the motorcycle.

Layout rotation can be easily accomplished in software, although a question is whether it is better to set the mode in the source code or allow the user to change it dynamically on the motorcycle. I don't want the modes to get too complicated or it will be hard too use.

Editing one line in the source code wouldn't be too hard, right? Just change: const int LAYOUT UP to const int LAYOUT DOWN, for example.

joncox123 commented 1 year ago

OK, I have an idea for how to rotate the layout dynamically. When the device is powered up, it checks whether one of the joystick directional buttons is held down. If so, it sets that direction to be up. It stores the setting and automatically applies it the next time it is powered.

Joergen57 commented 1 year ago

Battery power could be a possibility if current consumption is not too high. I'd have to measure this. My USB power meter is not showing any current (it starst at 0.00 Amps) so it must be below 9mA.

As for rotation of the button layout, I agree, this is something I had planned to do. I realized that you want the power cable running toward the front of the motorcycle. Correct!

Editing one line in the source code wouldn't be too hard, right? Just change: const int LAYOUT UP to const int LAYOUT DOWN, for example. That should be possible to change with an editor.

Joergen57 commented 1 year ago

OK, I have an idea for how to rotate the layout dynamically. When the device is powered up, it checks whether one of the joystick directional buttons is held down. If so, it sets that direction to be up. It stores the setting and automatically applies it the next time it is powered. This is of course a better solution.

joncox123 commented 1 year ago

Hi, I added the functionality to rotate the orientation of the buttons. This is done by holding down the "up" direction that you want on the joystick when applying power. The change is stored in memory for the next power cycle.

Joergen57 commented 1 year ago

Wow, you are so quick.

To overwrite a setting you just hold the joystick up again?

joncox123 commented 1 year ago

Well, I have been out sick and couldn't sleep well last night, so I have been working on this to pass some time.

But yes, you hold down the new "up" direction that you desire while powering on. Then it will set the new orientation and save it for the next power on.

To change it again in the future, you just do the same thing again.

Joergen57 commented 1 year ago

Hi, I hope it is getting better.

I just tried to install the new version and got an error:

_Possible causes:

Is this the problem with reset button?

joncox123 commented 1 year ago

yes, hold down the two buttons for 15 seconds until the COM port changes. Select the new port in the IDE and upload again.

Joergen57 commented 1 year ago

Great, thank you! (Thumb up) I got it!

By the way, I have difficulties with the center button from the joystick, it is not easy to press it without making an up, down, etc. I think about another button as replacement for the center. The joystick is working fine.

joncox123 commented 1 year ago

The center button can be improved with software.

Joergen57 commented 1 year ago

The long press is the main problem, it could happen that MyRouteApp went into an unknown mode where you can only stop and restart the App.

joncox123 commented 1 year ago

I implemented a feature that drastically improves that problem. The solution is to disable up/down/left/right whenever the center is depressed. I think more can be done, however.

joncox123 commented 1 year ago

Hi, please try the new version, v1.2.1. This includes the improvements to center button usability. I also fixed an issue where it was repeating the center click. I think it works much better, please let me know if you still have problems with it.

Joergen57 commented 1 year ago

Hi, I did a quick test ( I will a tour today). It looks like the button reaction is better. I only have the problem in MRA in BarButton mode how to get out of a menu? No button helps, I need to tap the screen. A left or right with the joystick could help. I am not sure if this barbutton conform. Or how they foot. May be with another button. May be I get some info in the forum. But tonight.

Joergen57 commented 1 year ago

At first, I ask some questions to the MRA developer.

@Corjan-Meijerink I build the MotoButtons and they work fine so far. The author made some changes already to improve the function. But they are not perfect, or may be I did something wrong. The MotoButtons are in BarButton mode as well as MRA. Moving map, zoom in out are ok, long press on the joystick Center open menu or Center map. If I am in the menu, I can move up down, but how to get out of the menu? What command is needed, or how does the BarButton do this? With another button? And how is the skip waypoint working, also with another button? May be a BarButton owner can help.

Next, there still something wrong with the joystick Center, I am not sure how to describe and if it is a button problem?

If you hit the Center button you change the view mode of the map. (Navigation view, 2D view etc.) With long press you change into total overview. Longer press opens menu, but here is the question how to get out of the menu. And if you press to long thr MRA screen goes black with nothing on the screen and you can get out only by restart of the app. May I will make a video for better understanding. There is one thing that also need a solution, the skip Waypoint function. In the App you can tap on the waypoint sign (right up) to get a skip waypoint window where you need to confirm this. Or you press longer to skip the WP directly. I fear Motobutton needs more buttons. ;-)

joncox123 commented 1 year ago

There are a few ways to handle this. Probably it's best if the long press for menu is shared with one of the large buttons. I think that should fix it.

joncox123 commented 1 year ago

Another thing is that DMD2 and MyRoute App handle button presses differently. DMD2 ignores key repeat, while MRA will see Android's internal key repeat presses.

I don't have an MRA subscription, so it's hard to test all of the features, but it seems like I can change the button functionality a bit to solve the problem.

I can make it so the A B buttons only fire once per press (not necessary with DMD2). Also, the long press for menu could be changed to a long press of the B button.

I think that will fix it.

Joergen57 commented 1 year ago

Good morning, you are a night worker. ;-) "I don't have an MRA subscription" I asked the developer for a solution. I am thinking about what is important while you are driving. Zoom in / out this also change into 2D view (I think it goes back to 3D when you are moving) Moving the map. Then a long press on the compass to get a total overview of the route. Skip waypoint, two methods short press on waypoint number (upper right) with confirmation or long press as direct skip. Then open/close menu and open menu items. e.g. open waypoint list and go directly to WP x etc.

I think more needs to be done manually by hand while staying of the road.

Joergen57 commented 1 year ago

Hi, you can contact Corjan (MRA developer). How can I pass his mail address to you? Is here a PN possible?

joncox123 commented 1 year ago

Hi, please try the latest release, v1.2.2. This fixes the issue of the center and center long press button handling for me. I do not think it is a problem with MRA. Handling the virtual buttons and center button in combination with the joystick is quite tricky to get right. But I think I have it pretty close now. Let me know what you think.

Joergen57 commented 1 year ago

Sorry no time today, I will try tomorrow.

Have you seen this? [@Jörgen] The BarButtons codes are here: https://jaxeadv.com/barbuttons/using-the-barbuttons/barbuttons-user-guide-v4/ The default keymap for MRA is Keymap 1:

And here's the specific info on what Keymap 1 does in MRA: https://jaxeadv.com/barbuttons/compatible-applications/#htoc-m So, combining those two together, to leave the menu you need to generate an 'N' = close drawer. Which on BarButtons is button 3.

Joergen57 commented 1 year ago

Have you seen mail email?

Joergen57 commented 1 year ago

Here a video that explains the problem:

https://youtu.be/UYnIyIdnH_o?si=aScruJCCABUo3m7Q

joncox123 commented 1 year ago

I watched your video, but I don't have this problem. For me, it is working OK with the latest version.

Which device and OS version are your using?

The only thing I noticed is that the first long press sometimes causes the menu to open and close quickly, but after that it works correctly. However, that seems to be a bug in MRA.

Can you try the latest version on a different Android device? MotoButtons simply sends key strokes, so the app should not crash.

Please try another device and let the MRA developer know about this.

One thing I can investigate, however, is whether MRA crashes if the menu key is not "held down" long enough or some other unusual situation. This is still an MRA bug, but I could possibly work around it. But on my Android phone, it's not crashing, so it's hard to troubleshoot.

joncox123 commented 1 year ago

Hello, I tried MotoButtons on my iPhone 11 Pro Max with iOS 17.0.3 with MyRoute App for iOS. It actually works very well. Also, its working very well on my OnePlus 5T Android 10.

Therefore, I think there is some issue with your device's Android version and MyRoute App that is causing a crash. However, I have a theory. I am sending key press and key release events in an automatic fashion, sometimes very quickly, to get the desired behavior from the center and long press buttons. Maybe if key events are sent too quickly, it causes MRA to crash on your device.

I could create a special verison for you that slows down the key events. However, before doing this, please confirm that you tested with the latest release, which I updated yesterday. It is working very well for me on both iOS and Android.

Joergen57 commented 1 year ago

OK, I will try on a different device and the latest version. Again the question, did you receive my mail? It contains the mail address from Corjan (MRA developer) I do not want to publish it here. He can give you access to a full version and may be can fix other issue, that I can not communicate.

joncox123 commented 1 year ago

If you haven't tried the latest version yet on the same device, then try that first. I fixed a lot of problems with center button handling, and it is working perfectly for me now on iOS and Android.

Joergen57 commented 1 year ago

The video was done with version 1.2.2

joncox123 commented 1 year ago

OK, I think something strange is happening with MRA on your device. However, I created a special version, v1.2.2B. This has a 100 ms delay between sending key events. Please test this and see if it improves or eliminates the problem. If so, we will have some information for the MRA developer that he can use to fix the bug.

Upload this version: v1.2.2B

Also, you can try changing the delay that is set on line 798. You could change it from 100 to 150 or even 250, for example. This will slow down the sending of key events to your phone.

Please make a new video and/or let me know if this changes the behavior.

Joergen57 commented 1 year ago

Test on my iPhone 12 with iOS 17.0.2, here there is no Zoom minus working. I get into the menu with long press center, but can't get out of the menu.

Test with Samsung tablet, Android 7. Same problem with the Oukitel tablet and Android 12, zoom in/out, map move ok, short click center change between 2D/3D view, long press open menu sometimes, if you miss a special timing MRA hangs (here with white screen). Only restart helps. If I am lucky and have the menu open, I can't get out with any button.

Ok, this was before your last information.

Joergen57 commented 1 year ago

Should we discuss MRA related issues better here: https://forum.myrouteapp.com/topic/5665/motobuttons-lite-diy-project?_=1699112464906

joncox123 commented 1 year ago

OK, this is strange. So for me it works perfectly on iOS and Android, but you are having problems with both.

I could test on another device. I have an Android 13 tablet. But double check that you are running version 1.2.2. Also, try the special version with a delay that I made for you.

I would say another possibility is that the button denouncing is not working right for you, but I increased the denouncing time, so it should certainly work OK.

Therefore, I think to troubleshoot further, I have to show you how to generate a log that you can send me. This will tell me which key events the controller is sending.

I will add some more detail to the logging, then make a new version that only runs when connected to the Arduino IDE. This will print the log in the Serial Console for you to send.

Joergen57 commented 1 year ago

OK, let me try 1.2.2b Could it be language problem German/English in setting or somewhere else?

joncox123 commented 1 year ago

Also, install this appfor Android. It will give you a detailed log of exactly which key events your phone is receiving. If it's going haywire or not properly registering keys, that is a clue: https://play.google.com/store/apps/details?id=aws.apps.keyeventdisplay&hl=en_US&gl=US

joncox123 commented 1 year ago

OK, let me try 1.2.2b

Could it be language problem German/English in setting or somewhere else?

Yes, maybe it could be the locale settings. The keyboard layout is set differently. I can try to set my phones to DE and see if it causes the same problem.

joncox123 commented 1 year ago

Alright, I have a plan to test the problem, including the locale hypothesis.

First, reinstall the regular Arduino code version 1.2.2.

  1. Install the key events logging app: https://play.google.com/store/apps/details?id=aws.apps.keyeventdisplay&hl=en_US&gl=US

  2. Start a new log in the KeyEventDisplay app.

  3. Connect the controller and change it to MRA mode, but don't launch the MRA app.

  4. Press the keys in this order: up, down, left, right, center click, center long press, top button, bottom button.

  5. Do the above sequence a couple of times.

  6. Send me the log from KeyEventDisplay.

Joergen57 commented 1 year ago

No, neither 100 nor 250 delay makes a change. I will add a different/additional button tomorrow for the center button, just for testing I find it difficult to hit the center (only) without touching a left/right/up/down button, So may be the button has a problem or this kind of double signal.
It's a shame that it doesn't work so easily and that you have so much work with it, but thanks for it anyway. I will continue tomorrow and follow your instructions.

joncox123 commented 1 year ago

I highly suspect it is a locale issue. Try the log test that I posted above. This will tell us for sure.

joncox123 commented 1 year ago

Also, do the log test before making any hardware changes.

Joergen57 commented 1 year ago

How to sent (Send me the log from KeyEventDisplay.)?

joncox123 commented 1 year ago

I tested the controller on my Android phone after setting the "keyboard layout" to German using the Android Settings. In this mode, the - key gets translated to "/" by the Android operating system. The other keys work correctly. Therefore, it is certain now that the "keyboard layout" for the controller must be set to US English in Android and iPhone settings to work correctly.

See instructions here for Android: https://www.mobilefun.co.uk/blog/2015/04/how-to-fix-bluetooth-keyboard-language-settings/

Also, are you using German layout on both of your phones, or is the Android different (maybe Dutch or something else)?

Lastly, I can't save a log from KeyEventDisplay app either. Instead, you can send me a screenshot. I just need to see the "action=0 code=XXX" part of each line.

Joergen57 commented 1 year ago

So, just a short one (familie is waiting) ;-) I played back Version 1.2.2 and checked with keyboard layout English (USA) and English (USA) international. No change. If I press longer then 2 sec. or do not stop pressure on center MRA hangs with black screen. By exident google opens and I could see what the key did in text editor. Longpress Center 2 sec. = n Short press = c Zoom + = + Zoom - = - Longpress Center > 2 sec. = nnnnnnnnnn The above result was the same with USA keyboard layout or NOT If you know to stop pressing when the LED is flashing you always jump into the menu. I am not sure if this is the right translation, but could be keyboard bouncing an iussue?

What I still not know is how to get out of the menu?

I will do later today the keyboard log, but I belive I will get the same result.

Joergen57 commented 1 year ago

Just had an Idea, and installed BT keyboard to the tablet. I could move the map with the arrow keys. I could not zoom in/out with +/- I could use c to change between 2D/3D mode I could use n to open and close menu

And if I press n longer MRA hangs with black screen, so first not a MotoButton issue. But some questions. Why does +/- not working? Why can I close menu, when I press again? And why hangs MRA by pressing n longer? (that is something for Corjan)

joncox123 commented 1 year ago

Based on your log result, it is working correctly. Key repeat is handled internally by Android and iOS, and it is working correctly for me on both iOS and Android with MRA.

MRA isn't supposed to crash because you hold down the n key a little too long.

The problem is with your version of Android and MRA causing a crash due to not handling key repeat correctly. I think this is clearly an usual MRA bug.

Also, if it's not working correctly with a BT keyboard set to US English layout, it's not going to work with any controller. There is something wrong with your device, I am afraid.

Joergen57 commented 1 year ago

Hi Jon, In principle, you are right, the controller works correctly. If you keep the timing. It seems to be a problem with MRA if you hold down the n key a little too long, the App crashes.

Do you think a key events logging is still needed? I don't think so, or? And, can the MRA developer improve something? I will report this anyway.

Thank you for your support and your patience.