Ejemplo n.º 1
0
        public virtual IEnumerator <ITask> ConfigureBatteryHandler(ConfigureBattery configure)
        {
            if (_state.BatteryPollingSeconds != configure.Body.PollingFrequencySeconds)
            {
                _state.BatteryPollingSeconds = configure.Body.PollingFrequencySeconds;
                Fault faultResponse = null;
                yield return(Arbiter.Choice(
                                 _legoBrickPort.AdjustPollingFrequency(ServiceInfo.Service, _state.BatteryPollingSeconds * 1000),
                                 delegate(brick.AdjustPollingFrequencyResponse response)
                {
                    _state.BatteryPollingSeconds = response.PollingFrequencyMs;
                },
                                 delegate(Fault fault)
                {
                    faultResponse = fault;
                }));

                if (faultResponse != null)
                {
                    configure.ResponsePort.Post(faultResponse);
                    yield break;
                }
            }

            _state.CriticalBatteryVoltage = configure.Body.CriticalBatteryVoltage;
            _state.MinVoltage             = configure.Body.MinVoltage;
            _state.MaxVoltage             = configure.Body.MaxVoltage;
            InitializeState(_state.Connected);
            configure.ResponsePort.Post(DefaultUpdateResponseType.Instance);
            yield break;
        }
        public virtual IEnumerator<ITask> ConfigureBatteryHandler(ConfigureBattery configure)
        {
            if (_state.BatteryPollingSeconds != configure.Body.PollingFrequencySeconds)
            {
                _state.BatteryPollingSeconds = configure.Body.PollingFrequencySeconds;
                Fault faultResponse = null;
                yield return Arbiter.Choice(
                    _legoBrickPort.AdjustPollingFrequency(ServiceInfo.Service, _state.BatteryPollingSeconds * 1000),
                    delegate(brick.AdjustPollingFrequencyResponse response)
                    {
                        _state.BatteryPollingSeconds = response.PollingFrequencyMs;
                    },
                    delegate(Fault fault)
                    {
                        faultResponse = fault;
                    });

                if (faultResponse != null)
                {
                    configure.ResponsePort.Post(faultResponse);
                    yield break;
                }
            }

            _state.CriticalBatteryVoltage = configure.Body.CriticalBatteryVoltage;
            _state.MinVoltage = configure.Body.MinVoltage;
            _state.MaxVoltage = configure.Body.MaxVoltage;
            InitializeState(_state.Connected);
            configure.ResponsePort.Post(DefaultUpdateResponseType.Instance);
            yield break;
        }