@@ -48,8 +48,14 @@ def init(self, mode=IN, pull=None):
48
48
"""Initialize the Pin"""
49
49
# Input,
50
50
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)
52
56
57
+ if mode is not None :
58
+ line_config = gpiod .LineSettings ()
53
59
if mode == self .IN :
54
60
line_config .direction = gpiod .line .Direction .INPUT
55
61
if pull is not None :
@@ -62,18 +68,24 @@ def init(self, mode=IN, pull=None):
62
68
else :
63
69
raise RuntimeError (f"Invalid pull for pin: { self .id } " )
64
70
71
+ self ._mode = self .IN
72
+ self ._line_request .reconfigure_lines (
73
+ {
74
+ int (self ._num ): line_config ,
75
+ }
76
+ )
65
77
elif mode == self .OUT :
66
78
if pull is not None :
67
79
raise RuntimeError ("Cannot set pull resistor on output" )
80
+ self ._mode = self .OUT
68
81
line_config .direction = gpiod .line .Direction .OUTPUT
69
-
82
+ self ._line_request .reconfigure_lines (
83
+ {
84
+ int (self ._num ): line_config ,
85
+ }
86
+ )
70
87
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 )
77
89
78
90
def value (self , val = None ):
79
91
"""Set or return the Pin Value"""
0 commit comments