static private void SetPreset(ref SMX.SMXConfig config,
                                      byte loadCellLow, byte loadCellHigh, byte loadCellLowCenter, byte loadCellHighCenter,
                                      byte fsrLow, byte fsrHigh, byte fsrLowCenter, byte fsrHighCenter)
        {
            for (int panel = 0; panel < 9; ++panel)
            {
                config.panelSettings[panel].loadCellLowThreshold  = loadCellLow;
                config.panelSettings[panel].loadCellHighThreshold = loadCellHigh;
            }

            // Center:
            config.panelSettings[4].loadCellLowThreshold  = loadCellLowCenter;
            config.panelSettings[4].loadCellHighThreshold = loadCellHighCenter;

            for (int panel = 0; panel < 9; ++panel)
            {
                for (int sensor = 0; sensor < 4; ++sensor)
                {
                    config.panelSettings[panel].fsrLowThreshold[sensor]  = fsrLow;
                    config.panelSettings[panel].fsrHighThreshold[sensor] = fsrHigh;
                }
            }

            // Center:
            for (int sensor = 0; sensor < 4; ++sensor)
            {
                config.panelSettings[4].fsrLowThreshold[sensor]  = fsrLowCenter;
                config.panelSettings[4].fsrHighThreshold[sensor] = fsrHighCenter;
            }
        }
Beispiel #2
0
        void RefreshVisibility()
        {
            LoadFromConfigDelegateArgs args = CurrentSMXDevice.singleton.GetState();

            SMX.SMXConfig config = args.controller[args.FirstController].config;
            this.Visibility = ShouldBeDisplayed(config)? Visibility.Visible:Visibility.Collapsed;
        }
        private void ImportSettings(object sender, RoutedEventArgs e)
        {
            // Prompt for a file to read.
            Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog();
            dialog.FileName   = "StepManiaX settings";
            dialog.DefaultExt = ".smxcfg";
            dialog.Filter     = "StepManiaX settings (.smxcfg)|*.smxcfg";
            bool?result = dialog.ShowDialog();

            if (result == null || !(bool)result)
            {
                return;
            }

            string json = Helpers.ReadFile(dialog.FileName);

            // Apply settings from the file to all active pads.
            foreach (Tuple <int, SMX.SMXConfig> activePad in ActivePad.ActivePads())
            {
                int           pad    = activePad.Item1;
                SMX.SMXConfig config = activePad.Item2;

                SMXHelpers.ImportSettingsFromJSON(json, ref config);
                SMX.SMX.SetConfig(pad, config);
            }

            CurrentSMXDevice.singleton.FireConfigurationChanged(null);
        }
        private void LoadUIFromConfig(SMX.SMXConfig config)
        {
            // Center panel, top sensor:
            bool enabled = config.panelSettings[4].fsrHighThreshold[2] < 255;

            EnableSensor = enabled;
        }
        // The floor color button is available if the firmware is v4 or greater.
        public override bool isEnabled(LoadFromConfigDelegateArgs args)
        {
            int pad = getPadNo();

            SMX.SMXConfig config = args.controller[pad].config;
            return(config.masterVersion >= 4);
        }
Beispiel #6
0
        private void GetValueFromConfig(SMX.SMXConfig config, out byte lower, out byte upper)
        {
            switch (Type)
            {
            case "up-left":    lower = config.panelThreshold0Low;     upper = config.panelThreshold0High; return;

            case "up":         lower = config.panelThreshold1Low;     upper = config.panelThreshold1High; return;

            case "up-right":   lower = config.panelThreshold2Low;     upper = config.panelThreshold2High; return;

            case "left":       lower = config.panelThreshold3Low;     upper = config.panelThreshold3High; return;

            case "center":     lower = config.panelThreshold4Low;     upper = config.panelThreshold4High; return;

            case "right":      lower = config.panelThreshold5Low;     upper = config.panelThreshold5High; return;

            case "down-left":  lower = config.panelThreshold6Low;     upper = config.panelThreshold6High; return;

            case "down":       lower = config.panelThreshold7Low;     upper = config.panelThreshold7High; return;

            case "down-right": lower = config.panelThreshold8Low;     upper = config.panelThreshold8High; return;

            case "cardinal":   lower = config.panelThreshold7Low;     upper = config.panelThreshold7High; return;

            case "corner":     lower = config.panelThreshold2Low;     upper = config.panelThreshold2High; return;

            default:
                lower = upper = 0;
                return;
            }
        }
        // Return true if this button should be displayed.
        private bool ShouldBeDisplayed(SMX.SMXConfig config)
        {
            bool[] enabledPanels = config.GetEnabledPanels();
            int    PanelIndex    = Panel % 9;

            return(enabledPanels[PanelIndex]);
        }
