XHC-WHB04-4 Python component

More
25 Jan 2021 21:21 #196559 by fixer
Replied by fixer on topic XHC-WHB04-4 Python component
sure.
h.fn is output pin of self hal component. "data" structure contains received data from whb device. Fields [2] and [3] are pressed buttons, value 12 means fn button pressed.

on metric inrements are 1mm, 0.1mm, 0.01mm, 0.001mm. On imperial each should be divided by 10 - line 196
can you check with halshow whb inc and axis jog-scale pins? what do they show on your configuration. Show your hal files so I can check.

Please Log in or Create an account to join the conversation.

More
25 Jan 2021 21:52 - 25 Jan 2021 21:59 #196568 by probotix
Sorry let me clarify my question. I don't have a full understanding of the python syntax, yet. I'm trying to understand the a = b == x or c == x syntax. I know what a,b,c, and x are, just not what the equals signs and or mean when combined like that. does it mean that a is true if either b == x or c == x.

If so, why do you have to check both data[2] and data[3]?
Last edit: 25 Jan 2021 21:59 by probotix.

Please Log in or Create an account to join the conversation.

More
25 Jan 2021 22:01 - 25 Jan 2021 22:05 #196569 by fixer
Replied by fixer on topic XHC-WHB04-4 Python component
yes.

read realpython.com/python-boolean/

whb allows 2 simultaneous keys pressed, it returns the first pressed in [2] and the second in [3] this allows to have alternate key functionality with fn key...
Last edit: 25 Jan 2021 22:05 by fixer.

Please Log in or Create an account to join the conversation.

More
25 Jan 2021 22:06 #196573 by probotix
Ok, understand now. So, why do you have to check both data[2] and data[3]?

Please Log in or Create an account to join the conversation.

More
25 Jan 2021 22:13 #196575 by fixer
Replied by fixer on topic XHC-WHB04-4 Python component
do a print(data) in line 180 and watch output in terminal while pressing different buttons on the pendant...

Please Log in or Create an account to join the conversation.

More
25 Jan 2021 22:18 #196577 by probotix
I couldn't come up with any combination of button presses that changed data[3], it appears to always be zero.

Please Log in or Create an account to join the conversation.

More
25 Jan 2021 22:40 #196579 by probotix
Also, have you come up with a way to identify button releases? I see the release events happen, but it doesn't appear to identify which button was released.

Please Log in or Create an account to join the conversation.

More
26 Jan 2021 04:37 #196602 by fixer
Replied by fixer on topic XHC-WHB04-4 Python component
Release event is identified as data[2]==0

If you want to know which button was released you should first save the state of pressed buttons and compare it with the state in the next iteration of while(1)

Please Log in or Create an account to join the conversation.

More
29 Jan 2021 22:08 #197093 by probotix
What if you had two buttons pressed, and released one. How could you know which one was released?

Please Log in or Create an account to join the conversation.

More
30 Jan 2021 06:35 #197121 by fixer
Replied by fixer on topic XHC-WHB04-4 Python component
What are you trying to do?
You can simply save the state of the pin you are interested in and compare it with the value of the said pin in the next iteration.

For a more Pythonic way investigate this:
stackoverflow.com/questions/51885246/cal...ble-change-in-python

Please Log in or Create an account to join the conversation.

Time to create page: 0.088 seconds
Powered by Kunena Forum