/// <summary>Maps the sliders of the joystick</summary> /// <param name="joystick">Joystick for which sliders are mapped</param> private void mapSliders(Joystick joystick) { IList<DeviceObjectInstance> sliders = joystick.GetObjects( ObjectDeviceType.AbsoluteAxis ); var unmappedReaders = new Queue<ISliderReader>(); for (int index = 0; index < sliders.Count; ++index) { if (sliders[index].ObjectTypeGuid == ObjectGuid.Slider) { ExtendedSliders slider = identifySlider( sliders[index].Aspect, sliders[index].ObjectTypeGuid ); // If this slider could not be identified but were still missing one // of the two standard sliders, remember it so we can use it in case // no exact matches are found for sliders 1 and 2. if (slider == 0) { if (unmappedReaders.Count < 2) { unmappedReaders.Enqueue(createSliderReader(joystick, slider, sliders[index])); } } else { // Slider was identified, assign it to the next free slot if ((this.availableSliders & slider) != 0) { ++slider; if ((this.availableSliders & slider) != 0) { slider = 0; } } } // If we identified this slider (exactly or by fallback), build a reader // for it and store it in the appropriate slot. if (slider != 0) { this.availableSliders |= slider; this.sliderReaders[indexFromSlider(slider)] = createSliderReader( joystick, slider, sliders[index] ); } } // if } // for // If sliders 1 and/or 2 are still not provided, use the unidentified // sliders we remembered earlier as a fallback solution. These could very // well be null, too, in which case the sliders simply aren't there. if ((this.sliderReaders[0] == null) && (unmappedReaders.Count > 0)) { this.availableSliders |= ExtendedSliders.Slider1; this.sliderReaders[0] = unmappedReaders.Dequeue(); } if ((this.sliderReaders[1] == null) && (unmappedReaders.Count > 0)) { this.availableSliders |= ExtendedSliders.Slider2; this.sliderReaders[1] = unmappedReaders.Dequeue(); } }
/// <summary>Maps the axes of the joystick</summary> /// <param name="joystick">Joystick for which axes are mapped</param> private void mapAxes(Joystick joystick) { IList<DeviceObjectInstance> axes = joystick.GetObjects( ObjectDeviceType.AbsoluteAxis ); var unmappedReaders = new Queue<IAxisReader>(); for (int index = 0; index < axes.Count; ++index) { if (axes[index].ObjectTypeGuid != ObjectGuid.Slider) { ExtendedAxes axis = identifyAxis( axes[index].Aspect, axes[index].ObjectTypeGuid ); // If this axis could not be identified but we're still missing one of // the standard axes (X, Y, Rx, Ry), remember it so we can later map it // to the next unassigned standard axes in case some are left unassigned. if (axis == 0) { if (unmappedReaders.Count < 4) { unmappedReaders.Enqueue(createAxisReader(joystick, axis, axes[index])); } } else { // Axis identified, build reader and store it this.availableAxes |= axis; this.axisReaders[indexFromAxis(axis)] = createAxisReader( joystick, axis, axes[index] ); } } // if } // for // If the four standard axes are still not completely provided, use // the unidentified axis we remembered earlier as a fallback solution. if ((this.axisReaders[0] == null) && (unmappedReaders.Count > 0)) { this.availableAxes |= ExtendedAxes.X; this.axisReaders[0] = unmappedReaders.Dequeue(); } if ((this.axisReaders[1] == null) && (unmappedReaders.Count > 0)) { this.availableAxes |= ExtendedAxes.Y; this.axisReaders[1] = unmappedReaders.Dequeue(); } if ((this.axisReaders[12] == null) && (unmappedReaders.Count > 0)) { this.availableAxes |= ExtendedAxes.RotationX; this.axisReaders[12] = unmappedReaders.Dequeue(); } if ((this.axisReaders[13] == null) && (unmappedReaders.Count > 0)) { this.availableAxes |= ExtendedAxes.RotationY; this.axisReaders[13] = unmappedReaders.Dequeue(); } }