@@ -48,8 +48,14 @@ def init(self, mode=IN, pull=None):
4848 """Initialize the Pin"""
4949 # Input,
5050 if not self ._line_request :
51- line_config = gpiod .LineSettings ()
51+ self ._line_request = self ._chip .request_lines (
52+ config = {int (self ._num ): None },
53+ consumer = self ._CONSUMER ,
54+ )
55+ # print("init line: ", self.id, self._line)
5256
57+ if mode is not None :
58+ line_config = gpiod .LineSettings ()
5359 if mode == self .IN :
5460 line_config .direction = gpiod .line .Direction .INPUT
5561 if pull is not None :
@@ -62,18 +68,24 @@ def init(self, mode=IN, pull=None):
6268 else :
6369 raise RuntimeError (f"Invalid pull for pin: { self .id } " )
6470
71+ self ._mode = self .IN
72+ self ._line_request .reconfigure_lines (
73+ {
74+ int (self ._num ): line_config ,
75+ }
76+ )
6577 elif mode == self .OUT :
6678 if pull is not None :
6779 raise RuntimeError ("Cannot set pull resistor on output" )
80+ self ._mode = self .OUT
6881 line_config .direction = gpiod .line .Direction .OUTPUT
69-
82+ self ._line_request .reconfigure_lines (
83+ {
84+ int (self ._num ): line_config ,
85+ }
86+ )
7087 else :
71- raise RuntimeError (f"Invalid mode for pin: { self .id } " )
72-
73- self ._line_request = self ._chip .request_lines (
74- {int (self ._num ): line_config },
75- consumer = self ._CONSUMER ,
76- )
88+ raise RuntimeError ("Invalid mode for pin: %s" % self .id )
7789
7890 def value (self , val = None ):
7991 """Set or return the Pin Value"""
0 commit comments