qtdragon mod
- Mr. Mass
-
Topic Author
- Offline
- Senior Member
-
Less
More
- Posts: 53
- Thank you received: 36
24 Apr 2025 06:01 #326984
by Mr. Mass
qtdragon mod was created by Mr. Mass
Trying to modify qtdragon a bit and add hal pins for slides. Found an example on the forum for analog, but I need to do for encoders. Tried to redo the code, at first glance everything seems ok, values change, sliders react. But the problem appears if we change the value by encoder, say by 50%, then press the button 100%, and if after that we reduce the value by encoder again, it immediately jumps to 40% (I specified a step of 10%). As far as I understand the problem is that absolute values are used, but it is necessary to use relative values. But I am completely stuck on how to implement it in the code.
Please Log in or Create an account to join the conversation.
- cmorley
- Away
- Moderator
-
Less
More
- Posts: 7876
- Thank you received: 2128
24 Apr 2025 16:41 - 25 Apr 2025 00:29 #327002
by cmorley
Replied by cmorley on topic qtdragon mod
The problem is that the 'on_counts_value_changed' function uses the 'value' (encoder counts) as an absolute value (as you said), but you could use it as a relative value.
if new value is higher then the last value, then move up 10% higher then the current rate.
if new value is less then the last value then move down 10% from the current rate
The current rate you can get from STATUS or from the appropriate widget.
I'm sure there will be some minor details to adjust to.
if new value is higher then the last value, then move up 10% higher then the current rate.
if new value is less then the last value then move down 10% from the current rate
The current rate you can get from STATUS or from the appropriate widget.
I'm sure there will be some minor details to adjust to.
Last edit: 25 Apr 2025 00:29 by cmorley.
The following user(s) said Thank You: Mr. Mass
Please Log in or Create an account to join the conversation.
- Mr. Mass
-
Topic Author
- Offline
- Senior Member
-
Less
More
- Posts: 53
- Thank you received: 36
25 Apr 2025 14:28 #327044
by Mr. Mass
Replied by Mr. Mass on topic qtdragon mod
Found the STATUS and values for the widgets, thanks.
But how can I add the previous encoder value? I tried adding a variable and assigning the encoder value to it so that I can compare them before calling the function. But it seems that I have not figured out where exactly this variable can be written. The “init_pins” function seems to be called only once at startup. And the “_on_counts_value_changed” function is triggered only when the encoder value changes and it can be passed only the current value. Or do I think wrong and there is another way?
But how can I add the previous encoder value? I tried adding a variable and assigning the encoder value to it so that I can compare them before calling the function. But it seems that I have not figured out where exactly this variable can be written. The “init_pins” function seems to be called only once at startup. And the “_on_counts_value_changed” function is triggered only when the encoder value changes and it can be passed only the current value. Or do I think wrong and there is another way?
Please Log in or Create an account to join the conversation.
- cmorley
- Away
- Moderator
-
Less
More
- Posts: 7876
- Thank you received: 2128
26 Apr 2025 03:07 #327075
by cmorley
Replied by cmorley on topic qtdragon mod
Initialize a variable as 0 at startup.
Update that variable with the current encoder count after checking if it is higher or lower.
I think if you look at the master version 9f qtdragon you will see encoder input code with a similar idea. I am on the road so can't go in more detail right now.
Update that variable with the current encoder count after checking if it is higher or lower.
I think if you look at the master version 9f qtdragon you will see encoder input code with a similar idea. I am on the road so can't go in more detail right now.
Please Log in or Create an account to join the conversation.
Moderators: cmorley
Time to create page: 0.085 seconds