Пример #1
0
 /// <summary>
 ///     Construct an LED shift register attached directly to a board SPI module
 /// </summary>
 /// <param name="SpiModule">The board's SPI module</param>
 /// <param name="LatchPin">The pin to use for latches</param>
 /// <param name="ChannelCount">Whether the driver is 16 or 8-channel</param>
 /// <param name="OutputEnablePin">The output enable pin, if any, to use.</param>
 /// <param name="speedMhz">The speed, in MHz, to use when communicating</param>
 public LedShiftRegister(Spi SpiModule, SpiChipSelectPin LatchPin,
                         LedChannelCount ChannelCount = LedChannelCount.SixteenChannel, DigitalOut OutputEnablePin = null,
                         double speedMhz = 6) : base(SpiModule, LatchPin, (int)ChannelCount / 8, speedMhz)
 {
     oe = OutputEnablePin;
     Start(ChannelCount);
 }
Пример #2
0
 /// <summary>
 ///     Construct an LED shift register attached to the output of another shift register
 /// </summary>
 /// <param name="upstreamDevice">The upstream device this shift register is attached to</param>
 /// <param name="OutputEnablePin">The digital pin to use, if any, to control the display state</param>
 /// <param name="ChannelCount">The number of channels this LED shift register has</param>
 public LedShiftRegister(ChainableShiftRegisterOutput upstreamDevice,
                         LedChannelCount ChannelCount = LedChannelCount.SixteenChannel, DigitalOut OutputEnablePin = null) : base(
         upstreamDevice, (int)ChannelCount / 8)
 {
     oe = OutputEnablePin;
     Start(ChannelCount);
 }
Пример #3
0
        /// <summary>
        /// Initialisiert die Roboter-Konsole mit den dazugehörigen LED's und Schalter.
        /// </summary>
        public RobotConsole()
        {
            if (Constants.IsWinCE == false)
            {
                _digitalIn  = new DigitalInSim();
                _digitalOut = new DigitalOutSim();
            }
            else
            {
                _digitalIn  = new DigitalInHW(Constants.IOConsoleSWITCH);
                _digitalOut = new DigitalOutHW(Constants.IOConsoleLED);
            }

            _leds = new Led[4];
            for (int i = 0; i < _leds.Length; i++)
            {
                _leds[i] = new Led((Leds)i, _digitalOut);
            }

            _switches = new Switch[4];
            for (int i = 0; i < _switches.Length; i++)
            {
                _switches[i] = new Switch((Switches)i, _digitalIn);
            }
        }
Пример #4
0
        /// <summary>
        ///     Construct a new HD44780-compatible display
        /// </summary>
        /// <param name="iface">The writable parallel interface to use</param>
        /// <param name="Columns">The number of columns in the display</param>
        /// <param name="Rows">The number of rows of the display</param>
        /// <param name="Backlight">The active-high pin to use for the backlight</param>
        /// <param name="font">The font mode to use</param>
        public Hd44780(WriteOnlyParallelInterface iface, int Columns, int Rows, DigitalOut Backlight = null,
                       FontMode font = FontMode.Font_5x8) : base(Columns, Rows)
        {
            if (iface.Width == 8)
            {
                bits = BitMode.EightBit;
            }
            else if (iface.Width == 4)
            {
                bits = BitMode.FourBit;
            }
            else
            {
                throw new ArgumentException("The IParallelInterface bus must be either 4 or 8 bits wide.", "iface");
            }

            if (Rows == 1)
            {
                lines = LinesMode.OneLine;
            }
            else
            {
                lines = LinesMode.TwoOrMoreLines;
            }

            this.font  = font;
            this.iface = iface;
            iface.DelayMicroseconds = 50;
            iface.Enabled           = true;
            byte cmd;

            if (bits == BitMode.FourBit)
            {
                Task.Run(() => iface.WriteCommandAsync(new uint[] { 0x03 })).Wait();
                Task.Run(() => Task.Delay(10)).Wait();
                Task.Run(() => iface.WriteCommandAsync(new uint[] { 0x03 })).Wait();
                Task.Run(() => Task.Delay(10)).Wait();
                Task.Run(() => iface.WriteCommandAsync(new uint[] { 0x03 })).Wait();
                Task.Run(() => Task.Delay(10)).Wait();
                Task.Run(() => iface.WriteCommandAsync(new uint[] { 0x02 })).Wait();
            }


            cmd = (byte)((byte)Command.FunctionSet | (byte)bits | (byte)lines | (byte)font);
            Task.Run(() => writeCommand(cmd)).Wait();

            Display = true;
            Task.Run(Clear).Wait();

            if (Backlight != null)
            {
                backlight = Backlight;
                Task.Run(backlight.MakeDigitalPushPullOutAsync).Wait();
            }


            this.Backlight = true;
        }
