• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# GPIOPins类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中GPIOPins的典型用法代码示例。如果您正苦于以下问题:C# GPIOPins类的具体用法?C# GPIOPins怎么用?C# GPIOPins使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



GPIOPins类属于命名空间,在下文中一共展示了GPIOPins类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: LCDWrapper

 public LCDWrapper(GPIOPins rs, GPIOPins enable, GPIOPins d0, GPIOPins d1, GPIOPins d2, GPIOPins d3, GPIOPins d4, GPIOPins d5, GPIOPins d6, GPIOPins d7, int columns = 40, int rows = 2, DisplayMode displayMode = DisplayMode.LCD_ONLY)
 {
     DisplayMode = displayMode;
     Columns = columns;
     Rows = rows;
     if (DisplayMode != DisplayMode.CONSOLE_ONLY) {
         transferProvider = new RaspPiGPIOMemLcdTransferProvider(
             fourBitMode: false,
             rs: rs,
             rw: GPIOPins.GPIO_NONE,
             enable: enable,
             d0: d0,
             d1: d1,
             d2: d2,
             d3: d3,
             d4: d4,
             d5: d5,
             d6: d6,
             d7: d7
         );
         lcd = new Lcd(transferProvider);
         lcd.Begin(Convert.ToByte(columns), Convert.ToByte(rows));
         lcd.Backlight = true;
         lcd.BlinkCursor = false;
         lcd.ShowCursor = false;
         lcd.Visible = true;
     }
     if (DisplayMode != DisplayMode.LCD_ONLY) {
         Console.Clear();
         Console.ForegroundColor = ConsoleColor.White;
         Console.BackgroundColor = ConsoleColor.Black;
         Console.CursorVisible = false;
     }
 }
开发者ID:bsutliffe,项目名称:RaspberryPandora,代码行数:34,代码来源:LCDWrapper.cs


示例2: ExportPin

        /// <summary>
        /// Export the GPIO setting the direction. This creates the /sys/class/gpio/gpioXX directory.
        /// </summary>
        /// <param name="pin">The GPIO pin</param>
        /// <param name="direction"></param>
        private static void ExportPin(GPIOPins pin, DirectionEnum direction)
        {
            // If the pin is already exported, check it's in the proper direction
            if (_exportedPins.Keys.Contains((int)pin))
                // If the direction matches, return out of the function. If not, change the direction
                if (_exportedPins[(int)pin] == direction)
                    return;
                else
                {
                    // Set the direction on the pin and update the exported list
                    File.WriteAllText(GPIO_PATH + "gpio" + GetGPIONumber(pin) + "/direction", direction.ToString().ToLower());
                    _exportedPins[(int)pin] = direction;
                    return;
                }

            if (!Directory.Exists(GPIO_PATH + "gpio" + GetGPIONumber(pin)))
            {
                Debug.WriteLine("Exporting " + GetGPIONumber(pin));
                //export
                File.WriteAllText(GPIO_PATH + "export", GetGPIONumber(pin));
            }

            // set i/o direction
            Debug.WriteLine("Setting direction on pin " + pin + "/gpio " + (int)pin + " as " + direction);
            File.WriteAllText(GPIO_PATH + "gpio" + GetGPIONumber(pin) + "/direction", direction.ToString().ToLower());

            // Update the list of exported pins
            _exportedPins[(int)pin] = direction;
        }
开发者ID:p07r0457,项目名称:RaspberryPi.Net,代码行数:34,代码来源:GPIOFile.cs


示例3: McuSerial

        public McuSerial(GPIOPins clockPin, GPIOPins ioPin, bool clockStartValue = false)
        {
            this.clockPin = clockPin;
            this.ioPin = ioPin;
            this.clockValue = clockStartValue;

            GPIOMem.Write(clockPin, clockValue);
            GPIOMem.Write(ioPin, false);
        }
开发者ID:phaetto,项目名称:FoosPi,代码行数:9,代码来源:McuSerial.cs


