public Module(bool enableLED = true, bool enableBuzzer = true) { this.LEDSwitch = enableLED; this.BuzzerSwitch = enableBuzzer; ThreadPool.QueueUserWorkItem(new WaitCallback((o) => { IndicatorStatus lastStatus = this.Status; IndicatorTask lastTask = new IndicatorTask(null); while (_switch) { while (this._status_queue.Count > 1 && this._status_queue.Peek() == lastStatus) { this._status_queue.Dequeue(); } if (this.Status != lastStatus) { var task = CreateTaskFromStatus(this.Status); task.Run(); lastStatus = this.Status; lastTask = task; } else if (lastTask.CircleAction != null) { lastTask.Run(); } else { Hardware.Library.Delay(_SHORT_TOTAL_DELAY); } } })); }
/// <summary> /// Updates the current indicator status for a specified amount of time and then sets back the previous status /// </summary> /// <param name="status">Indicator status</param> /// <param name="ttl">Indicator lifetime</param> internal void SetTimedIndicator(IndicatorStatus status, int ttl = 5_000) { SetIndicator(status); new Thread(() => { Thread.Sleep(ttl); SetIndicator(IndicatorStatus.Idle); }).Start(); }
/// <summary> /// Updates the current indicator status/animation frame /// </summary> /// <param name="status">Indicator status</param> internal void SetIndicator(IndicatorStatus status) { if (status != this.currentStatus && this.isIndicatorAnimated) { StopIndicatorAnimation(); } NotifyIcon.Icon = this.iconRenderer.RenderFrame(this.currentStatus = status); }
/// <summary> /// Animates the indicator with the specified status until another indicator is set /// </summary> /// <param name="status">Indicator status</param> /// <param name="frameTtl">Animation frame lifetime</param> internal void AnimateIndicator(IndicatorStatus status, int frameTtl = 60) { StopIndicatorAnimation(); SetIndicator(status); this.isIndicatorAnimated = true; (this.indicatorAnimationThread = new Thread(() => { while (this.isIndicatorAnimated) { Thread.Sleep(frameTtl); SetIndicator(status); } })).Start(); }
static void PerformIndicatorTest(IndicatorStatus indicatorStatus, DelcomIndicatorState expectedIndicatorState) { //arrange var mockLight = MockRepository.GenerateMock<IDelcomLight>(); mockLight.Expect(m => m.ChangeIndicator(expectedIndicatorState)).Repeat.Once(); var stubStatusSource = MockRepository.GenerateStub<IBuildStatusSource>(); stubStatusSource.Stub(s => s.Status).Return(indicatorStatus); var indicator = new DelcomUsbLightBuildIndicator(mockLight); //act indicator.ShowIndicator(stubStatusSource); //assert mockLight.VerifyAllExpectations(); }
/// <inheritdoc /> /// <summary> /// Renders a single tray icon frame /// </summary> /// <param name="status">Icon status</param> /// <returns>An <see cref="T:System.Drawing.Icon" /> instance</returns> public Icon RenderFrame(IndicatorStatus status) { switch (status) { case IndicatorStatus.Idle: // frame 0 - return application icon case IndicatorStatus.Recording: case IndicatorStatus.Success: return(this.indicators[0]); case IndicatorStatus.Warning: // frame 1 - return application icon with a warning badge return(this.indicators[1]); case IndicatorStatus.Progress: // frames [2..21] (18 frames) - increment the animation frame and return the icon return(this.indicators[2 + (this.counter = (byte)(++this.counter % 18))]); default: // unrecognized icon status throw new ArgumentOutOfRangeException(nameof(status), status, null); } }
/// <summary> /// Initializes a new instance of the <see cref="IndicatorResult"/> class /// </summary> /// <param name="value">The value output by the indicator</param> /// <param name="status">The status returned by the indicator</param> public IndicatorResult(decimal value, IndicatorStatus status = IndicatorStatus.Success) { Value = value; Status = status; }
/// <summary> /// Initializes a new instance of the <see cref="IndicatorResult"/> class /// </summary> /// <param name="value">The value output by the indicator</param> /// <param name="status">The status returned by the indicator</param> public IndicatorResult(DoubleArray value, IndicatorStatus status = IndicatorStatus.Success) { Value = value; Status = status; }
/// <summary> /// Status Indicator /// </summary> /// <param name="commandType"> Command Type </param> /// <param name="indicatorType"> Indicator Type </param> /// <param name="indicatorStatus"> Indicator Status</param> /// <returns></returns> public string Indicator(CommandType commandType, IndicatorType indicatorType, IndicatorStatus indicatorStatus) { return(CommandAssembly(Supplier, commandType.ToString().Equals("Finish") ? "FIN" : "SET", string.Format("{0}_{1}", indicatorType.ToString(), indicatorStatus.ToString()))); }
static public async void Toggle(IndicatorStatus ToggleIndicator) { OutputArgument OutArg = new OutputArgument(); HasTrailer = Function.Call <bool>(Hash.GET_VEHICLE_TRAILER_VEHICLE, Game.PlayerPed.CurrentVehicle.Handle, OutArg); Trailer = new CitizenFX.Core.Vehicle(OutArg.GetResult <int>()); Log.ToChat($"{HasTrailer} {OutArg.GetResult<int>()}"); if (ToggleIndicator == IndicatorStatus.Hazards) { if (IndicatorStatus == IndicatorStatus.Left || IndicatorStatus == IndicatorStatus.Right) { IndicatorStatus = IndicatorStatus.Hazards; SetIndicatorCombination(true, true); } else if (IndicatorStatus == IndicatorStatus.Hazards) { SetIndicatorCombination(false, false); IndicatorStatus = IndicatorStatus.None; } else { IndicatorStatus = IndicatorStatus.Hazards; SetIndicatorCombination(true, true); } return; } if (IndicatorStatus != IndicatorStatus.None) { SetIndicatorCombination(false, false); if (IndicatorStatus == ToggleIndicator) { IndicatorStatus = IndicatorStatus.None; return; } IndicatorStatus = IndicatorStatus.None; } if (ToggleIndicator != IndicatorStatus.None) { if (ToggleIndicator == IndicatorStatus.Left) { SetIndicatorCombination(true, false); } else if (ToggleIndicator == IndicatorStatus.Right) { SetIndicatorCombination(false, true); } IndicatorStatus = ToggleIndicator; // We don't want to await this Task.Factory.StartNew(async() => { float heading = Game.PlayerPed.CurrentVehicle.Heading; while (Math.Abs(heading - Game.PlayerPed.CurrentVehicle.Heading) < 55) { await BaseScript.Delay(250); } // If indicator status is unchanged disable signals now, otherwise do nothing if (IndicatorStatus == ToggleIndicator) { IndicatorStatus = IndicatorStatus.None; } }); while (IndicatorStatus != IndicatorStatus.None) { await BaseScript.Delay(50); } SetIndicatorCombination(false, false); } }