本文整理汇总了C#中Windows.Devices.Gpio.GpioPin.IsDriveModeSupported方法的典型用法代码示例。如果您正苦于以下问题:C# GpioPin.IsDriveModeSupported方法的具体用法?C# GpioPin.IsDriveModeSupported怎么用?C# GpioPin.IsDriveModeSupported使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Devices.Gpio.GpioPin
的用法示例。
在下文中一共展示了GpioPin.IsDriveModeSupported方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitGpio
/// <summary>
///
/// </summary>
private void InitGpio()
{
var gpio = GpioController.GetDefault();
if (gpio== null)
{
Debug.WriteLine("Can't find GpioController.");
return;
}
pin = gpio.OpenPin(inputPin);
if (pin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
{
pin.SetDriveMode(GpioPinDriveMode.InputPullUp);
}
else
{
pin.SetDriveMode(GpioPinDriveMode.Input);
}
Debug.WriteLine("GPIO initializing...");
//Sleep
for (int i = 0; i <= 10000; i++) { }
//Event
pin.ValueChanged += Pin_ValueChanged;
Debug.WriteLine("GPIO initialized.");
}
示例2: InitGPIO
private void InitGPIO()
{
var gpio = GpioController.GetDefault();
if (gpio == null)
{
GpioStatus.Text = "There is no GPIO controller on this device.";
return;
}
button1Pin = gpio.OpenPin(BUTTON1_PIN);
led1Pin = gpio.OpenPin(LED1_PIN);
// Initialize LED to the OFF state by first writing a HIGH value
led1Pin.Write(GpioPinValue.High);
led1Pin.SetDriveMode(GpioPinDriveMode.Output);
// Check if input pull-up resistors are supported
if (button1Pin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
button1Pin.SetDriveMode(GpioPinDriveMode.InputPullUp);
else
button1Pin.SetDriveMode(GpioPinDriveMode.Input);
// Set a debounce timeout to filter out switch bounce noise from a button press
button1Pin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
// Register for the ValueChanged event so our buttonPin_ValueChanged
// function is called when the button is pressed
button1Pin.ValueChanged += buttonPin_ValueChanged;
GpioStatus.Text = "GPIO pins initialized correctly.";
}
示例3: InitGPIO
private void InitGPIO()
{
var gpio = GpioController.GetDefault();
// error prompt
if (gpio == null) {
GpioStatus.Text = "There's no GPIO controller on this device";
return -1;
}
buttonPin = gpio.OpenPin(BUTTON_PIN);
ledPin = gpio.OpenPin(LED_PIN);
// init LED to OFF by HIGH, cuz LED is wired in LOW config
ledPin.Write(GpioPinValue.High);
ledPin.SetDriveMode(GpioPinDriveMode.Output);
// checking if input pull-up resistors are supported
if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp)) {
buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
}
else {
buttonPin.SetDriveMode(GpioPinDriveMode.Input);
}
// setting debounce timeout
buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
// register for ValueChanged event
// so buttonPin_ValueChanged()
// is called when button is pressed
buttonPin.ValueChanged += buttonPin_ValueChanged;
GpioStatus.Text = "GPIO pins initialized correctly";
}
示例4: Init
public override void Init()
{
Debug.WriteLine("Initializing push button.");
try
{
_pushButtonPin = _gpioController.OpenPin(Pin);
if (_pushButtonPin == null)
{
Debug.WriteLine(string.Format("Push button pin not found at GPIO {0}.", Pin));
throw new Exception(string.Format("Push button pin not found at GPIO {0}.", Pin));
}
else
{
Debug.WriteLine(string.Format("Push button initialized at GPIO {0}.", Pin));
}
if (_pushButtonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
_pushButtonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
else
_pushButtonPin.SetDriveMode(GpioPinDriveMode.Input);
_pushButtonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
_pushButtonPin.ValueChanged += _pushButtonPin_ValueChanged;
Debug.WriteLine("Push button initialized.");
}
catch
{
Debug.WriteLine("Failed to initialize push button.");
throw new Exception("Failed to initialize push button.");
}
}
示例5: InitGPIO
private void InitGPIO()
{
var gpio = GpioController.GetDefault();
// Show an error if there is no GPIO controller
if (gpio == null)
{
_buttonpin = null;
_buzzerpin = null;
GpioStatus.Text = "There is no GPIO controller on this device.";
return;
}
_buttonpin = gpio.OpenPin(BUTTON_PIN);
_buzzerpin = gpio.OpenPin(BUZZER_PIN);
if (_buttonpin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
_buttonpin.SetDriveMode(GpioPinDriveMode.InputPullUp);
else
_buttonpin.SetDriveMode(GpioPinDriveMode.Input);
_buttonpin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
_buttonpin.ValueChanged += Buttonpin_ValueChanged;
_buzzerpin.Write(GpioPinValue.Low);
_buzzerpin.SetDriveMode(GpioPinDriveMode.Output);
GpioStatus.Text = "GPIO button and buzzer pin initialized correctly.";
}
示例6: Init
public void Init(GpioPin gpioPin)
{
// Use InputPullUp if supported, otherwise fall back to Input (floating)
inputDriveMode =
gpioPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp) ?
GpioPinDriveMode.InputPullUp : GpioPinDriveMode.Input;
gpioPin.SetDriveMode(inputDriveMode);
pin = gpioPin;
}
示例7: _init
void _init()
{
_pin = _gpio.OpenPin(_pinNumber, _sharingMode);
if (!_pin.IsDriveModeSupported(_driveMode))
{
throw new NotSupportedException($"Drive mode {_driveMode} not supported on pin {_pinNumber}");
}
_pin.SetDriveMode(_driveMode);
}
示例8: Initialize
/// <summary>
/// Attempts to initialize Gpio for application. This includes doorbell interaction and locking/unlccking of door.
/// Returns true if initialization is successful and Gpio can be utilized. Returns false otherwise.
/// </summary>
public bool Initialize()
{
// Gets the GpioController
gpioController = GpioController.GetDefault();
if(gpioController == null)
{
// There is no Gpio Controller on this device, return false.
return false;
}
// Opens the GPIO pin that interacts with the doorbel button
doorbellPin = gpioController.OpenPin(GpioConstants.ButtonPinID);
if (doorbellPin == null)
{
// Pin wasn't opened properly, return false
return false;
}
// Set a debounce timeout to filter out switch bounce noise from a button press
doorbellPin.DebounceTimeout = TimeSpan.FromMilliseconds(25);
if (doorbellPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
{
// Take advantage of built in pull-up resistors of Raspberry Pi 2 and DragonBoard 410c
doorbellPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
}
else
{
// MBM does not support PullUp as it does not have built in pull-up resistors
doorbellPin.SetDriveMode(GpioPinDriveMode.Input);
}
// Opens the GPIO pin that interacts with the door lock system
doorLockPin = gpioController.OpenPin(GpioConstants.DoorLockPinID);
if(doorLockPin == null)
{
// Pin wasn't opened properly, return false
return false;
}
// Sets doorbell pin drive mode to output as pin will be used to output information to lock
doorLockPin.SetDriveMode(GpioPinDriveMode.Output);
// Initializes pin to high voltage. This locks the door.
doorLockPin.Write(GpioPinValue.High);
//Initialization was successfull, return true
return true;
}
示例9: InitGPIO
private void InitGPIO()
{
// Initialize the GPIO controller
GpioController gpio = GpioController.GetDefault();
// Show an error if there is no GPIO controller
if (gpio == null)
{
_pin1 = null;
_pin2 = null;
_pin3 = null;
GpioStatus.Text = "There is no GPIO controller on this device.";
return;
}
// Initialize the GPIO pin for the first LED
_pin1 = gpio.OpenPin(LED1_PIN);
_pin1.SetDriveMode(GpioPinDriveMode.Output);
_pin1.Write(GpioPinValue.High);
// Initialize the GPIO pin for the second LED
_pin2 = gpio.OpenPin(LED2_PIN);
_pin2.SetDriveMode(GpioPinDriveMode.Output);
_pin2.Write(GpioPinValue.Low);
// Initialize the LED1 Ellipse to draw Gray
LED1.Fill = _redBrush;
// Initialize Button pin
_pin3 = gpio.OpenPin(BUTT_PIN);
// Check if input pull-up resistors are supported
if (_pin3.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
_pin3.SetDriveMode(GpioPinDriveMode.InputPullUp);
else
_pin3.SetDriveMode(GpioPinDriveMode.Input);
// Set a debounce timeout to filter out switch bounce noise from a button press
_pin3.DebounceTimeout = TimeSpan.FromMilliseconds(50);
// Register for the ValueChanged event so our buttonPin_ValueChanged
// function is called when the button is pressed
_pin3.ValueChanged += _pin3_ValueChanged;
// Show the GPIO is OK message
GpioStatus.Text = "GPIO pin initialized correctly.";
}
示例10: MainPage
public MainPage()
{
this.InitializeComponent();
//GPIO();
//InitDancing();
stopwatch = Stopwatch.StartNew();
GpioController gpio = GpioController.GetDefault();
buttonPin = gpio.OpenPin(21);
if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
else
buttonPin.SetDriveMode(GpioPinDriveMode.Input);
buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
buttonPin2 = gpio.OpenPin(20);
if (buttonPin2.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
buttonPin2.SetDriveMode(GpioPinDriveMode.InputPullUp);
else
buttonPin2.SetDriveMode(GpioPinDriveMode.Input);
buttonPin2.DebounceTimeout = TimeSpan.FromMilliseconds(50);
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(BEAT_PACE);
timer.Tick += Beat;
servoPinA = gpio.OpenPin(SERVO_PIN_A);
servoPinA.SetDriveMode(GpioPinDriveMode.Output);
buttonPin.ValueChanged += Pin1_ValueChanged;
buttonPin2.ValueChanged += ButtonPin2_ValueChanged;
force();
//AsyncFunc();
//WebSocket();
}
示例11: InitGPIO
private void InitGPIO()
{
// Instantiate the Azure device client
deviceClient = DeviceClient.CreateFromConnectionString(IOT_HUB_CONN_STRING);
var gpio = GpioController.GetDefault();
// Show an error if there is no GPIO controller
if (gpio == null)
{
GpioStatus.Text = "There is no GPIO controller on this device.";
return;
}
buttonPin = gpio.OpenPin(BUTTON_PIN);
ledPin = gpio.OpenPin(LED_PIN);
// Initialize LED to the OFF state by first writing a HIGH value
// We write HIGH because the LED is wired in a active LOW configuration
ledPin.Write(GpioPinValue.High);
ledPin.SetDriveMode(GpioPinDriveMode.Output);
// Check if input pull-up resistors are supported
if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
else
buttonPin.SetDriveMode(GpioPinDriveMode.Input);
// Set a debounce timeout to filter out switch bounce noise from a button press
buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(5);
// Register for the ValueChanged event so our buttonPin_ValueChanged
// function is called when the button is pressed
buttonPin.ValueChanged += buttonPin_ValueChanged;
GpioStatus.Text = "GPIO pins initialized correctly.";
}
示例12: InitGPIO
private void InitGPIO()
{
var gpio = GpioController.GetDefault();
// Show an error if there is no GPIO controller
if (gpio == null)
{
return;
}
_doorUpPin = gpio.OpenPin(DOOR_UP_PIN);
_doorDownPin = gpio.OpenPin(DOOR_DOWN_PIN);
if (_doorUpPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
_doorUpPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
else
_doorUpPin.SetDriveMode(GpioPinDriveMode.Input);
_doorUpPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
_doorUpPin.ValueChanged += _doorUpPin_ValueChanged;
if (_doorDownPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
_doorDownPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
else
_doorDownPin.SetDriveMode(GpioPinDriveMode.Input);
_doorDownPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
_doorDownPin.ValueChanged += _doorDownPin_ValueChanged;
_doorRelayPin = gpio.OpenPin(DOOR_RELAY_PIN);
_doorRelayPin.Write(GpioPinValue.High);
_doorRelayPin.SetDriveMode(GpioPinDriveMode.Output);
}
示例13: InitHeartRateSensor
private void InitHeartRateSensor()
{
m_heart_rate_sensor = m_gpio.OpenPin(HEART_RATE_SENSOR_PIN);
if (m_heart_rate_sensor.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
{
//change this if you get rid of the external pull up
m_heart_rate_sensor.SetDriveMode(GpioPinDriveMode.Input);
}
else
{
m_heart_rate_sensor.SetDriveMode(GpioPinDriveMode.Input);
}
m_heart_rate_sensor.DebounceTimeout = TimeSpan.FromMilliseconds(0);
m_heart_rate_sensor.ValueChanged += M_heart_rate_sensor_ValueChanged;
}
示例14: InitGpio
/// <summary>
/// Initializes the GpioController on the board if it exists, and initializes the Led and Button pins.
/// </summary>
private void InitGpio()
{
//Attempt to get the GpioController instance for the
//device.
var gpio = GpioController.GetDefault();
// If no GpioController was found (gpio==null), null out the pins
// And throw an exception indicating there was no GPIO controller
if (gpio == null)
{
ledPin = null;
buttonPin = null;
throw new Exception("There is no GPIO controller on this device.");
}
//Init LED pin
ledPin = gpio.OpenPin(LED_PIN);
ledPin.SetDriveMode(GpioPinDriveMode.Output);
SetLedState(false);
//Init Button pin
buttonPin = gpio.OpenPin(BUTTON_PIN);
//Remember Windows 10 IoT Core runs on multiple boards.
//If the board's pin that the button is connected to supports
//pullup resistors, enable the pullup resistor, otherwise, just use
//it as a normal input
if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
{
buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
}
else
{
buttonPin.SetDriveMode(GpioPinDriveMode.Input);
}
//Set a debounce timeout to filter out switch bounce noice from a button press
buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
//Wire up an event hander to be called whenever the button gets pressed.
buttonPin.ValueChanged += ButtonPin_ValueChanged;
}
示例15: InitCadenceSensor
private void InitCadenceSensor()
{
m_cadence_sensor = m_gpio.OpenPin(CADENCE_SENSOR_PIN);
if (m_cadence_sensor.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
{
m_cadence_sensor.SetDriveMode(GpioPinDriveMode.InputPullUp);
}
else
{
m_cadence_sensor.SetDriveMode(GpioPinDriveMode.Input);
}
m_cadence_sensor.DebounceTimeout = TimeSpan.FromMilliseconds(10);
m_cadence_sensor.ValueChanged += M_cadence_sensor_ValueChanged;
RPM = 0;
}