Пример #1
0
 public LEDStrip(Cpu.Pin clockPin, Cpu.Pin dataPin)
 {
     NumOfLEDs = 32;
     _clock = new OutputPort(clockPin, false);
     _data = new OutputPort(dataPin, false);
     post_frame();
 }
Пример #2
0
        private OutputPort stcpPort; // Storage Register Clock pin

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="ds">Pin Serial Data</param>
        /// <param name="shcp">Pin Shift Register Clock</param>
        /// <param name="stcp">Pin Storage Register Clock</param>
        /// <param name="mr">Pin Master Reset</param>
        /// <param name="oe">Pin Output Enable</param>
        /// <param name="bitOrder">Bit order during transferring</param>
        public ShiftRegister74HC595(Cpu.Pin ds, Cpu.Pin shcp, Cpu.Pin stcp, Cpu.Pin mr, Cpu.Pin oe, BitOrder bitOrder)
        {
            // Serial Data (DS) pin is necessary
            if (ds == Cpu.Pin.GPIO_NONE)
                throw new ArgumentException("Serial Data (DS) pin is necessary");
            this.dsPort = new OutputPort(ds, false);

            // Shift Register Clock (SHCP) pin is necessary
            if (shcp == Cpu.Pin.GPIO_NONE)
                throw new ArgumentException("Shift Register Clock (SHCP) pin is necessary");
            this.shcpPort = new OutputPort(shcp, false);

            // you can save 1 pin connecting STCP and SHCP together
            if (stcp != Cpu.Pin.GPIO_NONE)
                this.stcpPort = new OutputPort(stcp, false);

            // you can save 1 pin connecting MR pin to Vcc (no reset)
            if (mr != Cpu.Pin.GPIO_NONE)
                this.mrPort = new OutputPort(mr, true);

            // you can save 1 pin connecting OE pin to GND (shift register output pins are always enabled)
            if (oe != Cpu.Pin.GPIO_NONE)
                this.oePort = new OutputPort(oe, false);

            this.bitOrder = bitOrder;
        }
Пример #3
0
 public RelayPort(Cpu.Pin pin, bool initialState, int timeout)
     : base(pin, initialState)
 {
     currentstate = initialState;
     relayThread = new Thread(new ThreadStart(RelayLoop));
     relayThread.Start();
 }
Пример #4
0
 /// <summary>
 /// LEDRGB Constructor.
 /// </summary>
 /// <param name="r">Red LED PWM channel</param>
 /// <param name="g">Green LED PWM channel</param>
 /// <param name="b">Blkue LED PWM channel</param>
 public LEDRGB(Cpu.PWMChannel r, Cpu.PWMChannel g, Cpu.PWMChannel b)
 {
     red = new PWM(r, 255, 0, PWM.ScaleFactor.Microseconds, false);
     green = new PWM(g, 255, 0, PWM.ScaleFactor.Microseconds, false);
     blue = new PWM(b, 255, 0, PWM.ScaleFactor.Microseconds, false);
     color = new RGBColor(0, 0, 0);
 }
Пример #5
0
 public OLED_sh1106(Cpu.Pin csPin, OutputPort dcPin, OutputPort rsPin)
 {
     displayStr = "";
     spiDevice = new SPI(new SPI.Configuration(csPin, false, 0, 0, false, true, 10000, SPI.SPI_module.SPI1));
     dataCommandPin = dcPin;
     resetOutputPort = rsPin;
 }
Пример #6
0
 public override void GetSerialPins(string comPort, out Cpu.Pin rxPin, out Cpu.Pin txPin, out Cpu.Pin ctsPin, out Cpu.Pin rtsPin)
 {
     switch (comPort)
     {
         case "COM1":
             rxPin = Pins.P6_5;
             txPin = Pins.P6_4;
             ctsPin = Pins.GPIO_NONE;
             rtsPin = Pins.GPIO_NONE;
             break;
         case "COM2":
             rxPin = Pins.P1_14;
             txPin = Pins.P5_6;
             ctsPin = Pins.P5_4;
             rtsPin = Pins.P4_2;
             break;
         case "COM3":
             rxPin = Pins.P2_11;
             txPin = Pins.P2_10;
             ctsPin = Pins.GPIO_NONE;
             rtsPin = Pins.GPIO_NONE;
             break;
         default:
             throw new NotSupportedException();
     }
 }
