nanoFramework.Iot.Device.Button 1.2.570

Prefix Reported
dotnet add package nanoFramework.Iot.Device.Button --version 1.2.570                
NuGet\Install-Package nanoFramework.Iot.Device.Button -Version 1.2.570                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="nanoFramework.Iot.Device.Button" Version="1.2.570" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add nanoFramework.Iot.Device.Button --version 1.2.570                
#r "nuget: nanoFramework.Iot.Device.Button, 1.2.570"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install nanoFramework.Iot.Device.Button as a Cake Addin
#addin nuget:?package=nanoFramework.Iot.Device.Button&version=1.2.570

// Install nanoFramework.Iot.Device.Button as a Cake Tool
#tool nuget:?package=nanoFramework.Iot.Device.Button&version=1.2.570                

按钮

基类 ButtonBase 是一个适用于按钮的硬件独立的基础实现,可用于跨设备。而 GpioButton 是按钮的 GPIO 实现,并从 ButtonBase 类继承而来。这种实现已在 ESP32 平台上进行过测试,特别是在 M5StickC Plus 上。

文档

M5StickC Plus 的文档(包括引脚映射),可以在这里找到: 链接。关于标准鼠标事件的信息(用作按钮事件的灵感来源),可以在这里找到: 链接

用法

samples 目录中您可以找到一个例子。

// Initialize a new button with the corresponding button pin
GpioButton button = new GpioButton(buttonPin: 37);

Debug.WriteLine("Button is initialized, starting to read state");

// Enable or disable holding or doublepress events
button.IsDoublePressEnabled = true;
button.IsHoldingEnabled = true;

// Write to debug if the button is down
button.ButtonDown += (sender, e) =>
{
    Debug.WriteLine($"buttondown IsPressed={button.IsPressed}");
};

// Write to debug if the button is up
button.ButtonUp += (sender, e) =>
{
    Debug.WriteLine($"buttonup IsPressed={button.IsPressed}");
};

// Write to debug if the button is pressed
button.Press += (sender, e) =>
{
    Debug.WriteLine($"Press");
};

// Write to debug if the button is double pressed
button.DoublePress += (sender, e) =>
{
    Debug.WriteLine($"Double press");
};

// Write to debug if the button is held and released
button.Holding += (sender, e) =>
{
    switch (e.HoldingState)
    {
        case ButtonHoldingState.Started:
            Debug.WriteLine($"Holding Started");
            break;
        case ButtonHoldingState.Completed:
            Debug.WriteLine($"Holding Completed");
            break;
    }
};

Thread.Sleep(Timeout.Infinite);

期望输出

Button is initialized, starting to read state
buttondown IsPressed=True
buttonup IsPressed=False
Press
buttondown IsPressed=True
buttonup IsPressed=False
Press
Double press
buttondown IsPressed=True
Holding Started
buttonup IsPressed=False
Press
Holding Completed

测试

单元测试项目可以在 tests 目录中找到。您可以通过 VS2019 内置的测试功能直接运行它们。

unit tests

产品 兼容的和其他计算目标框架版本。
.NET Framework net 兼容。
兼容的目标框架
包含的目标框架(在包中)
了解有关目标框架.NET Standard的更多信息。

NuGet 包 (9)

显示依赖 nanoFramework.Iot.Device.Button 的前 5 个 NuGet 包

下载
nanoFramework.M5Core2

此包包括 .NET nanoFramework C# 项目使用的 nanoFramework.M5Core2 组件。

nanoFramework.M5StickC

此包包括 .NET nanoFramework C# 项目使用的 nanoFramework.M5StickC 组件。

nanoFramework.M5Core

此包包括 .NET nanoFramework C# 项目使用的 nanoFramework.M5Core 组件。

nanoFramework.M5StickCPlus

此包包括 .NET nanoFramework C# 项目使用的 nanoFramework.M5StickCPlus 组件。

nanoFramework.AtomLite

此包包括 .NET nanoFramework C# 项目使用的 nanoFramework.AtomLite 组件。

GitHub 仓库 (2)

显示依赖 nanoFramework.Iot.Device.Button 的前 2 个流行 GitHub 仓库

仓库 星标
nanoframework/Samples
🍬 nanoFramework 团队用于测试、概念验证和其他探索性努力的代码示例
nanoframework/nanoFramework.IoT.Device
📦 此存储库包括针对各种传感器、芯片、显示器、帽子和驱动程序的 .NET nanoFramework 实现库
版本 下载 最后更新
1.2.570 1,503 6/14/2024
1.2.560 463 5/29/2024
1.2.552 247 5/17/2024
1.2.548 336 5/15/2024
1.2.536 680 4/15/2024
1.2.514 887 3/22/2024
1.2.436 2,513 11/10/2023
1.2.329 5,789 5/26/2023
1.2.313 1,551 5/12/2023
1.2.308 1,042 5/11/2023
1.2.302 743 5/10/2023
1.2.297 1,182 5/3/2023
1.2.273 3,888 3/17/2023
1.2.215 12,616 1/6/2023
1.2.203 3,152 12/28/2022
1.2.153 7,703 11/5/2022
1.2.141 8,130 10/25/2022
1.2.122 4,141 10/12/2022
1.2.114 3,269 10/8/2022
1.2.95 8,468 9/22/2022
1.2.87 8,584 9/15/2022
1.2.73 3,425 9/8/2022
1.2.32 18,670 8/2/2022
1.1.113.2032 36,625 6/23/2022
1.1.58.10097 32,389 5/23/2022
1.1.43.5388 8,621 5/5/2022
1.1.16 991 4/19/2022
1.1.1 29,765 4/14/2022
1.0.300 11,647 3/31/2022
1.0.289-preview.6 179 3/25/2022
1.0.289-preview.1 143 3/24/2022
1.0.288-preview.99 173 3/18/2022
1.0.288-preview.98 129 3/18/2022
1.0.288-preview.93 189 3/15/2022
1.0.288-preview.86 207 3/8/2022
1.0.288-preview.65 224 2/18/2022
1.0.288-preview.48 245 2/4/2022
1.0.288-preview.29 244 1/28/2022
1.0.288-preview.20 223 1/27/2022
1.0.288-preview.19 147 1/27/2022
1.0.288-preview.5 194 1/24/2022
1.0.288-preview.3 164 1/21/2022
1.0.288-preview.1 151 1/21/2022
1.0.272 281 1/10/2022
1.0.259 1,481 12/9/2021
1.0.218 366 10/18/2021
1.0.214 797 10/15/2021
1.0.207 826 10/11/2021
1.0.196 785 10/5/2021