Skip to content
This repository was archived by the owner on Feb 18, 2020. It is now read-only.
This repository was archived by the owner on Feb 18, 2020. It is now read-only.

Add function to return PCB revision #16

@rgl

Description

@rgl

To get the PCB revision (because at least two pins are different) you should add to gpio_linux.go something like:

var pcbRevision int

func PcbRevision() int {
    return pcbRevision
}

func getPcbRevision() int {
    r := regexp.MustCompile(`Revision\s*:\s*[0-9a-f]*([0-9a-f]{4})`)

    // See http://elinux.org/RPi_HardwareHistory#Board_Revision_History
    bytes, err := ioutil.ReadFile("/proc/cpuinfo")

    if err != nil {
        panic(err)
    }

    result := r.FindSubmatch(bytes)

    if result == nil {
        panic("Failed to get Revision from /proc/cpuinfo")
    }

    revision, err := strconv.ParseInt(string(result[1]), 16, 0)

    if err != nil {
        panic("Failed to parse Revision from /proc/cpuinfo")
    }

    if revision < 4 {
        return 1
    } else {
        return 2
    }
}

func init() {
    pcbRevision = getPcbRevision()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions