public static void GenerateSketch(ConfigurationOptions configurationOptions, ArduinoPins pins) { string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\iRduino\\"; // Configure save file dialog box var dlg = new SaveFileDialog { FileName = configurationOptions.Name, DefaultExt = ".ino", InitialDirectory = documentsPath, Filter = "Arduino Sketch (.ino)|*.ino" }; // Show save file dialog box bool? result = dlg.ShowDialog(); // Process save file dialog box results if (result != true) return; // Save document string fileLocation = dlg.FileName; int startOfName = fileLocation.LastIndexOf("\\", StringComparison.Ordinal); int startOfExtension = fileLocation.LastIndexOf('.'); if (startOfName < startOfExtension) { string name = fileLocation.Substring(startOfName+1,startOfExtension-startOfName-1); if (name.Length < startOfName - 1) { if (fileLocation.Substring(startOfName - name.Length, name.Length) != name) { //directory not valid fileLocation = fileLocation.Insert(startOfName + 1, String.Format("{0}\\",name)); } } } FileInfo file = new FileInfo(fileLocation); if (file.Directory != null) { file.Directory.Create(); // If the directory already exists, this method does nothing. } ArduinoSketchT4 sketch = new ArduinoSketchT4(configurationOptions, pins); String sketchContent = sketch.TransformText(); File.WriteAllText(fileLocation, sketchContent); MessageBox.Show("Finished Saving Arduino Sketch"); }
private void PageLoaded1(object sender, RoutedEventArgs e) { this.SerialPortSpeedLabel.IsEnabled = false; this.temp = (ConfigurationOptions)this.DataContext; this.numberTM1640 = 0; this.numberTM1638 = 0; for (var x = 2; x <= 50; x++) { this.FuelLapsCBox.Items.Add(x.ToString(CultureInfo.InvariantCulture)); } foreach (var item in Classes.AdvancedOptions.SerialSpeeds) { this.SerialSpeedCBox.Items.Add(item.ToString(CultureInfo.InvariantCulture)); } foreach (var unit in this.temp.DisplayUnitConfigurations) { if (unit.IsTM1640) { this.numberTM1640++; } else { this.numberTM1638++; } } this.RecommendSpeed.Content = Classes.AdvancedOptions.CalculateRecommendSerialSpeed(Classes.AdvancedOptions.ParseRefreshRatesString(temp.DisplayRefreshRate), Classes.AdvancedOptions.ParseRefreshRatesString(temp.LEDRefreshRate), this.numberTM1638, this.numberTM1640); //databinding var useCustomSpeedBinding = new Binding("UseCustomSerialSpeed") { Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(this.UseCustomSpeedCheck, ToggleButton.IsCheckedProperty, useCustomSpeedBinding); var serialSpeedBinding = new Binding("SerialPortSpeed") { Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(this.SerialSpeedCBox, Selector.SelectedValueProperty, serialSpeedBinding); var logMessagesBinding = new Binding("LogArduinoMessages") { Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(this.LogMessagesCheck, ToggleButton.IsCheckedProperty, logMessagesBinding); var useCustomFuelOptionsBinding = new Binding("UseCustomFuelCalculationOptions") { Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(this.UseCustomFuelOptionsCheck, ToggleButton.IsCheckedProperty, useCustomFuelOptionsBinding); var useWeightedFuelBinding = new Binding("UseWeightedFuelCalculations") { Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(this.WeightedFuelCheck, ToggleButton.IsCheckedProperty, useWeightedFuelBinding); var fuelLapsBinding = new Binding("FuelCalculationLaps") { Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(this.FuelLapsCBox, Selector.SelectedIndexProperty, fuelLapsBinding); }
private void DuplicateConfClick() { var temp = new ConfigurationOptions(); var random = new Random(); temp.LoadConfiguration(this.hostApp.DisplayMngr.CurrentConfiguration, this.hostApp.DisplayMngr.Dictionarys); temp.FileLocation = ""; temp.Name += "-Duplicate" + random.Next(0, 100).ToString(CultureInfo.InvariantCulture); Configuration temp2 = temp.SaveConfiguration(this.hostApp.DisplayMngr.Dictionarys); this.hostApp.DisplayMngr.Configurations.Add(temp2); this.hostApp.DisplayMngr.CurrentConfiguration = temp2; this.hostApp.CurrentConfigurationLabel.Content = temp2.Name; this.hostApp.TrySetComPort(temp2.SerialPortSettings.PreferredComPort); ReloadConfList(); }
private void CurrentConfigurationCBoxSelectionChanged(object sender, SelectionChangedEventArgs e) { if (CurrentConfigurationCBox.SelectedIndex >= 0) { Configuration temp = null; string confName = CurrentConfigurationCBox.SelectedItem.ToString(); foreach (Configuration conf in this.hostApp.DisplayMngr.Configurations.Where(conf => confName == conf.Name)) { temp = conf; } this.hostApp.DisplayMngr.CurrentConfiguration = temp; if (temp != null) { this.hostApp.CurrentConfigurationLabel.Content = temp.Name; this.hostApp.TrySetComPort(temp.SerialPortSettings.PreferredComPort); } else { this.hostApp.CurrentConfigurationLabel.Content = "None Loaded!"; } if (this.hostApp.DisplayMngr.CurrentConfiguration != null) this.hostApp.DisplayMngr.Intensity = this.hostApp.DisplayMngr.CurrentConfiguration.TMDisplaySettings.Intensity; this.hostApp.CheckCurrentConf(); if (this.hostApp.DisplayMngr.CurrentConfiguration != null) { if (!string.IsNullOrEmpty(this.hostApp.DisplayMngr.CurrentConfiguration.FileLocation)) { //write new current.opt string path = hostApp.DocumentsPath + "current.opt"; using (var outfile = new StreamWriter(path)) { outfile.Write(this.hostApp.DisplayMngr.CurrentConfiguration.FileLocation); } } this.configurationOptions = new ConfigurationOptions(); this.configurationOptions.LoadConfiguration(this.hostApp.DisplayMngr.CurrentConfiguration, this.hostApp.DisplayMngr.Dictionarys); } SetPage(PageTypes.Configuration, UnitToSet); RebuildTree(); } if (this.CurrentConfigurationCBox.SelectedIndex != -1) { return; } this.hostApp.DisplayMngr.CurrentConfiguration = null; this.hostApp.CurrentConfigurationLabel.Content = "None Loaded"; this.hostApp.CheckCurrentConf(); }
private void PageLoaded1(object sender, RoutedEventArgs e) { this.updateUiTimer = new DispatcherTimer {Interval = new TimeSpan(0, 0, 0, 0, 200)}; this.updateUiTimer.Tick += this.UpdateUiTimerTick; this.joysticks = ControllerDevice.Available(); foreach (ControllerDevice joystickDevice in this.joysticks) { this.JoyDevicesCBox.Items.Add(joystickDevice.Name); } this.Temp = (ConfigurationOptions) this.DataContext; this.JoyButtonCBoxs = new List<ComboBox> { this.JoyButtonCBox1, this.JoyButtonCBox2, this.JoyButtonCBox3, this.JoyButtonCBox4 }; this.ButtonFunctionsCBoxs = new List<ComboBox> { this.ButtonFunctionCBox1, this.ButtonFunctionCBox2, this.ButtonFunctionCBox3, this.ButtonFunctionCBox4 }; this.ButtonOptionsCBoxs = new List<ComboBox> { this.ButtonOptionCBox1, this.ButtonOptionCBox2, this.ButtonOptionCBox3, this.ButtonOptionCBox4 }; this.ButtonScreensCBoxs = new List<ComboBox> { this.ButtonScreenCBox1, this.ButtonScreenCBox2, this.ButtonScreenCBox3, this.ButtonScreenCBox4 }; //populate combo boxs foreach (var butFunc in this.Temp.Dictionarys.ButtonFunctions) { foreach (ComboBox cbox in this.ButtonFunctionsCBoxs) { cbox.Items.Add(butFunc.Value.Name); } } foreach (ComboBox cBox in this.ButtonScreensCBoxs) { cBox.IsEnabled = true; cBox.Items.Add("All"); for (int i = 1; i <= this.Temp.NumberDisplays + 1; i++) { cBox.Items.Add(i.ToString(CultureInfo.InvariantCulture)); } } //data binding here!!! for (int x = 0; x < NumberButtonsPerPage; x++) { var buttonFuncBinding = new Binding(String.Format("ControllerConfigurations[{0}].ButtonFunctions[{1}]", this.Temp.EditNumber, x)) { Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(this.ButtonFunctionsCBoxs[x], Selector.SelectedValueProperty, buttonFuncBinding); var buttonOptBinding = new Binding(String.Format("ControllerConfigurations[{0}].ButtonOptions[{1}]", this.Temp.EditNumber, x)) { Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(this.ButtonOptionsCBoxs[x], Selector.SelectedValueProperty, buttonOptBinding); var buttonScreenBinding = new Binding(String.Format("ControllerConfigurations[{0}].ButtonOptionsScreens[{1}]", this.Temp.EditNumber, x)) { Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(this.ButtonScreensCBoxs[x], Selector.SelectedIndexProperty, buttonScreenBinding); var buttonNumberBinding = new Binding(String.Format("ControllerConfigurations[{0}].ButtonNumbers[{1}]", this.Temp.EditNumber, x)) { Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(this.JoyButtonCBoxs[x], Selector.SelectedIndexProperty, buttonNumberBinding); } if (this.Temp.ControllerConfigurations[this.Temp.EditNumber].Selected) { //try select correct device in dropdown menu for (int p = 0; p < this.joysticks.Count; p++) { if (this.joysticks[p].Guid == this.Temp.ControllerConfigurations[this.Temp.EditNumber].DeviceGuid) { //found this.JoyDevicesCBox.SelectedIndex = p; } } } }
public ArduinoSketchT4(ConfigurationOptions configurationOptions, ArduinoPins pins) { this.configurationOptions = configurationOptions; this.pins = pins; }
public GenerateArduinoWizard(ConfigurationOptions confOpts) { InitializeComponent(); this.configurationOptions = confOpts; }