Example #1
0
        public void switchSetRepair()
        {
            List <long> semaphoreIDs = new List <long>();
            var         semaphores   = from s in Global.LocalStorage.Semaphore_Selector()
                                       where s.signal == Signal.GO
                                       select s.CellID;

            semaphoreIDs = semaphores.ToList();
            foreach (var semaphoreID in semaphoreIDs)
            {
                List <List <long> > routeFollows = new List <List <long> >();
                var routes = from r in Global.LocalStorage.Route_Selector()
                             where r.entry == semaphoreID
                             select r.follows;
                routeFollows = routes.ToList();
                foreach (var switchPositionIDs in routeFollows)
                {
                    foreach (var swithcPositionID in switchPositionIDs)
                    {
                        SwitchPosition swP;
                        using (var switchPosition = Global.LocalStorage.UseSwitchPosition(swithcPositionID))
                        {
                            swP = new SwitchPosition(cell_id: swithcPositionID, position: switchPosition.position, target: switchPosition.target);
                        }
                        using (var sw = Global.LocalStorage.UseSwitch(swP.target))
                        {
                            if (sw.currentPosition != swP.position)
                            {
                                sw.currentPosition = swP.position;
                            }
                        }
                    }
                }
            }
        }
Example #2
0
 public TwoPositionSwitchInstrument()
 {
     Name            = "Switch";
     Position1       = new SwitchPosition(this, "PosA");
     Position2       = new SwitchPosition(this, "PosB");
     CurrentPosition = new SwitchPosition(this, "");
 }
Example #3
0
        public override void MouseDown(System.Windows.Point location)
        {
            if (NonClickableZones != null)
            {
                foreach (NonClickableZone zone in NonClickableZones)
                {
                    if (SwitchPosition.ToString() == zone.PositionWhenApplicable.ToString() && zone.isClickInZone(location))
                    {
                        zone.ChildVisual.MouseDown(new System.Windows.Point(location.X - (zone.ChildVisual.Left - this.Left), location.Y - (zone.ChildVisual.Top - this.Top)));
                        return; //we get out to let the ChildVisual using the click
                    }
                }
            }

            base.MouseDown(location);

            if (SwitchPosition == ToggleSwitchPosition.One)
            {
                if (NonClickableZones != null)
                {
                    foreach (NonClickableZone zone in NonClickableZones)
                    {
                        switch (zone.ChildVisual.GetType().ToString())
                        {
                        case "GadrocsWorkshop.Helios.Controls.ToggleSwitch":
                            ToggleSwitch tSwitch = (ToggleSwitch)zone.ChildVisual;
                            tSwitch.SwitchPosition = zone.GuardedChildPosition;
                            break;
                        }
                    }
                }
            }
        }
    // Translate the data and edit the parameters of the virtual weapon
    public override void PacketTranslater(byte[] packet) // if reading problems occur, this can be due to the endian (the sequence in which the bits are send, LSB first or last?)
    {
        // Create storage containers
        byte[] triggerValue       = new byte[4];
        byte[] movablePiecesValue = new byte[4];
        byte[] magazineIDValue    = new byte[4];
        byte[] flags = new byte[4];


        // Store data in containers
        Array.Copy(packet, 0, triggerValue, 0, 1); //Copy(Array sourceArray, long sourceIndex, Array destinationArray, long destinationIndex, long length)
        Array.Copy(packet, 1, movablePiecesValue, 0, 1);
        Array.Copy(packet, 2, magazineIDValue, 0, 1);
        Array.Copy(packet, 3, flags, 0, 1);

        // Set current values
        triggerCurrentValue       = BitConverter.ToInt32(triggerValue, 0);
        movablePiecesCurrentValue = BitConverter.ToInt32(movablePiecesValue, 0);// BitConverter start reading at a certain index till the end.
        magazineID = BitConverter.ToInt32(magazineIDValue, 0);
        byte flagByte = flags[0];

        magazinePresent = !(flagByte % 2 == 0);  // Last bit in the flag byte shows the mag status. So, if there is no mag present the value of the flag is even.

        weaponType = GetWeaponTypeOutOfData(packet);

        byte switchPositionByte = (byte)(flagByte * Math.Pow(2, weaponTypesBits)); // bit shift left the enough of times to get rid of the used MSB's to encode the weapontype

        switchPositionByte    /= (byte)Math.Pow(2, weaponTypesBits + 1);           // BSR enough times to set the bits needed to recognize the selector switches position as LSB's
        selectorSwitchPosition = (SwitchPosition)switchPositionByte;
    }
    private DateTime lastUpdate; // Used to check if a weapon has been active


    // Translate the data and edit the parameters of the virtual weapon
    public void PacketTranslater(byte[] packet) // if reading problems occur, this can be due to the endian (the sequence in which the bits are send, LSB first or last?)
    {
        // Check if the data is still send by the same type of weapon. It should be impossible for a weapon to change type (this is just in case)
        // If the client keeps sending packets with the wrong weapontype tag, it will be considered as inactive and the weapon will get deleted after a certain time
        if (GetWeaponTypeOutOfData(packet) == weaponType)
        {
            // Create storage containers
            byte[] triggerValue       = new byte[4];
            byte[] movablePiecesValue = new byte[4];
            byte[] magazineIDValue    = new byte[4];
            byte[] flags = new byte[4];


            // Store data in containers
            Array.Copy(packet, 0, triggerValue, 0, 1); //Copy(Array sourceArray, long sourceIndex, Array destinationArray, long destinationIndex, long length)
            Array.Copy(packet, 1, movablePiecesValue, 0, 1);
            Array.Copy(packet, 2, magazineIDValue, 0, 1);
            Array.Copy(packet, 3, flags, 0, 1);

            // Set current values
            triggerCurrentValue       = BitConverter.ToInt32(triggerValue, 0);
            movablePiecesCurrentValue = BitConverter.ToInt32(movablePiecesValue, 0);// BitConverter start reading at a certain index till the end.
            magazineID = BitConverter.ToInt32(magazineIDValue, 0);
            byte flagByte = flags[0];

            magazinePresent = !(flagByte % 2 == 0);                                        // Last bit in the flag byte shows the mag status. So, if there is no mag present the value of the flag is even.

            byte switchPositionByte = (byte)(flagByte * Math.Pow(2, GetWeaponTypeBits())); // bit shift left the enough of times to get rid of the used MSB's to encode the weapontype
            switchPositionByte    /= (byte)Math.Pow(2, GetWeaponTypeBits() + 1);           // BSR enough times to set the bits needed to recognize the selector switches position as LSB's
            selectorSwitchPosition = (SwitchPosition)switchPositionByte;

            lastUpdate = DateTime.Now;// Use of this has to be reconsidered => it takes too much time
        }
    }
