Exemple #1
0
        public async Task <Response <bool> > ChangeStateAsync(LedState state, int deviceType, string serialNumber)
        {
            string uri = API.Devices.ExecuteCommand(_baseResourceApiAddress, ApiVersion.v1, serialNumber, _user.id);

            DeviceInfracstructureActionModel actionModel = new DeviceInfracstructureActionModel(DeviceCommands.SwitchLed, deviceType);

            actionModel.AddParameter("state", (int)state);

            var result = await CommandFactory.Instance.GetCommand("BASE_POST_COMMAND")
                         .RunAsync <ResponseInfrastructureModel <bool> >(uri, actionModel);

            if (result != null)
            {
                var response = new Response <bool>();

                response.Value            = result.HasValue ? result.Value.Value : false;
                response.Error            = result.HasValue ? result.Value.Error : result.Error;
                response.ErrorCode        = result.HasValue ? result.Value.ErrorCode : null;
                response.HttpResponseCode = (int)result.ResponseCode;

                return(response);
            }

            return(new Response <bool> {
                Error = "Unidentified error", ErrorCode = -999, Value = false, HttpResponseCode = 500
            });
        }
Exemple #2
0
        private async void ChangingLedColor(LedState led)
        {
            led.ButtonPressed = true;
            led.LedOn         = !led.LedOn;
            RGBColor color = RGBLedData.LedOFF;

            if (led.LedOn)
            {
                color = RGBLedData.LedON;
            }
            DisplayServerStatus(led.Led.SetColor(color));

            while (led.ButtonPressed)
            {
                await Task.Run(async() =>
                {
                    await Task.Delay(1000);   // in milliseconds
                }).ConfigureAwait(true);

                if (led.ButtonPressed)
                {
                    string msg = led.Led.SetColor(GetRandomRGBLedColor());
                    DisplayServerStatus(msg);
                }
            }
        }
Exemple #3
0
 public void SetLedStatus(int led, LedState newState)
 {
     NLED_SETTINGS_INFO pOutput = new NLED_SETTINGS_INFO();
     pOutput.LedNum = led;
     pOutput.OffOnBlink = (int)newState;
     NLedSetDevice(2, ref pOutput);
 }
Exemple #4
0
		/// <summary>
		/// Set the state of the specified LED
		/// </summary>
		/// <param name="led">0 based index of the LED</param>
		/// <param name="newState">New state of the LED - see LedState enumeration</param>
		public void SetLedStatus(int led, LedState newState)
		{
			NLED_SETTINGS_INFO nsi = new NLED_SETTINGS_INFO();

			nsi.LedNum = led;
			nsi.OffOnBlink = (int)newState;
			bool bSuccess = NLedSetDevice(NLED_SETTINGS_INFO_ID, ref nsi);
		}
Exemple #5
0
 public void TurnOff()
 {
     if (this.State != LedState.Off)
     {
         this.State = LedState.Off;
         this.SwitchOff();
     }
 }
Exemple #6
0
        /// <summary>
        /// Set the state of the specified LED
        /// </summary>
        /// <param name="led">0 based index of the LED</param>
        /// <param name="newState">New state of the LED - see LedState enumeration</param>
        public void SetLedStatus(int led, LedState newState)
        {
            NLED_SETTINGS_INFO nsi = new NLED_SETTINGS_INFO();

            nsi.LedNum     = led;
            nsi.OffOnBlink = (int)newState;
            bool bSuccess = NativeMethods.NLedSetDevice(NLED_SETTINGS_INFO_ID, ref nsi);
        }
Exemple #7
0
 public void SetError()
 {
     if (this.State != LedState.Error)
     {
         this.State = LedState.Error;
         this.SwitchError();
     }
 }
Exemple #8
0
 public void TurnOn()
 {
     if (this.State != LedState.On)
     {
         this.State = LedState.On;
         this.SwitchOn();
     }
 }
Exemple #9
0
 public void TurnOff([FromBody] LedState ledState)
 {
     if (ledState.lightOn == false)
     {
         Program.KillAllThreads();
         Program.ClearLeds();
     }
 }
