Esempio n. 1
0
 private void WriteRtcDateTime(DateTime value)
 {
     using (var i2c = new I2cDriver(SdaPin.ToProcessor(), SclPin.ToProcessor()))
     {
         var      conn = i2c.Connect(SsdI2cAddress);
         DateTime utc  = value.ToUniversalTime();
         conn.Write(0x00, GetBcd(utc.Second), GetBcd(utc.Minute), GetBcd(utc.Hour), 1, GetBcd(utc.Day),
                    GetBcd(utc.Month), // month
                    GetBcd(utc.Year % 100)
                    );
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Costruttore che permette di indicare il canale da usare come integer.
        /// Usa un trucco, perchè la libreria non supporta l'uso di un integer
        /// per istanziare la classe di controllo dell'IO digitale
        /// </summary>
        /// <param name="NumConnectorPin">
        /// Numero del canale
        /// E' il numero del piedino nel connettore Gpio del Raspberry Pi, NON quello
        /// del SoC Broadcom
        /// </param>
        /// <param name="IsInput">
        /// Direzione dell'IO: se true è un Input, altrimenti è un output
        /// </param>
        public DigitalIO(int NumConnectorPin, GpioPinDriveMode DriveMode)
        {
            foreach (ConnectorPin pin in Enum.GetValues(typeof(ConnectorPin)))
            {
                try
                {
                    if (Enum.GetName(typeof(ConnectorPin),
                                     pin).ToString().IndexOf(NumConnectorPin.ToString(), 0) >= 0)
                    {
                        connectorPin = pin;
                        processorPin = connectorPin.ToProcessor();
                        Console.WriteLine("Numero pin: {0} Definizione pin:{1}",
                                          NumConnectorPin, Enum.GetName(typeof(ConnectorPin), pin).ToString());
                    }
                    PinDirection dir;
                    if (DriveMode == GpioPinDriveMode.Input)
                    {
                        dir = PinDirection.Input;
                    }
                    else if (DriveMode == GpioPinDriveMode.Output)
                    {
                        dir = PinDirection.Output;
                    }
                    else
                    {
                        throw new NotImplementedException("Drive mode dell'I/O non ancora possibile con Mono");
                    }

                    driver.Allocate(processorPin, dir);
                }
                catch
                { // se quel pin non c'è nel Raspberry che uso, dà errore
                }
            }
        }
        public GpioOutputPin(int pinNumber, String name)
            : base(pinNumber, name)
        {
            _connectorPin = GpioController.IntToConnectorPin(pinNumber);
            _processorPin = _connectorPin.ToProcessor();

            Log.LogMessage("Output " + name + " on " + _connectorPin);
        }
 public void AllocatePin(ConnectorPin connectorPin)
 {
     if (!_allocatedPins.Contains(connectorPin))
     {
         Driver.Allocate(connectorPin.ToProcessor(), PinDirection.Output);
         _allocatedPins.Add(connectorPin);
         var msg = string.Format("{0} pin allocated", connectorPin);
         Console.WriteLine(msg);
     }
 }
Esempio n. 5
0
        public Driver()
        {
            Console.WriteLine("Initialising Pi & Bash");
            this.i2cDriver     = new I2cDriver(sdaPin.ToProcessor(), sclPin.ToProcessor());
            this.i2cConnection = new Mcp23017I2cConnection(i2cDriver.Connect(0x20));

            i2cConnection.SetDirection(ledGreen, Mcp23017PinDirection.Output);
            i2cConnection.SetDirection(ledYellow, Mcp23017PinDirection.Output);
            i2cConnection.SetDirection(ledRed, Mcp23017PinDirection.Output);

            Console.WriteLine("LEDs initialised");
        }
Esempio n. 6
0
        private IPwmDevice GetRealDevice()
        {
            PwmFrequency  = 60;
            DeviceAddress = 0x40;

            _i2cDriver = new I2cDriver(SdaPin.ToProcessor(), SclPin.ToProcessor());

            Log.Info("Creating device...");
            var device = Pca9685Connection.Create(_i2cDriver.Connect(DeviceAddress));

            Log.Info("Setting frequency...");
            device.SetPwmUpdateRate(PwmFrequency); //                        # Set frequency to 60 Hz


            IsConnected = true;
            return(device);
        }
Esempio n. 7
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();
 }
Esempio n. 8
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);
 }
		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);
		}
Esempio n. 10
0
        /// <summary>
        /// Costruttore che fa uso della classe ConnectorPin della libreria
        /// Da non usare se si vuole mantenere il programma portabile fra
        /// Win 10 Iot e
        /// </summary>
        /// <param name="ConnectorPin">
        /// Oggetto ConnectorPin usato per questo IO digitale
        /// </param>
        /// <param name="IsInput">
        /// Direzione dell'IO: se true è un Input, altrimenti è un output
        /// </param>
        public DigitalIO(ConnectorPin ConnectorPin, GpioPinDriveMode DriveMode)
        {
            connectorPin = (ConnectorPin)ConnectorPin;
            processorPin = connectorPin.ToProcessor();
            PinDirection dir;

            if (DriveMode == GpioPinDriveMode.Input)
            {
                dir = PinDirection.Input;
            }
            else if (DriveMode == GpioPinDriveMode.Output)
            {
                dir = PinDirection.Output;
            }
            else
            {
                throw new NotImplementedException("Drive mode dell'I/O non ancora possibile con Mono");
            }

            driver.Allocate(processorPin, dir);
        }
