| 
									
										
										
										
											2018-01-20 00:03:47 -05:00
										 |  |  | # Virtual pin that propagates its changes to multiple output pins | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Copyright (C) 2017,2018  Kevin O'Connor <kevin@koconnor.net> | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # This file may be distributed under the terms of the GNU GPLv3 license. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PrinterMultiPin: | 
					
						
							|  |  |  |     def __init__(self, config): | 
					
						
							|  |  |  |         self.printer = config.get_printer() | 
					
						
							| 
									
										
										
										
											2018-04-04 12:07:41 -04:00
										 |  |  |         ppins = self.printer.lookup_object('pins') | 
					
						
							| 
									
										
										
										
											2018-01-20 00:03:47 -05:00
										 |  |  |         try: | 
					
						
							| 
									
										
										
										
											2018-04-04 12:07:41 -04:00
										 |  |  |             ppins.register_chip('multi_pin', self) | 
					
						
							|  |  |  |         except ppins.error: | 
					
						
							| 
									
										
										
										
											2018-01-20 00:03:47 -05:00
										 |  |  |             pass | 
					
						
							|  |  |  |         self.pin_type = None | 
					
						
							|  |  |  |         self.pin_list = [pin.strip() for pin in config.get('pins').split(',')] | 
					
						
							|  |  |  |         self.mcu_pins = [] | 
					
						
							| 
									
										
										
										
											2018-07-26 09:44:45 -04:00
										 |  |  |     def setup_pin(self, pin_type, pin_params): | 
					
						
							| 
									
										
										
										
											2018-04-04 12:07:41 -04:00
										 |  |  |         ppins = self.printer.lookup_object('pins') | 
					
						
							| 
									
										
										
										
											2018-01-20 00:03:47 -05:00
										 |  |  |         pin_name = pin_params['pin'] | 
					
						
							|  |  |  |         pin = self.printer.lookup_object('multi_pin ' + pin_name, None) | 
					
						
							|  |  |  |         if pin is not self: | 
					
						
							|  |  |  |             if pin is None: | 
					
						
							| 
									
										
										
										
											2018-04-04 12:07:41 -04:00
										 |  |  |                 raise ppins.error("multi_pin %s not configured" % (pin_name,)) | 
					
						
							| 
									
										
										
										
											2018-07-26 09:44:45 -04:00
										 |  |  |             return pin.setup_pin(pin_type, pin_params) | 
					
						
							| 
									
										
										
										
											2018-01-20 00:03:47 -05:00
										 |  |  |         if self.pin_type is not None: | 
					
						
							| 
									
										
										
										
											2018-04-04 12:07:41 -04:00
										 |  |  |             raise ppins.error("Can't setup multi_pin %s twice" % (pin_name,)) | 
					
						
							| 
									
										
										
										
											2018-07-26 09:44:45 -04:00
										 |  |  |         self.pin_type = pin_type | 
					
						
							| 
									
										
										
										
											2018-01-20 00:03:47 -05:00
										 |  |  |         invert = "" | 
					
						
							|  |  |  |         if pin_params['invert']: | 
					
						
							|  |  |  |             invert = "!" | 
					
						
							| 
									
										
										
										
											2018-07-26 09:44:45 -04:00
										 |  |  |         self.mcu_pins = [ppins.setup_pin(pin_type, invert + pin_desc) | 
					
						
							| 
									
										
										
										
											2018-04-04 12:07:41 -04:00
										 |  |  |                          for pin_desc in self.pin_list] | 
					
						
							| 
									
										
										
										
											2018-01-20 00:03:47 -05:00
										 |  |  |         return self | 
					
						
							|  |  |  |     def get_mcu(self): | 
					
						
							|  |  |  |         return self.mcu_pins[0].get_mcu() | 
					
						
							|  |  |  |     def setup_max_duration(self, max_duration): | 
					
						
							|  |  |  |         for mcu_pin in self.mcu_pins: | 
					
						
							|  |  |  |             mcu_pin.setup_max_duration(max_duration) | 
					
						
							|  |  |  |     def setup_start_value(self, start_value, shutdown_value): | 
					
						
							|  |  |  |         for mcu_pin in self.mcu_pins: | 
					
						
							|  |  |  |             mcu_pin.setup_start_value(start_value, shutdown_value) | 
					
						
							| 
									
										
										
										
											2018-01-29 12:54:06 -05:00
										 |  |  |     def setup_cycle_time(self, cycle_time, hardware_pwm=False): | 
					
						
							| 
									
										
										
										
											2018-01-20 00:03:47 -05:00
										 |  |  |         for mcu_pin in self.mcu_pins: | 
					
						
							| 
									
										
										
										
											2018-01-29 12:54:06 -05:00
										 |  |  |             mcu_pin.setup_cycle_time(cycle_time, hardware_pwm) | 
					
						
							| 
									
										
										
										
											2018-01-20 00:03:47 -05:00
										 |  |  |     def set_digital(self, print_time, value): | 
					
						
							|  |  |  |         for mcu_pin in self.mcu_pins: | 
					
						
							|  |  |  |             mcu_pin.set_digital(print_time, value) | 
					
						
							| 
									
										
										
										
											2020-09-26 20:52:42 -04:00
										 |  |  |     def set_pwm(self, print_time, value, cycle_time=None): | 
					
						
							| 
									
										
										
										
											2018-01-20 00:03:47 -05:00
										 |  |  |         for mcu_pin in self.mcu_pins: | 
					
						
							| 
									
										
										
										
											2020-09-26 20:52:42 -04:00
										 |  |  |             mcu_pin.set_pwm(print_time, value, cycle_time) | 
					
						
							| 
									
										
										
										
											2018-01-20 00:03:47 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-03 12:53:11 -05:00
										 |  |  | def load_config_prefix(config): | 
					
						
							| 
									
										
										
										
											2018-01-20 00:03:47 -05:00
										 |  |  |     return PrinterMultiPin(config) |