Example #6
0
 public void ResetDefaultStatus()
 {
     position_     = SwitchPosition.PosError;
     isOccupied_   = true;
     isRouteLock_  = true;
     isBlocked_    = true;
     isSingleLock_ = true;
 }
Example #7
0
 public void SwitchRight()
 {
     if(pos != SwitchPosition.Right) {
         pos = SwitchPosition.Right;
         target.Switch();
         switchMesh.localRotation = Quaternion.Euler(new Vector3(0, 0, -90));
     }
 }
Example #8
0
 public void SetPosition(SwitchPosition pos)
 {
     Position1.IsActive = false;
     Position2.IsActive = false;
     Position3.IsActive = false;
     Positions.ForEach(x => x.IsActive = false);
     pos.IsActive = true;
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SwitchIntrument"/> class.
 /// </summary>
 public DummySwitchIntrument()
 {
     Name      = "Sw";
     Position1 = new SwitchPosition(this, "Pos1");
     Position2 = new SwitchPosition(this, "Pos2");
     Position3 = new SwitchPosition(this, "Pos3");
     Positions = new List <SwitchPosition> {
         new SwitchPosition(this, "PosN1"), new SwitchPosition(this, "PosN2"), new SwitchPosition(this, "PosN3")
     };
 }
 // Start is called before the first frame update
 void Start()
 {
     triggerMinRot           = 0;
     triggerMaxRot           = 15;
     triggerTransform        = transform.Find("Trigger").transform;
     movablePiecesTransform  = transform.Find("Movable Pieces").transform;
     selectorSwitchTransform = transform.Find("Selector Switch").transform;
     magazineObject          = transform.Find("Magazine").gameObject;
     selectorSwitchPosition  = SwitchPosition.SAFE;
 }
Example #11
0
 public void FlipSwitchPosition()
 {
     if (SwitchPosition == SwitchPosition.Up)
     {
         SwitchPosition = SwitchPosition.Down;
     }
     else
     {
         SwitchPosition = SwitchPosition.Up;
     }
 }
Example #12
0
 public Prisoner(
     IDomainIdentifier identifier,
     PersonOnShipRole personOnShipRole     = PersonOnShipRole.Prisoner,
     int numberOfTimesToFlipFirstSwitch    = 2,
     SwitchPosition flipFirstSwitchPostion = SwitchPosition.Down
     ) : base(personOnShipRole)
 {
     Identifier = identifier;
     NumberOfTimesToFlipFirstSwitch = numberOfTimesToFlipFirstSwitch;
     FlipFirstSwitchPostion         = flipFirstSwitchPostion;
 }
        // private methods...
        #region CheckSwitchPosition
        void CheckSwitchPosition(byte[] readData)
        {
            byte switchPos = (byte)(readData[11] & 16);

            if (switchPos == 0)
            {
                switchPosition = SwitchPosition.Down;
            }
            else
            {
                switchPosition = SwitchPosition.Up;
            }
        }
Example #14
0
        public SwitchBehaviorViewModel(bool IsModeEditor, object OriginPlugin, int SelectedSwitchTypeIndex = (int)SwitchType.OnOnOn,
                                       SwitchPosition SelectedDefaultPosition = SwitchPosition.One, string Nothings = null,
                                       string SelectedPanelUpName             = null, string SelectedPanelDnName = null)
        {
            this.OriginPlugin            = OriginPlugin;
            this.Nothings                = Nothings;
            this.SelectedSwitchTypeIndex = SelectedSwitchTypeIndex;
            this.SelectedDefaultPosition = SelectedDefaultPosition;
            this.SelectedPanelDnName     = SelectedPanelDnName ?? Nothings;
            this.SelectedPanelUpName     = SelectedPanelUpName ?? Nothings;
            Has3Images = true;

            Name = "Behavior";
        }
Example #15
0
        public Switch(BaseUDPInterface sourceInterface, string deviceId, string argId, SwitchPosition[] positions, string device, string name, string exportFormat, bool everyFrame)
            : base(sourceInterface)
        {
            _id = argId;
            _format = exportFormat;
            _everyframe = everyFrame;

            _positions = positions;
            _sendAction = new string[_positions.Length];
            _sendStopAction = new string[_positions.Length];
            _exitAction = new string[_positions.Length];

            _valueDescriptions = "";
            for (int i = 0; i < _positions.Length; i++)
            {
                SwitchPosition position = _positions[i];

                if (_valueDescriptions.Length > 0)
                {
                    _valueDescriptions += ",";
                }
                _valueDescriptions += (i + 1).ToString() + "=" + position.Name;
                if (position.Action != null)
                {
                    _sendAction[i] = "C" + deviceId + "," + position.Action + "," + position.ArgValue;
                }
                if (position.StopAction != null)
                {
                    _sendStopAction[i] = "C" + deviceId + "," + position.StopAction + "," + position.StopActionValue;
                }
                if (position.ExitValue != null)
                {
                    _exitAction[i] = "C" + deviceId + "," + position.Action + "," + position.ExitValue;
                }
            }

            _releaseAction = new HeliosAction(sourceInterface, device, name, "release", "Releases pressure on current position (allows momentary and electronically held switch to revert to another position if necessary).");
            _releaseAction.Execute += new HeliosActionHandler(Release_Execute);
            Actions.Add(_releaseAction);

            _value = new HeliosValue(sourceInterface, BindingValue.Empty, device, name, "Current position of this switch.", _valueDescriptions, BindingValueUnits.Numeric);
            _value.Execute += new HeliosActionHandler(Value_Execute);
            Actions.Add(_value);
            Triggers.Add(_value);
            Values.Add(_value);

            _currentPosition = -1;
        }
Example #16
0
 public void Flip()
 {
     if (_switchPosition == SwitchPosition.Off)
     {
         _switchPosition = SwitchPosition.On;
     }
     else
     {
         _switchPosition = SwitchPosition.Off;
     }
     //System.Console.WriteLine("Switch is {0}", _switchPosition.ToString());
     if (delSwitchAbleDevice != null)
     {
         delSwitchAbleDevice(_switchPosition);
     }
 }
Example #17
0
    // Set the position of the selector switch with the value received from the UDP packet
    private void SetSelectorSwitch(SwitchPosition switchPosition)
    {
        switch (switchPosition)
        {
        case SwitchPosition.SAFE:
            selectorSwitchTransform.localEulerAngles = new Vector3(0, 0, 30);
            break;

        case SwitchPosition.SEMI:
            selectorSwitchTransform.localEulerAngles = new Vector3(0, 0, 0);
            break;

        case SwitchPosition.AUTO:
            selectorSwitchTransform.localEulerAngles = new Vector3(0, 0, -30);
            break;
        }
    }
Example #18
0
        public GuardedSwitch(BaseUDPInterface sourceInterface, string deviceId, string argId, string guardAction, string guardArgId, string guardUpValue, string guardDownValue, SwitchPosition[] positions, string device, string name, string exportFormat, bool everyFrame)
            : base(sourceInterface, deviceId, argId, positions, device, name, exportFormat, everyFrame)
        {
            _guardArgId = guardArgId;
            _guardUpValue = guardUpValue;
            _guardDownValue = guardDownValue;

            _actionData[0] = "C" + deviceId + "," + guardAction + "," + guardUpValue;
            _actionData[1] = "C" + deviceId + "," + guardAction + "," + guardDownValue;

            _guardValue = new HeliosValue(sourceInterface, BindingValue.Empty, device, name + " guard", "Current position of the guard for this switch.", "1 = Up, 2 = Down", BindingValueUnits.Numeric);
            _guardValue.Execute += new HeliosActionHandler(GuardValue_Execute);
            Actions.Add(_guardValue);
            Triggers.Add(_guardValue);
            Values.Add(_guardValue);

            _autoguardPositionAction = new HeliosAction(sourceInterface, device, name, "autoguard set", "Sets the position of this switch, and automatically switches the guard up if necessary.", ValueDescriptions, BindingValueUnits.Numeric);
            _autoguardPositionAction.Execute += new HeliosActionHandler(AutoguardPositionAction_Execute);
            Actions.Add(_autoguardPositionAction);
        }
    // [EXTRA] Set the position of the selector switch
    private void SetSelectorSwitch(SwitchPosition switchPosition)
    {
        switch (switchPosition)
        {
        case SwitchPosition.SAFE:
            selectorSwitchLTransform.localEulerAngles = new Vector3(selectorSwitchMinRot, selectorSwitchLTransform.localEulerAngles.y, selectorSwitchLTransform.localEulerAngles.z);
            selectorSwitchRTransform.localEulerAngles = new Vector3(selectorSwitchMinRot, selectorSwitchRTransform.localEulerAngles.y, selectorSwitchRTransform.localEulerAngles.z);
            break;

        case SwitchPosition.SEMI:
            selectorSwitchLTransform.localEulerAngles = new Vector3(selectorSwitchMaxRot, selectorSwitchLTransform.localEulerAngles.y, selectorSwitchLTransform.localEulerAngles.z);
            selectorSwitchRTransform.localEulerAngles = new Vector3(selectorSwitchMaxRot, selectorSwitchRTransform.localEulerAngles.y, selectorSwitchRTransform.localEulerAngles.z);
            break;

        case SwitchPosition.AUTO:     // Same as SEMI, because there is no AUTO mode on a Five Seven
            selectorSwitchLTransform.localEulerAngles = new Vector3(selectorSwitchMaxRot, selectorSwitchLTransform.localEulerAngles.y, selectorSwitchLTransform.localEulerAngles.z);
            selectorSwitchRTransform.localEulerAngles = new Vector3(selectorSwitchMaxRot, selectorSwitchRTransform.localEulerAngles.y, selectorSwitchRTransform.localEulerAngles.z);
            break;
        }
    }
Example #20
0
 public void OnSwitcChanged(SwitchPosition switchPosition)
 {
     _lightOn = (switchPosition == SwitchPosition.On);
     Console.WriteLine("Lamp {0} is {1}", _name, _lightOn ? "Lightning" : "Dark");
 }
Example #21
0
        public void read()
        {
            TrinityConfig.CurrentRunningMode = RunningMode.Embedded;
            IGraph       g         = new Graph();
            TurtleParser ttlparser = new TurtleParser();

            //El kell helyezni az állományt!
            ttlparser.Load(g, modelPath);

            var typeNode = g.CreateUriNode("rdf:type");
            var triples  = g.GetTriplesWithPredicate(typeNode);

            foreach (var b in triples)
            {
                switch (((UriNode)b.Object).Uri.Fragment)
                {
                case "#Semaphore":
                    int    semaphoreId     = int.Parse(((UriNode)b.Subject).Uri.Fragment.Substring(2));
                    Signal semaphoreSignal = Signal.FAILURE;
                    foreach (var triple in g.GetTriplesWithSubject(b.Subject))
                    {
                        if (triple.Predicate.ToString().Split('#')[1] == "signal")
                        {
                            semaphoreSignal = getSignalFromString(((UriNode)triple.Object).Uri.Fragment.Substring(1));
                        }
                    }
                    Semaphore semaphore = new Semaphore(cell_id: semaphoreId, signal: semaphoreSignal);
                    Global.LocalStorage.SaveSemaphore(semaphore);
                    break;

                case "#Route":
                    int         routeId       = int.Parse(((UriNode)b.Subject).Uri.Fragment.Split('_')[1]);
                    bool        routeActive   = false;
                    int         routeEntry    = -1;
                    int         routeExit     = -1;
                    List <long> routeRequires = new List <long>();
                    List <long> routeFollows  = new List <long>();
                    foreach (var triple in g.GetTriplesWithSubject(b.Subject))
                    {
                        switch (triple.Predicate.ToString().Split('#')[1])
                        {
                        case "active":
                            routeActive = ((LiteralNode)triple.Object).Value == "true";
                            break;

                        case "entry":
                            routeEntry = int.Parse(((UriNode)triple.Object).Uri.Fragment.Substring(2));
                            break;

                        case "exit":
                            routeExit = int.Parse(((UriNode)triple.Object).Uri.Fragment.Substring(2));
                            break;

                        case "requires":
                            routeRequires.Add(int.Parse(((UriNode)triple.Object).Uri.Fragment.Substring(2)));
                            break;

                        case "follows":
                            routeFollows.Add(int.Parse(((UriNode)triple.Object).Uri.Fragment.Substring(2)));
                            break;

                        default:
                            break;
                        }
                    }
                    Route route = new Route(cell_id: routeId, requires: routeRequires, follows: routeFollows, entry: routeEntry, exit: routeExit, active: routeActive);
                    Global.LocalStorage.SaveRoute(route);
                    break;

                case "#Region":
                    int         regionId       = int.Parse(((UriNode)b.Subject).Uri.Fragment.Substring(2));
                    List <long> regionSensors  = new List <long>();
                    List <long> regionElements = new List <long>();
                    foreach (var triple in g.GetTriplesWithSubject(b.Subject))
                    {
                        switch (triple.Predicate.ToString().Split('#')[1])
                        {
                        case "sensors":
                            regionSensors.Add(int.Parse(((UriNode)triple.Object).Uri.Fragment.Substring(2)));
                            break;

                        case "elements":
                            regionElements.Add(int.Parse(((UriNode)triple.Object).Uri.Fragment.Substring(2)));
                            break;

                        default:
                            break;
                        }
                    }
                    Region region = new Region(cell_id: regionId, sensors: regionSensors, elements: regionElements);
                    Global.LocalStorage.SaveRegion(region);
                    break;

                case "#Switch":
                    int         switchId = int.Parse(((UriNode)b.Subject).Uri.Fragment.Substring(2));
                    Position    switchCurrentPosition = Position.FAILURE;
                    List <long> switchMonitoredBy     = new List <long>();
                    foreach (var triple in g.GetTriplesWithSubject(b.Subject))
                    {
                        switch (triple.Predicate.ToString().Split('#')[1])
                        {
                        case "currentPosition":
                            // az Id típusú mezőknél 2 karaktert kell levágni, mert "#_" kezdődik, itt viszont csak a '#' lesz benne
                            switchCurrentPosition = getPositionFromString(((UriNode)triple.Object).Uri.Fragment.Substring(1));
                            break;

                        case "monitoredBy":
                            switchMonitoredBy.Add(int.Parse(((UriNode)triple.Object).Uri.Fragment.Substring(2)));
                            break;

                        default:
                            break;
                        }
                    }
                    Switch sw = new Switch(cell_id: switchId, currentPosition: switchCurrentPosition, monitoredBy: switchMonitoredBy);
                    Global.LocalStorage.SaveSwitch(sw);
                    break;

                case "#Sensor":
                    int    sensorId = int.Parse(((UriNode)b.Subject).Uri.Fragment.Substring(2));
                    Sensor sensor   = new Sensor(cell_id: sensorId);
                    Global.LocalStorage.SaveSensor(sensor);
                    break;

                case "#Segment":
                    int         segmentId          = int.Parse(((UriNode)b.Subject).Uri.Fragment.Substring(2));
                    int         segmentLength      = -1;
                    List <long> segmentSemaphores  = new List <long>();
                    List <long> segmentMonitoredBy = new List <long>();
                    foreach (var triple in g.GetTriplesWithSubject(b.Subject))
                    {
                        switch (triple.Predicate.ToString().Split('#')[1])
                        {
                        case "length":
                            segmentLength = int.Parse(((LiteralNode)triple.Object).Value);
                            break;

                        case "semaphores":
                            segmentSemaphores.Add(int.Parse(((UriNode)triple.Object).Uri.Fragment.Substring(2)));
                            break;

                        case "monitoredBy":
                            segmentMonitoredBy.Add(int.Parse(((UriNode)triple.Object).Uri.Fragment.Substring(2)));
                            break;

                        default:
                            break;
                        }
                    }
                    Segment segment = new Segment(cell_id: segmentId, length: segmentLength, semaphores: segmentSemaphores, monitoredBy: segmentMonitoredBy);
                    Global.LocalStorage.SaveSegment(segment);
                    break;

                case "#SwitchPosition":
                    int      switchPositionId       = int.Parse(((UriNode)b.Subject).Uri.Fragment.Substring(2));
                    Position switchPositionPosition = Position.FAILURE;
                    int      switchPositionRoute    = -1;
                    int      switchPositionTarget   = -1;
                    foreach (var triple in g.GetTriplesWithSubject(b.Subject))
                    {
                        switch (triple.Predicate.ToString().Split('#')[1])
                        {
                        case "position":
                            switchPositionPosition = getPositionFromString(((UriNode)triple.Object).Uri.Fragment.Substring(1));
                            break;

                        case "route":
                            switchPositionRoute = int.Parse(((UriNode)triple.Object).Uri.Fragment.Substring(2));
                            break;

                        case "target":
                            switchPositionTarget = int.Parse(((UriNode)triple.Object).Uri.Fragment.Substring(2));
                            break;

                        default:
                            break;
                        }
                    }
                    SwitchPosition switchPosition = new SwitchPosition(cell_id: switchPositionId, position: switchPositionPosition, route: switchPositionRoute, target: switchPositionTarget);
                    Global.LocalStorage.SaveSwitchPosition(switchPosition);
                    break;

                case "#TrackElement":
                    //egyelőre
                    break;

                default:
                    Console.WriteLine("Error: unknown type: " + ((UriNode)b.Object).Uri.Fragment);
                    break;
                }
            }
            //Global.LocalStorage.SaveStorage();
        }
Example #22
0
 public void SetPosition(SwitchPosition newPosition)
 {
     CurrentPosition.IsActive = false;
     CurrentPosition          = newPosition;
     newPosition.IsActive     = true;
 }
Example #23
0
 public Switch(IDomainIdentifier switchIdentifier, SwitchPosition switchPosition)
 {
     SwitchIdentifier = switchIdentifier;
     SwitchPosition   = switchPosition;
 }
Example #24
0
 public GuardedSwitch(BaseUDPInterface sourceInterface, string deviceId, string argId, string guardAction, string guardArgId, string guardUpValue, string guardDownValue, SwitchPosition[] positions, string device, string name, string exportFormat)
     : this(sourceInterface, deviceId, argId, guardAction, guardArgId, guardUpValue, guardDownValue, positions, device, name, exportFormat, false)
 {
 }
Example #25
0
 public ThreeWayToggleSwitchBehaviorEvent(SwitchType switchtype, SwitchPosition defaultposition, bool indicatorlight)
 {
     SwitchType      = switchtype;
     DefaultPosition = defaultposition;
     IndicatorLight  = indicatorlight;
 }
Example #26
0
 public Switch(BaseUDPInterface sourceInterface, string deviceId, string argId, SwitchPosition[] positions, string device, string name, string exportFormat)
     : this(sourceInterface, deviceId, argId, positions, device, name, exportFormat, false)
 {
 }
Example #27
0
        // Update is called once per frame
        public void Update()
        {
            if (serialPort != null && serialPort.IsOpen)
            {
                serialPort.Write(pingData, 0, pingData.Length);

                serialPort.Read(incomingData, 0, 256);

                if (incomingData[0] == 0x55 && Time.unscaledTime > startTime)
                { // probably positioning data
                    Vector2        leftStick   = Vector2.zero;
                    Vector2        rightStick  = Vector2.zero;
                    SwitchPosition leftSwitch  = SwitchPosition.UP;
                    SwitchPosition rightSwitch = SwitchPosition.UP;
                    float          tiltLever;

                    leftStick.Set(
                        DeadzoneAdjust((float)LittleEndiansToInt(incomingData[43], incomingData[44]) / 1000), // left stick x
                        DeadzoneAdjust((float)LittleEndiansToInt(incomingData[39], incomingData[40]) / 1000)  // left stick y
                        );

                    rightStick.Set(
                        DeadzoneAdjust((float)LittleEndiansToInt(incomingData[31], incomingData[32]) / 1000), // right stick x
                        DeadzoneAdjust((float)LittleEndiansToInt(incomingData[35], incomingData[36]) / 1000)  // right stick y
                        );

                    int rawLeftSwitch  = LittleEndiansToInt(incomingData[47], incomingData[48]);
                    int rawRightSwitch = LittleEndiansToInt(incomingData[51], incomingData[52]);

                    if (rawLeftSwitch > 30)
                    {
                        leftSwitch = SwitchPosition.DOWN;
                    }
                    else if (rawLeftSwitch < -30)
                    {
                        leftSwitch = SwitchPosition.UP;
                    }
                    else
                    {
                        leftSwitch = SwitchPosition.CENTER;
                    }

                    if (rawRightSwitch > 30)
                    {
                        rightSwitch = SwitchPosition.DOWN;
                    }
                    else if (rawRightSwitch < -30)
                    {
                        rightSwitch = SwitchPosition.UP;
                    }
                    else
                    {
                        rightSwitch = SwitchPosition.CENTER;
                    }

                    tiltLever = ((float)LittleEndiansToInt(incomingData[55], incomingData[56]) / 1000);

                    if (rightSwitch == SwitchPosition.UP)
                    {
                        droneMovement.translateSpeed = 5f;
                        droneMovement.rotateSpeed    = 360;
                    }
                    else if (rightSwitch == SwitchPosition.CENTER)
                    {
                        droneMovement.translateSpeed = 10f;
                        droneMovement.rotateSpeed    = 360;
                    }
                    else if (rightSwitch == SwitchPosition.DOWN)
                    {
                        droneMovement.translateSpeed = 50f;
                        droneMovement.rotateSpeed    = 720;
                    }

                    MovementProfile movementProfile = MovementProfile.Orbit;

                    if (leftSwitch == SwitchPosition.UP)
                    {
                        movementProfile = MovementProfile.Drone;
                    }
                    else if (leftSwitch == SwitchPosition.CENTER)
                    {
                        movementProfile = MovementProfile.CourseLock;
                    }
                    else if (leftSwitch == SwitchPosition.DOWN)
                    {
                        movementProfile = MovementProfile.Orbit;
                    }

                    droneMovement.Move(movementProfile, new Vector3(rightStick.x, leftStick.y, rightStick.y),
                                       new Vector3((tiltLever * 89), leftStick.x, 0), true);

                    //Console.WriteLine("L: {0}, {1} R: {2}, {3}", leftStick.x, leftStick.y, rightStick.x, rightStick.y);
                }
            }
        }
Example #28
0
        public void OnKeyRelease(Keys key)
        {
            SwitchPosition switchPosition = KeySwitchesPositions[key];

            keySwitchesPressed[switchPosition.AddressLine, switchPosition.KeyboardOutputColumn] = false;
        }