예제 #1
0
        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");
        }
예제 #2
0
        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");
        }
예제 #3
0
 public ArduinoSketchT4(ConfigurationOptions configurationOptions, ArduinoPins pins)
 {
     this.configurationOptions = configurationOptions;
     this.pins = pins;
 }
예제 #4
0
 private void GenerateSketch()
 {
     int numberTM1640 = 0;
     int numberTM1638 = 0;
     foreach (var unit in configurationOptions.DisplayUnitConfigurations)
     {
         if (unit.IsTM1640)
         {
             numberTM1640++;
         }
         else
         {
             numberTM1638++;
         }
     }
     var pins = new ArduinoPins
                    {
                        ClockPin = numberTM1638 > 0 ? this.ClockPinCBox.SelectedIndex : -1,
                        DataPin = numberTM1638 > 0 ? this.DataPinCBox.SelectedIndex : -1,
                        UnitStrobePins = numberTM1638 > 0 ? this.units.Select(item => item.SelectedIndex).ToList() : new List<int> { -1 },
                        TM1640DataPins = numberTM1640 > 0 ? this.tm1640Datas.Select(item => item.SelectedIndex).ToList() : new List<int> { -1 },
                        TM1640ClockPins = numberTM1640 > 0 ?
                            this.tm1640Clocks.Select(item => item.SelectedIndex).ToList() : new List<int> { -1 }
                    };
     ArduinoSketch.GenerateSketch(this.configurationOptions, pins);
 }