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

1022 add programable buttons to webui #1026

Merged
merged 8 commits into from
Aug 14, 2022

Conversation

Ezward
Copy link
Contributor

@Ezward Ezward commented Jun 27, 2022

Issue #1022

This PR adds 5 general purpose buttons to the webui. Presses of these buttons can be processed by other donkeycar parts as input values.

  • reformatted webui layout into a 2 column layout that works better on a phone. This is in anticipation of using the phone while using an RC controller we we can get similar functionality to a game controller.
  • Also added code to hide the virtual joystick if it is not being used (if gamepad is being used).
  • Add 5 buttons to the ui
  • When a button is pressed the pressed state is sent to the donkeycar, which then latches the value.
  • The latched value is then written into vehicle memory.
  • Parts can detect button presses as input values and respond to them.

I've added code into the complete.py template that shows how to process the button presses. That is just there to test. Eventually we can decide if we want to add standard behavior to these buttons or add another mechanism for adding behaviors that can be configured.

This is what the webui looks like on a phone (sorry, github seems to be ignoring sizing and force width to fit)
image

This is what it looks like on desktop
image

@Ezward Ezward requested a review from DocGarbanzo June 27, 2022 05:55
@Ezward Ezward self-assigned this Jun 27, 2022
Ezward added a commit that referenced this pull request Jun 29, 2022
- merged from #1026
- provided 5 programmable buttons in the webui.
@DocGarbanzo
Copy link
Contributor

DocGarbanzo commented Jul 5, 2022

@Ezward - This is a great improvement, if we can use the web controller on the mobile phone. Can you please also update the version? You'll need to rebase, because I just merged the VESC PR.

Ezward and others added 6 commits August 5, 2022 15:41
- if key is a string, set the value directly.
- this will take a dictionary and add each individual
  key/value pair to vehicle memory
- it will optionally insert a prefix into the output key/value
- this will be used to write the button presses returned
  by the webUI into working memory.
- buttons, "w1" to "w5"
- button presses are returned by the LocalWebController part
- the dictionary of button presses isthen processed in the template
  using the ExplodeDict part to turn the dictionary into
  individual memory values
- this is just a demo of how to handle these button presses
@Ezward Ezward force-pushed the 1022-add-programable-buttons-to-webui branch from e168d3a to ca70f87 Compare August 5, 2022 22:42
@Ezward
Copy link
Contributor Author

Ezward commented Aug 5, 2022

@DocGarbanzo Thank you for the review, I've rebased and updated version="4.3.20"


def run(self, key_values):
if type(key_values) is dict:
for key in key_values:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better:

for key, value in key_values.items():
    self.memory[self.prefix + key] = value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made that change, thanks.

buttons = self.buttons
self.buttons = {}
for button in buttons:
if buttons[button]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this only be:

if button

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I'm checking to see if there is a button press. I'm not checking to see if there is a button. So if the Button is pressed then buttons[button] is true, so I want to clear it so we only see the button press once.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah got it, buttons is a dict, so probably we should try to avoid a duplicated lookup and iterate through buttons.items() which returns keys and values together?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made that change. It reads better now also. Thanks.

donkeycar/templates/complete.py Show resolved Hide resolved
Copy link
Contributor

@DocGarbanzo DocGarbanzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@Ezward Ezward merged commit e902d4e into main Aug 14, 2022
@Ezward Ezward deleted the 1022-add-programable-buttons-to-webui branch August 14, 2022 18:10
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

Successfully merging this pull request may close these issues.

2 participants