<commit_before>﻿using System;
using System.IO.Ports;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace ColorControl
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Color _color;
        private readonly SerialPort _arduinoPort;

        public MainWindow()
        {
            InitializeComponent();
            Closed += MainWindow_Closed;
            _color = new Color() { A = 255, R = 0, G = 0, B = 0 };
            try
            {
                _arduinoPort = new SerialPort(SerialPort.GetPortNames().First(), 115200);
                _arduinoPort.Open();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Exception");
                throw;
            }
        }

        void MainWindow_Closed(object sender, EventArgs e)
        {
            if (_arduinoPort != null)
            {
                if (_arduinoPort.IsOpen)
                _arduinoPort.Close();
            }
        }

        private void Slider_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            SetColorText((int)(((Slider)sender).Value), ReturnPositionIndex((Slider)sender));
            ColorOutGrid.Background = new SolidColorBrush(_color);
            PrintColorToSerial(_color);
        }

        private void PrintColorToSerial(Color xcolor)
        {
            try
            {
                _arduinoPort.Write(new byte[] { (byte)'#', xcolor.R, xcolor.G, xcolor.B }, 0, 4);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Exception");<commit_msg>Turn off light when closed<commit_after>﻿using System;
using System.IO.Ports;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace ColorControl
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Color _color;
        private readonly SerialPort _arduinoPort;

        public MainWindow()
        {
            InitializeComponent();
            Closed += MainWindow_Closed;
            _color = new Color() { A = 255, R = 0, G = 0, B = 0 };
            try
            {
                _arduinoPort = new SerialPort(SerialPort.GetPortNames().First(), 115200);
                _arduinoPort.Open();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Exception");
                throw;
            }
        }

        void MainWindow_Closed(object sender, EventArgs e)
        {
            if (_arduinoPort != null)
            {
                if (_arduinoPort.IsOpen)
                {
                    PrintColorToSerial(Colors.Black);
                    _arduinoPort.Close();
                }
            }
        }

        private void Slider_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            SetColorText((int)(((Slider)sender).Value), ReturnPositionIndex((Slider)sender));
            ColorOutGrid.Background = new SolidColorBrush(_color);
            PrintColorToSerial(_color);
        }

        private void PrintColorToSerial(Color xcolor)
        {
            try
            {
                _arduinoPort.Write(new byte[] { (byte)'#', xcolor.R, xcolor.G, xcolor.B }, 0, 4);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Exception");
{'fraction_non_alphanumeric': 0.09786428764530955, 'fraction_numerical': 0.007569613409029468, 'mean_word_length': 1.6485325697924123, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5618715', 'n_tokens_mistral': 1007, 'n_tokens_neox': 948, 'n_words': 206}