gobot.io/x/gobot/v2@v2.1.0/system/digitalpin_access.go (about) 1 package system 2 3 import ( 4 "strconv" 5 6 "gobot.io/x/gobot/v2" 7 ) 8 9 // sysfsDitalPinHandler represents the sysfs implementation 10 type sysfsDigitalPinAccess struct { 11 fs filesystem 12 } 13 14 // gpiodDigitalPinAccess represents the character device implementation 15 type gpiodDigitalPinAccess struct { 16 fs filesystem 17 chips []string 18 } 19 20 func (h *sysfsDigitalPinAccess) isSupported() bool { 21 // currently this is supported by all Kernels 22 return true 23 } 24 25 func (h *sysfsDigitalPinAccess) createPin(chip string, pin int, 26 o ...func(gobot.DigitalPinOptioner) bool) gobot.DigitalPinner { 27 return newDigitalPinSysfs(h.fs, strconv.Itoa(pin), o...) 28 } 29 30 func (h *sysfsDigitalPinAccess) setFs(fs filesystem) { 31 h.fs = fs 32 } 33 34 func (h *gpiodDigitalPinAccess) isSupported() bool { 35 chips, err := h.fs.find("/dev", "gpiochip") 36 if err != nil || len(chips) == 0 { 37 return false 38 } 39 h.chips = chips 40 return true 41 } 42 43 func (h *gpiodDigitalPinAccess) createPin(chip string, pin int, 44 o ...func(gobot.DigitalPinOptioner) bool) gobot.DigitalPinner { 45 return newDigitalPinGpiod(chip, pin, o...) 46 } 47 48 func (h *gpiodDigitalPinAccess) setFs(fs filesystem) { 49 h.fs = fs 50 }