将指针配置name也设定为可配置

This commit is contained in:
2024-11-21 17:29:32 +08:00
parent a923be10c4
commit 2886009d4d
4 changed files with 6 additions and 4 deletions

View File

@@ -19,7 +19,8 @@ aliyun:
game:
maxTimeout: 60 # 单位 s
cardGroups:
- outOK: 6
- name: gpiochip0
outOK: 6
lower: 13
error: 19
empty: 26

View File

@@ -123,12 +123,12 @@ func (d *Device) GetEmpty() int {
return d.status[d.lines.Empty].Get()
}
func New(name string, lines *LineGroup) (*Device, error) {
func New(lines *LineGroup) (*Device, error) {
if !lines.Ok() {
return nil, fmt.Errorf("针脚配置错误")
}
chip, err := gpiocdev.NewChip(name, gpiocdev.AsActiveLow)
chip, err := gpiocdev.NewChip(lines.Name, gpiocdev.AsActiveLow)
if err != nil {
return nil, fmt.Errorf("打开 GPIO 设备失败: %w", err)
}

View File

@@ -1,6 +1,7 @@
package card_device
type LineGroup struct {
Name string
OutOK int
Lower int
Error int

View File

@@ -28,7 +28,7 @@ func PushCard(ctx context.Context) leaf.HandlerFunc {
gv, _ := json.Marshal(group)
zap.S().Info("发卡指针初始化:", string(gv))
device, err := card_device.New("gpiochip0", group)
device, err := card_device.New(group)
if err != nil {
zap.S().Panicln("初始化发卡器失败: ", err)
}