Esempio n. 11
0
        private IPwmDevice GetRealDevice()
        {
            PwmFrequency  = new Frequency(60);
            DeviceAddress = 0x40;

            try
            {
                _i2cDriver = new I2cDriver(SdaPin.ToProcessor(), SclPin.ToProcessor());
            }
            catch (Exception e)
            {
                Log.Error("Failed to initialise i2c driver. Did you forget sudo?", e);
            }

            Log.Info("Creating device...");
            var device = new Pca9685Connection(_i2cDriver.Connect(DeviceAddress));

            Log.Info("Setting frequency...");
            device.SetPwmUpdateRate(PwmFrequency); //                        # Set frequency to 60 Hz


            IsConnected = true;
            return(device);
        }
Esempio n. 12
0
 /// <summary>
 /// Gets the status of the specified pin.
 /// </summary>
 public ConnectedPin this[ConnectorPin pin]
 {
     get { return(this[pin.ToProcessor()]); }
 }
 /// <summary>
 /// Removes the specified pin.
 /// </summary>
 /// <param name="pin">The pin.</param>
 public void Remove(ConnectorPin pin)
 {
     Remove(pinConfigurations[pin.ToProcessor()]);
 }
 /// <summary>
 /// Determines whether the connection contains the specified pin.
 /// </summary>
 /// <param name="pin">The pin.</param>
 /// <returns>
 ///   <c>true</c> if the connection contains the specified pin; otherwise, <c>false</c>.
 /// </returns>
 public bool Contains(ConnectorPin pin)
 {
     return pinConfigurations.ContainsKey(pin.ToProcessor());
 }
 /// <summary>
 /// Gets or sets the status of the specified pin.
 /// </summary>
 public bool this[ConnectorPin pin]
 {
     get { return this[pin.ToProcessor()]; }
     set { this[pin.ToProcessor()] = value; }
 }
 /// <summary>
 /// Configures the specified pin as an output pin.
 /// </summary>
 /// <param name="pin">The pin.</param>
 /// <returns>The pin configuration.</returns>
 public static OutputPinConfiguration Output(this ConnectorPin pin)
 {
     return(new OutputPinConfiguration(pin.ToProcessor()));
 }
Esempio n. 17
0
 /// <summary>
 /// Gets the status of the specified pin.
 /// </summary>
 /// <value>
 /// The <see cref="ConnectedPin"/>.
 /// </value>
 /// <param name="pin">The pin.</param>
 /// <returns>The <see cref="ConnectedPin"/> based on Connector pin.</returns>
 public ConnectedPin this[ConnectorPin pin] => this[pin.ToProcessor()];
 /// <summary>
 /// Determines whether the connection contains the specified pin.
 /// </summary>
 /// <param name="pin">The pin.</param>
 /// <returns>
 ///   <c>true</c> if the connection contains the specified pin; otherwise, <c>false</c>.
 /// </returns>
 public bool Contains(ConnectorPin pin)
 {
     return(pinConfigurations.ContainsKey(pin.ToProcessor()));
 }
 /// <summary>
 /// Removes the specified pin.
 /// </summary>
 /// <param name="pin">The pin.</param>
 public void Remove(ConnectorPin pin)
 {
     Remove(pinConfigurations[pin.ToProcessor()]);
 }
 /// <summary>
 /// Gets or sets the status of the specified pin.
 /// </summary>
 public bool this[ConnectorPin pin]
 {
     get { return(this[pin.ToProcessor()]); }
     set { this[pin.ToProcessor()] = value; }
 }
Esempio n. 21
0
 /// <summary>
 /// Gets an output pin on the current driver.
 /// </summary>
 /// <param name="driver">The driver.</param>
 /// <param name="pin">The pin.</param>
 /// <returns>The GPIO output binary pin.</returns>
 public static GpioOutputBinaryPin Out(this IGpioConnectionDriver driver, ConnectorPin pin)
 {
     return(driver.Out(pin.ToProcessor()));
 }
 /// <summary>
 /// Gets a bidirectional pin on the current driver.
 /// </summary>
 /// <param name="driver">The driver.</param>
 /// <param name="pin">The pin.</param>
 /// <param name="resistor">The resistor.</param>
 /// <returns>
 /// The GPIO input binary pin.
 /// </returns>
 public static GpioInputOutputBinaryPin InOut(this IGpioConnectionDriver driver, ConnectorPin pin, PinResistor resistor = PinResistor.None)
 {
     return driver.InOut(pin.ToProcessor(), resistor);
 }
 /// <summary>
 /// Gets an output pin on the current driver.
 /// </summary>
 /// <param name="driver">The driver.</param>
 /// <param name="pin">The pin.</param>
 /// <returns>The GPIO output binary pin.</returns>
 public static GpioOutputBinaryPin Out(this IGpioConnectionDriver driver, ConnectorPin pin)
 {
     return driver.Out(pin.ToProcessor());
 }
Esempio n. 24
0
 /// <summary>
 /// Gets a bidirectional pin on the current driver.
 /// </summary>
 /// <param name="driver">The driver.</param>
 /// <param name="pin">The pin.</param>
 /// <param name="resistor">The resistor.</param>
 /// <returns>
 /// The GPIO input binary pin.
 /// </returns>
 public static GpioInputOutputBinaryPin InOut(this IGpioConnectionDriver driver, ConnectorPin pin, PinResistor resistor = PinResistor.None)
 {
     return(driver.InOut(pin.ToProcessor(), resistor));
 }