| 
									
										
										
										
											2024-06-02 22:31:28 -07:00
										 |  |  | # Load Cell Implementation | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Copyright (C) 2024 Gareth Farrington <gareth@waves.ky> | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # This file may be distributed under the terms of the GNU GPLv3 license. | 
					
						
							|  |  |  | from . import hx71x | 
					
						
							| 
									
										
										
										
											2024-06-02 22:33:45 -07:00
										 |  |  | from . import ads1220 | 
					
						
							| 
									
										
										
										
											2024-06-02 22:31:28 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Printer class that controls a load cell | 
					
						
							|  |  |  | class LoadCell: | 
					
						
							|  |  |  |     def __init__(self, config, sensor): | 
					
						
							|  |  |  |         self.printer = printer = config.get_printer() | 
					
						
							|  |  |  |         self.sensor = sensor   # must implement BulkAdcSensor | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _on_sample(self, msg): | 
					
						
							|  |  |  |         return True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def get_sensor(self): | 
					
						
							|  |  |  |         return self.sensor | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def load_config(config): | 
					
						
							|  |  |  |     # Sensor types | 
					
						
							|  |  |  |     sensors = {} | 
					
						
							|  |  |  |     sensors.update(hx71x.HX71X_SENSOR_TYPES) | 
					
						
							| 
									
										
										
										
											2024-06-02 22:33:45 -07:00
										 |  |  |     sensors.update(ads1220.ADS1220_SENSOR_TYPE) | 
					
						
							| 
									
										
										
										
											2024-06-02 22:31:28 -07:00
										 |  |  |     sensor_class = config.getchoice('sensor_type', sensors) | 
					
						
							|  |  |  |     return LoadCell(config, sensor_class(config)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def load_config_prefix(config): | 
					
						
							|  |  |  |     return load_config(config) |