Пример #1
0
        public GpioOutputPin(IGpioConnectionDriver driver, ProcessorPin pin)
        {
            this.driver = driver;
            this.pin = pin;

            driver.Allocate(pin, PinDirection.Output);
        }
Пример #2
0
        public SpiConnection(ProcessorPin clock, ProcessorPin ss, ProcessorPin?miso, ProcessorPin?mosi, Endianness endianness)
        {
            this.clock      = clock;
            this.ss         = ss;
            this.miso       = miso;
            this.mosi       = mosi;
            this.endianness = endianness;

            driver = GpioConnectionSettings.DefaultDriver;

            driver.Allocate(clock, PinDirection.Output);
            driver.Write(clock, false);

            driver.Allocate(ss, PinDirection.Output);
            driver.Write(ss, true);

            if (mosi.HasValue)
            {
                driver.Allocate(mosi.Value, PinDirection.Output);
                driver.Write(mosi.Value, false);
            }

            if (miso.HasValue)
            {
                driver.Allocate(miso.Value, PinDirection.Input);
            }
        }
Пример #3
0
 public Button(int pin)
 {
     gpio          = GpioConnectionSettings.DefaultDriver;
     buttonGpioPin = Utilities.getPin(pin);
     gpio.Allocate(buttonGpioPin, PinDirection.Input);
     gpio.SetPinResistor(buttonGpioPin, PinResistor.PullUp);
 }
Пример #4
0
 /// <summary>
 /// Disposes the specified gpio connection driver if created by the factory.
 /// </summary>
 /// <param name="gpioConnectionDriver">The gpio connection driver.</param>
 public void Dispose(IGpioConnectionDriver gpioConnectionDriver)
 {
     if (this.gpioConnectionDrivers.Remove(gpioConnectionDriver))
     {
         gpioConnectionDriver.Dispose();
     }
 }
Пример #5
0
 public Led(int name, int pin)
 {
     this.name  = name;
     gpio       = GpioConnectionSettings.DefaultDriver;
     ledGpioPin = Utilities.getPin(pin);
     gpio.Allocate(ledGpioPin, PinDirection.Output);
 }
        public LcdConnection(IGpioConnectionDriver driver)
        {
            log.Debug(m => m("Init LCD connection"));

            var lcdSettings = new Hd44780LcdConnectionSettings
            {
                ScreenWidth = Columns,
                ScreenHeight = Rows,
                //Encoding = Encoding.ASCII
            };

            var dataPins = new[]
                {
                    ConnectorPin.P1Pin31,
                    ConnectorPin.P1Pin33,
                    ConnectorPin.P1Pin35,
                    ConnectorPin.P1Pin37
                }
                .Select(p => (IOutputBinaryPin)driver.Out(p))
                .ToArray();

            var lcdPins = new Hd44780Pins(
                driver.Out(ConnectorPin.P1Pin40),
                driver.Out(ConnectorPin.P1Pin38),
                dataPins);

            _lcdConnection = new Hd44780LcdConnection(lcdSettings, lcdPins);

            // init additonal characters
            _lcdConnection.SetCustomCharacter(0x0, new byte[] { 0x8, 0xc, 0xe, 0xf, 0xe, 0xc, 0x8 });       // play
            _lcdConnection.SetCustomCharacter(0x1, new byte[] { 0x0, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x0 });  // pause
            _lcdConnection.SetCustomCharacter(0x2, new byte[] { 0x0, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x0 });  // stop

        }
Пример #7
0
        public SpiConnection(ProcessorPin clock, ProcessorPin ss, ProcessorPin? miso, ProcessorPin? mosi, Endianness endianness)
        {
            this.clock = clock;
            this.ss = ss;
            this.miso = miso;
            this.mosi = mosi;
            this.endianness = endianness;

            driver = GpioConnectionSettings.DefaultDriver;

            driver.Allocate(clock, PinDirection.Output);
            driver.Write(clock, false);

            driver.Allocate(ss, PinDirection.Output);
            driver.Write(ss, true);

            if (mosi.HasValue)
            {
                driver.Allocate(mosi.Value, PinDirection.Output);
                driver.Write(mosi.Value, false);
            }

            if (miso.HasValue)
                driver.Allocate(miso.Value, PinDirection.Input);
        }
