PDA

View Full Version : quick click vs. hold


Lev
25-12-2004, 04:09 PM
First off, I just want to say how impressed I am with the support provided here for CH products - one of the reasons I got my Fighterstick and Pro Throttle about a week ago. In the last week, I've had more fun programming my controls and learning scripting than actually using them. I'm blown away with what you can do with CMS scripting. Way to go, everyone! :thumbsup:

So here's what I'd like to do, but I just can't seem to get it to work. While I've succeeded in copying JNOV's script (for Falcon 4) for making a button send one command when pressed quickly and work as a shift key when held down, I can't for the life of me get a button to send one command when pressed quickly and hold another command when held down.

For instance, I'd like Fighterstick Hat 2 UP (js1.b9) to send cms.b9 when quickly pressed up, but to send cms.b65 when held up. I have programmed cms.b65 to be HOLD RALT RCTL, and Left, Right, and Down to be similar modifiers, so that I can hold them while pressing the keypad to simulate Falcon 4's OSB buttons (don't even know if that's going to work yet :blink: ).

Here's where I've gotten. It seems to work, though if I hold Up followed by a quick select Up, then I seem to get some extra keypresses, which I can't figure out. There's probably a better way to do this, that is more elegant and actually works. (And it would probably be a good thing if I actually understood the various time parsing scripts).

//////////////////////////

script

timer(period, d2, 5) = js1.b9 and not d2; //////Quick Select for Up
sequence
wait(d2 and not js1.b9 and not (ls1 or ls2 or ls3) );
cms.b9 = TRUE;
delay(2);
cms.b9 = FALSE;
endsequence

timer(period, d3, 5) = js1.b10 and not d3; //////Quick Select for Right
sequence
wait(d3 and not js1.b10 and not (ls1 or ls2 or ls3) );
cms.b10 = TRUE;
delay(2);
cms.b10 = FALSE;
endsequence

timer(period, d4, 5) = js1.b11 and not d4; /////Quick Select for Down
sequence
wait(d4 and not js1.b11 and not (ls1 or ls2 or ls3) );
cms.b11 = TRUE;
delay(2);
cms.b11 = FALSE;
endsequence

timer(period, d5, 5) = js1.b12 and not d5; //////Quick Select for Left
sequence
wait(d5 and not js1.b12 and not (ls1 or ls2 or ls3) );
cms.b12 = TRUE;
delay(2);
cms.b12 = FALSE;
endsequence

if (not (d2 or d3 or d4 or d5) ) then //////These are the Hold keys
cms.b65 = js1.b9;
cms.b67 = js1.b10;
cms.b69 = js1.b11;
cms.b71 = js1.b12;
endif

endscript

JNOV
25-12-2004, 10:03 PM
Hi Lev:

Here's a snippet of the script I wrote for a prior version of my Falcon profile, in which I endeavored to copy Jagstang's famous Cougar profile as directly as possible. Because of the Cougar's limited programmability, Jag's profile has a number of different time-parsing schemes, including sending one command on a quick click, another on a hold, and yet another on a sufficiently quick double click. All three schemes are implemented in the code below (the s0 and s1 are shift-state variables):

// ================================================== ================================
// Fighterstick POV Hat (TRIM)
// Bits: cms.b2-cms.b12
// Timers: d2-d4
// variables: a1
//
// 1. Pan Views
// 2. Hold L/R: Check Six
// 3. Shift: Trim
// 4. Double down: Reset Trim
// ================================================== ================================

