コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Pca9685Connection"/> class.
        /// </summary>
        /// <param name="connection">The I2C connection.</param>
        public Pca9685Connection(I2cDeviceConnection connection)
        {
            this.connection = connection;

            log.Info(m => m("Resetting PCA9685"));
            WriteRegister(Register.MODE1, 0x00);
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Ssd1306Connection"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="displayWidth">The display displayWidth.</param>
 /// <param name="displayHeight">The display displayHeight.</param>
 public Ssd1306Connection(I2cDeviceConnection connection, int displayWidth = 128, int displayHeight = 64)
 {
     this.connection = connection;
     this.displayWidth = displayWidth;
     this.displayHeight = displayHeight;
     Initialize();
 }
コード例 #3
0
        public AmplifierConnection()
        {
            log.Debug(m => m("Init amplifier connection"));

            // connect volume via i2c
            _i2cDriver = new I2cDriver(ProcessorPin.Pin2, ProcessorPin.Pin3);
            _connection = _i2cDriver.Connect(0x4b);

            // connect shutdown via gpio
            _shutdownPin = ConnectorPin.P1Pin36.Output().Revert();
            _gpioConnection = new GpioConnection(_shutdownPin);
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Bmp085I2cConnection"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 public Bmp085I2cConnection(I2cDeviceConnection connection)
 {
     this.connection = connection;
     Initialize();
 }
コード例 #5
0
 /// <summary>
 /// Creates a new instance of the class using the provided I2C Connection.
 /// </summary>
 /// <param name="connection">I2C Connection to the Clock.</param>
 public Ds1307Connection(I2cDeviceConnection connection)
 {
     Connection = connection;
 }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Pcf8563I2cConnection"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 public Pcf8563I2cConnection(I2cDeviceConnection connection)
 {
     this.connection = connection;
 }
コード例 #7
0
ファイル: Display.cs プロジェクト: Equitis/RPiAqua
        public Display()
        {
            driver = new I2cDriver(sdaPin.ToProcessor(), sclPin.ToProcessor());
            //driver.ClockDivider = 400;
            connection = driver.Connect(LCDADRESS);
            //connection.WriteByte();
            this.Write(0x03);
            this.Write(0x03);
            this.Write(0x03);
            this.Write(0x02);

            this.Write(LCD_FUNCTIONSET | LCD_2LINE | LCD_5x8DOTS | LCD_4BITMODE);
            this.Write(LCD_DISPLAYCONTROL | LCD_DISPLAYON);
            this.Write(LCD_CLEARDISPLAY);
            this.Write(LCD_ENTRYMODESET | LCD_ENTRYLEFT);
        }
コード例 #8
0
 /// <summary>
 /// Initializes the connection
 /// </summary>
 /// <param name="addr">I2C address for the matrix.</param>
 private void InitializeConnection(int addr)
 {
     driver = new I2cDriver(Raspberry.IO.GeneralPurpose.ProcessorPin.Pin2, Raspberry.IO.GeneralPurpose.ProcessorPin.Pin3);
     connection = driver.Connect(addr);
 }
コード例 #9
0
 public static Pca9685Connection Create(I2cDeviceConnection connection)
 {
     return new Pca9685Connection(connection);
 }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Pcf8574I2cConnection"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 public Pcf8574I2cConnection(I2cDeviceConnection connection)
 {
     this.connection = connection;
     connection.WriteByte(0);
 }
コード例 #11
0
 public Mcp23017I2cConnection(I2cDeviceConnection connection)
 {
     this.connection = connection;
 }
コード例 #12
0
 public BarometricPressure_BMP180(int deviceAddress, I2cDriver driver)
     : base(false)
 {
     conn = driver.Connect(deviceAddress);
     Initialization();
 }
コード例 #13
0
        static void Main(string[] args)
        {
            Console.WriteLine("Ds1307 Test");
            Console.WriteLine("===========");

            Console.WriteLine("Opening Connection...");

            try
            {
                driver = new I2cDriver(ProcessorPin.Pin02, ProcessorPin.Pin03);
                i2cConnection = driver.Connect(0x68);
                clock = new Ds1307Connection(i2cConnection);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Unable to open connection.");
                Console.WriteLine(ex);
                Console.WriteLine("Press any key to close.");
                Console.Read();
                Environment.Exit(1);
            }

            Console.WriteLine("Connection open!");

            AskForKey();
        }
コード例 #14
0
ファイル: Rtc_PCF8563.cs プロジェクト: gamondue/GOR-4H-16
 public Rtc_PCF8563(int deviceAddress, I2cDriver driver)
 {
     connection = driver.Connect(deviceAddress);
 }
コード例 #15
0
ファイル: Program.cs プロジェクト: JelleLoeve/Raspberry-LED
        public static void Main()
        {
            Console.Title = "Raspberry-LED Domotica client";
            if (!Helpers.IsLinux)
            {
                Console.WriteLine("Sorry, almost everything in this script can only run on the Raspberry Pi.");
                Console.WriteLine("Press enter to close the script.");
                Console.Read();
                Environment.Exit(0);
            }
            Console.CancelKeyPress += delegate
            {
                Console.WriteLine("Stopping the program");
                HubConnection.Closed -= StartHubConnection;
                HubConnection.Closed += null;
                HubConnection.Stop();
                Console.WriteLine("Stopped SignalR communication");
                for (var i = 0; i == 32;)
                {
                    string str = $"gpio{i}";
                    if (Directory.Exists(Path.Combine("/sys/class/gpio", str)))
                    {
                        driver.Release((ProcessorPin) i);
                    }
                    i++;
                }
                gpio.Close();
                Console.WriteLine("Stopped driver allocating");
                Thread.Sleep(1000);
                Environment.Exit(0);
            };
            // Connection to the signalr hub
            HubConnection = new HubConnection("http://192.168.1.100");
            RaspberryHub = HubConnection.CreateHubProxy("Raspberry");
            // If the server decides to close the connection we need to start it again
            HubConnection.Closed += StartHubConnection;
            // Starts the connection
            StartHubConnection();

            gpio = new GpioConnection();
            driver = new GpioConnectionDriver();
            I2CDriver = new I2cDriver(ConnectorPin.P1Pin3.ToProcessor(), ConnectorPin.P1Pin5.ToProcessor());
            ArduinoConnection = I2CDriver.Connect(0x04);
            var switchButton = ConnectorPin.P1Pin13.Input().Revert().OnStatusChanged(x =>
            {
                Console.WriteLine(x);
                RaspberryHub.Invoke("SendChangedValue", ConnectorPin.P1Pin37, x ? "On" : "Off");
            });
            var doorSensor = ConnectorPin.P1Pin7.Input().PullUp().OnStatusChanged(x =>
            {
                RaspberryHub.Invoke("SendChangedValue", ConnectorPin.P1Pin7, x ? "Open" : "Closed");
            });
            var motionSensor = ConnectorPin.P1Pin13.Input().OnStatusChanged(x =>
            {
                RaspberryHub.Invoke("SendChangedValue", ConnectorPin.P1Pin11, x ? "Detected" : "Not detected");
                Console.WriteLine( DateTime.Now + ":Motion {0}", x ? "Detected" : "Not detected");
            });
            //            gpio.Add(switchButton);
            //            gpio.Add(doorSensor);
            //            gpio.Add(motionSensor);

            RaspberryHub.On<string>("ChangePiLed", pinnumber =>
            {
                int ledid = int.Parse(pinnumber);
                var procpin = ((ConnectorPin) ledid).ToProcessor();

                string str = string.Format("gpio{0}",procpin.ToString().Replace("Pin0","").Replace("Pin",""));
                if (!Directory.Exists(Path.Combine("/sys/class/gpio", str)))
                {
                    Console.WriteLine($"OutputPin {procpin} is not allocated!\nAllocating now.");
                    driver.Allocate(procpin, PinDirection.Output);
                    Console.WriteLine("Pin allocated");
                }
                driver.Write(procpin, !driver.Read(procpin));
                RaspberryHub.Invoke("SendChangedValue", pinnumber, driver.Read(procpin) ? "On" : "Off");
            });

            RaspberryHub.On<string, string>("SetupConfig", (pinnumber, type) =>
            {
                int pin = int.Parse(pinnumber);
                if (pin > 7)
                {
                    Action<bool> onstatusaction =
                        b =>
                        {
                            RaspberryHub.Invoke("SendChangedValue", pin,
                                driver.Read(((ConnectorPin) pin).ToProcessor()) ? "On" : "Off");
                        };
                    string str = string.Format("gpio{0}", ((ConnectorPin)pin).ToProcessor().ToString().Replace("Pin0", "").Replace("Pin", ""));
                    Console.WriteLine(str);
                    if (!Directory.Exists(Path.Combine("/sys/class/gpio", str)))
                    {
                        Console.WriteLine("Adding button");
                        var button = CreatePinConfig.CreateOutputPinConfiguration((ConnectorPin) pin, onstatusaction, "Button");
                        gpio.Add(button);
                    }
                }
            });

            RaspberryHub.On<int, string>("GetPinStatus", (pin, type) =>
            {
                driver.Read(((ConnectorPin) pin).ToProcessor());
                string status = string.Empty;
                if (type.Equals("Button"))
                {
                    status = driver.Read(((ConnectorPin) pin).ToProcessor()) ? "Pressed" : "Not pressed";
                }
                if (type.Equals("LED"))
                {
                    status = driver.Read(((ConnectorPin) pin).ToProcessor()) ? "On" : "Off";
                }
                if (type.Equals("Door sensor"))
                {
                    status = driver.Read(((ConnectorPin)pin).ToProcessor()) ? "Open" : "Closed";
                }

                RaspberryHub.Invoke("SendChangedValue", pin, status);
            });

            ServerWorkThread objThread = new ServerWorkThread();
            SendToArduino(1);
            while (true)
            {
                Thread.Sleep(50);
                ReadFromArduino();
                //objThread.HandleConnection(objThread.mySocket.Accept());
            }
        }