Пример #1
0
        public GPIOSolenoid(int id, string name, string address)
        {
            log     = LogManager.GetLogger("Device");
            Id      = id;
            Name    = name;
            Address = address;

            pin = GPIOService.GetGPIOPin(Address);

            pinConfig = pin.Output().Name(name);
            GPIOService.Gpio.Add(pinConfig);
        }
Пример #2
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);
        }
Пример #3
0
        private void Initialize()
        {
            driver   = new GpioConnectionDriver();
            settings = new GpioConnectionSettings()
            {
                Driver = driver
            };

            //Configure pins
            LedPinGreen  = ledPinGreen.Output();
            LedPinYellow = ledPinYellow.Output();
            LedPinRed    = ledPinRed.Output();

            InputPinA = inputPinA.Input();
            InputPinB = inputPinB.Input();
            InputPinC = inputPinC.Input();
            InputPinD = inputPinD.Input();

            OutputPinA = outputPinA.Output();
            OutputPinB = outputPinB.Output();
            OutputPinC = outputPinC.Output();
            OutputPinD = outputPinD.Output();

            BuzzerPin = buzzerPin.Output();

            //Declaring a ButtonPressed handler
            ButtonPin = buttonPin.Input().Name("Button").Revert().Switch().Enable().OnStatusChanged(x =>
            {
                OnButtonPressed(new EventArgs());
            });

            Pins = new PinConfiguration[] { LedPinGreen, LedPinYellow, LedPinRed,
                                            InputPinA, InputPinB, InputPinC, InputPinD,
                                            OutputPinA, OutputPinB, OutputPinC, OutputPinD,
                                            BuzzerPin, ButtonPin };

            Connection = new GpioConnection(settings, Pins);
        }
Пример #4
0
        public void InitGpio()
        {
            outputs = new PinConfiguration[]
            {
                Station1OutputPin.Output().Name("Station1"),
                Station2OutputPin.Output().Name("Station2"),
                Station3OutputPin.Output().Name("Station3"),
                Station4OutputPin.Output().Name("Station4"),
                Station5OutputPin.Output().Name("Station5"),
                Station6OutputPin.Output().Name("Station6"),
                Station7OutputPin.Output().Name("Station7"),
                Station8OutputPin.Output().Name("Station8"),
                PumpOperationPin.Output().Name("PumpOperation"),
                TankRelayOutputPin.Output().Name("TankRelay"),
                SpareOutputPin.Output().Name("Spare"),
                ResetRelayOutputPin.Output().Name("ResetRelay")
            };
            connection = new GpioConnection(outputs);

            connection.Add(LowPressureFaultInputPin.Input().OnStatusChanged(b =>
            {
                Console.WriteLine("LowPressureFaultInput {0}", b ? "on" : "off");
                bLowPressureFaultState = b;
                CreateEvent(EventType.IOEvent, string.Format("Input {0} on", LowPressureFaultInputPin.ToString()));
                CreateEvent(EventType.FaultEvent, string.Format("Low pressure fault  {0}", b ? "detected" : "cleared"));
            }));

            connection.Add(HighPressureFaultInputPin.Input().OnStatusChanged(b =>
            {
                Console.WriteLine("HighPressureFaultInput {0}", b ? "on" : "off");
                bHighPressureFaultState = b;
                CreateEvent(EventType.IOEvent, string.Format("Input {0} {1}", HighPressureFaultInputPin.ToString(), b ? "on" : "off"));
                CreateEvent(EventType.FaultEvent, string.Format("High pressure fault {0}", b ? "detected" : "cleared"));
            }));

            connection.Add(LowWellFaultInputPin.Input().OnStatusChanged(b =>
            {
                Console.WriteLine("LowWellFaultInput {0}", b ? "on" : "off");
                bLowWellFaultState = b;
                CreateEvent(EventType.IOEvent, string.Format("Input {0} {1}", LowWellFaultInputPin.ToString(), b ? "on" : "off"));
                CreateEvent(EventType.FaultEvent, string.Format("Low well fault {0}", b ? "detected" : "cleared"));
                if (b)
                {
                    dtFaultStartDate = DateTime.Now;
                    Log(string.Format("Initializing timeout at {0}", dtFaultStartDate.ToString()));
                    ChangeState(State.WaitForTimeout);
                }
                else
                {
                    ChangeState(State.Monitor);
                }
            }));

            connection.Add(OverloadFaultInputPin.Input().OnStatusChanged(b =>
            {
                Console.WriteLine("OverloadFaultInput {0}", b ? "on" : "off");
                bOverloadFaultState = b;
            }));

            //ElectricPotential referenceVoltage = ElectricPotential.FromVolts(3.3);

            var driver = new MemoryGpioConnectionDriver(); //GpioConnectionSettings.DefaultDriver;

            Mcp3008SpiConnection spi = new Mcp3008SpiConnection(
                driver.Out(adcClock),
                driver.Out(adcCs),
                driver.In(adcMiso),
                driver.Out(adcMosi));

            spiInput = spi.In(Mcp3008Channel.Channel0);

            connection.Open();
        }