Пример #8
0
        public GpioOutputPin(IGpioConnectionDriver driver, ProcessorPin pin)
        {
            this.driver = driver;
            this.pin    = pin;

            driver.Allocate(pin, PinDirection.Output);
        }
        public RaspiAtxConnection(IController controller, IGpioConnectionDriver driver)
        {
            // set boot ok pin
            _bookOkPin = ConnectorPin.P1Pin11.Output().Revert();

            // listen to shutdown gpio
            var shutdownPin = ConnectorPin.P1Pin13
                .Input()
                .PullDown()
                .OnStatusChanged(state =>
                {
                    if (state)
                    {
                        log.Info(m => m("Shutdown triggered by RaspiAtx"));

                        controller.Shutdown();
                    }
                });

            // connect on/off button trigger pin
            _triggerOnOffButtonPin = driver.Out(ConnectorPin.P1Pin32);

            // open connection
            _gpioConnection = new GpioConnection(_bookOkPin, shutdownPin);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GpioConnectionSettings"/> class.
 /// </summary>
 /// <param name="driver">The driver to use.</param>
 public GpioConnectionSettings(IGpioConnectionDriver driver)
 {
     Driver        = driver;
     BlinkDuration = DefaultBlinkDuration;
     PollInterval  = DefaultPollInterval;
     Opened        = true;
 }
Пример #11
0
 public IOFactory(DataServerWebClient d, GpioConnection g)
 {
     log4net.Config.XmlConfigurator.Configure();
     log        = LogManager.GetLogger("Device");
     dataServer = d;
     gpio       = g;
     driver     = GpioConnectionSettings.DefaultDriver;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="GpioOutputBinaryPin"/> class.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="pin">The pin.</param>
        /// <param name="resistor">The resistor.</param>
        public GpioOutputBinaryPin(IGpioConnectionDriver driver, ProcessorPin pin, PinResistor resistor = PinResistor.None)
        {
            this.driver = driver;
            this.pin = pin;

            driver.Allocate(pin, PinDirection.Output);
            driver.SetPinResistor(pin, resistor);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GpioOutputBinaryPin"/> class.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="pin">The pin.</param>
        /// <param name="resistor">The resistor.</param>
        public GpioOutputBinaryPin(IGpioConnectionDriver driver, ProcessorPin pin, PinResistor resistor = PinResistor.None)
        {
            this.driver = driver;
            this.pin    = pin;

            driver.Allocate(pin, PinDirection.Output);
            driver.SetPinResistor(pin, resistor);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PullDownSwitchDevice" /> class.
 /// </summary>
 /// <param name="switchConnectorPin">The switch connector pin.</param>
 /// <param name="gpioConnectionDriver">The gpio connection driver.</param>
 public PullDownSwitchDevice(ConnectorPin switchConnectorPin, IGpioConnectionDriver gpioConnectionDriver)
 {
     this.PinConfiguration = switchConnectorPin.Input().PullDown();
     this.PinConfiguration.OnStatusChanged(this.OnSwitchChanged);
     using (var switchPin = gpioConnectionDriver.In(switchConnectorPin))
     {
         this.State = switchPin.Read();
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="GpioOutputBinaryPin"/> class.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="pin">The pin.</param>
        /// <param name="resistor">The resistor.</param>
        public GpioOutputBinaryPin(IGpioConnectionDriver driver, ProcessorPin pin, PinResistor resistor = PinResistor.None)
        {
            this.driver = driver;
            this.pin = pin;

            driver.Allocate(pin, PinDirection.Output);
            if ((driver.GetCapabilities() & GpioConnectionDriverCapabilities.CanSetPinResistor) > 0)
                driver.SetPinResistor(pin, resistor);
        }
Пример #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HcSr04Connection"/> class.
        /// </summary>
        /// <param name="triggerPin">The trigger pin.</param>
        /// <param name="echoPin">The echo pin.</param>
        public HcSr04Connection(ProcessorPin triggerPin, ProcessorPin echoPin)
        {
            this.triggerPin = triggerPin;
            this.echoPin    = echoPin;

            driver = new MemoryGpioConnectionDriver();

            driver.Allocate(triggerPin, PinDirection.Output);
            driver.Allocate(echoPin, PinDirection.Input);
        }
Пример #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GpioConnectionDriverFactory" /> class.
        /// </summary>
        /// <param name="useSingleton">if set to <c>true</c> [use singleton].</param>
        public GpioConnectionDriverFactory(bool useSingleton)
        {
            if (useSingleton)
            {
                this.gpioConnectionDriver = GetBestDriver(
                    Board.Current.IsRaspberryPi ? GpioConnectionDriverCapabilities.None : GpioConnectionDriverCapabilities.CanWorkOnThirdPartyComputers);
            }

            this.shouldDisposeDriver = true;
        }
Пример #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HcSr04Connection"/> class.
        /// </summary>
        /// <param name="triggerPin">The trigger pin.</param>
        /// <param name="echoPin">The echo pin.</param>
        public HcSr04Connection(ProcessorPin triggerPin, ProcessorPin echoPin)
        {
            this.triggerPin = triggerPin;
            this.echoPin = echoPin;

            driver = new MemoryGpioConnectionDriver();

            driver.Allocate(triggerPin, PinDirection.Output);
            driver.Allocate(echoPin, PinDirection.Input);
        }
Пример #19
0
        /// <summary>
        /// Waits for a pin to reach the specified state, then measures the time it remains in this state.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="pin">The measure pin.</param>
        /// <param name="waitForUp">if set to <c>true</c>, wait for the pin to be up.</param>
        /// <param name="phase1Timeout">The first phase timeout.</param>
        /// <param name="phase2Timeout">The second phase timeout.</param>
        /// <returns>
        /// The time the pin remains up.
        /// </returns>
        public static decimal Time(this IGpioConnectionDriver driver, ProcessorPin pin, bool waitForUp = true, TimeSpan phase1Timeout = new TimeSpan(), TimeSpan phase2Timeout = new TimeSpan())
        {
            driver.Wait(pin, waitForUp, phase1Timeout);

            var waitDown = DateTime.Now.Ticks;

            driver.Wait(pin, !waitForUp, phase2Timeout);

            return((DateTime.Now.Ticks - waitDown) / 10000m);
        }
Пример #20
0
        public Button(InputPinConfiguration outputPin, IGpioConnectionDriver driver = null)
        {
            PinConfig = outputPin;
            Driver    = driver ?? GpioConnectionSettings.DefaultDriver;
            Driver.Allocate(PinConfig.Pin, PinDirection.Output);
            TokenScource = new System.Threading.CancellationTokenSource();
            Action a = Watch;

            Task.Run(a, TokenScource.Token);
            // Task.Start(Watch);
        }
        public VolumeConnection(IGpioConnectionDriver driver)
        {
            log.Debug(m => m("Init volume connection"));

            _mcpConnection = new Mcp3202SpiConnection(
                driver.Out(ConnectorPin.P1Pin23),
                driver.Out(ConnectorPin.P1Pin24),
                driver.In(ConnectorPin.P1Pin21),
                driver.Out(ConnectorPin.P1Pin19),
                8191);
        }
Пример #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GpioOutputBinaryPin"/> class.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="pin">The pin.</param>
        /// <param name="resistor">The resistor.</param>
        public GpioOutputBinaryPin(IGpioConnectionDriver driver, ProcessorPin pin, PinResistor resistor = PinResistor.None)
        {
            this.driver = driver;
            this.pin    = pin;

            driver.Allocate(pin, PinDirection.Output);
            if ((driver.GetCapabilities() & GpioConnectionDriverCapabilities.CanSetPinResistor) > 0)
            {
                driver.SetPinResistor(pin, resistor);
            }
        }
Пример #23
0
 static void rapidBlink(IGpioConnectionDriver driver, ProcessorPin led)
 {
     //blink the LED for 5 seconds, 4 times per second
     for (int i = 0; i < 20; i++)
     {
         driver.Write(led, true);
         System.Threading.Thread.Sleep(125);
         driver.Write(led, false);
         System.Threading.Thread.Sleep(125);
     }
 }
Пример #24
0
        /// <summary>
        /// GPIO出力
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            ProcessorPin p14 = ProcessorPin.Pin14;

            _ = p14.Output();
            IGpioConnectionDriver drv = GpioConnectionSettings.DefaultDriver;

            drv.Allocate(p14, PinDirection.Output);
            drv.Write(p14, isOutput);
            isOutput = !isOutput;
        }
        public ITransceiverSpiConnection Create(ConnectorPin slaveSelectPin, ConnectorPin resetPin, string spiPath = "/dev/spidev0.0")
        {
            NativeSpiConnection spiConnection = new NativeSpiConnection(new SpiControlDevice(new UnixFile(spiPath, UnixFileMode.ReadWrite)));

            spiConnection.SetDelay(0);
            spiConnection.SetMaxSpeed(500000);
            spiConnection.SetBitsPerWord(8);

            IGpioConnectionDriver driver = GpioConnectionSettings.DefaultDriver;

            return(new TransceiverSpiConnection(spiConnection, driver.Out(slaveSelectPin), driver.Out(resetPin)));
        }
        public HardwareService()
        {
            //initialize logging
            log4net.Config.XmlConfigurator.Configure();
            log = LogManager.GetLogger("Device");

            //initialize hardware
            gpio       = new GpioConnection();
            gpioDriver = new MemoryGpioConnectionDriver();

            Solenoids = new List <ISolenoid>();
            Alarms    = new List <IAlarm>();
            Analogs   = new List <IAnalog>();
            Spis      = new List <ISpi>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HcSr04Connection"/> class.
        /// </summary>
        /// <param name="triggerPin">The trigger pin.</param>
        /// <param name="echoPin">The echo pin.</param>
        public HcSr04Connection(ProcessorPin triggerPin, ProcessorPin echoPin)
        {
            this.triggerPin = triggerPin;
            this.echoPin = echoPin;

            Timeout = DefaultTimeout;

            driver = GpioConnectionSettings.DefaultDriver;

            driver.Allocate(echoPin, PinDirection.Input);
            driver.Allocate(triggerPin, PinDirection.Output);

            try
            {
                GetDistance();
            } catch {}
        }
        /// <summary>
        /// Waits for the specified pin to reach a given state.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="pin">The pin.</param>
        /// <param name="waitForUp">if set to <c>true</c>, waits for the pin to become up; otherwise, waits for the pin to become down.</param>
        /// <param name="timeout">The timeout.</param>
        public static void Wait(this IGpioConnectionDriver driver, ProcessorPin pin, bool waitForUp = true, int timeout = 0)
        {
            if (timeout == 0)
            {
                timeout = 5000;
            }

            var startWait = DateTime.Now;

            while (driver.Read(pin) != waitForUp)
            {
                if (DateTime.Now.Ticks - startWait.Ticks >= 10000 * timeout)
                {
                    throw new TimeoutException();
                }
            }
        }
Пример #29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HcSr04Connection"/> class.
        /// </summary>
        /// <param name="triggerPin">The trigger pin.</param>
        /// <param name="echoPin">The echo pin.</param>
        public HcSr04Connection(ProcessorPin triggerPin, ProcessorPin echoPin)
        {
            this.triggerPin = triggerPin;
            this.echoPin    = echoPin;

            Timeout = DefaultTimeout;

            driver = GpioConnectionSettings.DefaultDriver;

            driver.Allocate(echoPin, PinDirection.Input);
            driver.Allocate(triggerPin, PinDirection.Output);

            try
            {
                GetDistance();
            } catch {}
        }
Пример #30
0
        /// <summary>
        /// 意図したタイミングでGPIOの入力をチェック
        /// </summary>
        private void getIO()
        {
            ProcessorPin p2 = ProcessorPin.Pin02;
            ProcessorPin p3 = ProcessorPin.Pin03;
            ProcessorPin p4 = ProcessorPin.Pin04;

            _ = p2.Input().PullUp();
            _ = p3.Input().PullUp();
            _ = p4.Input().PullUp();
            IGpioConnectionDriver drv = GpioConnectionSettings.DefaultDriver;

            drv.Allocate(p2, PinDirection.Input);
            drv.Allocate(p3, PinDirection.Input);
            drv.Allocate(p4, PinDirection.Input);
            checkBox1.Checked = drv.Read(p2);
            checkBox2.Checked = drv.Read(p3);
            checkBox3.Checked = drv.Read(p4);
        }
Пример #31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Mfrc522Connection" /> class.
 /// </summary>
 /// <param name="spiDevicePath">The spi device path.</param>
 /// <param name="resetConnectorPin">The reset connector pin.</param>
 /// <param name="gpioConnectionDriverFactory">The gpio connection driver factory.</param>
 /// <param name="threadFactory">The thread factory.</param>
 /// <param name="rfidConnectionReporter">The rfid connection reporter.</param>
 public Mfrc522Connection(
     string spiDevicePath,
     ConnectorPin?resetConnectorPin,
     IGpioConnectionDriverFactory?gpioConnectionDriverFactory = null,
     IThreadFactory?threadFactory = null,
     IRfidConnectionReporter?rfidConnectionReporter = null)
 {
     this.spiDevicePath          = spiDevicePath;
     this.resetConnectorPin      = resetConnectorPin;
     this.rfidConnectionReporter = rfidConnectionReporter;
     this.rfidConnectionReporter?.SetSource(typeof(IRfidConnectionReporter), this);
     this.thread = ThreadFactory.EnsureThreadFactory(threadFactory).Create();
     this.gpioConnectionDriverFactory =
         GpioConnectionDriverFactory.EnsureGpioConnectionDriverFactory(gpioConnectionDriverFactory);
     this.gpioConnectionDriver = this.gpioConnectionDriverFactory.Get();
     this.mfrc522Device        = new Mfrc522Device(this.thread, this.gpioConnectionDriver);
     this.scanningJob          = new ContinuousJob(this.CheckForTags, (Exception exception, ref bool _) => this.rfidConnectionReporter?.OnException(exception));
 }
        /// <summary>
        /// Measures the time the specified pin remains up.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="pin">The measure pin.</param>
        /// <param name="waitForDown">if set to <c>true</c>, waits for the pin to become down; otherwise, waits for the pin to become up.</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns>
        /// The time the pin remains up, in milliseconds.
        /// </returns>
        public static decimal Time(this IGpioConnectionDriver driver, ProcessorPin pin, bool waitForDown = true, int timeout = 0)
        {
            if (timeout == 0)
            {
                timeout = 5000;
            }

            var waitDown = DateTime.Now;

            while (driver.Read(pin) == waitForDown)
            {
                if (DateTime.Now.Ticks - waitDown.Ticks >= 10000 * timeout)
                {
                    throw new TimeoutException();
                }
            }

            return((DateTime.Now.Ticks - waitDown.Ticks) / 10000m);
        }
Пример #33
0
        public GPIO(ConnectorPin pin, PinDirection direction)
        {
            //_gpioDriver = new FileGpioConnectionDriver();
            _gpioDriver = new MemoryGpioConnectionDriver();
            _gpioDriver.InOut(pin);

            _syncRoot   = _gpioDriver;
            _pin        = pin;
            _connection = _gpioDriver.InOut(pin);

            if (direction == PinDirection.Input)
            {
                _connection.AsInput();
            }
            else
            {
                _connection.AsOutput();
            }
        }
Пример #34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Ky040Device" /> class.
 /// </summary>
 /// <param name="clockConnectorPin">The clock connector pin.</param>
 /// <param name="dataConnectorPin">The data connector pin.</param>
 /// <param name="buttonConnectorPin">The button connector pin.</param>
 /// <param name="gpioConnectionDriverFactory">The gpio connection driver factory.</param>
 /// <param name="rotaryEncoderReporter">The ky040 reporter.</param>
 public Ky040Device(
     ConnectorPin clockConnectorPin,
     ConnectorPin dataConnectorPin,
     ConnectorPin buttonConnectorPin,
     IGpioConnectionDriverFactory?gpioConnectionDriverFactory = null,
     IRotaryEncoderReporter?rotaryEncoderReporter             = null)
 {
     this.gpioConnectionDriverFactory = GpioConnectionDriverFactory.EnsureGpioConnectionDriverFactory(gpioConnectionDriverFactory);
     this.gpioConnectionDriver        = this.gpioConnectionDriverFactory.Get();
     this.rotaryEncoderReporter       = rotaryEncoderReporter;
     this.rotaryEncoderReporter?.SetSource(typeof(IRotaryEncoderReporter), this);
     this.clkPinConfiguration = clockConnectorPin.Input().PullUp();
     this.clkPinConfiguration.OnStatusChanged(this.OnEncoderChanged);
     this.dtPinConfiguration = dataConnectorPin.Input().PullUp();
     this.dtPinConfiguration.OnStatusChanged(this.OnEncoderChanged);
     this.buttonPinConfiguration = buttonConnectorPin.Input().PullUp();
     this.buttonPinConfiguration.OnStatusChanged(this.OnButtonPressed);
     this.clockProcessorPin = clockConnectorPin.ToProcessor();
     this.dataProcessorPin  = dataConnectorPin.ToProcessor();
 }
		public GroveRgbConnection(ConnectorPin dataPin, ConnectorPin clockPin, int ledCount)
		{
			ledColors = new List<RgbColor>();
			for(int i = 0; i < ledCount; i++)
			{
				// Initialize all leds with white color
				ledColors.Add(new RgbColor());
			}
			this.dataPin = dataPin.ToProcessor();
			this.clockPin = clockPin.ToProcessor();
			if (Raspberry.Board.Current.IsRaspberryPi) 
			{
				driver = new GpioConnectionDriver();
			}
			else 
			{
				driver = new FileGpioConnectionDriver();
			}
			driver.Allocate(this.dataPin, PinDirection.Output);
			driver.Allocate(this.clockPin, PinDirection.Output);
		}
Пример #36
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Max9744Device" /> class.
        /// </summary>
        /// <param name="i2cAddress">The i2c address.</param>
        /// <param name="mutePin">The mute pin.</param>
        /// <param name="shutdownPin">The shutdown pin.</param>
        /// <param name="sdaPin">The sda pin.</param>
        /// <param name="sclPin">The SCL pin.</param>
        /// <param name="gpioConnectionDriverFactory">The gpio connection driver factory.</param>
        /// <param name="i2CDeviceConnectionReporter">The i2 c device connection reporter.</param>
        public Max9744Device(
            byte i2cAddress,
            ConnectorPin mutePin,
            ConnectorPin shutdownPin,
            ProcessorPin sdaPin,
            ProcessorPin sclPin,
            IGpioConnectionDriverFactory? gpioConnectionDriverFactory,
            II2cDeviceConnectionReporter? i2CDeviceConnectionReporter = null)
        {
            this.gpioConnectionDriverFactory = GpioConnectionDriverFactory.EnsureGpioConnectionDriverFactory(gpioConnectionDriverFactory);
            this.gpioConnectionDriver = this.gpioConnectionDriverFactory.Get();

            // connect volume via i2c
            this.i2CDriver = new I2cDriver(sdaPin, sclPin);
            this.connection = this.i2CDriver.Connect(i2cAddress, i2CDeviceConnectionReporter);

            // connect shutdown via gpio
            this.mutePin = mutePin.Output().Revert();
            this.shutdownPin = shutdownPin.Output().Revert();
            this.gpioConnection = new GpioConnection(this.gpioConnectionDriverFactory, this.shutdownPin, this.mutePin);
        }
Пример #37
0
 public GroveRgbConnection(ConnectorPin dataPin, ConnectorPin clockPin, int ledCount)
 {
     ledColors = new List <RgbColor>();
     for (int i = 0; i < ledCount; i++)
     {
         // Initialize all leds with white color
         ledColors.Add(new RgbColor());
     }
     this.dataPin  = dataPin.ToProcessor();
     this.clockPin = clockPin.ToProcessor();
     if (Raspberry.Board.Current.IsRaspberryPi)
     {
         driver = new GpioConnectionDriver();
     }
     else
     {
         driver = new FileGpioConnectionDriver();
     }
     driver.Allocate(this.dataPin, PinDirection.Output);
     driver.Allocate(this.clockPin, PinDirection.Output);
 }
Пример #38
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RemotePiDevice" /> class.
        /// </summary>
        /// <param name="shutdownInConnectorPin">The shutdown in connector pin.</param>
        /// <param name="shutdownOutConnectorPin">The shutdown out connector pin.</param>
        /// <param name="operatingSystemShutdown">The operation system shutdown.</param>
        /// <param name="shutdownTimeSpan">The shutdown time span.</param>
        /// <param name="gpioConnectionDriverFactory">The gpio connection driver factory.</param>
        /// <param name="dateTime">The date time.</param>
        /// <param name="threadFactory">The thread factory.</param>
        public RemotePiDevice(
            ConnectorPin shutdownInConnectorPin,
            ConnectorPin shutdownOutConnectorPin,
            IOperatingSystemShutdown operatingSystemShutdown,
            TimeSpan shutdownTimeSpan,
            IGpioConnectionDriverFactory?gpioConnectionDriverFactory = null,
            IDateTime?dateTime           = null,
            IThreadFactory?threadFactory = null)
        {
            this.gpioConnectionDriverFactory = GpioConnectionDriverFactory.EnsureGpioConnectionDriverFactory(gpioConnectionDriverFactory);
            this.gpioConnectionDriver        = this.gpioConnectionDriverFactory.Get();
            this.shutdownInConnectorPin      = shutdownInConnectorPin;
            this.shutdownOutConnectorPin     = shutdownOutConnectorPin;
            this.operatingSystemShutdown     = operatingSystemShutdown;
            this.shutdownTimeSpan            = shutdownTimeSpan < TimeSpan.FromSeconds(4) ? TimeSpan.FromSeconds(4) : shutdownTimeSpan;
            this.dateTime = dateTime ?? new DateTimeProvider();
            this.thread   = ThreadFactory.EnsureThreadFactory(threadFactory).Create();
            var pinConfiguration = shutdownInConnectorPin.Input().PullDown();

            pinConfiguration.OnStatusChanged(this.OnShutdown);
            this.gpioConnection = new GpioConnection(new GpioConnectionDriverFactory(this.gpioConnectionDriver), pinConfiguration);
        }
Пример #39
0
        public SpiDevice(
            int id,
            string name,
            ConnectorPin clock,
            ConnectorPin cs,
            ConnectorPin miso,
            ConnectorPin mosi)
        {
            Id        = id;
            Name      = name;
            Clock     = clock;
            CS        = cs;
            MISO      = miso;
            MOSI      = mosi;
            spiDriver = GPIOService.GpioDriver;

            spiConnection = new Mcp3008SpiConnection(
                spiDriver.Out(Clock),
                spiDriver.Out(CS),
                spiDriver.In(MISO),
                spiDriver.Out(MOSI));
        }
Пример #40
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Hd44780Pins" /> class.
        /// </summary>
        /// <param name="gpioConnectionDriver">The gpio connection driver.</param>
        /// <param name="registerSelect">The register select.</param>
        /// <param name="clock">The clock.</param>
        /// <param name="backlight">The backlight.</param>
        /// <param name="readWrite">The read write.</param>
        /// <param name="data">The data.</param>
        public Hd44780Pins(
            IGpioConnectionDriver gpioConnectionDriver,
            ConnectorPin registerSelect,
            ConnectorPin clock,
            ConnectorPin?backlight,
            ConnectorPin?readWrite,
            params ConnectorPin[] data)
        {
            this.RegisterSelect = gpioConnectionDriver.Out(registerSelect);
            this.Clock          = gpioConnectionDriver.Out(clock);
            if (backlight != null)
            {
                this.Backlight = gpioConnectionDriver.Out(backlight.Value);
            }

            if (readWrite != null)
            {
                this.ReadWrite = gpioConnectionDriver.Out(readWrite.Value);
            }

            this.Data = data.Select(gpioConnectionDriver.Out).ToArray();
        }
		private void SetupPins(GpioConfiguration gpioConfiguration)
		{
			if (!PlatformHelper.IsLinux) return;
			_log.Info("Default driver");
			_driver = GpioConnectionSettings.DefaultDriver;
			_pins = new Dictionary<PinName, ProcessorPin>();
			foreach (var target in gpioConfiguration.Targets)
			{
				var processorPin = GetPin(target.Pin);
				_pins.Add(target.PinName, processorPin);
				_log.Info(string.Format("Add pin output {0}", target.PinName));
				_driver.Allocate(processorPin, PinDirection.Output);
				SetPin(target, false);
			}

			foreach (var target in gpioConfiguration.Buttons)
			{	
				var processorPin = GetPin(target.Pin);
				_pins.Add(PinName.MainButton, processorPin);
				_log.Info(string.Format("Add pin Input {0}", PinName.MainButton));
				_driver.Allocate(processorPin, PinDirection.Input);
			}	
		}
Пример #42
0
 private void Init()
 {
     driver = GpioConnectionSettings.DefaultDriver;
 }
 public GpioDriverHelper(IGpioConnectionDriver driver)
 {
     Driver = driver;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GpioInputOutputBinaryPin"/> class.
 /// </summary>
 /// <param name="driver">The driver.</param>
 /// <param name="pin">The pin.</param>
 /// <param name="resistor">The resistor.</param>
 public GpioInputOutputBinaryPin(IGpioConnectionDriver driver, ProcessorPin pin, PinResistor resistor = PinResistor.None)
 {
     this.driver = driver;
     this.pin = pin;
     this.resistor = resistor;
 }
Пример #45
0
    public GpioHal(IList<Pin> pins, string driverName = "", bool useProcessorPinsNames = false, PinResistor inputResistor = PinResistor.PullUp)
    {
      _inUse = false;
      _driver = GetDriver(driverName);  // GPIO driver
      _inputResistor = inputResistor;   // Pullup/pulldown input resistors
      _pins = new Dictionary<string, ProcessorPin>(); // Global pins

      foreach (var pin in pins)
      {
        ProcessorPin procPin;

        if (useProcessorPinsNames)
        {
          ConnectorPin userPin;

          if (!Enum.TryParse(pin.Source, true, out userPin))
          {
            throw new HardwareException(string.Format("raspberry connector pin {0} not found", pin.Source));
          }

          procPin = userPin.ToProcessor();
        }
        else
        {
          if (!Enum.TryParse(pin.Source, true, out procPin))
          {
            throw new HardwareException(string.Format("raspberry processor pin {0} not found", pin.Source));
          }
        }

        switch (pin.Type)
        {
          case PinTypes.Input:
          case PinTypes.Counter:
          case PinTypes.Analog:

            //Allocate pin
            _driver.Allocate(procPin, PinDirection.Input);

            //Set pullup/pulldown resistor
            if (_inputResistor != PinResistor.None && (_driver.GetCapabilities() & GpioConnectionDriverCapabilities.CanSetPinResistor) > 0)
              _driver.SetPinResistor(procPin, _inputResistor);

            break;
          case PinTypes.Output:
          case PinTypes.Pwm:
            //Allocate output pin
            _driver.Allocate(procPin, PinDirection.Output);
            break;
        }

        //set input pins in global input pins
        _globalPins |= (ProcessorPins)((uint)1 << (int)procPin);

        //Add proessor pin
        _pins.Add(pin.Source, procPin);

      }
      Info = new HardwareInfo
      {
        Name = "Raspberry model " + Raspberry.Board.Current.Model + "GPIO HAL",
        Inputs = GpioConnectionSettings.ConnectorPinout == Raspberry.ConnectorPinout.Rev2 ? 26 : 17,
        Outputs = GpioConnectionSettings.ConnectorPinout == Raspberry.ConnectorPinout.Rev2 ? 26 : 17,
        Analogs = 0,
        Pwms = 0,
        Counters = 0,
        Vendor = "Raspberry foundation"
      };
    }
        /// <summary>
        /// Initializes a new instance of the <see cref="Hd44780LcdConnection"/> class.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="registerSelectPin">The register select pin.</param>
        /// <param name="clockPin">The clock pin.</param>
        /// <param name="dataPins">The data pins.</param>
        public Hd44780LcdConnection(Hd44780LcdConnectionSettings settings, ProcessorPin registerSelectPin, ProcessorPin clockPin, IEnumerable<ProcessorPin> dataPins)
        {
            settings = settings ?? new Hd44780LcdConnectionSettings();

            this.registerSelectPin = registerSelectPin;
            this.clockPin = clockPin;
            this.dataPins = dataPins.ToArray();

            if (this.dataPins.Length != 4 && this.dataPins.Length != 8)
                throw new ArgumentOutOfRangeException("dataPins", this.dataPins.Length, "There must be either 4 or 8 data pins");

            width = settings.ScreenWidth;
            height = settings.ScreenHeight;
            if (height < 1 || height > 2)
                throw new ArgumentOutOfRangeException("ScreenHeight", height, "Screen must have either 1 or 2 rows");
            if (width * height > 80)
                throw new ArgumentException("At most 80 characters are allowed");

            if (settings.PatternWidth != 5)
                throw new ArgumentOutOfRangeException("PatternWidth", settings.PatternWidth, "Pattern must be 5 pixels width");
            if (settings.PatternHeight != 8 && settings.PatternHeight != 10)
                throw new ArgumentOutOfRangeException("PatternHeight", settings.PatternWidth, "Pattern must be either 7 or 10 pixels height");
            if (settings.PatternHeight == 10 && height == 2)
                throw new ArgumentException("10 pixels height pattern cannot be used with 2 rows");

            functions = (settings.PatternHeight == 8 ? Functions.Matrix5x8 : Functions.Matrix5x10)
                | (height == 1 ? Functions.OneLine : Functions.TwoLines)
                | (this.dataPins.Length == 4 ? Functions.Data4bits : Functions.Data8bits);

            entryModeFlags = /*settings.RightToLeft
                ? EntryModeFlags.EntryRight | EntryModeFlags.EntryShiftDecrement
                :*/ EntryModeFlags.EntryLeft | EntryModeFlags.EntryShiftDecrement;

            encoding = settings.Encoding;

            connectionDriver = new MemoryGpioConnectionDriver();

            connectionDriver.Allocate(registerSelectPin, PinDirection.Output);
            connectionDriver.Write(registerSelectPin, false);

            connectionDriver.Allocate(clockPin, PinDirection.Output);
            connectionDriver.Write(clockPin, false);

            foreach (var dataPin in this.dataPins)
            {
                connectionDriver.Allocate(dataPin, PinDirection.Output);
                connectionDriver.Write(dataPin, false);
            }

            WriteByte(0x33, false); // Initialize
            WriteByte(0x32, false);

            WriteCommand(Command.SetFunctions, (int) functions);
            WriteCommand(Command.SetDisplayFlags, (int) displayFlags);
            WriteCommand(Command.SetEntryModeFlags, (int) entryModeFlags);

            Clear();
        }