Beispiel #8
0
        private void LoadUIFromConfig(SMX.SMXConfig config)
        {
            // Make sure SaveToConfig doesn't treat these as the user changing values.
            UpdatingUI = true;

            byte lower, upper;

            GetValueFromConfig(config, out lower, out upper);

            if (lower == 0xFF)
            {
                LowerLabel.Content = "Off";
                UpperLabel.Content = "";
            }
            else
            {
                slider.LowerValue  = lower;
                slider.UpperValue  = upper;
                LowerLabel.Content = lower.ToString();
                UpperLabel.Content = upper.ToString();
            }

            RefreshVisibility();
            UpdatingUI = false;
        }
        // If the user disables inner-sensors after setting a value and control of those thresholds
        // goes back to other sliders, the old inner-sensors thresholds will still be set in config
        // until the user changes them, which is confusing.  Make sure the value of each slider is
        // actually set to config, even if the user doesn't change them.
        //
        // This isn't perfect.  If the user assigns the first up sensor to custom and then removes it,
        // so that sensor goes back to the normal up slider, this will sync the custom value to up.
        // That's because we don't know which thresholds were actually being controlled by the up slider
        // before it was changed.  This is tricky to fix and not a big problem.
        private static void SyncSliderThresholdsForConfig(ref SMX.SMXConfig config)
        {
            if (!config.fsr())
            {
                return;
            }

            bool AdvancedModeEnabled = Properties.Settings.Default.AdvancedMode;

            foreach (string sliderName in thresholdSliderNames)
            {
                List <PanelAndSensor> controlledSensors = GetControlledSensorsForSliderType(sliderName, AdvancedModeEnabled, false);
                if (controlledSensors.Count == 0)
                {
                    continue;
                }
                PanelAndSensor firstSensor = controlledSensors[0];

                foreach (PanelAndSensor panelAndSensor in controlledSensors)
                {
                    config.panelSettings[panelAndSensor.panel].fsrLowThreshold[panelAndSensor.sensor] =
                        config.panelSettings[firstSensor.panel].fsrLowThreshold[firstSensor.sensor];
                    config.panelSettings[panelAndSensor.panel].fsrHighThreshold[panelAndSensor.sensor] =
                        config.panelSettings[firstSensor.panel].fsrHighThreshold[firstSensor.sensor];
                }
            }
        }
Beispiel #10
0
        // Return true if this slider should be displayed.  Only display a slider if it affects
        // at least one panel which is enabled.
        private bool ShouldBeDisplayed(SMX.SMXConfig config)
        {
            bool[] enabledPanels = config.GetEnabledPanels();

            // Up and center are shown in both modes.
            switch (Type)
            {
            case "up-left":    return(AdvancedModeEnabled && enabledPanels[0]);

            case "up":         return(enabledPanels[1]);

            case "up-right":   return(AdvancedModeEnabled && enabledPanels[2]);

            case "left":       return(AdvancedModeEnabled && enabledPanels[3]);

            case "center":     return(enabledPanels[4]);

            case "right":      return(AdvancedModeEnabled && enabledPanels[5]);

            case "down-left":  return(AdvancedModeEnabled && enabledPanels[6]);

            case "down":       return(AdvancedModeEnabled && enabledPanels[7]);

            case "down-right": return(AdvancedModeEnabled && enabledPanels[8]);

            // Show cardinal and corner if at least one panel they affect is enabled.
            case "cardinal":   return(!AdvancedModeEnabled && (enabledPanels[3] || enabledPanels[5] || enabledPanels[8]));

            case "corner":     return(!AdvancedModeEnabled && (enabledPanels[0] || enabledPanels[2] || enabledPanels[6] || enabledPanels[8]));

            default:           return(true);
            }
        }