示例4: ExportPin

        /// <summary>
        /// Export the GPIO setting the direction. This creates the /sys/class/gpio/gpioXX directory.
        /// </summary>
        /// <param name="pin">The GPIO pin</param>
        /// <param name="direction"></param>
        private static void ExportPin(GPIOPins pin, DirectionEnum direction)
        {
            Initialize();

            // If the pin is already exported, check it's in the proper direction
            if (_exportedPins.Keys.Contains((int)pin))
                // If the direction matches, return out of the function. If not, change the direction
                if (_exportedPins[(int)pin] == direction)
                    return;
                else
                {
                    // Set the direction on the pin and update the exported list
                    bcm2835_gpio_fsel((uint)pin, direction == DirectionEnum.IN ? (uint)0 : (uint)1);
                    _exportedPins[(int)pin] = direction;
                    return;
                }
        }
开发者ID:sadgit,项目名称:RaspberryPi.Net,代码行数:22,代码来源:GPIOMem.cs


示例5: GPIO

		/// <summary>
		/// Access to the specified GPIO setup with the specified direction with the specified initial value
		/// </summary>
		/// <param name="pin">The GPIO pin</param>
		/// <param name="direction">Direction</param>
		/// <param name="initialValue">Initial Value</param>
		protected GPIO(GPIOPins pin, GPIODirection direction, bool initialValue) {
			if (pin == GPIOPins.GPIO_NONE) throw new ArgumentException("Invalid pin");
			lock (_exportedPins) {
				if (_exportedPins.ContainsKey(pin))
					throw new Exception("Cannot use pin with multiple instances. Unexport the previous instance with Dispose() first! (pin " + (uint)pin + ")");
				_exportedPins[pin] = new WeakReference(this);

				_pin = pin;
				try {
					PinDirection = direction;
					Write(initialValue);
				}
				catch {
					Dispose();
					throw;
				}
			}
		}
开发者ID:Arakis,项目名称:RaspberryPi.Net,代码行数:24,代码来源:GPIO.cs


示例6: ExportPin

		/// <summary>
		/// Export the GPIO setting the direction. This creates the /sys/class/gpio/gpioXX directory.
		/// </summary>
		/// <param name="pin">The GPIO pin</param>
		/// <param name="direction"></param>
		private static void ExportPin(GPIOPins pin, DirectionEnum direction) {
			Initialize();

			// If the pin is already exported, check it's in the proper direction
			if (_exportedPins.Keys.Contains((int)pin))
				// If the direction matches, return out of the function. If not, change the direction
				if (_exportedPins[(int)pin] == direction)
					return;

			// Set the direction on the pin and update the exported list
			// BCM2835_GPIO_FSEL_INPT = 0
			// BCM2835_GPIO_FSEL_OUTP = 1
			bcm2835_gpio_fsel((uint)pin, direction == DirectionEnum.IN ? (uint)0 : (uint)1);
			if (direction == DirectionEnum.IN)
				// BCM2835_GPIO_PUD_OFF = 0b00 = 0
				// BCM2835_GPIO_PUD_DOWN = 0b01 = 1
				// BCM2835_GPIO_PUD_UP = 0b10 = 2
				bcm2835_gpio_set_pud((uint)pin, 0);
			_exportedPins[(int)pin] = direction;
		}
开发者ID:Arakis,项目名称:TamaniChess,代码行数:25,代码来源:GPIOMem.cs


示例7: RaspPiGPIOFileLcdTransferProvider

        /// <summary>
        /// Creates a variable of type LiquidCrystal. The display can be controlled using 4 or 8 data lines. If the former, omit the pin numbers for d0 to d3 and leave those lines unconnected. The RW pin can be tied to ground instead of connected to a pin on the Arduino; if so, omit it from this function's parameters. 
        /// </summary>
        /// <param name="fourBitMode"></param>
        /// <param name="rs">The number of the CPU pin that is connected to the RS (register select) pin on the LCD.</param>
        /// <param name="rw">The number of the CPU pin that is connected to the RW (Read/Write) pin on the LCD (optional).</param>
        /// <param name="enable">the number of the CPU pin that is connected to the enable pin on the LCD.</param>
        /// <param name="d0"></param>
        /// <param name="d1"></param>
        /// <param name="d2"></param>
        /// <param name="d3"></param>
        /// <param name="d4"></param>
        /// <param name="d5"></param>
        /// <param name="d6"></param>
        /// <param name="d7"></param>
        public RaspPiGPIOFileLcdTransferProvider(bool fourBitMode, GPIOPins rs, GPIOPins rw, GPIOPins enable, 
                                                 GPIOPins d0, GPIOPins d1, GPIOPins d2, GPIOPins d3, 
                                                 GPIOPins d4, GPIOPins d5, GPIOPins d6, GPIOPins d7)
        {
            _fourBitMode = fourBitMode;

            if (rs == GPIOPins.GPIO_NONE) throw new ArgumentException("rs");
            _rsPort = new GPIOFile(rs);

            // we can save 1 pin by not using RW. Indicate by passing GPIO.GPIOPins.GPIO_NONE instead of pin#
            if (rw != GPIOPins.GPIO_NONE) // (RW is optional)
                _rwPort = new GPIOFile(rw);

            if (enable == GPIOPins.GPIO_NONE) throw new ArgumentException("enable");
            _enablePort = new GPIOFile(enable);

            var dataPins = new[] { d0, d1, d2, d3, d4, d5, d6, d7};
            _dataPorts = new GPIOFile[8];
            for (int i = 0; i < 8; i++)
            {
                if (dataPins[i] != GPIOPins.GPIO_NONE)
                    _dataPorts[i] = new GPIOFile(dataPins[i]);
            }
        }
