Documentation for the "SwitchItem" structure?
- pvogel
-
Topic Author
- Offline
- Junior Member
-
- Posts: 22
- Thank you received: 3
TPL_KUNENA_MESSAGE_CREATED Documentation for the "SwitchItem" structure?
30 Dec 2016 22:29
I was not able to find any documentation for the "SwitchItem" structure. I would like to vibrate the gimbal associated with a selected switch (if the switch is P1, P2, P3, or P4 obviously) when the control is set to a certain proportional value. Sure, I could ask the user in the form if I should vibrate left or right gimbal, but I should be able to figure it out from the switch they selected!
Thanks,
Peter+
Thanks,
Peter+
Please Log in or Create an account to join the conversation.
- TeroS
-
- Offline
- Platinum Member
-
- RC-Thoughts
- Posts: 527
- Thank you received: 370
TPL_KUNENA_MESSAGE_REPLIED_NEW Documentation for the "SwitchItem" structure?
30 Dec 2016 22:56pvogel wrote: I was not able to find any documentation for the "SwitchItem" structure. I would like to vibrate the gimbal associated with a selected switch (if the switch is P1, P2, P3, or P4 obviously) when the control is set to a certain proportional value. Sure, I could ask the user in the form if I should vibrate left or right gimbal, but I should be able to figure it out from the switch they selected!
Thanks,
Peter+
I think you are after this:
"If P3 or P4 is over user chosen value then vibrate left stick" and "If P1 or P2 is over user chosen value then vibrate right stick"
It that was right, then it's something like this:
- Give user a choice to select a switch and value
- Make the conditions in loop
Then go.
Note that switches have values between -1.0 and 1.0, not -100% and 100%. This means that 25% equals 0.25.
So for example after defining Sw1 to be P3 or P4:
if(Sw1 >= 0.75) then
system.vibration(false, 3)
end
This would vibrate left stick with two short pulses when P1 is over 75%. You can find all the definitions in Lua API pdf.
Hope this helps, I had fun playing with vibrating sticks some months ago
Please Log in or Create an account to join the conversation.
- pvogel
-
Topic Author
- Offline
- Junior Member
-
- Posts: 22
- Thank you received: 3
TPL_KUNENA_MESSAGE_REPLIED_NEW Documentation for the "SwitchItem" structure?
30 Dec 2016 23:06 - 30 Dec 2016 23:07
Yes, that's what I'm after (I've written the code already, just hard-coded to shake the left stick for my mode 2 usage) the question is, from the "switchItem" object obtained from the inputBox selector, how do I know if it is P1, P2, P3 or P4 (or something else)?
Current state of the code is here:
github.com/pvogel1967/Lua-Apps/tree/master/Throttle%20Detent
Current state of the code is here:
github.com/pvogel1967/Lua-Apps/tree/master/Throttle%20Detent
Last edit: 30 Dec 2016 23:07 by pvogel.
Please Log in or Create an account to join the conversation.
- TeroS
-
- Offline
- Platinum Member
-
- RC-Thoughts
- Posts: 527
- Thank you received: 370
TPL_KUNENA_MESSAGE_REPLIED_NEW Documentation for the "SwitchItem" structure?
30 Dec 2016 23:20pvogel wrote: Yes, that's what I'm after (I've written the code already, just hard-coded to shake the left stick for my mode 2 usage) the question is, from the "switchItem" object obtained from the inputBox selector, how do I know if it is P1, P2, P3 or P4 (or something else)?
Current state of the code is here:
github.com/pvogel1967/Lua-Apps/tree/master/Throttle%20Detent
If you want to hard-code the P1 and P2 to one stick vibrating and P3 and P4 to one gimbal then consider this for reading all axes in loop:
local P1, P2, P3, P4 = system.getInputs("P1", "P2", "P3", "P4")
Now you have the values of all gimbal-axes between -1.0 and 1.0 and can use them to do what you want. User does not have to select any switch either. After this all you need to do is to give user a possibility to choose the alarm-limits. And for good user-experience maybe the vibration patterns.
Please Log in or Create an account to join the conversation.
- pvogel
-
Topic Author
- Offline
- Junior Member
-
- Posts: 22
- Thank you received: 3
TPL_KUNENA_MESSAGE_REPLIED_NEW Documentation for the "SwitchItem" structure?
30 Dec 2016 23:42TeroS wrote:pvogel wrote: Yes, that's what I'm after (I've written the code already, just hard-coded to shake the left stick for my mode 2 usage) the question is, from the "switchItem" object obtained from the inputBox selector, how do I know if it is P1, P2, P3 or P4 (or something else)?
Current state of the code is here:
github.com/pvogel1967/Lua-Apps/tree/master/Throttle%20Detent
If you want to hard-code the P1 and P2 to one stick vibrating and P3 and P4 to one gimbal then consider this for reading all axes in loop:
local P1, P2, P3, P4 = system.getInputs("P1", "P2", "P3", "P4")
Now you have the values of all gimbal-axes between -1.0 and 1.0 and can use them to do what you want. User does not have to select any switch either. After this all you need to do is to give user a possibility to choose the alarm-limits. And for good user-experience maybe the vibration patterns.
I understand all that. But I want the USER to be able to select the control for which they want to have a "detent" vibration. Then I want to apply the vibration to gimbal associated with that control. So I don't want to read all axes, I just want to read one, and then I want to put a gentle "bump" (vibration mode 2) when that one control is within 1% of the set value. Yes, I could let them choose a vibration pattern, but I'm starting simple
Peter+
Please Log in or Create an account to join the conversation.
- TeroS
-
- Offline
- Platinum Member
-
- RC-Thoughts
- Posts: 527
- Thank you received: 370
TPL_KUNENA_MESSAGE_REPLIED_NEW Documentation for the "SwitchItem" structure?
31 Dec 2016 09:34
You need to have the switch-selection in form:
form.addRow(2)
form.addLabel({label="Select Axis"})
form.addInputbox(Ax,true,AxChanged)
Then you need to save user's selection (this needs to be above the form)
local function AxChanged(value)
Ax1 = value
system.pSave("Ax",value)
end
In your init-section you need to have the loading of the axis:
Ax = system.pLoad("Ax")
Now you have the users selected axis as "Ax" you can use, the axis-selection needs to be proportional.
form.addRow(2)
form.addLabel({label="Select Axis"})
form.addInputbox(Ax,true,AxChanged)
Then you need to save user's selection (this needs to be above the form)
local function AxChanged(value)
Ax1 = value
system.pSave("Ax",value)
end
In your init-section you need to have the loading of the axis:
Ax = system.pLoad("Ax")
Now you have the users selected axis as "Ax" you can use, the axis-selection needs to be proportional.
Please Log in or Create an account to join the conversation.
Moderators: Thorn, IG-Modellbau
Time to create page: 0.342 seconds