public BalboaHotTub Set_LED(string value) { LED = (LEDState)Enum.Parse(typeof(LEDState), value); _panelInfoRawData = null; return(this); }
public LedStateViewModel(ISource <LEDState> source, ISource <LEDStateConfig> configSource) { Source = source; ConfigSource = configSource; Source.OnChange += (LEDState value) => LedState = value; Switch = new LedSwitchCommand(ConfigSource); }
/// <summary> /// /// </summary> /// <param name="Top_Left"></param> /// <param name="Top_Right"></param> /// <param name="Bottom_Left"></param> /// <param name="Bottom_Right"></param> public void SetLeds(LEDState Top_Left, LEDState Top_Right, LEDState Bottom_Left, LEDState Bottom_Right) { object[] Resolver = new object[] { "consolefeatures ver=", 2, " type=14 params=\"A\\0\\A\\4\\", 1, "\\", (uint)Top_Left, "\\", 1, "\\", (uint)Top_Right, "\\", 1, "\\", (uint)Bottom_Left, "\\", 1, "\\", (uint)Bottom_Right, "\\\"" }; SendTextCommand(string.Concat(Resolver)); }
public static void Command(Dictionary<JointType, Point> jointPoints, Body body) { if (!MainWindow.xsocketClient.IsConnected) return; if (jointPoints[JointType.HandLeft].Y < jointPoints[JointType.ShoulderLeft].Y && jointPoints[JointType.HandRight].Y < jointPoints[JointType.ShoulderRight].Y) { //Maybe we need to send a message... if (body.HandLeftState == HandState.Open && body.HandRightState == HandState.Open) { if (LEDState == LEDState.Off) { //Turn on LED LEDState = LEDState.On; System.Diagnostics.Debug.WriteLine("TURN LED ON AND START SENDING"); MainWindow.xsocketClient.Controller("monitor").Invoke("command", "on"); } } if (body.HandLeftState == HandState.Closed && body.HandRightState == HandState.Closed) { if (LEDState == LEDState.On) { //Turn off LED LEDState = LEDState.Off; System.Diagnostics.Debug.WriteLine("TURN LED OFF AND STOP SENDING"); MainWindow.xsocketClient.Controller("monitor").Invoke("command", "off"); } } } }
private bool CheckLightStatus(LEDState ls) { //调用函数 lock (m_objDll) { Log(DateTime.Now.ToString() + ", 处理看灯开始, Thresthod=[" + MyData.r_thresthod.ToString() + "," + MyData.b_thresthod.ToString() + "," + MyData.y_thresthod.ToString() + "]"); //判断是否处于结束态, 调用HALCON函数 object[] parm = new object[4]; parm[0] = MyData.b_thresthod; parm[1] = MyData.r_thresthod; parm[2] = MyData.y_thresthod; parm[3] = 0; int res = (int)(m_dicMethod[MyData.halconCheckLightStatusName].Invoke(obj, parm)); Log(DateTime.Now.ToString() + ", 处理看灯结束, 颜色为value=" + parm[3].ToString()); if (res != (int)ls) { Log("灯状态为:【" + res.ToString() + "】, 看灯失败,要看灯的颜色为:" + ((int)ls).ToString()); return(false); } Log("灯状态为:【" + res.ToString() + "】, 看灯成功"); return(true); } }
public static void Initialize() { ledPort = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di10, true); state = LEDState.Initializing; ledThread = new Thread(ControlLED); ledThread.Priority = ThreadPriority.BelowNormal; ledThread.Start(); }
public void SetLeds(LEDState Top_Left, LEDState Top_Right, LEDState Bottom_Left, LEDState Bottom_Right) { if (this.activeConnection) { this.CallStruct(string.Concat(new object[] { @"A\0\T\14\A\4\", this.Int, @"\", Top_Left, this.Int, @"\", Top_Right, this.Int, @"\", Bottom_Left, this.Int, @"\", Top_Left, this.Int, @"\", Bottom_Right, @"\" })); this.Recv(); } }
private void setLEDState(LEDState state) { this.state = state; switch (this.state) { case LEDState.ON: PictureLED.Image = Resource.LedOn; break; case LEDState.OFF: PictureLED.Image = Resource.LedOff; break; default: throw new ArgumentException("Tried to set LED to invalid state."); } }
/// <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, c; r = Math.DivRem(ledNo, 4, out c) * 2; if (ledNo >= 12) { c += 4; } if (r > 4) { r -= 6; } switch (state) { case LEDState.Off: base.SetLed((uint)r, (uint)c, false); base.SetLed((uint)r + 1, (uint)c, false); break; case LEDState.Red: base.SetLed((uint)r, (uint)c, true); base.SetLed((uint)r + 1, (uint)c, false); break; case LEDState.Yellow: base.SetLed((uint)r, (uint)c, true); base.SetLed((uint)r + 1, (uint)c, true); break; case LEDState.Green: base.SetLed((uint)r, (uint)c, false); base.SetLed((uint)r + 1, (uint)c, true); break; } }
public BalboaHotTub ToggleLEDState() { switch (LED) { case LEDState.Off: LED = LEDState.Cycle; break; case LEDState.Purple: case LEDState.Blue: case LEDState.Red: case LEDState.Green: case LEDState.Cycle: case LEDState.Fade: LED = LEDState.Off; break; default: throw new ArgumentOutOfRangeException(); } _panelInfoRawData = null; return(this); }
public static void Main() { /* Initialize Display Module elements */ InitDisplayModule(); /* Initialize Talon and Victor with various configurations */ InitMotors(); /* LED Variables */ float _Brightness = 0.25f; /* Default LED Brightness */ Boolean On = true; /* Color Flashing state */ byte i = 0; /* Color Duration track variable for flashing */ int colorDelay = 0; /* Color Duration track variable for Sequence speed */ /* State variables */ DriveState MotionState = DriveState.MotionMagicTalon; LEDState OperationState = LEDState.Pigeon; /* Buttons and boolean for motor control */ Boolean lastButton1 = false; Boolean lastButton2 = false; Boolean lastButton3 = false; Boolean lastbutton4 = false; while (true) { /* Check gamepad connection */ if (_Gamepad.GetConnectionStatus() == CTRE.Phoenix.UsbDeviceConnection.Connected) { OperationState = LEDState.Controller; } else { OperationState = LEDState.Pigeon; } if (OperationState == LEDState.Controller) { CTRE.Phoenix.Watchdog.Feed(); if (_Battery.IsLow()) { _labelTitle.SetText("Low voltage"); _labelTitle.SetColor(DisplayModule.Color.Red); } else { _labelTitle.SetText("Controller"); _labelTitle.SetColor(DisplayModule.Color.Green); } /* Get gamepad values */ float LeftX = _Gamepad.GetAxis(0); float LeftY = _Gamepad.GetAxis(1); float RightY = _Gamepad.GetAxis(5); float RightX = _Gamepad.GetAxis(2); /* Deadband gamepad values */ CTRE.Phoenix.Util.Deadband(ref LeftX); CTRE.Phoenix.Util.Deadband(ref LeftY); CTRE.Phoenix.Util.Deadband(ref RightX); CTRE.Phoenix.Util.Deadband(ref RightY); /* Update Guages */ UpdateGauge(_leftX, LeftX); UpdateGauge(_leftY, LeftY); UpdateGauge(_rightX, RightX); UpdateGauge(_rightY, RightY); /* Update Crosshairs */ _leftCrossHair.SetPosition((int)(30 + 15 * LeftX), 100 + (int)(15 * LeftY)); _rightCrossHair.SetPosition((int)(100 + 15 * RightX), 100 + (int)(15 * RightY)); /* Get single button presses to control MotionState */ Boolean Button1 = _Gamepad.GetButton(1); Boolean Button2 = _Gamepad.GetButton(2); Boolean Button3 = _Gamepad.GetButton(3); Boolean Button4 = _Gamepad.GetButton(4); if (Button1 && !lastButton1) { MotionState = DriveState.MotionMagicTalon; } else if (Button2 && !lastButton2) { MotionState = DriveState.PercentOutputBoth; } else if (Button3 && !lastButton3) { MotionState = DriveState.MotionMagicVictor; } else if (Button4 && !lastbutton4) { MotionState = DriveState.SensorReset; } lastButton1 = Button1; lastButton2 = Button2; lastButton3 = Button3; lastbutton4 = Button4; /* Controls Motoroutput based on MotionState */ MotorDriveControl(-LeftY, MotionState); if (LeftX != 0 || LeftY != 0) { /** Left joystick in use, stop color cycling and give user control */ /* Grab brightness from the right joystick ([-1,1] + 1 * 0.5 => [0,1]) */ float Brightness = (RightY - 1f) * -0.5f; _Brightness = Brightness; /* Update LED strip with left joystick, right joystick, and brightness */ UpdateLedStrip(Brightness, LeftX, LeftY); } else { /** Left joystick not in use, start color cycling */ /* You can change the sequence in ColorSequencer.cs by ordering the premade colors or creating your own values */ colorDelay++; if (colorDelay >= 3) { _ColorSequencer.Process(); colorDelay = 0; } /* Go through a color sequence at half brightness when idle */ UpdateLedStrip(_Brightness, _ColorSequencer.Red, _ColorSequencer.Green, _ColorSequencer.Blue); } } else if (OperationState == LEDState.Pigeon) { if (_Battery.IsLow()) { _labelTitle.SetText("Low Batt..."); _labelTitle.SetColor(DisplayModule.Color.Red); } else { _labelTitle.SetText("Pigeon"); _labelTitle.SetColor(DisplayModule.Color.Magenta); } /* Check status of Pigeon to see if it is connected */ CTRE.Phoenix.Sensors.PigeonState _PigeonState = _Pigeon.GetState(); if (_PigeonState == CTRE.Phoenix.Sensors.PigeonState.Ready) { /** Pigeon connected, giver user tilt control */ /* Pull Yaw, Pitch, and Roll from Pigeon */ float[] YPR = new float[3]; _Pigeon.GetYawPitchRoll(YPR); float Pitch = YPR[1]; float Roll = YPR[2]; CTRE.Phoenix.Util.Cap(Pitch, 90); CTRE.Phoenix.Util.Cap(Roll, 90); float Brightness = 0.5f; /* Update LED strip */ UpdateLedStrip(Brightness, Pitch / 90, Roll / 90, true); } else { /* Pigeon is not Ready/Available, so flash us */ i++; if (i >= 100) { On = !On; i = 0; } /* Decide if strip is white or off */ if (On == true) { UpdateLedStrip(1, 255, 255, 255); /* White */ } else if (On == false) { UpdateLedStrip(1, 0, 0, 0); /* Off */ } } } int idx = GetFirstButton(_Gamepad); if (idx < 0) { _labelRow1.SetColor((DisplayModule.Color) 0xA0A0A0); // gray RGB _labelRow2.SetColor((DisplayModule.Color) 0xA0A0A0); // gray RGB _labelRow3.SetColor((DisplayModule.Color) 0xA0A0A0); // gray RGB float[] ypr = new float[3]; _Pigeon.GetYawPitchRoll(ypr); _labelRow1.SetText("Yaw:" + ypr[0]); _labelRow2.SetText("Pitch:" + ypr[1]); _labelRow3.SetText("Roll:" + ypr[2]); } else { switch (idx % 4) { case 0: _labelRow1.SetColor(DisplayModule.Color.Cyan); break; case 1: _labelRow1.SetColor(DisplayModule.Color.Green); break; case 2: _labelRow1.SetColor(DisplayModule.Color.Red); break; case 3: _labelRow1.SetColor(DisplayModule.Color.Yellow); break; } _labelRow1.SetText("Pressed Button " + idx); _labelRow2.SetText(""); _labelRow3.SetText(""); } /* Let he program to sleep for a little */ Thread.Sleep(5); } }
/// <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); CallAddressEx(Kernel.HalWriteSMBusValue, null, false, SMBusDevices.PIC, PICCommand.LedRegister, 0, State); CallAddressEx(Kernel.HalWriteSMBusValue, null, false, SMBusDevices.PIC, PICCommand.LedMode, 0, LEDSubCommand.Custom); Thread.Sleep(10); }
internal async void Activate() { this.LedState = await Source.GetValue(); Source.Enable(); }
public LEDMessage(Int16 pin, LEDState state) { Pin = pin; State = state; }