Пример #5
0
 /// <summary>
 ///     Construct a new IS31FL3236
 /// </summary>
 /// <param name="i2c">The I2C peripheral this chip is attached to</param>
 /// <param name="rateKhz">The frequency, in kHz, that should be used to communicate with the chip</param>
 /// <param name="sdb">The (optional) hardware shutdown pin, SDB</param>
 public Is31fl3236(I2C i2c, int rateKhz = 100, bool ad0 = false, DigitalOut sdb = null) : base(36, false, true)
 {
     if (sdb != null)
     {
         sdb.DigitalValue = true;
     }
     dev = new SMBusDevice(0x3C, i2c, rateKhz);
     dev.WriteByteDataAsync((byte)Registers.Shutdown, 0x01).Wait();
 }
Пример #6
0
        /// <summary>
        ///     Construct a dual half bridge with PWM speed control
        /// </summary>
        /// <param name="A">The "A" channel half-bridge input</param>
        /// <param name="B">The "B" channel half-bridge input</param>
        /// <param name="Enable">The PWM input used to control the output enable</param>
        public DualHalfBridge(DigitalOut A, DigitalOut B, Pwm Enable)
        {
            Enable.EnablePwmAsync();
            Enable.DutyCycle = 0;
            Enable.EnablePwmAsync();
            A.MakeDigitalPushPullOutAsync();
            B.MakeDigitalPushPullOutAsync();

            enablePwm = Enable;
            this.A    = A;
            this.B    = B;
        }
Пример #7
0
        public void setup()
        {
            ioMock = new Mock <IOPort>();
            IOPort.set(ioMock.Object);
            port       = 0xf0;
            digitalOut = new DigitalOut(port);

            // mocking Led backend
            int portvalue = 0x00;

            ioMock.Setup(m => m._read(port))
            .Returns(portvalue);
            ioMock.Setup(m => m._write(port, It.IsAny <int>()))
            .Callback((int p, int v) => portvalue = v);
        }
Пример #8
0
        /// <summary>
        ///     Construct a dual half bridge with no speed control
        /// </summary>
        /// <param name="A">The "A" channel half-bridge input</param>
        /// <param name="B">The "B" channel half-bridge input</param>
        /// <param name="Enable">An optional Enable pin of the H-bridge</param>
        public DualHalfBridge(DigitalOut A, DigitalOut B, DigitalOut Enable = null)
        {
            if (Enable != null)
            {
                Enable.DigitalValue = false;
                Enable.MakeDigitalPushPullOutAsync();
                enable = Enable;
            }

            A.MakeDigitalPushPullOutAsync();
            B.MakeDigitalPushPullOutAsync();


            this.A = A;
            this.B = B;
        }