Exemple #10
0
        /// <summery>
        /// Map the LedState from the application domain to the PinValue in the hardware domain
        /// </summery>
        public static PinValue ToPinValue(this LedState state)
        {
            if (state == LedState.Off)
            {
                return(PinValue.Low);
            }

            return(PinValue.High);
        }
        public void SetLedStatus(int led, LedState newState)
        {
            NLED_SETTINGS_INFO pOutput = new NLED_SETTINGS_INFO
            {
                LedNum     = led,
                OffOnBlink = (int)newState
            };

            NativeMethods.NLedSetDevice(2, ref pOutput);
        }
Exemple #12
0
 public void Flick()
 {
     if (State == LedState.On)
     {
         State = LedState.Off;
     }
     else
     {
         State = LedState.On;
     }
 }
        private void SetButtonLedStateImpl(byte midiButton, LedState state)
        {
            byte midiState = state switch
            {
                LedState.Off => 0,
                LedState.On => 0x7f,
                LedState.Blinking => 0x01,
                _ => 0
            };

            SendMidiMessage(0x90, midiButton, midiState);
        }
Exemple #14
0
        public LBLed()
        {
            InitializeComponent();

            this.Size          = new Size(20, 20);
            this.ledColor      = Color.Red;
            this.state         = LBLed.LedState.Off;
            this.style         = LBLed.LedStyle.Circular;
            this.blinkIsOn     = false;
            this.ledSize       = new SizeF(10F, 10F);
            this.labelPosition = LedLabelPosition.Top;
        }
Exemple #15
0
        /// <summary>
        /// Returns a <see cref="HarpMessage"/> command to initialize the device operation control register.
        /// </summary>
        /// <param name="operationMode">The desired operation mode of the device.</param>
        /// <param name="ledState">Specifies whether the operation mode LED should report the device state.</param>
        /// <param name="visualIndicators">Specifies whether any visual indicator LEDs should be enabled on the Harp device.</param>
        /// <param name="heartbeat">Specifies whether to enable or disable the heartbeat register.</param>
        /// <param name="replies">Specifies whether write commands should report back the state of the register.</param>
        /// <param name="dumpRegisters">Specifies whether the state of all registers should be reported after initialization.</param>
        /// <returns>A valid <see cref="HarpMessage"/> command to set the device operation mode.</returns>
        public static HarpMessage OperationControl(DeviceState operationMode, LedState ledState, LedState visualIndicators, EnableType heartbeat, EnableType replies, bool dumpRegisters)
        {
            int operationFlags;

            operationFlags  = heartbeat == EnableType.Enable      ? 0x80 : 0x00;
            operationFlags += ledState == LedState.On             ? 0x40 : 0x00;
            operationFlags += visualIndicators == LedState.On     ? 0x20 : 0x00;
            operationFlags += replies == EnableType.Enable        ? 0x00 : 0x10;
            operationFlags += dumpRegisters                       ? 0x08 : 0x00;
            operationFlags += operationMode == DeviceState.Active ? 0x01 : 0x00;
            return(WriteByte(Registers.OperationControl, (byte)operationFlags));
        }
Exemple #16
0
        public LBLed()
        {
            InitializeComponent();

            this.Size           = new Size(20, 20);
            this.ledColor		= Color.Red;
            this.state 			= LBLed.LedState.Off;
            this.style          = LBLed.LedStyle.Circular;
            this.blinkIsOn		= false;
            this.ledSize		= new SizeF ( 10F, 10F );
            this.labelPosition = LedLabelPosition.Top;
        }
Exemple #17
0
        /// <summary>
        /// Sets the Xbox LED state.
        /// </summary>
        /// <param name="state1">First LED state.</param>
        /// <param name="state2">Second LED state.</param>
        /// <param name="state3">Third LED state.</param>
        /// <param name="state4">Fourth LED state.</param>
        public void SetLedState(LedState state1, LedState state2, LedState state3, LedState state4)
        {
            byte state = 0;

            state |= (byte)state1;
            state |= (byte)((byte)state2 >> 1);
            state |= (byte)((byte)state3 >> 2);
            state |= (byte)((byte)state4 >> 3);
            _xbox.Process.Call(_xbox.Kernel.Exports.HalWriteSMBusValue, SmcDevices.SmBus, SmBusCommand.LedStates, 0, state);
            _xbox.Process.Call(_xbox.Kernel.Exports.HalWriteSMBusValue, SmcDevices.SmBus, SmBusCommand.LedOverride, 0, LedSubCommand.Custom);
            Thread.Sleep(10);
        }
Exemple #18
0
        public void Write(PinNumber pin, LedState value)
        {
            if (pin > 15)
            {
                throw new ArgumentException(
                          $"The Mcp23017 device can only handle pin number between 0 and 15. Provided PinNumber was {pin}");
            }

            _logger.LogDebug($"Setting pin {pin:x} to {value}");
            _pinValues = SetBit(_pinValues, (ushort)pin, (bool)value.ToPinValue());
            _device.WriteUInt16(Register.GPIO, _pinValues);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="ledIndex">
        /// A <see cref="System.Int32"/>
        /// </param>
        /// <param name="newLedState">
        /// A <see cref="LedState"/>
        /// </param>
        public void Led(int ledIndex, LedState newLedState)
        {
            ThrowIfNotOpen();

            if (newLedState == LedState.On)
            {
                AirPcapSafeNativeMethods.AirpcapTurnLedOn(AirPcapDeviceHandle, (UInt32)ledIndex);
            }
            else if (newLedState == LedState.Off)
            {
                AirPcapSafeNativeMethods.AirpcapTurnLedOff(AirPcapDeviceHandle, (UInt32)ledIndex);
            }
        }
 public HMILed()
 {
     InitializeComponent();
     this.tmrBlink       = new Timer();
     this.tmrBlink.Tick += this.OnBlink;
     this.Size           = new Size(20, 20);
     this.ledColor       = Color.Red;
     this.state          = HMILed.LedState.Off;
     this.style          = HMILed.LedStyle.Circular;
     this.blinkIsOn      = false;
     this.ledSize        = new SizeF(10F, 10F);
     this.labelPosition  = LedLabelPosition.Top;
 }
Exemple #21
0
            /// <summary>
            /// Set state of all LEDs.
            /// </summary>
            ///
            /// <param name="state">State, which will be set to all LEDs.</param>
            ///
            /// <remarks><para>The method sets the same state to all Qwerk's on-board LEDs.</para></remarks>
            ///
            /// <exception cref="NotConnectedException">No connection to Qwerk or its service.</exception>
            /// <exception cref="ConnectionLostException">Connestion to Qwerk is lost.</exception>
            ///
            public void SetLedsState(LedState state)
            {
                bool[]     ledsMask = new bool[Count];
                LedState[] states   = new LedState[Count];

                for (int i = 0; i < Count; i++)
                {
                    ledsMask[i] = true;
                    states[i]   = state;
                }

                SetLedsState(ledsMask, states);
            }
        public void SetLayerButtonLedState(Layer layer, LedState state)
        {
            switch (layer)
            {
            case Layer.LayerA:
                SetButtonLedStateImpl(LayerAMidiButton, state);
                break;

            case Layer.LayerB:
                SetButtonLedStateImpl(LayerBMidiButton, state);
                break;
            }
        }
Exemple #23
0
        private bool Initialize()
        {
            if (!_initialized)
            {
                try
                {
                    // initialize PiCar
                    _piCar = PiCarClientFactory.CreatePiCar(_controlTopic.Server, _controlTopic.Credential);
                    if (_piCar != null)
                    {
                        _piCar.Initialize(_controlTopic.ServerAddress, _controlTopic.VideoPort);
                        _cameraHorizontalServo = new ServoStat {
                            Servo = _piCar.HeadHorizontalServo
                        };
                        _cameraVertialServo = new ServoStat {
                            Servo = _piCar.HeadVerticalServo
                        };
                        _rightLed = new LedState {
                            Led = _piCar.RightLed
                        };
                        _leftLed = new LedState {
                            Led = _piCar.LeftLed
                        };
                        // initialize AppServiceHost
                        DeviceSettings settings = DeviceSettings.Instance;
                        _host = new AppServiceHost(settings.ServerPrefix, settings.ServiceRootPath, settings.ServiceActionRootPath, settings.ServiceCredentials);
                        _host.Init();

                        _initialized = true;
                    }
                }
                catch (Exception err)
                {
                    responseLabel.Text = "Failed to initialize PiCar \n" + err.ToString();
                }
            }
            if (_initialized)
            {
                CommandButton.IsEnabled      = true;
                GpioButton.IsEnabled         = true;
                ServiceOnOffButton.IsEnabled = true;
            }
            else
            {
                CommandButton.IsEnabled      = false;
                GpioButton.IsEnabled         = false;
                ServiceOnOffButton.IsEnabled = false;
            }
            return(_initialized);
        }
Exemple #24
0
            /// <summary>
            /// Set state of specified LED.
            /// </summary>
            ///
            /// <param name="led">LED to set state for, [0, <see cref="Leds.Count"/>).</param>
            /// <param name="state">LED's state to set.</param>
            ///
            /// <remarks><para>The method sets state of one of Qwerk's LEDs, which index is specified.</para></remarks>
            ///
            /// <exception cref="ArgumentOutOfRangeException">Invalid LED is specified.</exception>
            /// <exception cref="NotConnectedException">No connection to Qwerk or its service.</exception>
            /// <exception cref="ConnectionLostException">Connestion to Qwerk is lost.</exception>
            ///
            public void SetLedState(int led, LedState state)
            {
                if ((led < 0) || (led >= Count))
                {
                    throw new ArgumentOutOfRangeException("Invalid LED is specified.");
                }

                bool[]     ledsMask = new bool[Count];
                LedState[] states   = new LedState[Count];

                ledsMask[led] = true;
                states[led]   = state;

                SetLedsState(ledsMask, states);
            }
Exemple #25
0
        /// <summary>
        /// Sets the ring lights for a knob.
        /// </summary>
        /// <param name="knob">The knob to set the lights for</param>
        /// <param name="state">The overall state: off, on, or blinking</param>
        /// <param name="value">The individual value (0 for off, </param>
        public void SetKnobRingLights(int knob, LedState state, int value)
        {
            byte midiValue = (state, value) switch
            {
                (LedState.Off, _) => 0,
                (_, 0) => 0,
                (LedState.On, 14) => 27,
                (LedState.Blinking, 14) => 28,
                (LedState.On, >= 1 and <= 13) => (byte)value,
                (LedState.Blinking, >= 1 and <= 13) => (byte)(value + 13),
                _ => 0
            };

            SendMidiMessage(0xb0, (byte)(knob + 8), midiValue);
        }
Exemple #26
0
        /// <summary>
        /// Writes a custom command to the device to turn LEDs on/off
        /// using a DataWriter to the OutputStream
        /// </summary>
        /// <param name="ledNumber"></param>
        /// <param name="ledState"></param>
        private async void WriteLedCommand(String ledNumber, LedState ledState)
        {
            if (EventHandlerForDevice.Current.IsDeviceConnected)
            {
                try
                {
                    rootPage.NotifyUser("Writing...", NotifyType.StatusMessage);

                    DataWriterObject = new DataWriter(EventHandlerForDevice.Current.Device.OutputStream);

                    switch (ledState)
                    {
                    case LedState.LedStateOn:
                        DataWriterObject.WriteString("ledon " + ledNumber + "\r");
                        break;

                    case LedState.LedStateOff:
                        DataWriterObject.WriteString("ledoff " + ledNumber + "\r");
                        break;

                    default:
                        break;
                    }

                    await WriteAsync(WriteCancellationTokenSource.Token);
                }
                catch (OperationCanceledException /*exception*/)
                {
                    NotifyWriteTaskCanceled();
                }
                catch (Exception exception)
                {
                    MainPage.Current.NotifyUser(exception.Message.ToString(), NotifyType.ErrorMessage);
                    Debug.WriteLine(exception.Message.ToString());
                }
                finally
                {
                    DataWriterObject.DetachStream();
                    DataWriterObject = null;
                }
            }
            else
            {
                Utilities.NotifyDeviceNotConnected();
            }
        }
Exemple #27
0
    private void mononokeOn()
    {
        MononokeInfo minfo = mononokeData.GetInfo(mononokeId);

        captureLen = minfo.level * 3.5f / 3;
        float aspect = (float)minfo.tex.width / minfo.tex.height;

        mononoke.GetComponent <Renderer>().material.mainTexture = minfo.tex;
        Vector3 scale = new Vector3(0.1f, 0.1f, 0.1f);

        scale.x = scale.y * aspect;
        mononoke.transform.localScale = scale;
        level.value = minfo.level;
        mononoke.SetActive(true);
        ledState = LedState.WAVE;
        vacuumSound.Play();
    }
Exemple #28
0
        public HTLed()
        {
            InitializeComponent();

            this.Size          = new Size(20, 20);
            this.ledColor      = Color.Red;
            this.state         = HTLed.LedState.Off;
            this.style         = HTLed.LedStyle.Circular;
            this.blinkIsOn     = false;
            this.ledSize       = new SizeF(10F, 10F);
            this.labelPosition = LedLabelPosition.Top;

            //data subjection
            RunningServer server = RunningServer.getServer();

            server.Connected += OnConnected;
        }
Exemple #29
0
 public void SetLed(LedType ledType, uint ledIndex, LedState state, bool autoExecute = true)
 {
     if ((uint)ledIndex > 7 && (uint)ledIndex != 0xff)
     {
         throw new IndexOutOfRangeException("ledIndex");
     }
     lock (this) {
         BasicTypeSerializer.Put(SendContext, (byte)Command.SetLedState);
         BasicTypeSerializer.Put(SendContext, (byte)ledType);
         BasicTypeSerializer.Put(SendContext, (byte)ledIndex);
         BasicTypeSerializer.Put(SendContext, (byte)state);
         if (autoExecute)
         {
             Execute();
         }
     }
 }
Exemple #30
0
        /// <summary>
        /// Sets the led (0 to 23).
        /// </summary>
        /// <param name="ledNo">Led no.</param>
        /// <param name="state">State.</param>
        public void SetLed(uint ledNo, LedState state)
        {
            if (ledNo > 23)
            {
                throw new Exception("led must be between 0 and 23");
            }

            long r;

            r = Math.DivRem(ledNo, 4, out var c) * 2;
            if (ledNo >= 12)
            {
                c += 4;
            }

            if (r > 4)
            {
                r -= 6;
            }

            switch (state)
            {
            case LedState.Off:
                this.SetLed((uint)r, (uint)c, false);
                this.SetLed((uint)r + 1, (uint)c, false);
                break;

            case LedState.Red:
                this.SetLed((uint)r, (uint)c, true);
                this.SetLed((uint)r + 1, (uint)c, false);
                break;

            case LedState.Yellow:
                this.SetLed((uint)r, (uint)c, true);
                this.SetLed((uint)r + 1, (uint)c, true);
                break;

            case LedState.Green:
                this.SetLed((uint)r, (uint)c, false);
                this.SetLed((uint)r + 1, (uint)c, true);
                break;
            }
        }
    void CheckStartLedState()
    {
        if (StartLedSt == LedState.Shan)
        {
            pcvr.StartLightStateP1        = LedState.Shan;
            pcvr.StartLightStateP2        = LedState.Shan;
            StartLedUITexture.mainTexture = StartLedUI[0];
            StartLedSt = LedState.Mie;
            return;
        }

        if (StartLedSt == LedState.Mie)
        {
            pcvr.StartLightStateP1        = LedState.Mie;
            pcvr.StartLightStateP2        = LedState.Mie;
            StartLedUITexture.mainTexture = StartLedUI[1];
            StartLedSt = LedState.Shan;
            return;
        }
    }
Exemple #32
0
        public LBLed()
        {
            InitializeComponent();

            // Set the styles for drawing
            SetStyle(ControlStyles.AllPaintingInWmPaint |
                ControlStyles.ResizeRedraw |
                ControlStyles.DoubleBuffer |
                ControlStyles.SupportsTransparentBackColor,
                true);

            // Transparent background
            this.BackColor = Color.Transparent;

            this.ledColor		= Color.Red;
            this.state 			= LBLed.LedState.Off;
            this.blinkIsOn		= false;
            this.ledSize		= new SizeF ( 10F, 10F );
            this.labelPosition = LedLabelPosition.Top;

            this.defaultRenderer = new LBLedRenderer();
            this.defaultRenderer.Led = this;
        }
Exemple #33
0
        public LBLed()
        {
            InitializeComponent();

            // Set the styles for drawing
            SetStyle(ControlStyles.AllPaintingInWmPaint |
                     ControlStyles.ResizeRedraw |
                     ControlStyles.DoubleBuffer |
                     ControlStyles.SupportsTransparentBackColor,
                     true);

            // Transparent background
            this.BackColor = Color.Transparent;

            this.ledColor      = Color.Red;
            this.state         = LBLed.LedState.Off;
            this.blinkIsOn     = false;
            this.ledSize       = new SizeF(10F, 10F);
            this.labelPosition = LedLabelPosition.Top;

            this.defaultRenderer     = new LBLedRenderer();
            this.defaultRenderer.Led = this;
        }
Exemple #34
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="ledIndex">
        /// A <see cref="System.Int32"/>
        /// </param>
        /// <param name="newLedState">
        /// A <see cref="LedState"/>
        /// </param>
        public void Led(int ledIndex, LedState newLedState)
        {
            ThrowIfNotOpen();

            if (newLedState == LedState.On)
            {
                AirPcapSafeNativeMethods.AirpcapTurnLedOn(AirPcapDeviceHandle, (UInt32)ledIndex);
            }
            else if (newLedState == LedState.Off)
            {
                AirPcapSafeNativeMethods.AirpcapTurnLedOff(AirPcapDeviceHandle, (UInt32)ledIndex);
            }
        }
 public void On()
 {
     Board.DigitalWrite(Pin, DigitalPin.High);
     State = LedState.On;
     OnStateChanged(State);
 }
 public void Off()
 {
     Board.DigitalWrite(Pin, DigitalPin.Low);
     State = LedState.Off;
     OnStateChanged(State);
 }
Exemple #37
0
 public Led()
 {
     this.State = LedState.Off;
 }
            /// <summary>
            /// Set state of all LEDs.
            /// </summary>
            /// 
            /// <param name="ledsMask">Mask array specifying which LED's state need to be set.</param>
            /// <param name="states">Array of LEDs' states.</param>
            /// 
            /// <remarks><para>The <paramref name="ledsMask"/> and <paramref name="states"/> arrays specify
            /// which Qwerk's on-board LED's state should be updated. If value of the <paramref name="ledsMask"/>
            /// array is set to <see langword="true"/>, then corresponding LED's state is changed to the state,
            /// which is specified in <paramref name="states"/> array.</para>
            /// </remarks>
            /// 
            /// <exception cref="ArgumentException">Incorrect length of LEDs' masks or states array.</exception>
            /// <exception cref="NotConnectedException">No connection to Qwerk or its service.</exception>
            /// <exception cref="ConnectionLostException">Connestion to Qwerk is lost.</exception>
            /// 
            public void SetLedsState( bool[] ledsMask, LedState[] states )
            {
                if ( ( ledsMask.Length != Count ) || ( states.Length != Count ) )
                {
                    throw new ArgumentException( "Incorrect length of leds' masks or states array." );
                }

                TeRKIceLib.LEDMode[] modes = new TeRKIceLib.LEDMode[Count];

                for ( int i = 0; i < Count; i++ )
                {
                    modes[i] = modesMapping[(int) states[i]];
                }

                // check controller
                if ( ledController == null )
                {
                    throw new NotConnectedException( "Qwerk's service is not connected." );
                }

                try
                {
                    // execute leds' command
                    ledController.execute( new TeRKIceLib.LEDCommand( ledsMask, modes ) );
                }
                catch
                {
                    throw new ConnectionLostException( "Connection is lost." );
                }
            }
 /// <summary>
 /// Overload of SetLed that accepts enumerators
 /// </summary>
 /// <param name="device"></param>
 /// <param name="page"></param>
 /// <param name="index"></param>
 /// <param name="value"></param>
 public void SetLed(IntPtr device, int page, Leds index, LedState value)
 {
     SetLed(device, page, (int)index, (int)value);
 }
            /// <summary>
            /// Set state of specified LED.
            /// </summary>
            /// 
            /// <param name="led">LED to set state for, [0, <see cref="Leds.Count"/>).</param>
            /// <param name="state">LED's state to set.</param>
            /// 
            /// <remarks><para>The method sets state of one of Qwerk's LEDs, which index is specified.</para></remarks>
            /// 
            /// <exception cref="ArgumentOutOfRangeException">Invalid LED is specified.</exception>
            /// <exception cref="NotConnectedException">No connection to Qwerk or its service.</exception>
            /// <exception cref="ConnectionLostException">Connestion to Qwerk is lost.</exception>
            /// 
            public void SetLedState( int led, LedState state )
            {
                if ( ( led < 0 ) || ( led >= Count ) )
                {
                    throw new ArgumentOutOfRangeException( "Invalid LED is specified." );
                }

                bool[] ledsMask = new bool[Count];
                LedState[] states = new LedState[Count];

                ledsMask[led] = true;
                states[led] = state;

                SetLedsState( ledsMask, states );
            }
Exemple #41
0
        public Boolean SetLedStatus(int channelNo, LedState color)
        {
            int retVal;

            retVal = AD101NativeMethods.AD101_SetLED(channelNo, (int)color);

            return (retVal == OK);
        }
Exemple #42
0
 static void LedUpdateFn(int vid, LedState state)
 {
     Console.WriteLine($"LED #{vid} set to state {state.State}");
 }
Exemple #43
0
        static IObservable <string> GetDeviceName(string portName, LedState ledState, LedState visualIndicators, EnableType heartbeat)
        {
            return(Observable.Create <string>(observer =>
            {
                var transport = default(SerialTransport);
                var writeOpCtrl = HarpCommand.OperationControl(DeviceState.Standby, ledState, visualIndicators, heartbeat, EnableType.Enable, false);
                var cmdReadWhoAmI = HarpCommand.ReadUInt16(Registers.WhoAmI);
                var cmdReadMajorHardwareVersion = HarpCommand.ReadByte(Registers.HardwareVersionHigh);
                var cmdReadMinorHardwareVersion = HarpCommand.ReadByte(Registers.HardwareVersionLow);
                var cmdReadMajorFirmwareVersion = HarpCommand.ReadByte(Registers.FirmwareVersionHigh);
                var cmdReadMinorFirmwareVersion = HarpCommand.ReadByte(Registers.FirmwareVersionLow);
                var cmdReadTimestampSeconds = HarpCommand.ReadUInt32(Registers.TimestampSecond);
                var cmdReadDeviceName = HarpCommand.ReadByte(Registers.DeviceName);
                var cmdReadSerialNumber = HarpCommand.ReadUInt16(Registers.SerialNumber);

                var whoAmI = 0;
                var timestamp = 0u;
                var hardwareVersionHigh = 0;
                var hardwareVersionLow = 0;
                var firmwareVersionHigh = 0;
                var firmwareVersionLow = 0;
                var serialNumber = default(ushort?);
                var messageObserver = Observer.Create <HarpMessage>(
                    message =>
                {
                    switch (message.Address)
                    {
                    case Registers.OperationControl:
                        transport.Write(cmdReadWhoAmI);
                        transport.Write(cmdReadMajorHardwareVersion);
                        transport.Write(cmdReadMinorHardwareVersion);
                        transport.Write(cmdReadMajorFirmwareVersion);
                        transport.Write(cmdReadMinorFirmwareVersion);
                        transport.Write(cmdReadTimestampSeconds);
                        transport.Write(cmdReadSerialNumber);
                        transport.Write(cmdReadDeviceName);
                        break;

                    case Registers.WhoAmI: whoAmI = message.GetPayloadUInt16(); break;

                    case Registers.HardwareVersionHigh: hardwareVersionHigh = message.GetPayloadByte(); break;

                    case Registers.HardwareVersionLow: hardwareVersionLow = message.GetPayloadByte(); break;

                    case Registers.FirmwareVersionHigh: firmwareVersionHigh = message.GetPayloadByte(); break;

                    case Registers.FirmwareVersionLow: firmwareVersionLow = message.GetPayloadByte(); break;

                    case Registers.TimestampSecond: timestamp = message.GetPayloadUInt32(); break;

                    case Registers.SerialNumber: if (!message.Error)
                        {
                            serialNumber = message.GetPayloadUInt16();
                        }
                        break;

                    case Registers.DeviceName:
                        var deviceName = nameof(Device);
                        if (!message.Error)
                        {
                            var namePayload = message.GetPayload();
                            deviceName = Encoding.ASCII.GetString(namePayload.Array, namePayload.Offset, namePayload.Count);
                        }
                        Console.WriteLine("Serial Harp device.");
                        if (!serialNumber.HasValue)
                        {
                            Console.WriteLine($"WhoAmI: {whoAmI}");
                        }
                        else
                        {
                            Console.WriteLine($"WhoAmI: {whoAmI}-{serialNumber:x4}");
                        }
                        Console.WriteLine($"Hw: {hardwareVersionHigh}.{hardwareVersionLow}");
                        Console.WriteLine($"Fw: {firmwareVersionHigh}.{firmwareVersionLow}");
                        Console.WriteLine($"Timestamp (s): {timestamp}");
                        Console.WriteLine($"DeviceName: {deviceName}");
                        Console.WriteLine();
                        observer.OnNext(deviceName);
                        observer.OnCompleted();
                        break;

                    default:
                        break;
                    }
                },
                    observer.OnError,
                    observer.OnCompleted);
                transport = new SerialTransport(portName, messageObserver);
                transport.IgnoreErrors = true;
                transport.Open();

                transport.Write(writeOpCtrl);
                return transport;
            }).Timeout(TimeSpan.FromMilliseconds(500))
                   .OnErrorResumeNext(Observable.Return(nameof(Device)))
                   .SubscribeOn(Scheduler.Default)
                   .FirstAsync());
        }
Exemple #44
0
 public void SetLedStatus(int led, LedState newState)
 {
     NLED_SETTINGS_INFO pOutput = new NLED_SETTINGS_INFO
     {
         LedNum = led,
         OffOnBlink = (int)newState
     };
     NativeMethods.NLedSetDevice(2, ref pOutput);
 }
        /// <summary>
        /// Writes a custom command to the device to turn LEDs on/off
        /// using a DataWriter to the OutputStream
        /// </summary>
        /// <param name="ledNumber"></param>
        /// <param name="ledState"></param>
        private async void WriteLedCommand(String ledNumber, LedState ledState)
        {
            if (EventHandlerForDevice.Current.IsDeviceConnected)
            {
                try
                {
                    rootPage.NotifyUser("Writing...", NotifyType.StatusMessage);

                    DataWriterObject = new DataWriter(EventHandlerForDevice.Current.Device.OutputStream);

                    switch (ledState)
                    {
                        case LedState.LedStateOn:
                            DataWriterObject.WriteString("ledon " + ledNumber + "\r");
                            break;

                        case LedState.LedStateOff:
                            DataWriterObject.WriteString("ledoff " + ledNumber + "\r");
                            break;

                        default:
                            break;
                    }

                    await WriteAsync(WriteCancellationTokenSource.Token);
                }
                catch (OperationCanceledException /*exception*/)
                {
                    NotifyWriteTaskCanceled();
                }
                catch (Exception exception)
                {
                    MainPage.Current.NotifyUser(exception.Message.ToString(), NotifyType.ErrorMessage);
                    Debug.WriteLine(exception.Message.ToString());
                }
                finally
                {
                    DataWriterObject.DetachStream();
                    DataWriterObject = null;
                }
            }
            else
            {
                Utilities.NotifyDeviceNotConnected();
            }
        }
            /// <summary>
            /// Set state of all LEDs.
            /// </summary>
            /// 
            /// <param name="state">State, which will be set to all LEDs.</param>
            /// 
            /// <remarks><para>The method sets the same state to all Qwerk's on-board LEDs.</para></remarks>
            /// 
            /// <exception cref="NotConnectedException">No connection to Qwerk or its service.</exception>
            /// <exception cref="ConnectionLostException">Connestion to Qwerk is lost.</exception>
            /// 
            public void SetLedsState( LedState state )
            {
                bool[] ledsMask = new bool[Count];
                LedState[] states = new LedState[Count];

                for ( int i = 0; i < Count; i++ )
                {
                    ledsMask[i] = true;
                    states[i] = state;
                }

                SetLedsState( ledsMask, states );
            }
 public void Write(PinNumber pin, LedState value)
 {
     _logger.LogInformation($"Writing '{value.ToPinValue()}' to pin '{pin:x}'");
 }
Exemple #48
0
 public StateEventArgs(LedState state1, LedState state2)
 {
     BeforeChanged = state1;
     AfterChanged = state2;
 }