Пример #1
0
        /// <summary>
        /// Sets all pins to low level.
        /// </summary>
        /// <param name="expander">Object of type IGpioExpander.</param>
        /// <exception cref="ArgumentNullException">Object of type IGpioExpander is null.</exception>
        public static void DigitalPortLowLevel(this GpioExpander expander)
        {
            if (expander is null)
            {
                throw ThrowHelper.ArgumentNullException(nameof(expander));
            }

            expander.DigitalWritePort(0);
        }
Пример #2
0
        /// <summary>
        /// Fixes click of the TroykaButton.
        /// </summary>
        /// <param name="expander">Object of type IGpioExpander.</param>
        /// <param name="pin">Pin number.</param>
        /// <returns>True - click, False - not click.</returns>
        /// <exception cref="ArgumentNullException">Object of type IGpioExpander is null.</exception>
        public static bool TroykaButtonClick(this GpioExpander expander, int pin)
        {
            if (expander is null)
            {
                throw ThrowHelper.ArgumentNullException(nameof(expander));
            }

            return(!expander.DigitalRead(pin));
        }
Пример #3
0
        private static void AddressOrReset()
        {
            Console.WriteLine("Enter 1 or 2 to select a mode:\n1. Change address.\n2. Reset chip.");

            if (int.TryParse(Console.ReadLine(), out int mode))
            {
                switch (mode)
                {
                case 1:
                {
                    Console.WriteLine("Enter a new address:");

                    if (ushort.TryParse(Console.ReadLine(), out ushort address))
                    {
                        _expander.ChangeAddress(address);

                        Console.WriteLine("Change address.");

                        _expander.SaveAddress();

#if WIRING_PI
                        _expander = Pi.I2C.GetGpioExpander();
#endif

#if NOT_WIRING_PI
                        _expander = I2cBus.Create(1).GetGpioExpander();
#endif

                        Console.WriteLine("Save address.");
                    }
                    else
                    {
                        Console.WriteLine("Invalid new address value.");
                    }

                    break;
                }

                case 2:
                {
                    _expander.Reset();

                    Console.WriteLine("Reset chip.");

                    break;
                }

                default:
                {
                    Console.WriteLine("Invalid mode value.");
                    break;
                }
                }
            }
        }
Пример #4
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Enter the device address:");

            int expanderAddress = int.TryParse(Console.ReadLine(), out int address)
                ? address
                : GpioExpander.DefaultAddress;

            try
            {
#if WIRING_PI
                Pi.Init <BootstrapWiringPi>();

                _expander = Pi.I2C.GetGpioExpander(expanderAddress);
#endif

#if NOT_WIRING_PI
                _expander = I2cBus.Create(1).GetGpioExpander(expanderAddress);
#endif
            }
            catch (Exception error)
            {
                Console.WriteLine($"Fail initialization GPIO Expander. Error: {error}");

                return;
            }

            if (args.Length == 0)
            {
                Console.WriteLine("Select a mode:\n1. {0}\n2. {1}\n3. {2}\n4. {3}\n5. {4}\n6. {5}\n7. {6}\n",
                                  nameof(Analog1), nameof(Analog2), nameof(Digital), nameof(Port),
                                  nameof(Pwm), "Address/Reset", nameof(Adc));

                switch (Console.ReadLine())
                {
                case nameof(Analog1):
                {
                    Analog1();
                    break;
                }

                case nameof(Analog2):
                {
                    Analog2();
                    break;
                }

                case nameof(Digital):
                {
                    Digital();
                    break;
                }

                case nameof(Port):
                {
                    Port();
                    break;
                }

                case nameof(Pwm):
                {
                    Pwm();
                    break;
                }

                case nameof(Adc):
                {
                    Adc();
                    break;
                }

                case "Address":
                case "Reset":
                {
                    AddressOrReset();
                    break;
                }

                default:
                {
                    Console.WriteLine("Invalid program mode.");
                    break;
                }
                }
            }
            else if (args[0].Equals("Freq", StringComparison.OrdinalIgnoreCase))
            {
                FindFreq();
            }
            else
            {
                Console.WriteLine("Invalid app mode.");
            }

            _expander?.Dispose();

            Console.WriteLine("Application is shutting down...");
        }