Page 1 of 1

Mapping keys to parameters

Posted: Wed Dec 24, 2014 4:04 pm
by dbrgn
Is there a way to map keys to arbitrary parameters?

E.g. I'd like to turn on the headlight or change the LED effect using my gamepad.

Re: Mapping keys to parameters

Posted: Thu Dec 25, 2014 6:05 am
by chad
I'm not sure if there's an easy way to do this after the latest changes for CF2.0 but when I modded my CF1.0 with a NeoPixel LED ring, I added similar controller functionality myself... Maybe this will be of some help to you?

Re: Mapping keys to parameters

Posted: Thu Dec 25, 2014 8:03 pm
by marcus
dbrgn wrote:Is there a way to map keys to arbitrary parameters?

E.g. I'd like to turn on the headlight or change the LED effect using my gamepad.
I have code for this, but it's based on the old pygame and not the pysdl2/linuxdev changes, so it needs some work before it's merged. I'll try to sit down tomorrow and merge it in.

Re: Mapping keys to parameters

Posted: Fri Dec 26, 2014 3:47 am
by chad
marcus wrote:I have code for this, but it's based on the old pygame and not the pysdl2/linuxdev changes, so it needs some work before it's merged. I'll try to sit down tomorrow and merge it in.
Cool! I'll be happy to use this code too. Thanks Marcus!!

Re: Mapping keys to parameters

Posted: Sat Dec 27, 2014 7:32 pm
by marcus
The code is merged now, it's on the branch dev-inputdev. To make a long story short we have been talking about refactoring the input layer for a while now, but never gotten around to it. So I thought that I might as well start the changes we talked about while merging in the old code. Everything is a bit messy and there's more changes than is required for what you wanted, but here's the explanation.

We have added two new buttons that can be mapped, alt1 and alt2. They can be configured in the input configuration dialog and then used in the application. They were put in to enable us to do all kinds of things, among them changing the LED-ring effect and turning off the headlights. When the state of the button is changed up->down or down->up a callback is called from the input layer that you can register to. Currently it's registered in the FlightTab to call two functions, one for alt1 and one for alt2. The function alt1_updated can be used to roll over all the LED-ring effects. When it's released the effect number is increased until you reach the number of effects, then it rolls back to zero. The function alt2_updated can be used to switch the LED-ring headlight on and off. Currently it's implemented to switch the light on while the alt2 buttons is pressed, and switch it off otherwise.

So to use the code just go to the Input Device -> Configure device mapping... dialog, start the configuration and map the Alt1/Alt2 buttons. Then use the callbacks in the FlightTab to implement whatever functionality you want when the buttons are pressed/released. Here's the current code:

Code: Select all

    def alt1_updated(self, state):
        if state:
            self._ring_effect += 1
            if self._ring_effect > self._ledring_nbr_effects:
                self._ring_effect = 0
            self.helper.cf.param.set_value("ring.effect", str(self._ring_effect))

    def alt2_updated(self, state):
        self.helper.cf.param.set_value("ring.headlightEnable", str(state))

Re: Mapping keys to parameters

Posted: Sat Dec 27, 2014 8:17 pm
by chad
Cool. Thanks for the explanation and link to the branch!

Re: Mapping keys to parameters

Posted: Mon Jan 12, 2015 9:24 am
by Psichosix
I'd like to map this as well. However, I don't see a alt 1 or an alternative 2 button in my input screen.

Re: Mapping keys to parameters

Posted: Mon Jan 12, 2015 9:09 pm
by chad
Psichosix wrote:I'd like to map this as well. However, I don't see a alt 1 or an alternative 2 button in my input screen.
Are you using the dev-inputdev branch? The mappings are not on the master yet.

The alt buttons should be on the lower-right of the configure mappings window.
alt mappings
alt mappings
alt_buttons.png (20.47 KiB) Viewed 6569 times

Re: Mapping keys to parameters

Posted: Mon Jan 18, 2016 2:37 pm
by Ziboul
Hello!
About post by Marcus 2014-12-27-8:32pm:
My problems
1/ everything like you say, Alt 1 mapped on Button 3 of a Xbox360 wireless. But pressing the button just turn off the ring, not shifting through different choices. My Python client is 2015-09. Firmware is the original latest one.
2/ The input configure device tab does not function. All places are greyed when I ask configure and load json file Xbox360...
Yours truly
Z.