Skip to content

Instantly share code, notes, and snippets.

@longsleep
Last active December 7, 2022 22:24
Show Gist options
  • Save longsleep/6ab75289bf92cbe3d02a0c5d3f6a4764 to your computer and use it in GitHub Desktop.
Save longsleep/6ab75289bf92cbe3d02a0c5d3f6a4764 to your computer and use it in GitHub Desktop.
Simple helper to compute sysfs GPIO numbers from PIN names on Pine64
#!/usr/bin/python3
import sys
import string
def convert(value):
value = value.upper()
alp = value[1]
idx = string.ascii_uppercase.index(alp)
num = int(value[2:], 10)
res = idx * 32 + num
return res
if __name__ == "__main__":
args = sys.argv[1:]
if not args:
print("Usage: %s <pin>" % sys.argv[0])
sys.exit(1)
print("%d" % convert(args[0]))
@mateo08c
Copy link

mateo08c commented Dec 7, 2022

Hey, I did this in GO. Thx! ❤️

func convertPIN(p string) (string, error) {
	v := strings.ToUpper(p)
	le := v[1:2]
	li := strings.Index("ABCDEFGHIJKLMNOPQRSTUVWXYZ", le)
	ln := v[2:]
	ai, err := strconv.Atoi(ln)
	if err != nil {
		return "", err
	}
	res := (li * 32) + ai
	return strconv.Itoa(res), nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment