Exemple #1
0
        // Returns true when file settings are active
        public bool Startup()
        {
            if (RawAccelSettings.Exists())
            {
                try
                {
                    RawAccelSettings = RawAccelSettings.Load(() => MakeGUISettingsFromFields());
                    UpdateFieldsFromGUISettings();
                    if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup)
                    {
                        TryUpdateAccel(RawAccelSettings.AccelerationSettings);
                    }
                    return(RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup);
                }
                catch (JsonException e)
                {
                    Console.WriteLine($"bad settings: {e}");
                }
            }

            RawAccelSettings = new RawAccelSettings(
                DriverInterop.GetActiveSettings(),
                MakeGUISettingsFromFields());
            RawAccelSettings.Save();
            return(true);
        }
Exemple #2
0
        public AccelGUI(
            RawAcceleration accelForm,
            AccelCalculator accelCalculator,
            AccelCharts accelCharts,
            SettingsManager settings,
            ApplyOptions applyOptions,
            Button writeButton,
            ButtonBase toggleButton,
            MouseWatcher mouseWatcher,
            ToolStripMenuItem scaleMenuItem)
        {
            AccelForm         = accelForm;
            AccelCalculator   = accelCalculator;
            AccelCharts       = accelCharts;
            ApplyOptions      = applyOptions;
            WriteButton       = writeButton;
            ToggleButton      = (CheckBox)toggleButton;
            ScaleMenuItem     = scaleMenuItem;
            Settings          = settings;
            DefaultButtonFont = WriteButton.Font;
            SmallButtonFont   = new Font(WriteButton.Font.Name, WriteButton.Font.Size * Constants.SmallButtonSizeFactor);
            MouseWatcher      = mouseWatcher;

            ScaleMenuItem.Click   += new System.EventHandler(OnScaleMenuItemClick);
            WriteButton.Click     += new System.EventHandler(OnWriteButtonClick);
            ToggleButton.Click    += new System.EventHandler(OnToggleButtonClick);
            AccelForm.FormClosing += new FormClosingEventHandler(SaveGUISettingsOnClose);

            ButtonTimerInterval = Convert.ToInt32(DriverInterop.WriteDelayMs);
            ButtonTimer         = new Timer();
            ButtonTimer.Tick   += new System.EventHandler(OnButtonTimerTick);

            ChartRefresh = SetupChartTimer();

            bool settingsActive = Settings.Startup();

            SettingsNotDefault = !Settings.RawAccelSettings.IsDefaultEquivalent();

            if (settingsActive)
            {
                LastToggleChecked    = SettingsNotDefault;
                ToggleButton.Enabled = LastToggleChecked;
                RefreshOnRead(Settings.RawAccelSettings.AccelerationSettings);
            }
            else
            {
                DriverSettings active           = DriverInterop.GetActiveSettings();
                bool           activeNotDefault = !RawAccelSettings.IsDefaultEquivalent(active);

                LastToggleChecked    = activeNotDefault;
                ToggleButton.Enabled = SettingsNotDefault || activeNotDefault;
                RefreshOnRead(active);
            }

            SetupButtons();
            AccelForm.DoResize();
        }
Exemple #3
0
        public static SettingsErrors SendToDriverSafe(DriverSettings settings)
        {
            var errors = DriverInterop.GetSettingsErrors(settings);

            if (errors.Empty())
            {
                SendToDriver(settings);
            }
            return(errors);
        }
Exemple #4
0
        static void Send(JToken settingsToken)
        {
            var settings = settingsToken.ToObject <DriverSettings>();

            var errors = DriverInterop.GetSettingsErrors(settings);

            if (errors.Empty())
            {
                DriverInterop.Write(settings);
                return;
            }

            Show($"Bad settings:\n\n{errors}");
        }
Exemple #5
0
        static void Send(JToken settingsToken)
        {
            var settings = settingsToken.ToObject <DriverSettings>();

            var errors = DriverInterop.GetSettingsErrors(settings);

            if (errors.Empty())
            {
                DriverInterop.Write(settings);
                return;
            }

            foreach (var err in errors.x)
            {
                Console.WriteLine(err + (settings.combineMagnitudes ? "" : " (x)"));
            }
            foreach (var err in errors.y)
            {
                Console.WriteLine(err + " (y)");
            }
        }
Exemple #6
0
        public void Startup()
        {
            if (RawAccelSettings.Exists())
            {
                try
                {
                    RawAccelSettings = RawAccelSettings.Load(() => MakeGUISettingsFromFields());
                    UpdateFieldsFromGUISettings();
                    UpdateActiveAccelFromFileSettings(RawAccelSettings.AccelerationSettings);
                    return;
                }
                catch (JsonException e)
                {
                    Console.WriteLine($"bad settings: {e}");
                }
            }

            RawAccelSettings = new RawAccelSettings(
                DriverInterop.GetActiveSettings(),
                MakeGUISettingsFromFields());
            RawAccelSettings.Save();
        }
Exemple #7
0
 public static void SendToDriver(DriverSettings settings)
 {
     new Thread(() => DriverInterop.Write(settings)).Start();
 }