Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Iot
提交
80c5547b
I
Iot
项目概览
jobily
/
Iot
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
Iot
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
80c5547b
编写于
10月 30, 2018
作者:
J
Jose Perez Rodriguez
提交者:
GitHub
10月 30, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removing Singleton pattern on the Gpio controller. (#21)
上级
84b88b7a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
21 addition
and
57 deletion
+21
-57
src/System.Device.Gpio/System/Device/Gpio/GpioController.cs
src/System.Device.Gpio/System/Device/Gpio/GpioController.cs
+21
-57
未找到文件。
src/System.Device.Gpio/System/Device/Gpio/GpioController.cs
浏览文件 @
80c5547b
...
...
@@ -25,8 +25,6 @@ namespace System.Device.Gpio
}
private
GpioDriver
_driver
;
private
HashSet
<
int
>
_openPins
;
private
static
GpioController
_controllerInstance
=
null
;
private
static
readonly
object
_lock
=
new
object
();
private
const
string
_cpuInfoPath
=
"/proc/cpuinfo"
;
private
const
string
_raspberryPiHardware
=
"BCM2835"
;
private
const
string
_hummingBoardHardware
=
@"Freescale i.MX6 Quad/DualLite (Device Tree)"
;
...
...
@@ -59,11 +57,7 @@ namespace System.Device.Gpio
/// <returns>A GpioController instance</returns>
public
static
GpioController
GetController
()
{
if
(
_controllerInstance
==
null
)
{
return
GetController
(
PinNumberingScheme
.
Logical
);
}
return
_controllerInstance
;
return
GetController
(
PinNumberingScheme
.
Logical
);
}
/// <summary>
...
...
@@ -73,40 +67,29 @@ namespace System.Device.Gpio
/// <returns>A GpioController instance</returns>
public
static
GpioController
GetController
(
PinNumberingScheme
numberingScheme
)
{
if
(
_controllerInstance
==
null
)
GpioDriver
driver
;
if
(
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
Windows
))
{
GpioDriver
driver
;
if
(
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
Windows
))
{
driver
=
new
Windows10Driver
();
}
else
{
BoardType
boardType
=
GetBoardHardware
();
switch
(
boardType
)
{
case
BoardType
.
RaspberryPi3
:
driver
=
new
RaspberryPi3Driver
();
break
;
case
BoardType
.
Hummingboard
:
driver
=
new
HummingboardDriver
();
break
;
case
BoardType
.
Unknown
:
default
:
driver
=
new
UnixDriver
();
break
;
}
}
if
(
_controllerInstance
==
null
)
{
return
GetController
(
driver
,
numberingScheme
);
}
driver
=
new
Windows10Driver
();
}
if
(
numberingScheme
!=
_controllerInstance
.
NumberingScheme
)
else
{
throw
new
GpioException
(
"There is a controller instance that uses a different numbering scheme already opened."
);
BoardType
boardType
=
GetBoardHardware
();
switch
(
boardType
)
{
case
BoardType
.
RaspberryPi3
:
driver
=
new
RaspberryPi3Driver
();
break
;
case
BoardType
.
Hummingboard
:
driver
=
new
HummingboardDriver
();
break
;
case
BoardType
.
Unknown
:
default
:
driver
=
new
UnixDriver
();
break
;
}
}
return
_controllerInstance
;
return
GetController
(
driver
,
numberingScheme
)
;
}
/// <summary>
...
...
@@ -117,26 +100,7 @@ namespace System.Device.Gpio
/// <returns>A GpioController instance</returns>
public
static
GpioController
GetController
(
GpioDriver
driver
,
PinNumberingScheme
numberingScheme
)
{
if
(
_controllerInstance
==
null
)
{
lock
(
_lock
)
{
if
(
_controllerInstance
==
null
)
{
_controllerInstance
=
new
GpioController
(
driver
,
numberingScheme
);
}
}
}
// Check if the singleton instance matches the parameters that where passed in.
if
(
driver
.
GetType
()
!=
_controllerInstance
.
_driver
.
GetType
())
{
throw
new
GpioException
(
"There is a controller instance that uses a different driver already opened.."
);
}
if
(
numberingScheme
!=
_controllerInstance
.
NumberingScheme
)
{
throw
new
GpioException
(
"There is a controller instance that uses a different numbering scheme already opened."
);
}
return
_controllerInstance
;
return
new
GpioController
(
driver
,
numberingScheme
);
}
/// <summary>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录