pjueon/JetsonGPIO

Bug when you set a pin as output twice

ma-ludw opened this issue · 2 comments

If you set a pin as an output twice, the output stops working.

This does not work:

  GPIO::setmode(GPIO::BOARD);
  GPIO::setup(32, GPIO::OUT, 0);
  GPIO::setup(32, GPIO::OUT, 0);
  std::this_thread::sleep_for(std::chrono::milliseconds(100));
  GPIO::output(32, 1);

I think the problem is, that the pins are exported every time the setup function is called.
I did not test it with input or pwm pins, or switching from input to output.

I use some other library that calls the GPIO library and in there, the pin needs the possibility to change the direction.

To solve the problem, I tried to check in the _setup_single_out function if the ch_info.f_direction stream is opened and only call _export_gpio if it's not. But this broke my i2c port and I have no idea why.

As a workaround, the pin needs to be cleaned up manually before every reassignment.

Thanks for the report. Fixed it by cleaning up before setup if the channel is already set.