Пример #7
0
        public MidiDriver(Cpu.Pin resetPin, string serialPortName = Serial.COM2)
        {
            _resetPinPort = new OutputPort(resetPin, false);

            _serialPort = new SerialPort(serialPortName, 31250, Parity.None, 8, StopBits.One);
            _serialPort.Open();
        }
Пример #8
0
 public static TempSensor Start(Cpu.Pin pin, int sampleInterval = 1000, TempSensorMode mode = TempSensorMode.Celcius)
 {
     TempSensor sensor = new TempSensor(pin, sampleInterval, mode);
     sensor._thread = new Thread(sensor.Run);
     sensor._thread.Start();
     return sensor;
 }
 //private OutputPort _commitPin;
 public ShiftRegisterWriter(Cpu.Pin clock, Cpu.Pin reset, Cpu.Pin data, Cpu.Pin commit)
 {
     _clockPin = new OutputPort(clock, false);
     _dataPin = new OutputPort(data, false);
     _resetPin = new OutputPort(reset, false);
     _commitPin = new OutputPort(commit, false);
 }
Пример #10
0
 /// <summary>
 /// Common RGB-led
 /// </summary>
 /// <param name="RedPin">The PWM-pin connected to Red</param>
 /// <param name="GreenPin">The PWM-pin connected to Green</param>
 /// <param name="BluePin">The PWM-pin connected to Blue</param>
 /// <param name="CommonAnode">Specifies if the led is common anode</param>
 public RGBLed(Cpu.Pin RedPin, Cpu.Pin GreenPin, Cpu.Pin BluePin, bool CommonAnode = true)
 {
     this._Red = new PWM(RedPin);
     this._Green = new PWM(GreenPin);
     this._Blue = new PWM(BluePin);
     this._CommonAnode = CommonAnode;
 }
Пример #11
0
 public PanTilter(Cpu.Pin panPin, int panMin, int panMax, Cpu.Pin tiltPin, int tiltMin, int tiltMax)
 {
     this.tilter = new PWM(tiltPin);
     this.tiltMin = tiltMin;
     this.tiltMax = tiltMax;
     this.tilter.SetDutyCycle(0);
 }
Пример #12
0
        public ContactSensor(Cpu.Pin sensorPin)
        {
            this.sensorPin = sensorPin;

            sensorPort = new InterruptPort(sensorPin, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLevelLow);
            sensorPort.OnInterrupt += new NativeEventHandler(OnInterrupt);
        }
Пример #13
0
        public Stepper(Cpu.Pin pinCoil1A, Cpu.Pin pinCoil1B, Cpu.Pin pinCoil2A, Cpu.Pin pinCoil2B, uint stepsPerRevolution, string name)
            : base(name, "stepper")
        {
            // remember the steps per revolution
            this.StepsPerRevolution = stepsPerRevolution;

            // reset the step-counter
            this.currentStep = 0;

            // determine correct pins for the coils; turn off all motor pins
            this.portCoil1A = new OutputPort(pinCoil1A, false);

            Util.Delay(500);
            this.portCoil1B = new OutputPort(pinCoil1B, false);

            Util.Delay(500);
            this.portCoil2A = new OutputPort(pinCoil2A, false);

            Util.Delay(500);

            this.portCoil2B = new OutputPort(pinCoil2B, false);

            // set the maximum speed
            SetSpeed(120);
        }