Beispiel #11
0
        protected override void OnClick()
        {
            if (AdvancedModeEnabled)
            {
                // Stop forcing advanced mode on, and sync the thresholds so we exit advanced mode.
                ForcedOn = false;

                foreach (Tuple <int, SMX.SMXConfig> activePad in ActivePad.ActivePads())
                {
                    int           pad    = activePad.Item1;
                    SMX.SMXConfig config = activePad.Item2;
                    ConfigPresets.SyncUnifiedThresholds(ref config);
                    SMX.SMX.SetConfig(pad, config);
                }
                CurrentSMXDevice.singleton.FireConfigurationChanged(this);
            }
            else
            {
                // Enable advanced mode.
                ForcedOn = true;
            }

            // Refresh the UI.
            LoadUIFromConfig(ActivePad.GetFirstActivePadConfig());
        }
 // Return true if the config matches, only comparing values that we set in presets.
 static private bool SamePreset(SMX.SMXConfig config1, SMX.SMXConfig config2)
 {
     // These aren't arrays for compatibility reasons.
     if (config1.panelThreshold0High != config2.panelThreshold0High ||
         config1.panelThreshold1High != config2.panelThreshold1High ||
         config1.panelThreshold2High != config2.panelThreshold2High ||
         config1.panelThreshold3High != config2.panelThreshold3High ||
         config1.panelThreshold4High != config2.panelThreshold4High ||
         config1.panelThreshold5High != config2.panelThreshold5High ||
         config1.panelThreshold6High != config2.panelThreshold6High ||
         config1.panelThreshold7High != config2.panelThreshold7High ||
         config1.panelThreshold8High != config2.panelThreshold8High)
     {
         return(false);
     }
     if (config1.panelThreshold0Low != config2.panelThreshold0Low ||
         config1.panelThreshold1Low != config2.panelThreshold1Low ||
         config1.panelThreshold2Low != config2.panelThreshold2Low ||
         config1.panelThreshold3Low != config2.panelThreshold3Low ||
         config1.panelThreshold4Low != config2.panelThreshold4Low ||
         config1.panelThreshold5Low != config2.panelThreshold5Low ||
         config1.panelThreshold6Low != config2.panelThreshold6Low ||
         config1.panelThreshold7Low != config2.panelThreshold7Low ||
         config1.panelThreshold8Low != config2.panelThreshold8Low)
     {
         return(false);
     }
     return(true);
 }
