private IObservable <HarpMessage> FromSlider(Slider slider, int address)
 {
     return(Observable.FromEventPattern(
                handler => slider.ValueChanged += handler,
                handler => slider.ValueChanged -= handler)
            .Select(evt => HarpCommand.WriteUInt16(address, (ushort)slider.Value)));
 }
Beispiel #2
0
        public void FromUInt16_Value_PayloadHasValue()
        {
            ushort value   = 1024;
            var    message = HarpCommand.WriteUInt16(DefaultAddress, value);

            AssertIsValid(message);
            Assert.AreEqual(value, message.GetPayloadUInt16());
        }
        IEnumerable <HarpMessage> LedCalibration()
        {
            const ushort DefaultTriggerPeriod = 25000;
            const ushort DefaultDwellTime     = 24500;

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerPeriod, (ushort)DefaultTriggerPeriod));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerTimeUpdateOutputs, (ushort)DefaultDwellTime));
        }
Beispiel #4
0
        public void FromUInt16_Array_PayloadHasValue()
        {
            var value   = new ushort[] { 512, 2048 };
            var message = HarpCommand.WriteUInt16(DefaultAddress, value);

            AssertIsValid(message);
            var payload = message.GetPayloadArray <ushort>();

            AssertArrayEqual(value, payload);
            Assert.AreEqual(value[1], message.GetPayloadUInt16(1));
        }
        IEnumerable <HarpMessage> LaserCalibration()
        {
            const ushort CalibrationPower = (ushort)(ushort.MaxValue * 0.1);

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL415, 0));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL470, 0));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL560, 0));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacLaser, CalibrationPower));
        }
        private IEnumerable <HarpMessage> SetTriggerMode(FrameFlags[] pattern, int triggerPeriod, int dwellTime)
        {
            var triggerState = TriggerHelper.FromFrameFlags(pattern);

            yield return(HarpCommand.WriteByte(ConfigurationRegisters.TriggerState, triggerState));

            yield return(HarpCommand.WriteByte(ConfigurationRegisters.TriggerStateLength, (byte)pattern.Length));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerPeriod, (ushort)triggerPeriod));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerTimeUpdateOutputs, (ushort)dwellTime));
        }
        IEnumerable <HarpMessage> WriteRegisters(bool savePersistent)
        {
            var triggerState = configuration.TriggerState;

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.Config, (ushort)configuration.Config));

            yield return(HarpCommand.WriteByte(ConfigurationRegisters.ScreenBrightness, (byte)configuration.ScreenBrightness));

            yield return(HarpCommand.WriteByte(ConfigurationRegisters.TriggerState, TriggerHelper.FromFrameFlags(triggerState)));

            yield return(HarpCommand.WriteByte(ConfigurationRegisters.TriggerStateLength, (byte)triggerState.Length));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerPeriod, (ushort)configuration.TriggerPeriod));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerTimeUpdateOutputs, (ushort)configuration.DwellTime));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerLaserOn, (ushort)configuration.TriggerLaserOn));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerLaserOff, (ushort)configuration.TriggerLaserOff));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL415, LedPowerConverter.ClampLedPower((ushort)configuration.L415)));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL470, LedPowerConverter.ClampLedPower((ushort)configuration.L470)));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL560, LedPowerConverter.ClampLedPower((ushort)configuration.L560)));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacLaser, (ushort)configuration.LaserAmplitude));

            yield return(HarpCommand.WriteByte(ConfigurationRegisters.Out0Conf, (byte)configuration.DigitalOutput0));

            yield return(HarpCommand.WriteByte(ConfigurationRegisters.Out1Conf, (byte)configuration.DigitalOutput1));

            yield return(HarpCommand.WriteByte(ConfigurationRegisters.In0Conf, (byte)configuration.DigitalInput0));

            yield return(HarpCommand.WriteByte(ConfigurationRegisters.In1Conf, (byte)configuration.DigitalInput1));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.StimPeriod, (ushort)configuration.PulsePeriod));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.StimOn, (ushort)configuration.PulseWidth));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.StimReps, (ushort)configuration.PulseCount));

            if (savePersistent)
            {
                yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.StimWavelength, 0));

                yield return(HarpCommand.Reset(ResetMode.Save));
            }
        }
        IEnumerable <HarpMessage> RestoreCalibration()
        {
            yield return(HarpCommand.WriteByte(ConfigurationRegisters.StimStart, (byte)CommandMode.Stop));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerPeriod, (ushort)configuration.TriggerPeriod));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerTimeUpdateOutputs, (ushort)configuration.DwellTime));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL415, LedPowerConverter.ClampLedPower((ushort)configuration.L415)));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL470, LedPowerConverter.ClampLedPower((ushort)configuration.L470)));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL560, LedPowerConverter.ClampLedPower((ushort)configuration.L560)));

            yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacLaser, (ushort)configuration.LaserAmplitude));
        }
        IEnumerable <HarpMessage> WritePropertyRegister(string propertyName)
        {
            switch (propertyName)
            {
            case nameof(configuration.ClockSynchronizer):
            case nameof(configuration.Output1Routing):
                yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.Config, (ushort)configuration.Config));

                yield return(HarpCommand.WriteByte(ConfigurationRegisters.Out1Conf, (byte)configuration.DigitalOutput1));

                break;

            case nameof(configuration.ScreenBrightness):
                yield return(HarpCommand.WriteByte(ConfigurationRegisters.ScreenBrightness, (byte)configuration.ScreenBrightness));

                break;

            case nameof(configuration.FrameRate):
            case nameof(configuration.DwellTime):
            case nameof(configuration.InterleaveWidth):
                yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerPeriod, (ushort)configuration.TriggerPeriod));

                yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerTimeUpdateOutputs, (ushort)configuration.DwellTime));

                yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerLaserOn, (ushort)configuration.TriggerLaserOn));

                yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerLaserOff, (ushort)configuration.TriggerLaserOff));

                break;

            case nameof(configuration.TriggerState):
                var triggerState = configuration.TriggerState;
                yield return(HarpCommand.WriteByte(ConfigurationRegisters.TriggerState, TriggerHelper.FromFrameFlags(triggerState)));

                yield return(HarpCommand.WriteByte(ConfigurationRegisters.TriggerStateLength, (byte)triggerState.Length));

                break;

            case nameof(configuration.L415):
                yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL415, LedPowerConverter.ClampLedPower((ushort)configuration.L415)));

                break;

            case nameof(configuration.L470):
                yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL470, LedPowerConverter.ClampLedPower((ushort)configuration.L470)));

                break;

            case nameof(configuration.L560):
                yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL560, LedPowerConverter.ClampLedPower((ushort)configuration.L560)));

                break;

            case nameof(configuration.LaserAmplitude):
                yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacLaser, (ushort)configuration.LaserAmplitude));

                break;

            case nameof(configuration.DigitalOutput0):
                yield return(HarpCommand.WriteByte(ConfigurationRegisters.Out0Conf, (byte)configuration.DigitalOutput0));

                break;

            case nameof(configuration.DigitalOutput1):
                yield return(HarpCommand.WriteByte(ConfigurationRegisters.Out1Conf, (byte)configuration.DigitalOutput1));

                break;

            case nameof(configuration.DigitalInput0):
                yield return(HarpCommand.WriteByte(ConfigurationRegisters.In0Conf, (byte)configuration.DigitalInput0));

                break;

            case nameof(configuration.DigitalInput1):
                yield return(HarpCommand.WriteByte(ConfigurationRegisters.In1Conf, (byte)configuration.DigitalInput1));

                break;

            case nameof(configuration.LaserWavelength):
                yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.StimWavelength, (ushort)configuration.LaserWavelength));

                if (configuration.LaserWavelength != LaserWavelength.None)
                {
                    yield return(HarpCommand.WriteByte(ConfigurationRegisters.ScreenBrightness, (byte)configuration.ScreenBrightness));
                }
                break;

            case nameof(configuration.PulseFrequency):
                yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.StimPeriod, (ushort)configuration.PulsePeriod));

                break;

            case nameof(configuration.PulseWidth):
                yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.StimOn, (ushort)configuration.PulseWidth));

                yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacLaser, (ushort)configuration.LaserAmplitude));

                break;

            case nameof(configuration.PulseCount):
                yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.StimReps, (ushort)configuration.PulseCount));

                break;

            default: yield break;
            }
        }