public CommandStateHolder(CommandStateHolderSettings init)
        {
            UpdateIPAndPort(init.IpAddress, init.Port);
            BroadcastResolution = init.UDPPacketsPerSecond;
            AccelerationTime = init.AccelerationTime;
            AccelerationEnabled = init.Acceleration;
            MaxSpeed = init.MaxSpeed;
            FrontLigthsState = init.FrontLightsState;
            RearLigthsState = init.RearLigthsState;

            sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            _keyStates = new Dictionary<Keys, int>();
            _keysToWatch = new List<Keys>();

            _keysToWatch.Add(MOVE_FORWARD_KEY);
            _keysToWatch.Add(MOVE_BACKWARDS_KEY);
            _keysToWatch.Add(TURN_LEFT_KEY);
            _keysToWatch.Add(TURN_RIGHT_KEY);
            _keysToWatch.Add(HORN_KEY);
            _keysToWatch.Add(FRONT_LIGHTS_KEY);
            _keysToWatch.Add(REAR_LIGHTS_KEY);

            InitializeKeyStates(_keyStates, _keysToWatch);
        }
示例#2
0
        public MainForm()
        {
            InitializeComponent();

            CommandStateHolderSettings cmdSettings = new CommandStateHolderSettings()
            {
                IpAddress = BROADCAST_IP,
                Port = BROADCAST_PORT,
                UDPPacketsPerSecond = BROADCAST_PER_SEC,
                AccelerationTime = ACCELERATION_TIME_MS,
                Acceleration = ACCELERATION_ENABLED,
                MaxSpeed = DEFAULT_MAX_SPEED,
                FrontLightsState = DEFAULT_HEADLIGHTS_STATUS,
                RearLigthsState = DEFAULT_REARLIGHTS_STATUS
            };

            cmd = new CommandStateHolder(cmdSettings);

            timer = GetNewTimer(1000 / BROADCAST_PER_SEC);

            tb_udpPacketsPerSec.Value = BROADCAST_PER_SEC;
            tb_accelerationTimeInMs.Value = ACCELERATION_TIME_MS;
            check_Acceleration.Checked = ACCELERATION_ENABLED;

            timer.Enabled = false;
            isRunning = false;

            InitGUI();
        }