Beispiel #13
0
        private void LoadUIFromConfig(SMX.SMXConfig config)
        {
            // Make sure SaveToConfig doesn't treat these as the user changing values.
            UpdatingUI = true;

            // Reverse the scaling we applied in SaveToConfig.
            int   PanelIndex = SelectedPanel % 9;
            Color rgb        = Helpers.UnscaleColor(Color.FromRgb(
                                                        config.stepColor[PanelIndex * 3 + 0],
                                                        config.stepColor[PanelIndex * 3 + 1],
                                                        config.stepColor[PanelIndex * 3 + 2]));
            double h, s, v;

            Helpers.ToHSV(rgb, out h, out s, out v);

            // Check for white.  Since the conversion through LightsScaleFactor may not round trip
            // back to exactly #FFFFFF, give some room for error in the value (brightness).
            if (s <= 0.001 && v >= .90)
            {
                // This is white, so set it to the white block at the left edge of the slider.
                HueSlider.Value = HueSlider.Minimum;
            }
            else
            {
                HueSlider.Value = h;
            }

            UpdatingUI = false;
        }
 // Copy the P2 pad configuration to P1.
 //
 // This only copies settings that we actually configure, and it doesn't copy pad
 // colors, which is separate from pad selection.
 void SyncP2FromP1(SMX.SMXConfig config1, SMX.SMXConfig config2)
 {
     // Copy P1's configuration to P2.
     Array.Copy(config1.enabledSensors, config2.enabledSensors, config1.enabledSensors.Count());
     config2.SetLowThresholds(config1.GetLowThresholds());
     config2.SetHighThresholds(config1.GetHighThresholds());
     SMX.SMX.SetConfig(1, config2);
     CurrentSMXDevice.singleton.FireConfigurationChanged(null);
 }
        // Export configurable values in SMXConfig to a JSON string.
        public static string ExportSettingsToJSON(SMX.SMXConfig config)
        {
            Dictionary <string, Object> dict = new Dictionary <string, Object>();
            List <int> panelLowThresholds    = new List <int>();

            panelLowThresholds.Add(config.panelThreshold0Low);
            panelLowThresholds.Add(config.panelThreshold1Low);
            panelLowThresholds.Add(config.panelThreshold2Low);
            panelLowThresholds.Add(config.panelThreshold3Low);
            panelLowThresholds.Add(config.panelThreshold4Low);
            panelLowThresholds.Add(config.panelThreshold5Low);
            panelLowThresholds.Add(config.panelThreshold6Low);
            panelLowThresholds.Add(config.panelThreshold7Low);
            panelLowThresholds.Add(config.panelThreshold8Low);
            dict.Add("panelLowThresholds", panelLowThresholds);

            List <int> panelHighThresholds = new List <int>();

            panelHighThresholds.Add(config.panelThreshold0High);
            panelHighThresholds.Add(config.panelThreshold1High);
            panelHighThresholds.Add(config.panelThreshold2High);
            panelHighThresholds.Add(config.panelThreshold3High);
            panelHighThresholds.Add(config.panelThreshold4High);
            panelHighThresholds.Add(config.panelThreshold5High);
            panelHighThresholds.Add(config.panelThreshold6High);
            panelHighThresholds.Add(config.panelThreshold7High);
            panelHighThresholds.Add(config.panelThreshold8High);
            dict.Add("panelHighThresholds", panelHighThresholds);

            // Store the enabled panel mask as a simple list of which panels are selected.
            bool[]     enabledPanels    = config.GetEnabledPanels();
            List <int> enabledPanelList = new List <int>();

            for (int panel = 0; panel < 9; ++panel)
            {
                if (enabledPanels[panel])
                {
                    enabledPanelList.Add(panel);
                }
            }
            dict.Add("enabledPanels", enabledPanelList);

            // Store panel colors.
            List <string> panelColors = new List <string>();

            for (int PanelIndex = 0; PanelIndex < 9; ++PanelIndex)
            {
                // Scale colors from the hardware value back to the 0-255 value we use in the UI.
                Color color = Color.FromRgb(config.stepColor[PanelIndex * 3 + 0], config.stepColor[PanelIndex * 3 + 1], config.stepColor[PanelIndex * 3 + 2]);
                color = Helpers.UnscaleColor(color);
                panelColors.Add(Helpers.ColorToString(color));
            }
            dict.Add("panelColors", panelColors);

            return(SMXJSON.SerializeJSON.Serialize(dict));
        }
        // The simplified configuration scheme sets thresholds for up, center, cardinal directions
        // and corners.  Rev1 firmware uses those only.  Copy cardinal directions (down) to the
        // other cardinal directions (except for up, which already had its own setting) and corners
        // to the other corners.
        static public void SyncUnifiedThresholds(ref SMX.SMXConfig config)
        {
            // left = right = down (cardinal)
            config.panelThreshold3Low  = config.panelThreshold5Low = config.panelThreshold7Low;
            config.panelThreshold3High = config.panelThreshold5High = config.panelThreshold7High;

            // UL = DL = DR = UR (corners)
            config.panelThreshold0Low  = config.panelThreshold6Low = config.panelThreshold8Low = config.panelThreshold2Low;
            config.panelThreshold0High = config.panelThreshold6High = config.panelThreshold8High = config.panelThreshold2High;
        }
        // If the selected panel isn't enabled for input, select another one.
        private void SelectValidPanel(SMX.SMXConfig config)
        {
            bool[] enabledPanels      = config.GetEnabledPanels();
            int    SelectedPanelIndex = SelectedPanel % 9;

            // If we're not selected, or this button is visible, we don't need to do anything.
            if (!enabledPanels[SelectedPanelIndex])
            {
                SelectedPanel = config.GetFirstEnabledPanel();
            }
        }
        public static void SyncSliderThresholds()
        {
            foreach (Tuple <int, SMX.SMXConfig> activePad in ActivePad.ActivePads())
            {
                SMX.SMXConfig config = activePad.Item2;
                SyncSliderThresholdsForConfig(ref config);
                SMX.SMX.SetConfig(activePad.Item1, config);
            }

            CurrentSMXDevice.singleton.FireConfigurationChanged(null);
        }
        // Set PanelColor.  This widget doesn't change the color, it only reflects the current configuration.
        private void LoadUIFromConfig(LoadFromConfigDelegateArgs args)
        {
            SMX.SMXConfig config = args.controller[getPadNo()].config;

            // Hide disabled color buttons.
            Visibility = isEnabled(args)? Visibility.Visible:Visibility.Hidden;

            Color rgb = getColor();

            PanelColor = new SolidColorBrush(rgb);
        }
        // Update which of the "Leave this application running", etc. blocks to display.
        private void RefreshUploadPadText(LoadFromConfigDelegateArgs args)
        {
            foreach (Tuple <int, SMX.SMXConfig> activePad in ActivePad.ActivePads())
            {
                SMX.SMXConfig config = activePad.Item2;

                bool uploadsSupported = config.masterVersion >= 4;
                LeaveRunning.Visibility = uploadsSupported ? Visibility.Collapsed : Visibility.Visible;
                break;
            }
        }
        static public void SetPreset(string name, ref SMX.SMXConfig config)
        {
            switch (name)
            {
            case "low": SetLowPreset(ref config); return;

            case "normal": SetNormalPreset(ref config); return;

            case "high": SetHighPreset(ref config); return;
            }
        }
        private void Select()
        {
            foreach (Tuple <int, SMX.SMXConfig> activePad in ActivePad.ActivePads())
            {
                int           pad    = activePad.Item1;
                SMX.SMXConfig config = activePad.Item2;

                ConfigPresets.SetPreset(Type, ref config);
                SMX.SMX.SetConfig(pad, config);
            }
            CurrentSMXDevice.singleton.FireConfigurationChanged(this);
        }
        static private void SetHighPreset(ref SMX.SMXConfig config)
        {
            config.panelThreshold7Low =                                                                // cardinal
                                        config.panelThreshold1Low =                                    // up
                                                                    config.panelThreshold2Low = 20;    // corner
            config.panelThreshold7High =                                                               // cardinal
                                         config.panelThreshold1High =                                  // up
                                                                      config.panelThreshold2High = 25; // corner

            config.panelThreshold4Low  = 20;                                                           // center
            config.panelThreshold4High = 30;
            SyncUnifiedThresholds(ref config);
        }
        static private void SetNormalPreset(ref SMX.SMXConfig config)
        {
            config.panelThreshold7Low =                                                                // cardinal
                                        config.panelThreshold1Low =                                    // up
                                                                    config.panelThreshold2Low = 33;    // corner
            config.panelThreshold7High =                                                               // cardinal
                                         config.panelThreshold1High =                                  // up
                                                                      config.panelThreshold2High = 42; // corner

            config.panelThreshold4Low  = 35;                                                           // center
            config.panelThreshold4High = 60;
            SyncUnifiedThresholds(ref config);
        }