Пример #5
0
 //        public static HubConnection hubconnection;
 //        public static IHubProxy raspberryHub;
 //
 //        public CreatePinConfig(HubConnection hubcon, IHubProxy hub)
 //        {
 //            hubconnection = hubcon;
 //            raspberryHub = hub;
 //        }
 public static OutputPinConfiguration CreateOutputPinConfiguration(ConnectorPin pin, Action<bool> Onstatuschanged, string type)
 {
     return pin.Output().Revert().OnStatusChanged(Onstatuschanged);
 }
Пример #6
0
        //const ConnectorPin Station12OutputPin = ConnectorPin.P1Pin36;

        static void Main(string[] args)
        {
            // Declare outputs (leds)
            var leds = new PinConfiguration[]
            {
                Station1OutputPin.Output().Name("Led1").Enable(),
                Station2OutputPin.Output().Name("Led2"),
                Station3OutputPin.Output().Name("Led3").Enable(),
                Station4OutputPin.Output().Name("Led4"),
                Station5OutputPin.Output().Name("Led5").Enable(),
                Station6OutputPin.Output().Name("Led6"),
                Station7OutputPin.Output().Name("Led7").Enable(),
                Station8OutputPin.Output().Name("Led8"),
                Station9OutputPin.Output().Name("Led9").Enable(),
                Station10OutputPin.Output().Name("Led10"),
                Station11OutputPin.Output().Name("Led11").Enable(),
                //Station12OutputPin.Output().Name("Led12")
            };

            Console.WriteLine("Chaser Sample: Sample a LED chaser with a switch to change behavior");
            Console.WriteLine();
            Console.WriteLine("\tLed 1: {0}", Station1OutputPin);
            Console.WriteLine("\tLed 2: {0}", Station2OutputPin);
            Console.WriteLine("\tLed 3: {0}", Station3OutputPin);
            Console.WriteLine("\tLed 4: {0}", Station4OutputPin);
            Console.WriteLine("\tLed 5: {0}", Station5OutputPin);
            Console.WriteLine("\tLed 6: {0}", Station6OutputPin);
            Console.WriteLine("\tSwitch: {0}", PushButtonInputPin);
            Console.WriteLine();

            // Assign a behavior to the leds
            int period   = 250;
            var behavior = new ChaserBehavior(leds)
            {
                Loop      = true,                             // args.GetLoop(),
                RoundTrip = true,                             // args.GetRoundTrip(),
                Width     = 12,                               // args.GetWidth(),
                Interval  = TimeSpan.FromMilliseconds(period) //TimeSpan.FromMilliseconds(args.GetSpeed())
            };
            var switchButton = LowPressureFaultInputPin.Input()
                               //.Name("Switch")
                               //.Revert()
                               //.Switch()
                               //.Enable()
                               .OnStatusChanged(b =>
            {
                behavior.RoundTrip = !behavior.RoundTrip;
                Console.WriteLine("Button switched {0}", b ? "on" : "off");
            });

            // Create connection
            var settings = new GpioConnectionSettings();// { Driver = driver };

            using (var connection = new GpioConnection(settings, leds))
            {
                Console.WriteLine("Using {0}, frequency {1:0.##}hz", settings.Driver.GetType().Name, 1000.0 / period);

                Thread.Sleep(1000);

                connection.Add(switchButton);
                connection.Start(behavior); // Starting the behavior automatically registers the pins to the connection, if needed.

                Console.ReadKey(true);

                connection.Stop(behavior);
            }
        }
