/// <summary> /// Sets all the locations in the current frame with a transparent color. /// </summary> public void ClearFrame() { foreach (var tuple in _data.GetData()) { tuple[CurrentFrame] = new RGBValue(Color.Transparent); } }
/// <summary> /// Returns next RGBValue to set when fading. Attention: sets values of newvalue (does not create new instanec) /// </summary> /// <param name="oldValue">Old Value to compare to</param> /// <param name="newValue">New Value to compare to and set</param> /// <returns>New set value / newInstance</returns> static private RGBValue GetNextFadeIteration(RGBValue oldValue, RGBValue newValue) { int rFactor = 1; int gFactor = 1; int bFactor = 1; byte temp_r = oldValue.R, temp_g = oldValue.G, temp_b = oldValue.B; // Look if decrement or increment if (oldValue.R > newValue.R) { rFactor = -1; } if (oldValue.G > newValue.G) { gFactor = -1; } if (oldValue.B > newValue.B) { bFactor = -1; } if (oldValue.R != newValue.R) { temp_r += (byte)rFactor; } if (oldValue.G != newValue.G) { temp_g += (byte)gFactor; } if (oldValue.B != newValue.B) { temp_b += (byte)bFactor; } return(new RGBValue(temp_r, temp_g, temp_b)); }
protected override RGBValue my_callback(RGBValue rgb_template, byte[] specArray, int min_slider, int max_slider, int min_trigger) { byte[] rgb = new byte[colors]; // Now convert these 16 lines (from 0 to 255) to 3 RGB-Colours (from 0 to 255) byte right = (byte)(max_slider + 1); byte left = (byte)min_slider; byte stepsPerColor = (byte)((right - left) / 3); for (byte rgbIndex = 0; rgbIndex < colors; rgbIndex++) { for (int i = left + (stepsPerColor * rgbIndex); i < left + (stepsPerColor * rgbIndex) + stepsPerColor; i++) { // Only take values that are higher than that value given by the vertical slider if (specArray[i] > min_trigger) { rgb[rgbIndex] += specArray[i]; } } rgb[rgbIndex] = (byte)(rgb[rgbIndex] / stepsPerColor); // Calculate Average } rgb_template.SetArray(rgb); return(rgb_template); }
public static EffectIntents ConvertToStaticArrayIntents(EffectIntents intents, TimeSpan duration, bool discrete = false) { if (discrete) { return(ConvertToDiscreteStaticArrayIntents(intents, duration)); } var interval = VixenSystem.DefaultUpdateTimeSpan; var intervals = (int)(duration.TotalMilliseconds / interval.TotalMilliseconds); EffectIntents effectIntents = new EffectIntents(); foreach (var effectIntent in intents) { RGBValue[] values = new RGBValue[intervals + 1]; for (int i = 0; i < intervals + 1; i++) { var currentTime = TimeSpan.FromMilliseconds(interval.TotalMilliseconds * i); var color = ProcessIntentNodes(effectIntent, currentTime); values[i] = new RGBValue(color); } effectIntents.AddIntentForElement(effectIntent.Key, new StaticArrayIntent <RGBValue>(interval, values, duration), TimeSpan.Zero); } return(effectIntents); }
/// <summary> /// Given one or more intent states, this will calculate a Color that is the combination of them all, in a 'max /// RGB component' fashion (ie. max of R, max of G, max of B). /// </summary> public static Color GetOpaqueRGBMaxColorForIntents(IIntentStates states) { byte R = 0; byte G = 0; byte B = 0; foreach (IIntentState intentState in states) { object value = intentState.GetValue(); if (value is LightingValue) { LightingValue lv = (LightingValue)value; if (lv.Intensity > 0) { Color intentColor = lv.FullColor; R = Math.Max(R, intentColor.R); G = Math.Max(G, intentColor.G); B = Math.Max(B, intentColor.B); } } else if (value is RGBValue) { RGBValue rv = (RGBValue)value; R = Math.Max(R, rv.R); G = Math.Max(G, rv.G); B = Math.Max(B, rv.B); } } return(Color.FromArgb(R, G, B)); }
public override void Handle(IIntentState <RGBValue> obj) { RGBValue value = obj.GetValue(); if (_mixColors) { float maxProportion = _getMaxProportion(value.Color); Color finalColor = Color.FromArgb((int)(_breakdownItem.Color.R * maxProportion), (int)(_breakdownItem.Color.G * maxProportion), (int)(_breakdownItem.Color.B * maxProportion)); _intentValue = new StaticIntentState <RGBValue>(obj, new RGBValue(finalColor)); } else { // if we're not mixing colors, we need to compare the input color against the filter color -- but only the // hue and saturation components; ignore the intensity. HSV inputColor = HSV.FromRGB(value.Color); if (Math.Abs(inputColor.H - _breakdownColorAsHSV.H) < Tolerance && Math.Abs(inputColor.S - _breakdownColorAsHSV.S) < Tolerance) { _intentValue = new StaticIntentState <RGBValue>(obj, value); } else { // TODO: return 'null', or some sort of empty intent state here instead. (null isn't handled well, and we don't have an 'empty' state class.) _intentValue = new StaticIntentState <RGBValue>(obj, new RGBValue(Color.Black)); } } }
public void ShowRGB(RGBValue rgb) { foreach (var output in _current_outputs) { output.ShowRGB(rgb); } }
/// <summary> /// Adds new RGB-LED to daisy-chain /// </summary> /// <param name="color"></param> public void AddLED(RGBValue startColor) { RGBset tLED = new RGBset(); tLED.SetRGBvalue(startColor); LEDs.Add(tLED); }
/// <summary> /// Add a frame and set the pixel to the given color. This cannot be used to update a pixel that /// has already been set. See update functions. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="c"></param> public void SetPixel(int x, int y, Color c) { RGBValue[] elementData; if (_data.TryGetAt(x, y, out elementData)) { elementData[CurrentFrame] = new RGBValue(c); } }
/// <summary> /// Sets LED intensity and color by generic RGBvalue of a certain LED in the daisy-chain /// </summary> /// <param name="index">Index of LED (starting with 0)</param> /// <param name="color">Color value to be set on chosen Index</param> public void SetLED(int index, RGBValue color) { if (index < LEDs.Count) { RGBset tLED = new RGBset(); tLED.SetRGBvalue(color); LEDs[index] = tLED; } }
/// <summary> /// Setter-method to set color and intensity of RGB-LED /// </summary> /// <param name="color"></param> public void SetRGBvalue(RGBValue color) { byte intens = (byte)(color.Intensity >> 3); byte red = color.Red; byte green = color.Green; byte blue = color.Blue; this.SetRGBvalue(intens, red, green, blue); }
static private RGBValue[] CreateNewRGBs(int amount_rgbs) { RGBValue[] new_rgbs = new RGBValue[amount_rgbs]; for (int led = 0; led < amount_rgbs; led++) { new_rgbs[led] = new RGBValue(); } return(new_rgbs); }
public void CopyValues(RGBValue rgb) { if (rgb != null) { this.R = rgb.R; this.G = rgb.G; this.B = rgb.B; } }
public override void Handle(IIntentState <RGBValue> obj) { RGBValue rgbValue = obj.GetValue(); HSV hsv = HSV.FromRGB(rgbValue.FullColor); double newIntensity = _curve.GetValue(rgbValue.Intensity * 100.0) / 100.0; hsv.V = newIntensity; _intentValue = new StaticIntentState <RGBValue>(new RGBValue(hsv.ToRGB())); }
protected override RGBValue[] my_callback(byte[] specArray, int min_slider, int max_slider, int min_trigger) // TODO TRIGGER!? { int left = (int)min_slider; int right = ((int)max_slider) + 1; int bass = 0; for (int i = left; i < right; i++) { bass += specArray[i]; } if (right - left > 0) { bass /= (right - left); } bassAvg[bass_avg_Index] = bass; bass_avg_Index = (bass_avg_Index + 1) % bassAvg.Length; int currBassAvg = 0; for (int i = 0; i < bassAvg.Length; i++) { currBassAvg += bassAvg[i]; } currBassAvg /= bassAvg.Length; bass = currBassAvg; int leds = 0; if (bass > 0 && min_trigger > 0) { leds = (int)(((float)(amount_rgbs * bass)) / ((float)min_trigger)); } /* if (bass > min_trigger) // TODO this is not possible anymore to automatically adjust trigger value * { * min_trigger = bass; * _triggerSlider.Value = bass; * } */ RGBValue emptyRGB = new RGBValue(); RGBValue setRGB = valueToRGB((byte)bass, min_trigger); for (int i = 0; i < rgbs.Length; i++) { if (i <= leds) { rgbs[i] = setRGB; } else { rgbs[i] = emptyRGB; } } return(rgbs); }
/// <summary> /// Methode zum einstellen des nächsten Farbwertes /// Der Farbwert wird per Kreuzblende sanft umgeschaltet /// </summary> /// <param name="myStripe"></param> public void SetSingleColor(libSharedProject.ProtolV1Commands.RGBstripeColor myStripe) { StripeColor.StripeSingleColor = myStripe.StripeSingleColor; RGBValue tLEDval = new RGBValue(StripeColor.StripeSingleColor.Red, StripeColor.StripeSingleColor.Green, StripeColor.StripeSingleColor.Blue, StripeColor.StripeSingleColor.Intensity); //ColorStripe.SetLED(0, tLEDval); //ColorStripe.UpdateLEDs(); StripePattern.InitColorChange(tLEDval); }
/// <summary> /// Get color of LED object /// </summary> /// <param name="index"></param> /// <param name="color"></param> public void GetLEDvalue(int index, out RGBValue color) { if (index < LEDs.Count) { LEDs[index].GetRGBvalue(out color); } else { color = new RGBValue(); } }
public void ShowRGB(RGBValue rgb) { _ser_mutex.WaitOne(); if (_enabled && rgb != null) { byte[] bytes = { System.Convert.ToByte('('), rgb.R, System.Convert.ToByte(','), rgb.G, System.Convert.ToByte(','), rgb.B, System.Convert.ToByte(')') }; _port.Write(bytes, 0, bytes.Length); } _ser_mutex.ReleaseMutex(); }
/// Constructor for the Thing class. The objective is to create a instance of an inanimate object. /// All parameters together defines this object. /// /// public Thing(long objId, string name, string tag, RGBValue color, CartesianPos pos, PhysicalState state, Material mat, string uri) { objectId = objId; this.name = name; tagInfo = tag; this.color = color; this.pos = pos; this.state = state; material = mat; uriId = uri; }
/// <summary> /// Fade multiple RGB-Values" /// </summary> /// <param name="oldValues">List of old values to fade from</param> /// <param name="newValues">List of new values to fade to</param> /// <param name="fade_time_ms">Time to sleep between each fade iteration</param> public void Fade(RGBValue[] oldValues, RGBValue[] newValues, int fade_time_ms = 50) { while (!RGBValue.Equals(oldValues, newValues) && _pauseEvent.WaitOne()) { for (int i = 0; i < newValues.Length; i++) { oldValues[i] = GetNextFadeIteration(oldValues[i], newValues[i]); } _rgbOutput.ShowRGBs(oldValues); Thread.Sleep(fade_time_ms); } }
/// <summary> /// Static Equal check between two given RGBValues /// </summary> /// <param name="val1">First object to compare to</param> /// <param name="val2">Second object to compare to</param> /// <returns></returns> public static bool StaticEquals(RGBValue val1, RGBValue val2) { if (val1 != null && val2 != null) { RGBValue that = (RGBValue)val2; if (val1.R == that.R && val1.G == that.G && val1.B == that.B) { return(true); } } return(false); }
public void ShowRGB(RGBValue rgb) { // Logitech works in percent (0-100), usual rgb is 0-255 double r = (double)rgb.R * rgb_to_perc; double g = (double)rgb.G * rgb_to_perc; double b = (double)rgb.B * rgb_to_perc; if (!NativeMethods.LogiLedSetLighting((int)r, (int)g, (int)b)) { throw new RGBOutputException("Did not work to set LogiLedSetLighting"); } }
private void StatusRefresh_Tick(ThreadPoolTimer timer) { int tempRed = (int)RGBValue.MaxValue * 50 / MaxSliderValue; int tempGreen = (int)RGBValue.MaxValue * 50 / MaxSliderValue; int tempBlue = (int)RGBValue.MaxValue * 0 / MaxSliderValue; int tempIntens = (int)RGBValue.MaxValue * 10 / MaxSliderValue; RGBValue newLEDval = new RGBValue { Red = (byte)tempRed, Green = (byte)tempGreen, Blue = (byte)tempBlue, Intensity = (byte)tempIntens }; StatusLED.SetLED(0, newLEDval); StatusLED.UpdateLEDs(); }
public override void Handle(ColorCommand obj) { if (CombinatorValue == null) { CombinatorValue = new _8BitCommand(RGBValue.GetGrayscaleLevel(obj.CommandValue)); } else { byte value1 = (CombinatorValue as _8BitCommand).CommandValue; byte value2 = RGBValue.GetGrayscaleLevel(obj.CommandValue); CombinatorValue = new _8BitCommand(Math.Max(value1, value2)); } }
protected override RGBValue my_callback(RGBValue rgb_template, byte[] specArray, int min_slider, int max_slider, int min_trigger) { bool with_avg = true; byte right_max = (byte)(max_slider + 1); byte left_max = (byte)min_slider; int diff = (right_max - left_max) / colors; byte peak_volume; // TODO slider too much to the right -> exception byte[] rgb = new byte[colors]; int left; int right; for (int i = 0; i < colors; i++) { left = left_max + (diff * i); right = left_max + (diff * (i + 1)); int maximumIndex = get_maximum_peak_index_range(left, right, specArray); if (with_avg) { // To avoid OutOfBounds if (maximumIndex <= left) { maximumIndex += 1; } else if (maximumIndex >= right) { maximumIndex -= 1; } // TODO maybe too much casting right now peak_volume = (byte)((int)((int)specArray[maximumIndex - 1] + (int)specArray[maximumIndex] + (int)specArray[maximumIndex + 1]) / 3); } else { peak_volume = specArray[maximumIndex]; } if (peak_volume < min_slider) { peak_volume = 0; } rgb[i] = peak_volume; } rgb_template.SetArray(rgb); return(rgb_template); }
/// <summary> /// Fade a single RGB-Value /// </summary> /// <param name="oldValues">Old value to fade from</param> /// <param name="newValues">New Values to fade to</param> /// <param name="fade_time_ms">Time to sleedpbetween each fade iteration</param> public void Fade(RGBValue oldValue, RGBValue newValue, int fade_time_ms = 50) { RGBValue lastRGB = new RGBValue(); lastRGB.CopyValues(oldValue); while (!lastRGB.Equals(newValue) && _pauseEvent.WaitOne()) { lastRGB = GetNextFadeIteration(lastRGB, newValue); _rgbOutput.ShowRGB(lastRGB); Thread.Sleep(fade_time_ms); } }
//static ProtocolV1Base ProtocolV1BaseObj = new ProtocolV1Base(); //static string ProtocolV1Marker = nameof(ProtocolV1BaseObj.MyType); //App_IO_Demo.IoDemoBoard ioDemoBoard = new App_IO_Demo.IoDemoBoard(); //libCore.IOevalBoard.IoDemoBoard ioDemoBoard = new libCore.IOevalBoard.IoDemoBoard(); //private void Server_NotifyMessageReceivedEvent(object sender, byte[] data) //{ // try // { // var obj = libSharedProject.ProtolV1Commands.ProtocolV1Base.ConvertJsonStingToObj(System.Text.Encoding.UTF8.GetString(data)); // if (obj != null) // { // if (obj.GetType().Equals(typeof(libSharedProject.ProtolV1Commands.IoDemoGetRequest))) // { // switch (((libSharedProject.ProtolV1Commands.IoDemoGetRequest)obj).Key) // { // case IoDemoGetRequest.CmdValue.Adc: // this.SendText(Newtonsoft.Json.JsonConvert.SerializeObject(ioDemoBoard.GetAdc())); // break; // case IoDemoGetRequest.CmdValue.Dac: // this.SendText(Newtonsoft.Json.JsonConvert.SerializeObject(ioDemoBoard.GetDac())); // break; // case IoDemoGetRequest.CmdValue.Gpio: // this.SendText(Newtonsoft.Json.JsonConvert.SerializeObject(ioDemoBoard.GetGpio())); // break; // case IoDemoGetRequest.CmdValue.Powerstate: // this.SendText(Newtonsoft.Json.JsonConvert.SerializeObject(ioDemoBoard.GetPowerState())); // break; // case IoDemoGetRequest.CmdValue.Rgb: // this.SendText(Newtonsoft.Json.JsonConvert.SerializeObject(ioDemoBoard.GetRgb())); // break; // case IoDemoGetRequest.CmdValue.State: // this.SendText(Newtonsoft.Json.JsonConvert.SerializeObject(ioDemoBoard.GetState())); // break; // default: // break; // } // } // else if (obj.GetType().Equals(typeof(IoDemoDac))) // { // ioDemoBoard.SetDac((IoDemoDac)obj); // } // else if (obj.GetType().Equals(typeof(IoDemoGpio))) // { // ioDemoBoard.SetGpio((IoDemoGpio)obj); // } // else if (obj.GetType().Equals(typeof(IoDemoPowerState))) // { // ioDemoBoard.SetPowerState((IoDemoPowerState)obj); // } // else if (obj.GetType().Equals(typeof(IoDemoState))) // { // ioDemoBoard.SetState((IoDemoState)obj); // } // else if (obj.GetType().Equals(typeof(IoDemoRgb))) // { // ioDemoBoard.SetRgb((IoDemoRgb)obj); // } // } // else // { // this.AddInfoTextLine("Text:" + System.Text.Encoding.UTF8.GetString(data) + " Data:" + Converters.ConvertByteArrayToHexString(data, " ")); // } // } // catch (Exception ex) // { // ShowMessageBox(ExceptionHandling.GetExceptionText(new System.Exception(string.Format("Exception In: {0}", CallerName()), ex))); // } //} //libShared.Interfaces.IEthernetAsync server; //public IEthernetAsync Server //{ // get // { // return server; // } // internal set // { // server = value; // } //} //string port = "27200"; //public string Port //{ // get { return port; } // set // { // port = value; // this.OnPropertyChanged(); // } //} //string host = "localhost"; //public string Host //{ // get { return host; } // set // { // host = value; // this.OnPropertyChanged(); // } //} //ObservableCollection<string> hostNames = new ObservableCollection<string>(); //public ObservableCollection<string> HostNames //{ // get // { // return hostNames; // } // set // { // hostNames = value; // } //} //private string valueSendText = "Test Cmd"; //public string ValueSendText //{ // get { return valueSendText; } // set // { // valueSendText = value; // this.OnPropertyChanged(); // } //} //ObservableCollection<byte> valueSendData = new ObservableCollection<byte>(); //public ObservableCollection<byte> ValueSendData //{ // get { return valueSendData; } // set // { // valueSendData = value; // this.OnPropertyChanged(); // } //} //public void SendText(string text) //{ // try // { // if (this.Server != null) // { // this.Server.SendText(text); // } // else // { // this.AddInfoTextLine("Server Not Running"); // } // } // catch (Exception ex) // { // //AddInfoTextLine(ExceptionHandling.GetExceptionText(new System.Exception(string.Format("Exception In: {0}", CallerName()), ex))); // } //} //public void SendData(byte[] data) //{ // try // { // if (this.Server != null) // { // this.Server.SendData(data); // } // else // { // this.AddInfoTextLine("Server Not Running"); // } // } // catch (Exception ex) // { // //AddInfoTextLine(ExceptionHandling.GetExceptionText(new System.Exception(string.Format("Exception In: {0}", CallerName()), ex))); // } //} #endregion #region Debug-Ausgaben ///// <summary> ///// Fühgt der Infotext Liste einen weiteren Eintrag hinzu ///// </summary> //public void AddInfoTextLine(string line) //{ // this.AddInfoTextLine(null, line); //} ///// <summary> ///// ühgt der Infotext Liste einen weiteren Eintrag hinzu ///// </summary> //public async void AddInfoTextLine(object sender, string line) //{ // //try // //{ // // //await this.dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => // // //{ // // // if (this.InfoText.Length > 1000) // // // { // // // this.InfoText = line + Environment.NewLine; // // // } // // // else // // // { // // // this.InfoText += line + Environment.NewLine; // // // } // // // Scoll1.ChangeView(null, Scoll1.ScrollableHeight, null); // // //this.InfoTextList.Add(line); // // //}); // //} // //catch (Exception ex) // //{ // // //ShowMessageBox(ExceptionHandling.GetExceptionText(new System.Exception(string.Format("Exception In: {0}", CallerName()), ex))); // //} //} #endregion private void btn_SetRGBvalues(object sender, RoutedEventArgs e) { //@todo hier auf Binding setzten int tempRed = (int)RGBValue.MaxValue * (int)RedChannel.Value / MaxSliderValue; int tempGreen = (int)RGBValue.MaxValue * (int)GreenChannel.Value / MaxSliderValue; int tempBlue = (int)RGBValue.MaxValue * (int)BlueChannel.Value / MaxSliderValue; int tempIntens = (int)RGBValue.MaxValue * (int)IntensitySet.Value / MaxSliderValue; RGBValue newLEDval = new RGBValue { Red = (byte)tempRed, Green = (byte)tempGreen, Blue = (byte)tempBlue, Intensity = (byte)tempIntens }; StatusLED.SetLED(0, newLEDval); StatusLED.UpdateLEDs(); }
public void ShowRGB(RGBValue rgb) { if (_lastColor == null) { _lastColor = new CorsairColor(rgb.R, rgb.G, rgb.B); _headset.Brush = new SolidColorBrush(_lastColor); } else { // Don't need to instantiate it again and again _lastColor.R = rgb.R; _lastColor.G = rgb.G; _lastColor.B = rgb.B; } _headset.Update(); }
/// <summary> /// Static Equal check between list of RGBValues /// </summary> /// <param name="val1"></param> /// <param name="val2"></param> /// <returns></returns> public static bool Equals(RGBValue[] val1, RGBValue[] val2) { if (val1 == null || val2 == null || val1.Length != val2.Length) { return(false); } for (int i = 0; i < val2.Length; i++) { if (!RGBValue.StaticEquals(val1[i], val2[i])) { return(false); } } return(true); }
void ProcessIncomingString(string incoming) { // Echo zurückschicken this.SendText("Received :" + incoming); // Daten verarbeiten byte newIndensitiy = 255; byte newRed = 0; byte newGreen = 0; byte newBlue = 0; int Iidx = incoming.IndexOf('I'); if (Iidx >= 0) { newIndensitiy = Convert.ToByte(incoming.Substring(Iidx, 3)); this.AddInfoTextLine("New intensity : " + newIndensitiy); } Iidx = incoming.IndexOf('R'); if (Iidx >= 0) { newRed = Convert.ToByte(incoming.Substring(Iidx, 3)); this.AddInfoTextLine("New Red : " + newRed); } Iidx = incoming.IndexOf('G'); if (Iidx >= 0) { newGreen = Convert.ToByte(incoming.Substring(Iidx, 3)); this.AddInfoTextLine("New Green : " + newGreen); } Iidx = incoming.IndexOf('B'); if (Iidx >= 0) { newBlue = Convert.ToByte(incoming.Substring(Iidx, 3)); this.AddInfoTextLine("New Blue : " + newBlue); } RGBValue tempLEDobj = new RGBValue(); tempLEDobj.Intensity = newIndensitiy; tempLEDobj.Red = newRed; tempLEDobj.Green = newGreen; tempLEDobj.Blue = newBlue; StripePattern.InitColorChange(tempLEDobj); this.SendText("Configuration done"); }