///////////////////////////////////////////////////////////////////
// Up
cms.b2 = s0 and js1.b25; // Pan View Up
cms.b3 = s1 and js1.b25; // Trim Nose Down
///////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////
// Down
// Shift 1
cms.b5 = s1 and js1.b29; // Trim Nose Up
// Double click parsing: Pan view down/Reset Trim
timer(period, d4, 5) = js1.b29 and not d4 and s0;
sequence
wait(d4 and js1.b29);
Clicks = Clicks + 1;
endsequence
sequence
wait(not d4 and [Clicks == 1]);
Clicks = 0;
cms.b4 = TRUE; // Pan View Down
delay(3);
cms.b4 = FALSE;
endsequence
sequence
wait(not d4 and [Clicks == 2]);
Clicks = 0;
cms.b12 = TRUE; // Reset trim
delay(3);
cms.b12 = FALSE;
endsequence
if (not d4 and [Clicks > 2]) then
Clicks = 0;
endif
////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////
// Right
// Unshifted Hold parsing
timer(period, d2, hold) = js1.b27 and s0;
sequence
wait(not d2);
cms.b6 = js1.b27; // Held: Check Six (7 o'clock)
cms.b7 = not js1.b27; // Not Held: Pan View Right
delay(3);
cms.b7 = FALSE;
endsequence
if (not js1.b27) then
cms.b6 = FALSE;
endif
// Shift 1
cms.b8 = s1 and js1.b27; // Trim roll right
////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////
// Left
// Unshifted Hold parsing
timer(period, d3, hold) = js1.b31 and s0;
sequence
wait(not d3);
cms.b9 = js1.b31; // Held: Check Six (7 o'clock)
cms.b10 = not js1.b31; // Not Held: Pan View Left
delay(3);
cms.b10 = FALSE;
endsequence
if (not js1.b31) then
cms.b9 = FALSE;
endif
// Shift 1
cms.b11 = s1 and js1.b31; // Trim roll left
////////////////////////////////////////////////////////////////////

I hope this is useful!

Best regards,

JNOV

Lev
25-12-2004, 10:58 PM
Hi JNOV!
Thanks for the reply. It looks like your script for the Right Hat is exactly what I want to do:

////////////////////////////////////////////////////////////////////
// Right
// Unshifted Hold parsing
timer(period, d2, hold) = js1.b27 and s0;
sequence
wait(not d2);
cms.b6 = js1.b27; // Held: Check Six (7 o'clock)
cms.b7 = not js1.b27; // Not Held: Pan View Right
delay(3);
cms.b7 = FALSE;
endsequence
if (not js1.b27) then
cms.b6 = FALSE;
endif[/b]

A few questions:

(1) What does the "hold" do in the time parsing? I'm used to seeing a number there, like with the Hat Down part of your script.

(2) It seems like cms.b7 is triggered when the right hat button is RELEASED - Am I reading that correctly? If that's the case, what keeps cms.b7 from going TRUE after you've been Checking Your Six for a few seconds? This might not be a problem for these two views, but what if the "Hold" button and quick-select button are totally unrelated?

Thanks,
Lev.

Lev
26-12-2004, 01:31 AM
Well, I see that "hold" above is supposed to be a time value for the hold, like 5. Duh. :blush:

I tested the script, and it actually seems to work. It's like some kind of Dark Magicke, because I still don't completely understand it.

Lev.

JNOV
26-12-2004, 03:39 AM
Sorry, Lev. I didn't look closely enough at the script. There are at least a couple of tokens, like hold and Clicks. that are defined earlier in the script. But you have it right--hold is just a value, like 5, that controls how long you have to hold the control before it sends the held command.

The basic principle for the quick-click/hold parsing scheme is:

1. start a period timer of duration "hold" when the button's pressed
2. wait until the period timer expires
3. check whether the button's still pressed
3a. if it is still pressed, send the "held" command
3b. if it is not still pressed, send the "quick-click" command

That approach is simple, but the downside is that no command is sent until the expiration of the hold timer. That is, even if you quick-click, the command isn't sent until the test when the hold timer expires. In my experience, this delay isn't noticeable for reasonably short hold timers.

If the delay bothers you, an alternative approach is to perform the test when the button is relased, rather than when the timer expires:

1. start a period timer of duration "hold" when the button's pressed
2. wait until the button is released
3. check whether the "hold" timer has expired
4. if not, send the "quick-click" command
5. if so, send the "held" command

I hope that makes some sense. If not, feel free to ask questions in this thread or to send me an e-mail or message.

Best regards,

JNOV