node-red-contrib-waveshare-shield-adda-11010
Loading...
Searching...
No Matches
gpio Namespace Reference

Functions

 config ()
 
 output_json ()
 
 parse_args (raw_args)
 

Variables

 register_data = dict([('pin', 0), ('output', 0)])
 

Function Documentation

◆ config()

gpio.config ( )
Configure the port mode

Definition at line 174 of file gpio.py.

174def config():
175 """Configure the port mode"""
176 GPIO.setmode(GPIO.BCM)
177 GPIO.setwarnings(False)
178
179 if (register_data['output'] == -1):
180 GPIO.setup(register_data['pin'], GPIO.IN)
181 print(GPIO.input(register_data['pin']))
182
183 if (register_data['output'] != -1):
184 GPIO.setup(register_data['pin'], GPIO.OUT)
185 GPIO.output(register_data['pin'], register_data['output'])
186
187
188# Convert CLI options to register_data.

◆ output_json()

gpio.output_json ( )
Prints a JSON of the register_data for development and testing.

Definition at line 130 of file gpio.py.

130def output_json():
131 """Prints a JSON of the register_data for development and testing."""
132 print(json.dumps(register_data, sort_keys=True, indent=4))
133
134

◆ parse_args()

gpio.parse_args ( raw_args)
Parses the args into ready to write register_data.

Definition at line 135 of file gpio.py.

135def parse_args(raw_args):
136 """Parses the args into ready to write register_data."""
137 # First parse the CLI.
138 parser = argparse.ArgumentParser()
139 parser.add_argument("--pin", type=str, default="P22",
140 help="Pin: P22, P23, P24, P25 default P22")
141 parser.add_argument("--output", type=str, default="-1",
142 help="Providing this puts the pin in output mode instead of input mode. Output: 0, 1")
143 parser.add_argument("-t", "--test", action="store_true",
144 help="Print JSON of register_data")
145 args = parser.parse_args(raw_args)
146
147 # Process pin selection
148 register_data['pin'] = 6
149 if (args.pin == 'P22'):
150 register_data['pin'] = 6
151 if (args.pin == 'P23'):
152 register_data['pin'] = 13
153 if (args.pin == 'P24'):
154 register_data['pin'] = 19
155 if (args.pin == 'P25'):
156 register_data['pin'] = 26
157
158 # Process output, which also selects input or output mode
159 register_data['output'] = -1
160 if (args.output == '0'):
161 register_data['output'] = 0
162 if (args.output == '1'):
163 register_data['output'] = 1
164
165 # Optionally output register state for development purposes.
166 if args.test:
167 output_json()
168 exit()
169
170
171# Functions that read or write device
172
173

Variable Documentation

◆ register_data

gpio.register_data = dict([('pin', 0), ('output', 0)])

Definition at line 124 of file gpio.py.