开发者ID:Redth,项目名称:JenkinsBerry,代码行数:39,代码来源:RaspPiGPIOFileLcdTransferProvider.cs


示例8: GPIOMem

 /// <summary>
 /// Access to the specified GPIO setup with the specified direction with an initial value of false (0)
 /// </summary>
 /// <param name="pin">The GPIO pin</param>
 /// <param name="direction">Direction</param>
 public GPIOMem(GPIOPins pin, DirectionEnum direction)
     : base(pin, direction, false)
 {
     ExportPin(pin, direction);
 }
开发者ID:sadgit,项目名称:RaspberryPi.Net,代码行数:10,代码来源:GPIOMem.cs


示例9: GPIO

 /// <summary>
 /// Access to the specified GPIO setup as an output port with an initial value of false (0)
 /// </summary>
 /// <param name="pin">The GPIO pin</param>
 public GPIO(GPIOPins pin)
     : this(pin,DirectionEnum.OUT,false)
 {
 }
开发者ID:p07r0457,项目名称:RaspberryPi.Net,代码行数:8,代码来源:GPIO.cs


示例10: Write

 /// <summary>
 /// Static method to write a value to the specified pin. Does nothing when using the GPIODebug class.
 /// </summary>
 /// <param name="pin">The GPIO pin</param>
 /// <param name="value">The value to write to the pin</param>
 public static void Write(GPIOPins pin, bool value)
 {
 }
开发者ID:p07r0457,项目名称:RaspberryPi.Net,代码行数:8,代码来源:GPIODebug.cs


示例11: GPIODebug

 /// <summary>
 /// Access to the specified GPIO setup with the specified direction with an initial value of false (0)
 /// </summary>
 /// <param name="pin">The GPIO pin</param>
 /// <param name="direction">Direction</param>
 public GPIODebug(GPIOPins pin, GPIODirection direction)
     : this(pin, direction, false)
 {
 }
开发者ID:phaetto,项目名称:FoosPi,代码行数:9,代码来源:GPIODebug.cs


示例12: Read

		/// <summary>
		/// Gets the value of a given pin.
		/// 
		/// Creates (exports) the pin if needed, and sets it to In direction.
		/// </summary>
		/// <param name="pin">The pin who's value to get</param>
		/// <returns>The value of the pin</returns>
		public static bool Read(GPIOPins pin) {
			return CreatePin(pin, GPIODirection.In).Read();
		}
开发者ID:Arakis,项目名称:RaspberryPi.Net,代码行数:10,代码来源:GPIO.cs


示例13: bcm2835_gpio_set_pud

		static extern void bcm2835_gpio_set_pud(GPIOPins pin, uint pud);
开发者ID:henniespies,项目名称:RaspberryPi.Net,代码行数:1,代码来源:GPIOMem.cs


示例14: bcm2835_gpio_lev

		static extern bool bcm2835_gpio_lev(GPIOPins pin);
开发者ID:henniespies,项目名称:RaspberryPi.Net,代码行数:1,代码来源:GPIOMem.cs


示例15: bcm2835_gpio_write

		static extern void bcm2835_gpio_write(GPIOPins pin, bool value);
