private static void StartTransition(TransitionProgram transition, bool repeat, int frameDuration) { if (transition != _curTransition || !repeat) { _curTransition = transition; if (transition == TransitionProgram.WakeUp) { _curTransitionFrames = wakeUpFrames; } else if (transition == TransitionProgram.ReverseWakeUp) { _curTransitionFrames = reverseWakeUpFrames; } else if (transition == TransitionProgram.Chase) { _curTransitionFrames = chaseFrames; } else if (transition == TransitionProgram.Curtain) { _curTransitionFrames = curtainFrames; } else if (transition == TransitionProgram.None) { _curTransitionFrames = noneFrames; } transitionCurrentFrame = 0; _repeatTransition = repeat; } _transitionFrameDuration = frameDuration; }
public static void Update(int tickCount) { // update timers var slowChangeTick = false; var fastChangeTick = false; var veryFastChangeTick = false; if (_curTransition != TransitionProgram.None) { if (tickCount > transitionTick) { if (transitionCurrentFrame < _curTransitionFrames.Length - 1) { transitionCurrentFrame++; } else if (_repeatTransition) { transitionCurrentFrame = 0; } else { _curTransition = TransitionProgram.None; if (_curFETransition == FETransition.RomChange) { _curFETransition = FETransition.None; } _curTransitionFrames = noneFrames; transitionCurrentFrame = 0; } transitionTick = tickCount + _transitionFrameDuration; // reset blink slowTick = tickCount + SLOW_TICK_DURATION; fastTick = tickCount + FAST_TICK_DURATION; veryFastTick = tickCount + VERYFAST_TICK_DURATION; } } else { if (tickCount > slowTick) { slowTick = tickCount + SLOW_TICK_DURATION; slowChangeTick = true; } if (tickCount > fastTick) { fastTick = tickCount + FAST_TICK_DURATION; fastChangeTick = true; } if (tickCount > veryFastTick) { veryFastTick = tickCount + VERYFAST_TICK_DURATION; veryFastChangeTick = true; } } _smartInput.bitvector1 = 0; if (_debugMode) { _background.SetAlpha(.6f); } // loop LEDs for (var ledNo = 0; ledNo < _ledImages.Length; ledNo++) { if ((_ledBlinkStyle[ledNo] == BlinkStyle.Slow && slowChangeTick) || (_ledBlinkStyle[ledNo] == BlinkStyle.Fast && fastChangeTick) || (_ledBlinkStyle[ledNo] == BlinkStyle.VeryFast && veryFastChangeTick)) { _ledBlinkStatus = _ledBlinkStatus ^ 1u << ledNo; } // set LED status var ledStatus = false; // apply blink when no transition running if (_curTransition == TransitionProgram.None) { ledStatus = (_ledStatus & _ledBlinkStatus & 1u << ledNo) > 0; } else { ledStatus = (_ledStatus & _curTransitionFrames[transitionCurrentFrame] & 1u << ledNo) > 0; } // update debug dashboard if (_debugMode) { _ledImages[ledNo].SetAlpha(ledStatus ? .6f : .2f); } // update LED status if (_wiringMode == SmartAsdMode.Hybrid) { // smartASD wiring type A (hybrid) switch (ledNo) { // PLAYER 1 case 0: _smartInput.d6 = ledStatus ? 1u : 0u; break; // start case 2: _smartInput.d7 = ledStatus ? 1u : 0u; break; // joy case 3: _smartInput.d8 = ledStatus ? 1u : 0u; break; // button 1 case 4: _smartInput.d9 = ledStatus ? 1u : 0u; break; // button 2 case 5: _smartInput.d10 = ledStatus ? 1u : 0u; break; // button 3 case 6: _smartInput.d11 = ledStatus ? 1u : 0u; break; // button 4 // PLAYER 2 case 14: _smartInput.d18 = ledStatus ? 1u : 0u; break; // start case 16: _smartInput.d19 = ledStatus ? 1u : 0u; break; // joy case 17: _smartInput.d20 = ledStatus ? 1u : 0u; break; // button 1 case 18: _smartInput.d21 = ledStatus ? 1u : 0u; break; // button 2 case 19: _smartInput.d22 = ledStatus ? 1u : 0u; break; // button 3 case 20: _smartInput.d23 = ledStatus ? 1u : 0u; break; // button 4 } } else if (_wiringMode == SmartAsdMode.Dedicated) { // smartASD wiring type B (dedicated) if (ledNo < 14) { _smartInput.bitvector1 |= ledStatus ? 1u << ledNo : 0u; // PLAYER 1 } else if (ledNo < 28) { _smartInput.bitvector1 |= ledStatus ? 1u << ledNo + 2 : 0u; // PLAYER 2 } else if (ledNo < 30) { _smartInput.bitvector1 |= ledStatus ? 1u << ledNo - 14 : 0u; // EXTRA 1-2 } else { _smartInput.bitvector1 |= ledStatus ? 1u << ledNo : 0u; // EXTRA 3-4 } } } // attach SmartASD if (_smartAsd == IntPtr.Zero && tickCount > attachTick) { attachTick = tickCount + ATTACH_TICK_RETRY; AttachSmartASD(); } // send LED changes if (_smartInput.bitvector1 != _ledOldStatus && _smartAsd != IntPtr.Zero) { _ledOldStatus = _smartInput.bitvector1; if (SmartSetAll(_smartAsd, _smartInput.bitvector1, 0xffffffff) != 0) { _smartAsd = IntPtr.Zero; } } }