// Called when an LEDs value changes. The argument passed is the first slot used by the LED, // regardless which slot in the LED changed. public void NotifiyLedChange(int baseSlot, LedChangeValue changedValue) { if (!m_ledMap.ContainsKey(baseSlot)) { throw new ArgumentException("Invalid Slot Number!"); } // Figure out how we want to update, if we need to update everything or just a slot if(m_updateType == ControlerUpdateType.AllSlots) { if(m_animationEnabled) { // If the animation thread is running it will take care of pushing updates. m_isDirty = true; return; } else { // We need to tell the listener of the new state m_controllerExtener.NotifiySlotsStateChanged(GetAllSlotValues()); } } else { // The controller is single slot update based. We need to send the change to the listener // Get the LED for the changed slot Led changedLed; if (m_ledMap[baseSlot].TryGetTarget(out changedLed)) { LedType type; double red, green, blue, intensity; changedLed.GetBase().GetLedState(out type, out red, out green, out blue, out intensity); if (type == LedType.SingleColor) { m_controllerExtener.NotifiySlotStateChanged(baseSlot, intensity * m_masterIntensity); } else { // Send the correct update for the color switch(changedValue) { case LedChangeValue.Red: m_controllerExtener.NotifiySlotStateChanged(baseSlot, red * intensity * m_masterIntensity); break; case LedChangeValue.Green: m_controllerExtener.NotifiySlotStateChanged(baseSlot + 1, green * intensity * m_masterIntensity); break; case LedChangeValue.Blue: m_controllerExtener.NotifiySlotStateChanged(baseSlot + 2, blue * intensity * m_masterIntensity); break; case LedChangeValue.All: m_controllerExtener.NotifiySlotStateChanged(baseSlot, red * intensity * m_masterIntensity); m_controllerExtener.NotifiySlotStateChanged(baseSlot + 1, green * intensity * m_masterIntensity); m_controllerExtener.NotifiySlotStateChanged(baseSlot + 2, blue * intensity * m_masterIntensity); break; } } } else { throw new Exception("The LED is gone!"); } } }
// Tells the controller that a value has changed. private void FireLedChangeNotificaiton(LedChangeValue valueChanged) { // Try to get the controller if (m_controller != null && m_firstSlot != -1) { m_controller.NotifiyLedChange(m_firstSlot, valueChanged); } }