Пример #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("GPIOTestHarness");
            bool Station1OutputState = false;
            bool Station2OutputState = false;
            bool Station3OutputState = false;
            bool Station4OutputState = false;

            //var Output1 = Station1OutputPin.Output();
            //var Output2 = Station2OutputPin.Output();
            //var Output3 = Station3OutputPin.Output();
            //var Output4 = Station4OutputPin.Output();
            var pins = new PinConfiguration[]
            {
                Station1OutputPin.Output().Name("Output1"),
                Station2OutputPin.Output().Name("Output2"),
                Station3OutputPin.Output().Name("Output3"),
                Station4OutputPin.Output().Name("Output4")
            };
            //var settings = new GpioConnectionSettings();
            var connection = new GpioConnection(pins);

            var Input1 = LowPressureFaultInputPin.Input().OnStatusChanged(b =>
            {
                Console.WriteLine("LowPressureFaultInput {0}", b ? "on" : "off");
                if (Station1OutputState != b)
                {
                    connection.Toggle("Output1"); Station1OutputState = b;
                }
            });

            connection.Add(Input1);
            var Input2 = HighPressureFaultInputPin.Input().OnStatusChanged(b =>
            {
                Console.WriteLine("HighPressureFaultInput {0}", b ? "on" : "off");
                if (Station2OutputState != b)
                {
                    connection.Toggle("Output2"); Station2OutputState = b;
                }
            });

            connection.Add(Input2);
            var Input3 = LowWellFaultInputPin.Input().OnStatusChanged(b =>
            {
                Console.WriteLine("LowWellFaultInput {0}", b ? "on" : "off");
                if (Station3OutputState != b)
                {
                    connection.Toggle("Output3"); Station3OutputState = b;
                }
            });

            connection.Add(Input3);
            var Input4 = OverloadFaultInputPin.Input().OnStatusChanged(b =>
            {
                Console.WriteLine("OverloadFaultInput {0}", b ? "on" : "off");
                if (Station4OutputState != b)
                {
                    connection.Toggle("Output4"); Station4OutputState = b;
                }
            });

            connection.Add(Input4);

            ElectricPotential referenceVoltage = ElectricPotential.FromVolts(3.3);

            var driver = new MemoryGpioConnectionDriver(); //GpioConnectionSettings.DefaultDriver;

            Mcp3008SpiConnection spi = new Mcp3008SpiConnection(
                driver.Out(adcClock),
                driver.Out(adcCs),
                driver.In(adcMiso),
                driver.Out(adcMosi));

            IInputAnalogPin inputPin = spi.In(Mcp3008Channel.Channel0);

            connection.Open();
            ElectricPotential volts = ElectricPotential.FromVolts(0);

            while (!Console.KeyAvailable)
            {
                var v = referenceVoltage * (double)inputPin.Read().Relative;
                if ((Math.Abs(v.Millivolts - volts.Millivolts) > 100))
                {
                    volts = ElectricPotential.FromMillivolts(v.Millivolts);
                    Console.WriteLine("Voltage ch0: {0}", volts.Millivolts.ToString());
                }
            }
            connection.Close();
        }