Пример #14
0
 public void Connect(Cpu.Pin pinTrig, Cpu.Pin pinEcho)
 {
     _portOut = new OutputPort(pinTrig, false);
     _interIn = new InterruptPort(pinEcho, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
     _interIn.OnInterrupt += new NativeEventHandler(interIn_OnInterrupt);
     Reset();
 }
Пример #15
0
 /// <summary>
 /// Piezo speaker driver and notes and playback manager
 /// </summary>
 /// <param name="pin">From the SecretLabs.NETMF.Hardware.NetduinoPlus.PWMChannels namespace</param>
 /// <param name="name">Unique identifying name for command and control</param>
 public Piezo(Cpu.PWMChannel pin, string name)
     : base(name, "piezo")
 {
     //_piezo = new PWM(pin, 2048, 0, PWM.ScaleFactor.Milliseconds, false);
     _piezo = new PWM(pin, 2048, 0, false);
     _piezo.Start();
 }
Пример #16
0
 public Configuration(
                       Cpu.Pin ChipSelect_Port,
                       bool ChipSelect_ActiveState,
                       uint ChipSelect_SetupTime,
                       uint ChipSelect_HoldTime,
                       bool Clock_IdleState,
                       bool Clock_Edge,
                       uint Clock_RateKHz,
                       SPI_module SPI_mod,
                       Cpu.Pin BusyPin,
                       bool BusyPin_ActiveState
                       
                     )
 {
     this.ChipSelect_Port = ChipSelect_Port;
     this.ChipSelect_ActiveState = ChipSelect_ActiveState;
     this.ChipSelect_SetupTime = ChipSelect_SetupTime;
     this.ChipSelect_HoldTime = ChipSelect_HoldTime;
     this.Clock_IdleState = Clock_IdleState;
     this.Clock_Edge = Clock_Edge;
     this.Clock_RateKHz = Clock_RateKHz;
     this.SPI_mod = SPI_mod;
     this.BusyPin = BusyPin;
     this.BusyPin_ActiveState = BusyPin_ActiveState;
 }
Пример #17
0
 override public void GetSerialPins(string comPort, out Cpu.Pin rxPin, out Cpu.Pin txPin, out Cpu.Pin ctsPin, out Cpu.Pin rtsPin)
 {
     switch (comPort)
     {
         case "COM1":           // STDUART
             rxPin  = Pins.GPIO_PORT_PIN_46;
             txPin  = Pins.GPIO_PORT_PIN_47;
             ctsPin = Pins.GPIO_NONE;
             rtsPin = Pins.GPIO_NONE;
             break;
         case "COM2":           // BTUART
             rxPin  = Pins.GPIO_PORT_PIN_42;
             txPin  = Pins.GPIO_PORT_PIN_43;
             ctsPin = Pins.GPIO_PORT_PIN_44;
             rtsPin = Pins.GPIO_PORT_PIN_45;
             break;
         case "COM3":           // FFUART
             rxPin  = Pins.GPIO_PORT_PIN_96;
             txPin  = Pins.GPIO_PORT_PIN_99;
             ctsPin = Pins.GPIO_PORT_PIN_100;
             rtsPin = Pins.GPIO_PORT_PIN_98;
             break;
         default:
             throw new NotSupportedException();                    
     }
 }
Пример #18
0
 /// <summary>
 /// Constructor for parallel LCD connection
 /// </summary>
 /// <param name="rs"></param>
 /// <param name="rw"></param>
 /// <param name="enable"></param>
 /// <param name="d4"></param>
 /// <param name="d5"></param>
 /// <param name="d6"></param>
 /// <param name="d7"></param>
 /// <param name="rows"></param>
 /// <param name="cols"></param>
 public clsLCD_MLC(Cpu.Pin rs, Cpu.Pin rw, Cpu.Pin enable, Cpu.Pin d4, Cpu.Pin d5, Cpu.Pin d6, 
     Cpu.Pin d7, byte rows, byte cols)
 {
     GpioLcdTransferProvider lcdProvider = new GpioLcdTransferProvider(rs, rw, enable, d4, d5, d6, d7);
     lcd = new Lcd(lcdProvider);
     lcd_begin(rows, cols);
 }
Пример #19
0
        /// <summary>
        /// Sets up the relay board using the passed in
        /// pin map. If that is null, it will set up one
        /// based on pin0 == GPIO_PIN_D2
        /// </summary>
        /// <param name="rawPinMap"></param>
        public RelayBoard(bool inverse = true, Cpu.Pin[] rawPinMap = null)
        {
            Inverse = inverse;

            if (null == rawPinMap)
            {
                rawPinMap = new Cpu.Pin[] {
                    Pins.GPIO_PIN_D2,
                    Pins.GPIO_PIN_D3,
                    Pins.GPIO_PIN_D4,
                    Pins.GPIO_PIN_D5,
                    Pins.GPIO_PIN_D6,
                    Pins.GPIO_PIN_D7,
                    Pins.GPIO_PIN_D8,
                    Pins.GPIO_PIN_D9
                };
            }

            MaxPin = rawPinMap.Length;

            // Build the outputs
            bool initalState = Inverse ? true : false;

            PinMap = new OutputPort[MaxPin];
            for (int i = 0; i < MaxPin; i++)
            {
                PinMap[i] = new OutputPort(rawPinMap[i], initalState);
            }
        }
Пример #20
0
 public Fan(Cpu.PWMChannel pin)
 {
     this.pwmChannel = pin;
     this.speed = Speed.None;
     this.frequency = (double)100;
     Start();
 }
Пример #21
0
        public RGBLed(Cpu.Pin red, Cpu.Pin green, Cpu.Pin blue, bool commonAnode = true) {
            _red = new PWM(red);
            _green = new PWM(green);
            _blue = new PWM(blue);

            CommonAnode = commonAnode;
        }
Пример #22
0
        protected LedCube(byte size, Cpu.Pin[] levelPins, Cpu.Pin[] ledPins, CubeOrientations orientation = CubeOrientations.ZPos )
        {
            Size = size;
            Orientation = orientation;
            Levels = new OutputPort[Size];
            Leds = new OutputPort[Size*Size];

            // Make sure we have the correct number of level pins.
            if(levelPins.Length != size)
            {
                throw new ArgumentOutOfRangeException("levelPins", "You must define " + Size + " level pins.");
            }

            // Make sure we have the correct number of LED pins.
            if (ledPins.Length != size * size)
            {
                throw new ArgumentOutOfRangeException("ledPins", "You must define " + Size*Size + " led pins.");
            }

            // Create level ports.
            for (byte lvl = 0; lvl < Size; lvl++ )
            {
                Levels[lvl] = new OutputPort(levelPins[lvl], false);
            }

            // Create LED ports.
            for (byte led = 0; led < Size*Size; led++)
            {
                Leds[led] = new OutputPort(ledPins[led], false);
            }
        }
Пример #23
0
 public HttpWiflyImpl(HttpImplementationClient.RequestReceivedDelegate requestReceived, int localPort, DeviceType deviceType, SPI.SPI_module spiModule, Cpu.Pin chipSelect)
 {
     m_requestReceived = requestReceived;
     LocalPort = localPort;
     this.m_spiModule = spiModule;
     this.m_chipSelect = chipSelect;
 }
Пример #24
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="xAccelPin"></param>
        /// <param name="yAccelPin"></param>
        /// <param name="zAccelPin"></param>
        /// <param name="xGyroPin"></param>
        /// <param name="yGyroPin"></param>
        public Analog5DOF(Cpu.Pin xAccelPin = Cpu.Pin.GPIO_NONE, 
            Cpu.Pin yAccelPin = Cpu.Pin.GPIO_NONE,
            Cpu.Pin zAccelPin = Cpu.Pin.GPIO_NONE,
            Cpu.Pin xGyroPin = Cpu.Pin.GPIO_NONE,
            Cpu.Pin yGyroPin = Cpu.Pin.GPIO_NONE)
        {
            this.Acceleration = new Vector(0, 0, 0);
            this.RotationRate = new Vector(0, 0, 0);

            if (xAccelPin != Cpu.Pin.GPIO_NONE)
            {
                _xAccelInput = new AnalogInput(xAccelPin);
            }
            if (yAccelPin != Cpu.Pin.GPIO_NONE)
            {
                _yAccelInput = new AnalogInput(yAccelPin);
            }
            if (zAccelPin != Cpu.Pin.GPIO_NONE)
            {
                _zAccelInput = new AnalogInput(zAccelPin);
            }
            if (xGyroPin != Cpu.Pin.GPIO_NONE)
            {
                _xGyroInput = new AnalogInput(xGyroPin);
            }
            if (yGyroPin != Cpu.Pin.GPIO_NONE)
            {
                _yGyroInput = new AnalogInput(yGyroPin);
            }
        }
Пример #25
0
        private readonly byte[] _shadowBuffers; // Will store the pixel data for each display

        #endregion Fields

        #region Constructors

        public MatrixDisplay32x8( byte numDisplays,
                          Cpu.Pin clkPin,
                          Cpu.Pin dataPin,
                          bool buildShadow )
        {
            _backBufferSize = BACKBUFFER_SIZE;
              DisplayCount = numDisplays;

              // set data & clock pin modes
              _clkPin = new OutputPort( clkPin, true );
              _dataPin = new OutputPort( dataPin, true );

              // allocate RAM buffer for display bits
              // 32 columns * 8 rows / 8 bits = 32 bytes
              int sz = DisplayCount * _backBufferSize;
              _displayBuffers = new byte[sz];

              if( buildShadow )
              {
            // allocate RAM buffer for display bits
            _shadowBuffers = new byte[sz];
              }

              // allocate a buffer for pin assignments
              _displayPins = new OutputPort[numDisplays];
        }
Пример #26
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="csPin">CS pin for SPI interface</param>
 /// <param name="spiModule">SPI module</param>
 public LIS302DL(Cpu.Pin csPin, SPI.SPI_module spiModule)
 {
     //The 302DL is a mode 3 device
     var spiConfig = new SPI.Configuration(csPin, false, 0, 0, true, true, 10000, spiModule);
     _spi = new SPI(spiConfig);
     Init();
 }
Пример #27
0
        //--//

        /// <summary>
        /// Build an instance of the PWM type
        /// </summary>
        /// <param name="channel">The channel to use</param>
        /// <param name="frequency_Hz">The frequency of the pulse in Hz</param>
        /// <param name="dutyCycle">The duty cycle of the pulse as a fraction of unity.  Value should be between 0.0 and 1.0</param>
        /// <param name="invert">Whether the output should be inverted or not</param>
        public PWM(Cpu.PWMChannel channel, double frequency_Hz, double dutyCycle, bool invert)
        {
            HardwareProvider hwProvider = HardwareProvider.HwProvider;

            if(hwProvider == null) throw new InvalidOperationException();

            m_pin = hwProvider.GetPwmPinForChannel(channel);
            m_channel = channel;
            //--//
            m_period = PeriodFromFrequency(frequency_Hz, out m_scale);
            m_duration = DurationFromDutyCycleAndPeriod(dutyCycle, m_period);
            m_invert = invert;
            //--//
            try
            {
                Init();
                
                Commit();
                
                Port.ReservePin(m_pin, true);
            }
            catch
            {
                Dispose(false);
            }
        }
Пример #28
0
 public XBeeDevice(SerialPort port, Cpu.Pin resetPin, Cpu.Pin sleepPin)
 {
     _resetPort = new OutputPort(resetPin, true);
     _sleepPort = new OutputPort(sleepPin, false);
     _serialPort = port;
     new Thread(ReadThread).Start();
 }
Пример #29
0
 public RelayPort(Cpu.Pin pin, bool initialState, bool glitchFilter, Port.ResistorMode resistor, int timeout)
     : base(pin, initialState, glitchFilter, resistor)
 {
     currentstate = initialState;
     relayThread = new Thread(new ThreadStart(RelayLoop));
     relayThread.Start();
 }
Пример #30
0
        private short senseResistor; // in mOhms

        #endregion Fields

        #region Constructors

        public Booster(
            bool ledToVcc,
            Cpu.Pin pinEnable,
            Cpu.Pin pinEnableLED,
            Cpu.AnalogChannel pinSense,
            Cpu.Pin pinOverloadLED,
            short senseResistor,
            int currentThreshould,
            Cpu.Pin pinGenerator,
            uint[] idleTimings
            )
        {
            portEnable = new OutputPort(pinEnable, false);
            portEnableLED = new OutputPort(pinEnableLED, ledToVcc);

            this.ledToVcc = ledToVcc;
            portOverloadLED = new OutputPort(pinOverloadLED, ledToVcc);
            portSense = new AnalogInput(pinSense);
            portSense.Scale = 3300;
            this.senseResistor = senseResistor;
            this.currentThreshould = currentThreshould;
            new Timer(TimerCurrent_Tick, null, 0, checkOverloadPeriod);

            portGenerator = new SignalGenerator((Cpu.Pin)pinGenerator, false, MaxTimingsCount);
            this.idleTimings = idleTimings;

            //new Thread(GeneratorWork) { Priority = ThreadPriority.AboveNormal }.Start();
            new Timer(TimerGenerator, null, 0, 2);
        }