@@ -31,7 +31,7 @@ class FASTDriver:
31
31
"""Base class for drivers connected to a FAST Controller."""
32
32
33
33
__slots__ = ["log" , "communicator" , "number" , "hw_number" , "autofire_config" , "baseline_driver_config" ,
34
- "current_driver_config" , "mode_param_mapping" , "platform_settings" ]
34
+ "config" , " current_driver_config" , "mode_param_mapping" , "platform_settings" ]
35
35
36
36
def __init__ (self , communicator : FastSerialCommunicator , hw_number : int ) -> None :
37
37
"""Initialize the driver object.
@@ -42,6 +42,7 @@ def __init__(self, communicator: FastSerialCommunicator, hw_number: int) -> None
42
42
self .communicator = communicator
43
43
self .number = hw_number # must be int to work with the rest of MPF
44
44
self .hw_number = Util .int_to_hex_string (hw_number ) # hex version the FAST hw actually uses
45
+ self .config = None
45
46
self .autofire_config = None
46
47
self .platform_settings = dict ()
47
48
@@ -56,6 +57,7 @@ def __init__(self, communicator: FastSerialCommunicator, hw_number: int) -> None
56
57
'12' : ['pwm1_ms' , 'pwm1_power' , 'pwm2_ms' , 'pwm2_power' , 'kick_ms' ],
57
58
'18' : ['pwm1_ms' , 'pwm1_power' , 'pwm2_power' , 'recycle_ms' , None ],
58
59
'20' : ['off_switch' , 'pwm1_ms' , 'pwm1_power' , 'pwm2_power' , 'rest_ms' ],
60
+ '25' : ['relay_on_report_ms' , 'relay_off_report_ms' ],
59
61
'30' : ['delay_ms_x10' , 'pwm1_ms' , 'pwm2_ms' , 'pwm2_power' , 'recycle_ms' ],
60
62
'70' : ['pwm1_ms' , 'pwm1_power' , 'pwm2_ms_x100' , 'pwm2_power' , 'recycle_ms' ],
61
63
'75' : ['off_switch' , 'pwm1_ms' , 'pwm2_ms_x100' , 'pwm2_power' , 'recycle_ms' ],
@@ -73,7 +75,7 @@ def set_initial_config(self, mpf_config: DriverConfig, platform_settings):
73
75
74
76
This will not be called for drivers that are not in the MPF config.
75
77
"""
76
-
78
+ self . config = mpf_config
77
79
self .platform_settings = platform_settings
78
80
self .current_driver_config = self .convert_mpf_config_to_fast (mpf_config , platform_settings )
79
81
self .baseline_driver_config = copy (self .current_driver_config )
@@ -144,8 +146,8 @@ def clear_bit(self, hex_string, bit):
144
146
return Util .int_to_hex_string (num )
145
147
146
148
def send_config_to_driver (self , one_shot : bool = False , wait_to_confirm : bool = False ):
147
- self .log .debug ("Sending config to driver %s. one_shot: %s. wait_to_confirm: %s" ,
148
- self .number , one_shot , wait_to_confirm )
149
+ self .log .debug ("Sending config to driver %s (0x%s) . one_shot: %s. wait_to_confirm: %s" ,
150
+ self .number , self . hw_number , one_shot , wait_to_confirm )
149
151
150
152
if one_shot :
151
153
trigger = self .set_bit (self .current_driver_config .trigger , 3 )
@@ -157,7 +159,7 @@ def send_config_to_driver(self, one_shot: bool = False, wait_to_confirm: bool =
157
159
f'{ self .current_driver_config .param2 } ,{ self .current_driver_config .param3 } ,{ self .current_driver_config .param4 } ,'
158
160
f'{ self .current_driver_config .param5 } ' )
159
161
if wait_to_confirm :
160
- self .communicator .send_with_confirmation (msg , f'{ self .communicator .DRIVER_CMD } ' )
162
+ self .communicator .send_with_confirmation (msg , f'{ self .communicator .DRIVER_CMD } : ' )
161
163
else :
162
164
self .communicator .send_and_forget (msg )
163
165
@@ -354,17 +356,38 @@ def clear_autofire(self):
354
356
self .autofire_config = None
355
357
self .communicator .send_and_forget (f'{ self .communicator .TRIGGER_CMD } :{ self .hw_number } ,02' )
356
358
359
+ def set_relay (self , relay_switch , debounce_closed_ms , debounce_open_ms ):
360
+ """Set an AC Relay rule with virtual switch."""
361
+
362
+ self .log .debug ("Setting A/C Relay for driver %s (0x%s) and switch %s (0x%s)" ,
363
+ self .number , self .hw_number , relay_switch .number , relay_switch .hw_number )
364
+ self .current_driver_config = FastDriverConfig (number = self .hw_number , trigger = '81' ,
365
+ switch_id = relay_switch .hw_number ,
366
+ mode = '25' ,
367
+ param1 = Util .int_to_hex_string (debounce_closed_ms ),
368
+ param2 = Util .int_to_hex_string (debounce_open_ms ),
369
+ param3 = '00' ,
370
+ param4 = '00' ,
371
+ param5 = '00' )
372
+ self .send_config_to_driver (wait_to_confirm = True )
373
+
357
374
def enable (self , pulse_settings : PulseSettings , hold_settings : HoldSettings ):
358
375
"""Enable (turn on) this driver."""
359
376
360
- self .log .debug ("Enabling (turning on) driver %s with pulse_settings: %s and hold_settings: %s." ,
361
- self .number , pulse_settings , hold_settings )
377
+ self .log .debug ("Enabling (turning on) driver %s (0x%s) mode %s with pulse_settings: %s and hold_settings: %s." ,
378
+ self .number , self . hw_number , self . current_driver_config . mode , pulse_settings , hold_settings )
362
379
363
380
self ._check_and_clear_delay ()
364
381
365
382
reconfigured = False
366
383
mode = self .current_driver_config .mode
367
384
385
+ # AC Relays have special behavior
386
+ if mode == '25' :
387
+ self .log .debug (" - A/C Relay activating!" )
388
+ self .communicator .send_and_forget (f'{ self .communicator .TRIGGER_CMD } :{ self .hw_number } ,03' )
389
+ return
390
+
368
391
pwm1_ms = Util .int_to_hex_string (pulse_settings .duration )
369
392
pwm1_power = Util .float_to_pwm8_hex_string (pulse_settings .power )
370
393
pwm2_power = Util .float_to_pwm8_hex_string (hold_settings .power )
0 commit comments