Пример #9
0
        public Nrf24l01(Spi spi, SpiChipSelectPin csPin, DigitalOut cePin, DigitalIn irqPin)
        {
            dev         = new SpiDevice(spi, csPin);
            this.irqPin = irqPin;
            this.cePin  = cePin;
            Task.Run(irqPin.MakeDigitalInAsync).Wait();
            Task.Run(cePin.MakeDigitalPushPullOutAsync).Wait();
            cePin.DigitalValue          = false;
            irqPin.DigitalValueChanged += IrqPin_DigitalValueChanged;

            Task.Run(() => dev.SendReceiveAsync(new byte[] { 0x50, 0x73 })).Wait(); // enable feature register
            Task.Run(() => WriteRegister((byte)Registers.Feature, 0b00000111)).Wait();
            Task.Run(() => WriteRegister((byte)Registers.DynamicPayloadLength, 0b00111111)).Wait();
            Task.Run(writeConfig).Wait();

            for (int i = 0; i < 6; i++)
            {
                pipes[i] = new Pipe(i, this);
            }
            // set default addresses
            pipes[0].address = 0xE7E7E7E7E7;
            pipes[1].address = 0xC2C2C2C2C2;
            pipes[2].address = 0xC2C2C2C2C3;
            pipes[3].address = 0xC2C2C2C2C4;
            pipes[4].address = 0xC2C2C2C2C5;
            pipes[5].address = 0xC2C2C2C2C6;

            // set default enable state
            pipes[0].enablePipe = true;
            pipes[1].enablePipe = true;

            Task.Run(() => Task.Delay(5)).Wait();
            Task.Run(FlushRx).Wait();
            Task.Run(FlushTx).Wait();

            powerUp = true;
            Task.Run(writeConfig).Wait();

            Task.Run(() => Task.Delay(5)).Wait();

            // manually call the ISR just in case there's something pending
            IrqPin_DigitalValueChanged(this, new DigitalInValueChangedEventArgs(cePin.DigitalValue));
        }
Пример #10
0
        /// <summary>
        ///     Create a ADJDS311 device
        /// </summary>
        /// <param name="I2CDevice">The I2c port to use</param>
        /// <param name="LedPin">The pin attached to the led</param>
        public Adjds311(I2C I2CDevice, DigitalOut LedPin) : base(0x74, I2CDevice)
        {
            _I2C         = I2CDevice;
            _I2C.Enabled = true;

            led = LedPin;
            led.MakeDigitalPushPullOutAsync();

            WriteByteDataAsync(CAP_RED, 15);
            WriteByteDataAsync(CAP_GREEN, 15);
            WriteByteDataAsync(CAP_BLUE, 15);
            WriteByteDataAsync(CAP_CLEAR, 15);

            WriteByteDataAsync(INT_RED_LO, 0x00);
            WriteByteDataAsync(INT_RED_HI, 0x4);
            WriteByteDataAsync(INT_GREEN_LO, 0x00);
            WriteByteDataAsync(INT_GREEN_HI, 0x5);
            WriteByteDataAsync(INT_BLUE_LO, 0x00);
            WriteByteDataAsync(INT_BLUE_HI, 0x9);
            WriteByteDataAsync(INT_CLEAR_LO, 0x00);
            WriteByteDataAsync(INT_CLEAR_HI, 0x2);
        }
Пример #11
0
        public Pcd8544(Spi spi, SpiChipSelectPin csPin, DigitalOut dc, DigitalOut rst,
                       byte biasValue = 0x04) : base(84, 48)
        {
            this.spi = new SpiDevice(spi, csPin, ChipSelectMode.SpiActiveLow, 6);

            this.dc  = dc;
            this.rst = rst;

            this.dc.MakeDigitalPushPullOutAsync();
            this.rst.MakeDigitalPushPullOutAsync();

            this.rst.DigitalValue = true;
            this.rst.DigitalValue = false;
            this.rst.DigitalValue = true;

            sendCommand(Command.EnterExtendedCommandMode).Wait();
            sendCommand(Command.SetVop, 0x30).Wait();
            sendCommand(Command.SetTempCoefficient, 0x00).Wait();
            sendCommand(Command.SetBias, biasValue).Wait();

            sendCommand(Command.ExitExtendedCommandMode).Wait();
            sendCommand(Command.DisplayOn).Wait();
        }
Пример #12
0
 /// <summary>
 ///     Construct a new instance of the Sn74hc166
 /// </summary>
 /// <param name="spiModule">SPI module to use</param>
 /// <param name="loadPin">latch pin</param>
 public Hc166(Spi spiModule, DigitalOut loadPin)
 {
     loadPin.MakeDigitalPushPullOutAsync();
     spiModule.Enabled = true;
 }