void InitializeDisplay(DisplayBase disp)
        {
            if (disp != null)
            {
                // Link power, warming, cooling to display
                disp.PowerIsOnFeedback.OutputChange += (o, a) =>
                {
                    if (disp.PowerIsOnFeedback.BoolValue != OnFeedback.BoolValue)
                    {
                        if (!disp.PowerIsOnFeedback.BoolValue)
                        {
                            disp.CurrentSourceInfo = null;
                        }
                        OnFeedback.FireUpdate();
                    }
                    if (disp.PowerIsOnFeedback.BoolValue)
                    {
                        SetDefaultLevels();
                    }
                };

                disp.IsWarmingUpFeedback.OutputChange += (o, a) =>
                {
                    IsWarmingUpFeedback.FireUpdate();
                    if (!IsWarmingUpFeedback.BoolValue)
                    {
                        (CurrentVolumeControls as IBasicVolumeWithFeedback).SetVolume(DefaultVolume);
                    }
                };
                disp.IsCoolingDownFeedback.OutputChange += (o, a) =>
                {
                    IsCoolingDownFeedback.FireUpdate();
                };
            }
        }
Ejemplo n.º 2
0
        void Initialize()
        {
            if (DefaultAudioDevice is IBasicVolumeControls)
            {
                DefaultVolumeControls = DefaultAudioDevice as IBasicVolumeControls;
            }
            else if (DefaultAudioDevice is IHasVolumeDevice)
            {
                DefaultVolumeControls = (DefaultAudioDevice as IHasVolumeDevice).VolumeDevice;
            }
            CurrentVolumeControls = DefaultVolumeControls;

            var disp = DefaultDisplay as DisplayBase;

            if (disp != null)
            {
                // Link power, warming, cooling to display
                disp.PowerIsOnFeedback.OutputChange += (o, a) =>
                {
                    if (disp.PowerIsOnFeedback.BoolValue != OnFeedback.BoolValue)
                    {
                        if (!disp.PowerIsOnFeedback.BoolValue)
                        {
                            CurrentSourceInfo = null;
                        }
                        OnFeedback.FireUpdate();
                    }
                };

                disp.IsWarmingUpFeedback.OutputChange += (o, a) =>
                {
                    IsWarmingUpFeedback.FireUpdate();
                    if (!IsWarmingUpFeedback.BoolValue)
                    {
                        (DefaultDisplay as IBasicVolumeWithFeedback).SetVolume(DefaultVolume);
                    }
                };
                disp.IsCoolingDownFeedback.OutputChange += (o, a) =>
                {
                    IsCoolingDownFeedback.FireUpdate();
                };
            }

            SourceListKey             = "default";
            EnablePowerOnToLastSource = true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a source from config list SourceListKey and dynamically build and executes the
        /// route or commands
        /// </summary>
        /// <param name="name"></param>
        public void RunRouteAction(string routeKey, Action successCallback)
        {
            // Run this on a separate thread
            new CTimer(o =>
            {
                Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Run route action '{0}'", routeKey);
                var dict = ConfigReader.ConfigObject.GetSourceListForKey(SourceListKey);
                if (dict == null)
                {
                    Debug.Console(1, this, "WARNING: Config source list '{0}' not found", SourceListKey);
                    return;
                }

                // Try to get the list item by it's string key
                if (!dict.ContainsKey(routeKey))
                {
                    Debug.Console(1, this, "WARNING: No item '{0}' found on config list '{1}'",
                                  routeKey, SourceListKey);
                    return;
                }

                var item = dict[routeKey];
                //Debug.Console(2, this, "Action {0} has {1} steps",
                //    item.SourceKey, item.RouteList.Count);

                // End usage timer on last source
                if (!string.IsNullOrEmpty(LastSourceKey))
                {
                    var lastSource = dict[LastSourceKey].SourceDevice;

                    try
                    {
                        if (lastSource != null && lastSource is IUsageTracking)
                        {
                            (lastSource as IUsageTracking).UsageTracker.EndDeviceUsage();
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.Console(1, this, "*#* EXCEPTION in end usage tracking (257):\r{0}", e);
                    }
                }

                // Let's run it
                if (routeKey.ToLower() != "roomoff")
                {
                    LastSourceKey = routeKey;
                }
                else
                {
                    CurrentSourceInfoKey = null;
                }

                foreach (var route in item.RouteList)
                {
                    // if there is a $defaultAll on route, run two separate
                    if (route.DestinationKey.Equals("$defaultAll", StringComparison.OrdinalIgnoreCase))
                    {
                        // Going to assume a single-path route for now
                        var tempVideo = new SourceRouteListItem
                        {
                            DestinationKey = "$defaultDisplay",
                            SourceKey      = route.SourceKey,
                            Type           = eRoutingSignalType.Video
                        };
                        DoRoute(tempVideo);

                        //var tempAudio = new SourceRouteListItem
                        //{
                        //    DestinationKey = "$defaultAudio",
                        //    SourceKey = route.SourceKey,
                        //    Type = eRoutingSignalType.Audio
                        //};
                        //DoRoute(tempAudio);
                        //continue; -- not sure why this was here
                    }
                    else
                    {
                        DoRoute(route);
                    }
                }

                // Start usage timer on routed source
                if (item.SourceDevice is IUsageTracking)
                {
                    (item.SourceDevice as IUsageTracking).UsageTracker.StartDeviceUsage();
                }



                // Set volume control, using default if non provided
                IBasicVolumeControls volDev = null;
                // Handle special cases for volume control
                if (string.IsNullOrEmpty(item.VolumeControlKey) ||
                    item.VolumeControlKey.Equals("$defaultAudio", StringComparison.OrdinalIgnoreCase))
                {
                    volDev = DefaultVolumeControls;
                }
                else if (item.VolumeControlKey.Equals("$defaultDisplay", StringComparison.OrdinalIgnoreCase))
                {
                    volDev = DefaultDisplay as IBasicVolumeControls;
                }
                // Or a specific device, probably rarely used.
                else
                {
                    var dev = DeviceManager.GetDeviceForKey(item.VolumeControlKey);
                    if (dev is IBasicVolumeControls)
                    {
                        volDev = dev as IBasicVolumeControls;
                    }
                    else if (dev is IHasVolumeDevice)
                    {
                        volDev = (dev as IHasVolumeDevice).VolumeDevice;
                    }
                }

                if (volDev != CurrentVolumeControls)
                {
                    // zero the volume on the device we are leaving.
                    // Set the volume to default on device we are entering
                    if (ZeroVolumeWhenSwtichingVolumeDevices && CurrentVolumeControls is IBasicVolumeWithFeedback)
                    {
                        var vd = CurrentVolumeControls as IBasicVolumeWithFeedback;
                        SavedVolumeLevels[vd] = (uint)vd.VolumeLevelFeedback.IntValue;
                        vd.SetVolume(0);
                    }
                    CurrentVolumeControls = volDev;
                    if (ZeroVolumeWhenSwtichingVolumeDevices && CurrentVolumeControls is IBasicVolumeWithFeedback)
                    {
                        var vd     = CurrentVolumeControls as IBasicVolumeWithFeedback;
                        ushort vol = (SavedVolumeLevels.ContainsKey(vd) ? (ushort)SavedVolumeLevels[vd] : DefaultVolume);
                        vd.SetVolume(vol);
                    }
                }



                // store the name and UI info for routes
                if (item.SourceKey == "$off")
                {
                    CurrentSourceInfoKey = routeKey;
                    CurrentSourceInfo    = null;
                }
                else if (item.SourceKey != null)
                {
                    CurrentSourceInfoKey = routeKey;
                    CurrentSourceInfo    = item;
                }
                // And finally, set the "control".  This will trigger event
                //CurrentControlDevice = DeviceManager.GetDeviceForKey(item.SourceKey) as Device;

                OnFeedback.FireUpdate();

                // report back when done
                if (successCallback != null)
                {
                    successCallback();
                }
            }, 0);                     // end of CTimer
        }
        /// <summary>
        /// Gets a source from config list SourceListKey and dynamically build and executes the
        /// route or commands
        /// </summary>
        /// <param name="name"></param>
        public void RunRouteAction(string routeKey, Action successCallback)
        {
            // Run this on a separate thread
            new CTimer(o =>
            {
                // try to prevent multiple simultaneous selections
                SourceSelectLock.TryEnter();

                try
                {
                    Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Run route action '{0}'", routeKey);
                    var dict = ConfigReader.ConfigObject.GetSourceListForKey(SourceListKey);
                    if (dict == null)
                    {
                        Debug.Console(1, this, "WARNING: Config source list '{0}' not found", SourceListKey);
                        return;
                    }

                    // Try to get the list item by it's string key
                    if (!dict.ContainsKey(routeKey))
                    {
                        Debug.Console(1, this, "WARNING: No item '{0}' found on config list '{1}'",
                                      routeKey, SourceListKey);
                        return;
                    }

                    // End usage timer on last source
                    if (!string.IsNullOrEmpty(LastSourceKey))
                    {
                        var usageLastSource = dict[LastSourceKey].SourceDevice as IUsageTracking;
                        if (usageLastSource != null && usageLastSource.UsageTracker != null)
                        {
                            try
                            {
                                // There MAY have been failures in here.  Protect
                                usageLastSource.UsageTracker.EndDeviceUsage();
                            }
                            catch (Exception e)
                            {
                                Debug.Console(1, this, "*#* EXCEPTION in end usage tracking:\r{0}", e);
                            }
                        }
                    }

                    // Let's run it
                    var item = dict[routeKey];
                    if (routeKey.ToLower() != "roomoff")
                    {
                        LastSourceKey = routeKey;
                    }
                    else
                    {
                        CurrentSourceInfoKey = null;
                    }

                    // hand off the individual routes to this helper
                    foreach (var route in item.RouteList)
                    {
                        DoRouteItem(route);
                    }

                    // Start usage timer on routed source
                    var usageNewSource = item.SourceDevice as IUsageTracking;
                    if (usageNewSource != null && usageNewSource.UsageTracker != null) // Have to make sure there is a usage tracker!
                    {
                        (item.SourceDevice as IUsageTracking).UsageTracker.StartDeviceUsage();
                    }

                    // See if this can be moved into common, base-class method -------------


                    // Set volume control, using default if non provided
                    IBasicVolumeControls volDev = null;
                    // Handle special cases for volume control
                    if (string.IsNullOrEmpty(item.VolumeControlKey) ||
                        item.VolumeControlKey.Equals("$defaultAudio", StringComparison.OrdinalIgnoreCase))
                    {
                        volDev = DefaultVolumeControls;
                    }
                    else if (item.VolumeControlKey.Equals("$defaultDisplay", StringComparison.OrdinalIgnoreCase))
                    {
                        volDev = DefaultDisplay as IBasicVolumeControls;
                    }
                    // Or a specific device, probably rarely used.
                    else
                    {
                        var dev = DeviceManager.GetDeviceForKey(item.VolumeControlKey);
                        if (dev is IBasicVolumeControls)
                        {
                            volDev = dev as IBasicVolumeControls;
                        }
                        else if (dev is IHasVolumeDevice)
                        {
                            volDev = (dev as IHasVolumeDevice).VolumeDevice;
                        }
                    }

                    if (volDev != CurrentVolumeControls)
                    {
                        // zero the volume on the device we are leaving.
                        // Set the volume to default on device we are entering
                        if (ZeroVolumeWhenSwtichingVolumeDevices && CurrentVolumeControls is IBasicVolumeWithFeedback)
                        {
                            var vd = CurrentVolumeControls as IBasicVolumeWithFeedback;
                            SavedVolumeLevels[vd] = (uint)vd.VolumeLevelFeedback.IntValue;
                            vd.SetVolume(0);
                        }

                        CurrentVolumeControls = volDev;
                        if (ZeroVolumeWhenSwtichingVolumeDevices && CurrentVolumeControls is IBasicVolumeWithFeedback)
                        {
                            var vd     = CurrentVolumeControls as IBasicVolumeWithFeedback;
                            ushort vol = (SavedVolumeLevels.ContainsKey(vd) ? (ushort)SavedVolumeLevels[vd] : DefaultVolume);
                            vd.SetVolume(vol);
                        }
                    }
                    // -----------------------------------------------------------------------



                    // store the name and UI info for routes
                    if (item.SourceKey == "$off")
                    {
                        CurrentSourceInfoKey = routeKey;
                        CurrentSourceInfo    = null;
                    }
                    else if (item.SourceKey != null)
                    {
                        CurrentSourceInfoKey = routeKey;
                        CurrentSourceInfo    = item;
                    }

                    OnFeedback.FireUpdate();

                    // report back when done
                    if (successCallback != null)
                    {
                        successCallback();
                    }
                }
                catch (Exception e)
                {
                    Debug.Console(1, this, "ERROR in routing: {0}", e);
                }

                SourceSelectLock.Leave();
            }, 0); // end of CTimer
        }
        void Initialize()
        {
            try
            {
                if (DefaultAudioDevice is IBasicVolumeControls)
                {
                    DefaultVolumeControls = DefaultAudioDevice as IBasicVolumeControls;
                }
                else if (DefaultAudioDevice is IHasVolumeDevice)
                {
                    DefaultVolumeControls = (DefaultAudioDevice as IHasVolumeDevice).VolumeDevice;
                }
                CurrentVolumeControls = DefaultVolumeControls;


                // Combines call feedback from both codecs if available
                InCallFeedback = new BoolFeedback(() =>
                {
                    bool inAudioCall = false;
                    bool inVideoCall = false;

                    if (AudioCodec != null)
                    {
                        inAudioCall = AudioCodec.IsInCall;
                    }

                    if (VideoCodec != null)
                    {
                        inVideoCall = VideoCodec.IsInCall;
                    }

                    if (inAudioCall || inVideoCall)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                });

                var disp = DefaultDisplay as DisplayBase;
                if (disp != null)
                {
                    // Link power, warming, cooling to display
                    disp.PowerIsOnFeedback.OutputChange += (o, a) =>
                    {
                        if (disp.PowerIsOnFeedback.BoolValue != OnFeedback.BoolValue)
                        {
                            if (!disp.PowerIsOnFeedback.BoolValue)
                            {
                                CurrentSourceInfo = null;
                            }
                            OnFeedback.FireUpdate();
                        }
                        if (disp.PowerIsOnFeedback.BoolValue)
                        {
                            SetDefaultLevels();
                        }
                    };

                    disp.IsWarmingUpFeedback.OutputChange += (o, a) =>
                    {
                        IsWarmingUpFeedback.FireUpdate();
                        if (!IsWarmingUpFeedback.BoolValue)
                        {
                            (CurrentVolumeControls as IBasicVolumeWithFeedback).SetVolume(DefaultVolume);
                        }
                    };
                    disp.IsCoolingDownFeedback.OutputChange += (o, a) =>
                    {
                        IsCoolingDownFeedback.FireUpdate();
                    };
                }



                // Get Microphone Privacy object, if any  MUST HAPPEN AFTER setting InCallFeedback
                this.MicrophonePrivacy = EssentialsRoomConfigHelper.GetMicrophonePrivacy(PropertiesConfig, this);

                Debug.Console(2, this, "Microphone Privacy Config evaluated.");

                // Get emergency object, if any
                this.Emergency = EssentialsRoomConfigHelper.GetEmergency(PropertiesConfig, this);

                Debug.Console(2, this, "Emergency Config evaluated.");


                VideoCodec.CallStatusChange += (o, a) => this.InCallFeedback.FireUpdate();

                if (AudioCodec != null)
                {
                    AudioCodec.CallStatusChange += (o, a) => this.InCallFeedback.FireUpdate();
                }

                IsSharingFeedback = new BoolFeedback(() => VideoCodec.SharingContentIsOnFeedback.BoolValue);
                VideoCodec.SharingContentIsOnFeedback.OutputChange += (o, a) => this.IsSharingFeedback.FireUpdate();

                // link privacy to VC (for now?)
                PrivacyModeIsOnFeedback = new BoolFeedback(() => VideoCodec.PrivacyModeIsOnFeedback.BoolValue);
                VideoCodec.PrivacyModeIsOnFeedback.OutputChange += (o, a) => this.PrivacyModeIsOnFeedback.FireUpdate();

                CallTypeFeedback = new IntFeedback(() => 0);

                SourceListKey             = "default";
                EnablePowerOnToLastSource = true;
            }
            catch (Exception e)
            {
                Debug.Console(0, this, "Error Initializing Room: {0}", e);
            }
        }