PKGBUILD/pkg/types/gpio.go

207 lines
3.6 KiB
Go
Raw Normal View History

2019-03-03 18:13:37 +00:00
package types
import (
"fmt"
)
type GPIO string
const (
GPIO02 GPIO = "GPIO02"
GPIO03 = "GPIO03"
GPIO04 = "GPIO04"
GPIO05 = "GPIO05"
GPIO06 = "GPIO06"
GPIO07 = "GPIO07"
GPIO08 = "GPIO08"
GPIO10 = "GPIO10"
GPIO11 = "GPIO11"
GPIO12 = "GPIO12"
GPIO13 = "GPIO13"
GPIO14 = "GPIO14"
GPIO15 = "GPIO15"
GPIO16 = "GPIO16"
GPIO17 = "GPIO17"
GPIO18 = "GPIO18"
GPIO19 = "GPIO19"
GPIO20 = "GPIO20"
GPIO21 = "GPIO21"
GPIO22 = "GPIO22"
GPIO23 = "GPIO23"
GPIO24 = "GPIO24"
GPIO25 = "GPIO25"
GPIO26 = "GPIO26"
GPIO27 = "GPIO27"
)
func GPIOToString(gpio GPIO) (string, error) {
switch gpio {
case GPIO02:
return "GPIO02", nil
case GPIO03:
return "GPIO03", nil
case GPIO04:
return "GPIO04", nil
case GPIO05:
return "GPIO05", nil
case GPIO06:
return "GPIO06", nil
case GPIO07:
return "GPIO07", nil
case GPIO08:
return "GPIO08", nil
case GPIO10:
return "GPIO10", nil
case GPIO11:
return "GPIO11", nil
case GPIO12:
return "GPIO12", nil
case GPIO13:
return "GPIO13", nil
case GPIO14:
return "GPIO14", nil
case GPIO15:
return "GPIO15", nil
case GPIO16:
return "GPIO16", nil
case GPIO17:
return "GPIO17", nil
case GPIO18:
return "GPIO18", nil
case GPIO19:
return "GPIO19", nil
case GPIO20:
return "GPIO20", nil
case GPIO21:
return "GPIO21", nil
case GPIO22:
return "GPIO22", nil
case GPIO23:
return "GPIO23", nil
case GPIO24:
return "GPIO24", nil
case GPIO25:
return "GPIO25", nil
case GPIO26:
return "GPIO26", nil
case GPIO27:
return "GPIO27", nil
default:
return "", fmt.Errorf("Can not determine gpio %v", gpio)
}
}
func GPIOToInt(gpio GPIO) (int, error) {
switch gpio {
case GPIO02:
return 2, nil
case GPIO03:
return 3, nil
case GPIO04:
return 4, nil
case GPIO05:
return 5, nil
case GPIO06:
return 6, nil
case GPIO07:
return 7, nil
case GPIO08:
return 8, nil
case GPIO10:
return 10, nil
case GPIO11:
return 11, nil
case GPIO12:
return 12, nil
case GPIO13:
return 13, nil
case GPIO14:
return 14, nil
case GPIO15:
return 15, nil
case GPIO16:
return 16, nil
case GPIO17:
return 17, nil
case GPIO18:
return 18, nil
case GPIO19:
return 19, nil
case GPIO20:
return 20, nil
case GPIO21:
return 21, nil
case GPIO22:
return 22, nil
case GPIO23:
return 23, nil
case GPIO24:
return 24, nil
case GPIO25:
return 25, nil
case GPIO26:
return 26, nil
case GPIO27:
return 27, nil
default:
return 0, fmt.Errorf("Can not determine gpio %v", gpio)
}
}
2019-03-03 18:13:37 +00:00
func StringToGPIO(gpio string) (GPIO, error) {
switch gpio {
case "GPIO02":
return GPIO02, nil
case "GPIO03":
return GPIO03, nil
case "GPIO04":
return GPIO04, nil
case "GPIO05":
return GPIO05, nil
case "GPIO06":
return GPIO06, nil
case "GPIO07":
return GPIO07, nil
case "GPIO08":
return GPIO08, nil
case "GPIO10":
return GPIO10, nil
case "GPIO11":
return GPIO11, nil
case "GPIO12":
return GPIO12, nil
case "GPIO13":
return GPIO13, nil
case "GPIO14":
return GPIO14, nil
case "GPIO15":
return GPIO15, nil
case "GPIO16":
return GPIO16, nil
case "GPIO17":
return GPIO17, nil
case "GPIO18":
return GPIO18, nil
case "GPIO19":
return GPIO19, nil
case "GPIO20":
return GPIO20, nil
case "GPIO21":
return GPIO21, nil
case "GPIO22":
return GPIO22, nil
case "GPIO23":
return GPIO23, nil
case "GPIO24":
return GPIO24, nil
case "GPIO25":
return GPIO25, nil
case "GPIO26":
return GPIO26, nil
case "GPIO27":
return GPIO27, nil
default:
return "", fmt.Errorf("Can not determine gpio %v", gpio)
}
}