@@ -22,15 +22,11 @@ namespace jetson_gpio
2222{
2323JetsonGpio::~JetsonGpio ()
2424{
25- if (state_file_descriptor_ > -1 ) {
26- close (state_file_descriptor_);
27- }
28-
2925 // Regardless of the existence of other processes that uses the same GPIO pin
3026 // (incl. zombie GPIO port opening because of failure exit),
31- // this unexport closes the target GPIO pin anyway.
27+ // this function closes the target GPIO pin anyway.
3228 // This behavior intends to make next try to use this GPIO pin success.
33- unexport_gpio ();
29+ close_gpio ();
3430}
3531
3632bool JetsonGpio::init_gpio_pin (
@@ -39,49 +35,29 @@ bool JetsonGpio::init_gpio_pin(
3935 std::string gpio_character_device = " /dev/gpiochip" + std::to_string (gpio_chip);
4036
4137 gpio_chip_ = gpiod::chip (gpio_character_device);
42- gpio_lines_ = gpio_chip_.get_lines (
43- std::vector<unsigned int >({gpio_line})); // XXX: 143 = Anvil misc.I/O GP_Out_1, 108 = PWM_Out_0
38+ gpio_line_ = gpio_chip_.get_line (gpio_line);
4439 gpio_request_ = {
45- " sensor_trigger" , // consumer name. XXX: fixed name may conflict for multiple instances
46- gpiod::line_request::DIRECTION_OUTPUT, // request_type
47- 0 // flag
40+ " sensor_trigger" , // consumer name
41+ direction, // request_type
42+ 0 // flag
4843 };
4944
50- if (!set_gpio_direction (direction)) {
51- return false ;
52- }
5345
54- gpio_lines_ .request (gpio_request_, std::vector< int >({ GPIO_LOW}) );
46+ gpio_line_ .request (gpio_request_, GPIO_LOW);
5547
5648 return true ;
5749}
5850
59- bool JetsonGpio::export_gpio () { return true ; }
60-
61- bool JetsonGpio::unexport_gpio ()
51+ bool JetsonGpio::close_gpio ()
6252{
6353 gpio_chip_.~chip ();
6454
6555 return true ;
6656}
6757
68- bool JetsonGpio::set_gpio_direction (gpio_direction direction)
69- {
70- switch (direction) {
71- case GPIO_INPUT:
72- gpio_request_.request_type = gpiod::line_request::DIRECTION_INPUT;
73- break ;
74- case GPIO_OUTPUT:
75- gpio_request_.request_type = gpiod::line_request::DIRECTION_OUTPUT;
76- break ;
77- }
78-
79- return true ;
80- }
81-
8258bool JetsonGpio::set_gpio_pin_state (gpio_state state)
8359{
84- gpio_lines_. set_values (std::vector< int >({ state}) );
60+ gpio_line_. set_value ( state);
8561
8662 return true ;
8763}
0 commit comments