2828
2929namespace VisualPinball . Engine . PinMAME
3030{
31- [ AddComponentMenu ( "Visual Pinball/Mechs/PinMAME Mech Handler" ) ]
32- public class PinMameMechComponent : MonoBehaviour , IMechHandler , ISwitchDeviceComponent , ICoilDeviceComponent , ISerializationCallbackReceiver
31+ [ AddComponentMenu ( "Pinball/Mechs/PinMAME Mech Handler" ) ]
32+ public class PinMameMechComponent : MonoBehaviour , IMechHandler , ISwitchDeviceComponent , ICoilDeviceComponent ,
33+ IPinballEventEmitter , ISerializationCallbackReceiver
3334 {
3435 #region Data
3536
@@ -78,6 +79,11 @@ public class PinMameMechComponent : MonoBehaviour, IMechHandler, ISwitchDeviceCo
7879 [ SerializeField ] private string _solenoid2 ;
7980
8081 public event EventHandler < MechEventArgs > OnMechUpdate ;
82+ public event EventHandler < PinballEventArgs > OnPinballEvent ;
83+ public PinballEvent [ ] Events => new [ ] {
84+ new PinballEvent ( EventNameSpeed , PinballEventUnit . DegreesPerSecond ) ,
85+ new PinballEvent ( EventNamePosition , PinballEventUnit . Degrees ) ,
86+ } ;
8187
8288 public PinMameMechConfig Config ( List < SwitchMapping > switchMappings , List < CoilMapping > coilMappings , Dictionary < string , int > switchIdToPinMameIdMappings , Dictionary < string , int > coilIdToPinMameIdMappings )
8389 {
@@ -155,6 +161,9 @@ public PinMameMechConfig Config(List<SwitchMapping> switchMappings, List<CoilMap
155161
156162 private static readonly Logger Logger = LogManager . GetCurrentClassLogger ( ) ;
157163
164+ private const string EventNameSpeed = "Mech Speed" ;
165+ private const string EventNamePosition = "Mech Position" ;
166+
158167 #endregion
159168
160169 #region Wiring
@@ -173,15 +182,16 @@ public PinMameMechConfig Config(List<SwitchMapping> switchMappings, List<CoilMap
173182
174183 public IEnumerable < GamelogicEngineCoil > AvailableCoils {
175184 get {
176- switch ( Type )
177- {
185+ switch ( Type ) {
178186 case PinMameMechType . OneSolenoid :
179187 return new [ ] { new GamelogicEngineCoil ( _solenoid1 ) { Description = "Motor Power" } } ;
188+
180189 case PinMameMechType . OneDirectionalSolenoid :
181190 return new [ ] {
182191 new GamelogicEngineCoil ( _solenoid1 ) { Description = "Motor Power" } ,
183192 new GamelogicEngineCoil ( _solenoid2 ) { Description = "Motor Direction" } ,
184193 } ;
194+
185195 case PinMameMechType . TwoDirectionalSolenoids :
186196 return new [ ] {
187197 new GamelogicEngineCoil ( _solenoid1 ) { Description = "Motor Clockwise" } ,
@@ -193,16 +203,20 @@ public IEnumerable<GamelogicEngineCoil> AvailableCoils {
193203 new GamelogicEngineCoil ( _solenoid1 ) { Description = "Stepper 1" } ,
194204 new GamelogicEngineCoil ( _solenoid2 ) { Description = "Stepper 2" } ,
195205 } ;
206+
196207 case PinMameMechType . FourStepperSolenoids :
197208 return new [ ] {
198209 new GamelogicEngineCoil ( _solenoid1 ) { Description = "First Stepper" } ,
199210 } ;
211+
200212 default :
201213 throw new ArgumentOutOfRangeException ( ) ;
202214 }
203215 }
204216 }
205217
218+ IApiCoil ICoilDeviceComponent . CoilDevice ( string deviceId ) => null ; // fixme
219+
206220 #endregion
207221
208222 #region Runtime
@@ -225,6 +239,8 @@ private void Start()
225239 public void UpdateMech ( PinMameMechInfo data )
226240 {
227241 OnMechUpdate ? . Invoke ( this , new MechEventArgs ( data . Speed , data . Pos ) ) ;
242+ OnPinballEvent ? . Invoke ( this , new PinballEventArgs ( EventNameSpeed , data . Speed , PinballEventUnit . MetersPerSecond ) ) ;
243+ OnPinballEvent ? . Invoke ( this , new PinballEventArgs ( EventNamePosition , data . Pos , PinballEventUnit . Degrees ) ) ;
228244 }
229245
230246 #endregion
0 commit comments