Skip to content

Commit

Permalink
pynfb: [FIX] loop read_temperature while returns EBUSY
Browse files Browse the repository at this point in the history
This hides the TimeoutError.
  • Loading branch information
martinspinler committed Oct 3, 2024
1 parent ee04c50 commit f96cb60
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 7 additions & 1 deletion libnfb/src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@

int nfb_sensor_get(struct nfb_device *dev, struct nfb_boot_ioc_sensor *s)
{
return ioctl(dev->fd, NFB_BOOT_IOC_SENSOR_READ, s);
int ret;

ret = ioctl(dev->fd, NFB_BOOT_IOC_SENSOR_READ, s);
if (ret == -1)
return -errno;

return ret;
}
12 changes: 8 additions & 4 deletions pynfb/nfb/libnfb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ from typing import Union, Optional, List, Tuple
from libc.stdlib cimport malloc
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, int32_t
from libcpp cimport bool
cimport libc.errno
from libc.errno cimport EBUSY, ETIMEDOUT, EAGAIN

from cpython.ref cimport PyObject
from cpython.exc cimport PyErr_SetFromErrno
Expand Down Expand Up @@ -172,9 +172,13 @@ cdef class Nfb:
assert units == "celsius"

self._handle.check_handle()
ret = libnetcope.nc_adc_sensors_get_temp(self._handle._dev, &int32)

ret = -EAGAIN
while ret == -EAGAIN:
ret = libnetcope.nc_adc_sensors_get_temp(self._handle._dev, &int32)
if ret < 0:
raise IOError

return int(int32) / 1000


Expand Down Expand Up @@ -352,9 +356,9 @@ cdef class Comp:
if timeout is None:
timeout = -1
ret = nfb_comp_trylock(self._comp, features, timeout)
if ret == -libc.errno.ETIMEDOUT:
if ret == -ETIMEDOUT:
raise TimeoutError()
elif ret == -libc.errno.EBUSY:
elif ret == -EBUSY:
raise BlockingIOError()
elif ret != 0:
raise OSError()
Expand Down

0 comments on commit f96cb60

Please sign in to comment.