Last active
December 7, 2022 22:24
-
-
Save longsleep/6ab75289bf92cbe3d02a0c5d3f6a4764 to your computer and use it in GitHub Desktop.
Simple helper to compute sysfs GPIO numbers from PIN names on Pine64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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])) |
@marcushh777 fixed in revision 3 thanks
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
hi, this does not run in Python3
... it does run in Python2 ... however.