Beispiel #25
0
        private void Select()
        {
            foreach (Tuple <int, SMX.SMXConfig> activePad in ActivePad.ActivePads())
            {
                int           pad    = activePad.Item1;
                SMX.SMXConfig config = activePad.Item2;

                ConfigPresets.SetPreset(Type, ref config);
                Console.WriteLine("PresetButton::Select (" + Type + "): " +
                                  config.panelThreshold1Low + ", " + config.panelThreshold4Low + ", " + config.panelThreshold7Low + ", " + config.panelThreshold2Low);
                SMX.SMX.SetConfig(pad, config);
            }
            CurrentSMXDevice.singleton.FireConfigurationChanged(this);
        }
        private void EnabledPanelButtonClicked(object sender, EventArgs e)
        {
            // One of the panel buttons on the panel toggle UI was clicked.  Toggle the
            // panel.
            int button = GetIndexFromButton(sender);

            Console.WriteLine("Clicked " + button);

            // Set the enabled sensor mask on both pads to the state of the UI.
            foreach (Tuple <int, SMX.SMXConfig> activePad in ActivePad.ActivePads())
            {
                int           pad    = activePad.Item1;
                SMX.SMXConfig config = activePad.Item2;

                // This could be done algorithmically, but this is clearer.
                int[] PanelButtonToSensorIndex =
                {
                    0, 0, 1, 1, 2, 2, 3, 3, 4
                };
                byte[] PanelButtonToSensorMask =
                {
                    0xF0, 0x0F,
                    0xF0, 0x0F,
                    0xF0, 0x0F,
                    0xF0, 0x0F,
                    0xF0,
                };
                for (int i = 0; i < 5; ++i)
                {
                    config.enabledSensors[i] = 0;
                }

                for (int Panel = 0; Panel < 9; ++Panel)
                {
                    int  index = PanelButtonToSensorIndex[Panel];
                    byte mask  = PanelButtonToSensorMask[Panel];
                    if (EnabledPanelButtons[Panel].IsChecked == true)
                    {
                        config.enabledSensors[index] |= (byte)mask;
                    }
                }

                // If we're not in "light all panels" mode, sync up autoLightPanelMask
                // with the new enabledSensors.
                config.refreshAutoLightPanelMask();

                SMX.SMX.SetConfig(pad, config);
            }
        }
Beispiel #27
0
        // Set PanelColor.  This widget doesn't change the color, it only reflects the current configuration.
        private void LoadUIFromConfig(SMX.SMXConfig config)
        {
            int PanelIndex = Panel % 9;

            // Hide color buttons for disabled panels.
            bool[] enabledPanels = config.GetEnabledPanels();
            Visibility = enabledPanels[PanelIndex]? Visibility.Visible:Visibility.Hidden;

            Color rgb = Helpers.UnscaleColor(Color.FromRgb(
                                                 config.stepColor[PanelIndex * 3 + 0],
                                                 config.stepColor[PanelIndex * 3 + 1],
                                                 config.stepColor[PanelIndex * 3 + 2]));

            PanelColor = new SolidColorBrush(rgb);
        }
        protected override void OnClick()
        {
            //SMX.SMXConfig firstConfig = ActivePad.GetFirstActivePadConfig();
            foreach (Tuple <int, SMX.SMXConfig> activePad in ActivePad.ActivePads())
            {
                int           pad    = activePad.Item1;
                SMX.SMXConfig config = activePad.Item2;
                config.setLightAllPanelsMode(!LightAllPanels);
                SMX.SMX.SetConfig(pad, config);
            }
            CurrentSMXDevice.singleton.FireConfigurationChanged(this);

            // Refresh the UI.
            //LoadUIFromConfig(firstConfig);
        }
        // A panel is enabled if it's enabled in the panel mask, which can be
        // changed on the advanced tab.
        public override bool isEnabled(LoadFromConfigDelegateArgs args)
        {
            int pad = getPadNo();

            SMX.SMXConfig config = args.controller[pad].config;

            if (!args.controller[pad].info.connected)
            {
                return(false);
            }

            int PanelIndex = Panel % 9;

            bool[] enabledPanels = config.GetEnabledPanels();
            return(enabledPanels[PanelIndex]);
        }
        private void LoadUIFromConfig(SMX.SMXConfig config)
        {
            // The master version doesn't actually matter, but we use this as a signal that the panels
            // have a new enough firmware to support this.
            bool SupportsAdvancedMode = config.masterVersion != 0xFF && config.masterVersion >= 2;

            Visibility = SupportsAdvancedMode? Visibility.Visible:Visibility.Collapsed;

            // If the controller doesn't support advanced mode, make sure advanced mode is disabled.
            if (!SupportsAdvancedMode)
            {
                Properties.Settings.Default.AdvancedMode = false;
            }

            AdvancedModeEnabled = Properties.Settings.Default.AdvancedMode;
        }