@@ -21,20 +21,22 @@ std::map<rf24_gpio_pin_t, gpio_fd> cachedPins;
2121struct gpio_v2_line_request request;
2222struct gpio_v2_line_values data;
2323
24+ // initialize static member.
25+ int GPIOChipCache::fd = -1 ;
26+
2427void GPIOChipCache::openDevice ()
2528{
2629 if (fd < 0 ) {
27- fd = open (chip , O_RDONLY );
30+ fd = open (RF24_LINUX_GPIO_CHIP , O_RDONLY );
2831 if (fd < 0 ) {
2932 std::string msg = " Can't open device " ;
30- msg += chip ;
33+ msg += RF24_LINUX_GPIO_CHIP ;
3134 msg += " ; " ;
3235 msg += strerror (errno);
3336 throw GPIOException (msg);
3437 return ;
3538 }
3639 }
37- chipInitialized = true ;
3840}
3941
4042void GPIOChipCache::closeDevice ()
@@ -75,31 +77,21 @@ GPIO::~GPIO()
7577
7678void GPIO::open (rf24_gpio_pin_t port, int DDR )
7779{
78- try {
79- gpioCache.openDevice ();
80- }
81- catch (GPIOException& exc) {
82- if (gpioCache.chipInitialized ) {
83- throw exc;
84- return ;
85- }
86- gpioCache.chip = " /dev/gpiochip0" ;
87- gpioCache.openDevice ();
88- }
80+ gpioCache.openDevice ();
8981
9082 // get chip info
9183 gpiochip_info info;
9284 memset (&info, 0 , sizeof (info));
9385 int ret = ioctl (gpioCache.fd , GPIO_GET_CHIPINFO_IOCTL , &info);
9486 if (ret < 0 ) {
9587 std::string msg = " Could not gather info about " ;
96- msg += gpioCache. chip ;
88+ msg += RF24_LINUX_GPIO_CHIP ;
9789 throw GPIOException (msg);
9890 return ;
9991 }
10092
10193 if (port > info.lines ) {
102- std::string msg = " pin number " + std::to_string (port) + " not available for " + gpioCache. chip ;
94+ std::string msg = " pin number " + std::to_string (port) + " not available for " + RF24_LINUX_GPIO_CHIP ;
10395 throw GPIOException (msg);
10496 return ;
10597 }
0 commit comments