Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
F
fast_scripts
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
aohui.li
fast_scripts
Commits
a24d358f
Commit
a24d358f
authored
Aug 21, 2025
by
aohui.li
😋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[add] 快速验证linux网关的LED状态,可以关闭,可以打开
parent
6358856e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
0 deletions
+86
-0
01_test_linux_led_status.sh
01_test_linux_led_status.sh
+86
-0
No files found.
01_test_linux_led_status.sh
0 → 100644
View file @
a24d358f
#!/bin/bash
# 定义引脚范围
MIN_PIN
=
447
MAX_PIN
=
462
# 检查参数是否正确
if
[
$#
-ne
2
]
;
then
echo
"用法:
$0
<引脚号|all> <状态(on/off)"
echo
"示例:
$0
447 on # 点亮447号引脚连接的LED"
echo
"
$0
all on # 点亮所有447~462引脚的LED"
echo
"
$0
all off # 关闭所有LED"
exit
1
fi
TARGET
=
$1
STATE
=
$2
# 检查状态参数是否有效
if
[
"
$STATE
"
!=
"on"
]
&&
[
"
$STATE
"
!=
"off"
]
;
then
echo
"错误: 状态必须是'on'或'off'"
exit
1
fi
# 处理单个引脚
control_single_pin
()
{
local
PIN
=
$1
local
STATE
=
$2
# 检查引脚是否在有效范围内
if
[
$PIN
-lt
$MIN_PIN
]
||
[
$PIN
-gt
$MAX_PIN
]
;
then
echo
"错误: 引脚号必须在
$MIN_PIN
~
$MAX_PIN
之间"
return
1
fi
# 导出GPIO引脚(如果尚未导出)
if
[
!
-d
"/sys/class/gpio/gpio
$PIN
"
]
;
then
echo
"导出GPIO引脚
$PIN
..."
echo
$PIN
>
/sys/class/gpio/export
||
{
echo
"导出引脚
$PIN
失败,请检查权限或引脚是否被占用"
return
1
}
# 等待系统响应
sleep
0.1
fi
# 设置引脚为输出模式
echo
"out"
>
/sys/class/gpio/gpio
$PIN
/direction
||
{
echo
"引脚
$PIN
设置输出模式失败"
return
1
}
# 控制LED状态
if
[
"
$STATE
"
=
"on"
]
;
then
echo
"1"
>
/sys/class/gpio/gpio
$PIN
/value
echo
"LED (引脚
$PIN
) 已点亮"
else
echo
"0"
>
/sys/class/gpio/gpio
$PIN
/value
echo
"LED (引脚
$PIN
) 已关闭"
fi
}
# 处理所有引脚
control_all_pins
()
{
local
STATE
=
$1
echo
"正在
$STATE
所有LED (
$MIN_PIN
~
$MAX_PIN
)..."
for
((
PIN
=
$MIN_PIN
;
PIN<
=
$MAX_PIN
;
PIN++
))
;
do
control_single_pin
$PIN
$STATE
done
echo
"所有LED已
$STATE
"
}
# 根据目标执行相应操作
if
[
"
$TARGET
"
=
"all"
]
;
then
control_all_pins
$STATE
else
# 检查输入是否为数字
if
!
[[
"
$TARGET
"
=
~ ^[0-9]+
$
]]
;
then
echo
"错误: 引脚号必须是数字或'all'"
exit
1
fi
control_single_pin
$TARGET
$STATE
fi
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment