本文整理汇总了C#中GPIOPins类的典型用法代码示例。如果您正苦于以下问题:C# GPIOPins类的具体用法?C# GPIOPins怎么用?C# GPIOPins使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GPIOPins类属于命名空间,在下文中一共展示了GPIOPins类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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;
}
示例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);
}
示例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;
}
}
示例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;
}
}
}
示例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;
}
示例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]);
}
}
示例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);
}
示例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)
{
}
示例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)
{
}
示例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)
{
}
示例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();
}
示例13: bcm2835_gpio_set_pud
static extern void bcm2835_gpio_set_pud(GPIOPins pin, uint pud);
示例14: bcm2835_gpio_lev
static extern bool bcm2835_gpio_lev(GPIOPins pin);
示例15: bcm2835_gpio_write
static extern void bcm2835_gpio_write(GPIOPins pin, bool value);