开发者ID:henniespies,项目名称:RaspberryPi.Net,代码行数:1,代码来源:GPIOMem.cs


示例16: bcm2835_gpio_fsel

		static extern void bcm2835_gpio_fsel(GPIOPins pin, bool mode_out);
开发者ID:henniespies,项目名称:RaspberryPi.Net,代码行数:1,代码来源:GPIOMem.cs


示例17: Read

 /// <summary>
 /// Static method to read a value to the specified pin. Always returns false when using the GPIODebug class.
 /// </summary>
 /// <param name="pin">The GPIO pin</param>
 /// <returns>The value read from the pin</returns>
 public static bool Read(GPIOPins pin)
 {
     return false;
 }
开发者ID:p07r0457,项目名称:RaspberryPi.Net,代码行数:9,代码来源:GPIODebug.cs


示例18: Write

		/// <summary>
		/// Sets a pin to output the give value.
		/// 
		/// Creates (exports) the pin if needed, and sets it to Out direction.
		/// </summary>
		/// <param name="pin">The pin who's value to set</param>
		/// <param name="value">The value to set</param>
		public static void Write(GPIOPins pin, bool value) {
			CreatePin(pin, GPIODirection.Out).Write(value);
		}
开发者ID:Arakis,项目名称:RaspberryPi.Net,代码行数:10,代码来源:GPIO.cs


示例19: CreatePin

		/// <summary>
		/// Creates a pin if it has not already been created (exported), creates a GPIOMem if possible, otherwise falls back to GPIOFile.
		/// </summary>
		/// <param name="pin">The pin to create or export</param>
		/// <param name="dir">The direction the pin is to have</param>
		/// <returns>The GPIO instance representing the pin</returns>
		public static GPIO CreatePin(GPIOPins pin, GPIODirection dir) {
			lock (_exportedPins) {
				if (_exportedPins.ContainsKey(pin) ) {
					var reference = _exportedPins[pin];
					if (reference.IsAlive) {
						var gpio = (GPIO)_exportedPins[pin].Target;
						if (gpio.PinDirection != dir)
							gpio.PinDirection = dir;
						return gpio;
					}
					else {
						_exportedPins.Remove(pin);
					}
				}

			}

			try {
				return new GPIOMem(pin, dir);
			}
#if DEBUG
			catch (Exception e) {
				System.Diagnostics.Debug.WriteLine("Unable to create pin " + (uint)pin + " as GPIOMem because: " + e.ToString());
			}
#else
			catch //stuff like lib load problems, wrong exports, etc...
			{
			}
#endif
			try {
				return new GPIOFile(pin, dir);
			}
#if DEBUG
			catch (Exception e) {
				System.Diagnostics.Debug.WriteLine("Unable to create pin " + (uint)pin + " as GPIOFile because: " + e.ToString());
			}
#else
			catch //stuff like GPIO Sys FS does not exist or is not responding, open by another process, etc...
			{
			}
#endif

#if DEBUG
			System.Diagnostics.Debug.WriteLine("Using debug GPIO pin for pin number " + (uint)pin);
			return new GPIODebug(pin, dir);
#else
			throw new Exception("Cannot access GPIO pin " + (uint)pin + ". Make sure libbcm2835.so is accessible, or that GPIO SYSFS is working and not in use by another process");
#endif
		}
开发者ID:Arakis,项目名称:RaspberryPi.Net,代码行数:55,代码来源:GPIO.cs


示例20: Write

        /// <summary>
        /// Static method to write a value to the specified pin.
        /// </summary>
        /// <param name="pin">The GPIO pin</param>
        /// <param name="value">The value to write to the pin</param>
        public static void Write(GPIOPins pin, bool value)
        {
            if (pin == GPIOPins.GPIO_NONE)
                return;

            ExportPin(pin, DirectionEnum.OUT);

            bcm2835_gpio_write((uint)pin, value ? (uint)1 : (uint)0);
            Debug.WriteLine("output to pin " + pin + "/gpio " + (int)pin + ", value was " + value);
        }
开发者ID:sadgit,项目名称:RaspberryPi.Net,代码行数:15,代码来源:GPIOMem.cs



注:本文中的GPIOPins类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# GPoint类代码示例发布时间:2022-05-24
下一篇:
C# GMarkerGoogle类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap