Example #1
0
            public void setIOMode(byte pin, IOState state, ResistorMode resistorMode)
            {
                this.writeRegister(IO60P16.PORT_SELECT_REGISTER, this.getPort(pin));

                byte mask = this.getMask(pin);
                byte val  = this.readRegister(IO60P16.ENABLE_PWM_REGISTER);

                if (state == IOState.PWM)
                {
                    this.writeRegister(IO60P16.ENABLE_PWM_REGISTER, (byte)(val | mask));

                    this.writeDigital(pin, true);

                    byte pwm = 255;
                    for (var i = 0; i < 30; i += 2)
                    {
                        if (this.pwms[i] == pin)
                        {
                            pwm = this.pwms[i + 1];
                        }
                    }

                    this.writeRegister(IO60P16.PWM_SELECT_REGISTER, pwm);
                    this.writeRegister(IO60P16.PWM_CONFIG, IO60P16.CLOCK_SOURCE); //93.75KHz clock

                    val = this.readRegister(IO60P16.PIN_STRONG_DRIVE);
                    this.writeRegister(IO60P16.PIN_STRONG_DRIVE, (byte)(val | mask));
                }
                else
                {
                    this.writeRegister(IO60P16.ENABLE_PWM_REGISTER, (byte)(val & ~mask));
                    val = this.readRegister(IO60P16.PIN_DIRECTION_REGISTER);

                    if (state == IOState.Output)
                    {
                        this.writeRegister(IO60P16.PIN_DIRECTION_REGISTER, (byte)(val & ~mask));

                        val = this.readRegister(IO60P16.PIN_STRONG_DRIVE);
                        this.writeRegister(IO60P16.PIN_STRONG_DRIVE, (byte)(val | mask));
                    }
                    else
                    {
                        this.writeRegister(IO60P16.PIN_DIRECTION_REGISTER, (byte)(val | mask));

                        val = this.readRegister((byte)resistorMode);
                        this.writeRegister((byte)resistorMode, (byte)(val | mask));
                    }
                }

                val = this.readRegister(IO60P16.INTERRUPT_MASK_REGISTER);
                if (state == IOState.InputInterrupt)
                {
                    this.writeRegister(IO60P16.INTERRUPT_MASK_REGISTER, (byte)(val & ~mask));
                }
                else
                {
                    this.writeRegister(IO60P16.INTERRUPT_MASK_REGISTER, (byte)(val | mask));
                }
            }
Example #2
0
        private void SetIOMode(byte pin, IOState state, GTI.ResistorMode resistorMode)
        {
            switch (resistorMode)
            {
            case GTI.ResistorMode.Disabled: this.SetIOMode(pin, state, ResistorMode.HighImpedence); break;

            case GTI.ResistorMode.PullDown: this.SetIOMode(pin, state, ResistorMode.ResistivePullDown); break;

            case GTI.ResistorMode.PullUp: this.SetIOMode(pin, state, ResistorMode.ResistivePullUp); break;
            }
        }
Example #3
0
            public void setIOMode(byte pin, IOState state, GTI.ResistorMode resistorMode)
            {
                switch (resistorMode)
                {
                case GTI.ResistorMode.Disabled: this.setIOMode(pin, state, ResistorMode.Floating); break;

                case GTI.ResistorMode.PullDown: this.setIOMode(pin, state, ResistorMode.PullDown); break;

                case GTI.ResistorMode.PullUp: this.setIOMode(pin, state, ResistorMode.PullUp); break;
                }
            }
