Пример #1
0
            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="io60p16">The IO60 the port is on.</param>
            /// <param name="pin">Pin to be created</param>
            /// <param name="resisterMode">Desired resistor mode for the pin to be constructed</param>
            public InputPort(IO60P16 io60p16, IOPin pin, ResistorMode resisterMode)
            {
                _io60p16 = io60p16;
                _portId  = _io60p16.GetPortNumber(pin);
                _pinId   = _io60p16.GetPinNumber(pin);

                if (_io60p16.IsPinReserved(_portId, _pinId))
                {
                    throw new Exception("This pin has already been reserved");
                }

                _io60p16.MakePinInput(_portId, _pinId, resisterMode);

                _io60p16.port_reserve[_portId] |= (byte)(1 << _pinId);
            }
Пример #2
0
            /// <summary>
            /// Sets the PWM Pulse width and period
            /// </summary>
            /// <param name="highPulseWidthTicks">Number of ticks for the PWM to be high</param>
            /// <param name="periodTicks">Number of ticks for the period</param>
            public void SetPulse(byte highPulseWidthTicks, byte periodTicks)
            {
                if (highPulseWidthTicks > periodTicks)
                {
                    throw new Exception("Invalid param. highPulseWidthTicks should be smaller than " + periodTicks);
                }

                if (!_io60p16.IsPinReserved(_portId, _pinId))
                {
                    throw new Exception("This pin has already been reset or has not been initialized.");// reserve already
                }

                _periodTicks         = periodTicks;
                _highPulseWidthTicks = highPulseWidthTicks;
                SetPWM();
            }
Пример #3
0
            /// <summary>
            /// Writes the state of the pin
            /// </summary>
            /// <param name="state">The state to set the pin to. High (true) or low (false)</param>
            public void Write(Boolean state)
            {
                if (!_io60p16.IsPinReserved(_portId, _pinId))
                {
                    throw new Exception("This pin has already been reset or has not been initialized.");// reserve already
                }

                if (state)
                {
                    _io60p16.MakePinHigh(_portId, _pinId);
                }
                else
                {
                    _io60p16.MakePinLow(_portId, _pinId);
                }
            }
Пример #4
0
            /// <summary>
            /// Reads the state of a pin
            /// </summary>
            /// <returns>Returns the state of the pin</returns>
            public Boolean Read()
            {
                if (!_io60p16.IsPinReserved(_portId, _pinId))
                {
                    throw new Exception("This pin has already been reset or has not been initialized.");// reserve already
                }

                byte b = _io60p16.ReadPort(_portId);

                if ((b & (1 << _pinId)) != 0)
                {
                    return(true);
                }

                return(false);
            }
Пример #5
0
            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="io60p16">The IO60 the port is on.</param>
            /// <param name="pin">The pin to be constructed</param>
            /// <param name="tickWidth">The desired width between ticks</param>
            public PWM(IO60P16 io60p16, PWMPin pin, TickWidth tickWidth)
            {
                _io60p16 = io60p16;
                _portId  = _io60p16.GetPortNumber((IOPin)pin);
                _pinId   = _io60p16.GetPinNumber((IOPin)pin);

                if (_io60p16.IsPinReserved(_portId, _pinId))
                {
                    throw new Exception("This pin has already been reserved");// reserve already
                }

                _io60p16.port_reserve[_portId] |= (byte)(1 << _pinId);

                _tickWidth = tickWidth;
                _io60p16.MakePinOutput(_portId, _pinId);
                _io60p16.MakePinHigh(_portId, _pinId);
                SetPWM();
            }
Пример #6
0
            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="io60p16">The IO60 the port is on.</param>
            /// <param name="pin">Pin to be created</param>
            /// <param name="initialState">If the pin should be created and set high (true) or low (false)</param>
            public OutputPort(IO60P16 io60p16, IOPin pin, Boolean initialState)
            {
                _io60p16 = io60p16;
                _portId  = _io60p16.GetPortNumber(pin);
                _pinId   = _io60p16.GetPinNumber(pin);

                if (_io60p16.IsPinReserved(_portId, _pinId))
                {
                    throw new Exception("This pin has already been reserved");
                }

                _io60p16.MakePinOutput(_portId, _pinId);

                _io60p16.port_reserve[_portId] |= (byte)(1 << _pinId);

                if (initialState)
                {
                    _io60p16.MakePinHigh(_portId, _pinId);
                }
                else
                {
                    _io60p16.MakePinLow(_portId, _pinId);
                }
            }