mirror of
https://github.com/kidoman/embd
synced 2024-12-22 12:50:19 +01:00
gpio: consistent naming
This commit is contained in:
parent
b6f5d8d640
commit
6003f2249d
@ -31,33 +31,33 @@ func (i *interrupt) Signal() {
|
|||||||
i.handler(i.pin)
|
i.handler(i.pin)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ePollListener struct {
|
type epollListener struct {
|
||||||
epollFd int
|
mu sync.Mutex // Guards the following.
|
||||||
|
fd int
|
||||||
interruptablePins map[int]*interrupt
|
interruptablePins map[int]*interrupt
|
||||||
mu sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ePollListenerInstance *ePollListener
|
var epollListenerInstance *epollListener
|
||||||
|
|
||||||
func getEPollListenerInstance() *ePollListener {
|
func getEpollListenerInstance() *epollListener {
|
||||||
if ePollListenerInstance == nil {
|
if epollListenerInstance == nil {
|
||||||
ePollListenerInstance = initEPollListener()
|
epollListenerInstance = initEpollListener()
|
||||||
}
|
}
|
||||||
return ePollListenerInstance
|
return epollListenerInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
func initEPollListener() *ePollListener {
|
func initEpollListener() *epollListener {
|
||||||
epollFd, err := syscall.EpollCreate1(0)
|
fd, err := syscall.EpollCreate1(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("Unable to create epoll: %v", err))
|
panic(fmt.Sprintf("Unable to create epoll: %v", err))
|
||||||
}
|
}
|
||||||
listener := &ePollListener{epollFd: epollFd, interruptablePins: make(map[int]*interrupt)}
|
listener := &epollListener{fd: fd, interruptablePins: make(map[int]*interrupt)}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
var epollEvents [MaxGPIOInterrupt]syscall.EpollEvent
|
var epollEvents [MaxGPIOInterrupt]syscall.EpollEvent
|
||||||
|
|
||||||
for {
|
for {
|
||||||
n, err := syscall.EpollWait(listener.epollFd, epollEvents[:], -1)
|
n, err := syscall.EpollWait(listener.fd, epollEvents[:], -1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("EpollWait error: %v", err))
|
panic(fmt.Sprintf("EpollWait error: %v", err))
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ func initEPollListener() *ePollListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func registerInterrupt(pin *digitalPin, handler func(embd.DigitalPin)) error {
|
func registerInterrupt(pin *digitalPin, handler func(embd.DigitalPin)) error {
|
||||||
l := getEPollListenerInstance()
|
l := getEpollListenerInstance()
|
||||||
|
|
||||||
pinFd := int(pin.val.Fd())
|
pinFd := int(pin.val.Fd())
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ func registerInterrupt(pin *digitalPin, handler func(embd.DigitalPin)) error {
|
|||||||
|
|
||||||
event.Fd = int32(pinFd)
|
event.Fd = int32(pinFd)
|
||||||
|
|
||||||
if err := syscall.EpollCtl(l.epollFd, syscall.EPOLL_CTL_ADD, pinFd, &event); err != nil {
|
if err := syscall.EpollCtl(l.fd, syscall.EPOLL_CTL_ADD, pinFd, &event); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ func registerInterrupt(pin *digitalPin, handler func(embd.DigitalPin)) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func unregisterInterrupt(pin *digitalPin) error {
|
func unregisterInterrupt(pin *digitalPin) error {
|
||||||
l := getEPollListenerInstance()
|
l := getEpollListenerInstance()
|
||||||
|
|
||||||
pinFd := int(pin.val.Fd())
|
pinFd := int(pin.val.Fd())
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ func unregisterInterrupt(pin *digitalPin) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := syscall.EpollCtl(l.epollFd, syscall.EPOLL_CTL_DEL, pinFd, nil); err != nil {
|
if err := syscall.EpollCtl(l.fd, syscall.EPOLL_CTL_DEL, pinFd, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user