Example #4
0
            public void SetIOMode(byte pin, IOState state, ResistorMode resistorMode)
            {
                this.WriteRegister(IO60P16.PORT_SELECT_REGISTER, this.GetPort(pin));

                byte mask = this.GetMask(pin);
                byte val  = this.ReadRegister(IO60P16.ENABLE_PWM_REGISTER);

                if (state == IOState.Pwm)
                {
                    this.WriteRegister(IO60P16.ENABLE_PWM_REGISTER, (byte)(val | mask));

                    this.WriteDigital(pin, true);

                    val = this.ReadRegister(IO60P16.PIN_STRONG_DRIVE);
                    this.WriteRegister(IO60P16.PIN_STRONG_DRIVE, (byte)(val | mask));
                }
                else
                {
                    this.WriteRegister(IO60P16.ENABLE_PWM_REGISTER, (byte)(val & ~mask));
                    val = this.ReadRegister(IO60P16.PIN_DIRECTION_REGISTER);

                    if (state == IOState.Output)
                    {
                        this.WriteRegister(IO60P16.PIN_DIRECTION_REGISTER, (byte)(val & ~mask));

                        val = this.ReadRegister(IO60P16.PIN_STRONG_DRIVE);
                        this.WriteRegister(IO60P16.PIN_STRONG_DRIVE, (byte)(val | mask));
                    }
                    else
                    {
                        this.WriteRegister(IO60P16.PIN_DIRECTION_REGISTER, (byte)(val | mask));

                        val = this.ReadRegister((byte)resistorMode);
                        this.WriteRegister((byte)resistorMode, (byte)(val | mask));
                    }
                }

                val = this.ReadRegister(IO60P16.INTERRUPT_MASK_REGISTER);
                if (state == IOState.InputInterrupt)
                {
                    this.WriteRegister(IO60P16.INTERRUPT_MASK_REGISTER, (byte)(val & ~mask));
                }
                else
                {
                    this.WriteRegister(IO60P16.INTERRUPT_MASK_REGISTER, (byte)(val | mask));
                }
            }
Example #5
0
        public bool UpdateStatus()
        {
            logger.DebugFormat("Updating IOLinc {0} status...", Address);

            byte value;
            if (TryGetStatus(out value, 0x0))
            {
                RelayStatus = value == 0 ? IOState.Open : IOState.Closed;

                if (TryGetStatus(out value, 0x01))
                {
                    SensorStatus = value == 0 ? IOState.Open : IOState.Closed;
                    return true;
                }
            }

            return false;
        }
Example #6
0
        public bool UpdateStatus()
        {
            logger.DebugFormat("Updating IOLinc {0} status...", Address);

            byte value;

            if (TryGetStatus(out value, 0x0))
            {
                RelayStatus = value == 0 ? IOState.Open : IOState.Closed;

                if (TryGetStatus(out value, 0x01))
                {
                    SensorStatus = value == 0 ? IOState.Open : IOState.Closed;
                    return(true);
                }
            }

            return(false);
        }
        public void Update()
        {
            Vector2 aimpoint;
            Ship    focus = this.game.GetLocalPlayerFocus();

            //this.game.ControllerFocus.GetFocus(this.game.PlayerID);
            if (focus != null)
            {
                aimpoint = this.game.Camera.ScreenToWorldPosition(IOState.MouseScreenPosition()) - focus.Position;
            }
            else
            {
                aimpoint = new Vector2(0);
            }
            this.AngleControl    = angleControl;
            this.TargetAngle     = (float)(2 * Math.PI + 1);
            this.MovementControl = movementControl;
            this.Aimpoint        = aimpoint;
            this.Fire            = isFire;

            angleControl    = 0;
            movementControl = 0;
            isFire          = false;
        }
Example #8
0
 public IO(string channel, IOState input, int iinput)
 {
     sChannel = channel;
     mInput = input;
     iInput = iinput;
 }
Example #9
0
 public DemoOutput(OutputId id)
 {
     this.Id    = id;
     this.State = IOState.Off;
 }
 public override bool hasOccured()
 {
     return(IOState.leftButtonDown());
 }
 /// <summary>Set the visual state of the IO control from the state machine state</summary>
 /// <param name="ctrl">The visual control</param>
 /// <param name="state">The state to change</param>
 public static void Set(this UC_Output ctrl, IOState state)
 {
     ctrl.SetState(state == IOState.On ? UC_Output.State.On : UC_Output.State.Off);
 }
Example #12
0
 public DemoInput(InputId id)
 {
     this.Id    = id;
     this.State = IOState.Off;
 }
        public MonitorIOState(HSTSettings settings)
        {
            _InputState    = new IOState[8, 8];
            _AnalogueState = new IOState[1, 2];
            _OutputState   = new IOState[8, 8];

            _directory = settings.Directory.IOChangeStatePath;

            if (!Directory.Exists(_directory))
            {
                Directory.CreateDirectory(_directory);
            }
            // ********************************input*************************************************
            int iloop = 0;

            for (int icard = 0; icard < 3; icard++, iloop++)
            {
                for (int ibit = 0; ibit < 8; ibit++)
                {
                    _InputState[icard, ibit] = new IOState(settings.Directory.IOChangeStatePath, settings, true, HSTMachine.Workcell, 0, ibit + (8 * iloop));
                }
            }

            for (int icard = 3; icard < 8; icard++)
            {
                for (int ibit = 0; ibit < 8; ibit++)
                {
                    _InputState[icard, ibit] = new IOState(settings.Directory.IOChangeStatePath, settings, true, HSTMachine.Workcell, icard - 2, ibit);
                }
            }
            // ********************************input*************************************************


            // ********************************Analogue*************************************************
            for (int analogueInput = 0; analogueInput < 2; analogueInput++)
            {
                _AnalogueState[0, analogueInput] = new IOState(settings.Directory.IOChangeStatePath, settings, false, HSTMachine.Workcell, 0, analogueInput);
            }

            // ********************************Analogue*************************************************

            // ********************************Output*************************************************

            iloop = 0;
            for (int icard = 0; icard < 3; icard++, iloop++)
            {
                for (int ibit = 0; ibit < 8; ibit++)//each card got 8 bits
                {
                    _OutputState[icard, ibit] = new IOState(settings.Directory.IOChangeStatePath, settings, true, HSTMachine.Workcell, 0, ibit + (8 * iloop));
                }
            }

            for (int icard = 3; icard < 8; icard++)
            {
                for (int ibit = 0; ibit < 8; ibit++)//each card got 8 bits
                {
                    _OutputState[icard, ibit] = new IOState(settings.Directory.IOChangeStatePath, settings, true, HSTMachine.Workcell, icard - 2, ibit);
                }
            }

            // ********************************Output*************************************************
        }
Example #14
0
 public InputChangeArgs(DemoInput input)
 {
     this.Id    = input.Id;
     this.State = input.State;
 }
Example #15
0
 public override bool hasOccured()
 {
     return(IOState.isKeyDown(key));
 }
Example #16
0
 public OutputChangeArgs(DemoOutput output)
 {
     this.Id    = output.Id;
     this.State = output.State;
 }
Example #17
0
        public void Close(Action <Response> callback = null)
        {
            if (Stream == null)
            {
                return;
            }

            Stream.Close();
            request.BeginGetResponse((IAsyncResult asyncResult) =>
            {
                try
                {
                    var req      = (HttpWebRequest)asyncResult.AsyncState;
                    var response = req.EndGetResponse(asyncResult);
                    var rStream  = response.GetResponseStream();
                    var state    = new IOState()
                    {
                        Stream   = rStream,
                        Buffer   = new byte[response.ContentLength],
                        Response = response
                    };

                    rStream.BeginRead(state.Buffer, 0, state.Buffer.Length, (IAsyncResult asyncRead) =>
                    {
                        var readState  = (IOState)asyncRead.AsyncState;
                        var rawMessage = Encoding.UTF8.GetString(readState.Buffer);
                        var dict       = Json.Deserialize(rawMessage) as Dictionary <string, object>;
                        var endpoint   = response.Headers[Keys.EndpointHeader];
                        dict.Add(Keys.EndpointHeader, endpoint);

                        readState.Stream.EndRead(asyncRead);
                        readState.Stream.Close();
                        readState.Response.Close();

                        var psResponse = new Response(dict);
                        // if we don't set the internal reference to null, the resources are
                        // not freed correctly
                        Stream = null;

                        if (callback != null)
                        {
                            callback(psResponse);
                        }
                    }, state);
                }
                catch (WebException e)
                {
                    var webResponse = (HttpWebResponse)e.Response;
                    var psResponse  = new Response()
                    {
                        Status = new Status()
                        {
                            Success      = false,
                            StatusCode   = (long)webResponse.StatusCode,
                            ErrorMessage = webResponse.StatusDescription
                        }
                    };

                    if (callback != null)
                    {
                        callback(psResponse);
                    }
                }
            }, request);
        }
 public override bool hasOccured()
 {
     return(IOState.isKeyPressed(key));
 }