// ---------------------------------------------------------------------------------------- // pattern handling // /// <summary> // Play a color pattern. // Can restart if already playing, or just leave be an already playing pattern // /// </summary> /// <param name="pname">pattern name / color code to play</param> /// <returns> true if pattern was played, false if not</returns> public Boolean playPattern(string pname) { Log("playPattern:" + pname); if (pname == null) { return(false); } // if rgb hex code, just do it if (pname.StartsWith("#")) { Color c = ColorTranslator.FromHtml(pname); fadeToRGB(0.1, c); return(true); } // otherwise treat it as a color pattern name Blink1Pattern patt = null; if (patterns.TryGetValue(pname, out patt)) { patt.blink1Server = this; // just in case patt.play(); return(true); } return(false); }
// /blink1/pattern/add -- Add color pattern to color pattern list static string Ublink1PatternAdd(HttpRequest request, Blink1Server blink1Server) { string pname = request.Query.Get("pname"); string patternstr = request.Query.Get("pattern"); string statusstr = "pattern add"; Blink1Pattern pattern = null; if (pname != null && patternstr != null) { pattern = new Blink1Pattern(pname); Boolean goodpattern = pattern.parsePatternStr(patternstr); if (goodpattern) { blink1Server.patterns[pname] = pattern; // NOTE: this replaces pattern if already exists } else { statusstr = "error: pattern badly formatted"; } } else { statusstr = "error: need 'pname' and 'pattern' (e.g. '2,#ff00ff,0.5,#00ff00,0.5') argument"; } blink1Server.saveSettings(); Dictionary <string, object> result = new Dictionary <string, object>(); result.Add("status", statusstr); result.Add("pattern", pattern); return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings)); }
/// <summary> /// Stop a playing pattern /// </summary> /// <param name="pname"></param> /// <returns></returns> public Boolean stopPattern(string pname) { if (pname == null) { return(false); } Blink1Pattern patt = null; if (patterns.TryGetValue(pname, out patt)) { patt.stop(); return(true); } return(false); }
// /blink1/pattern/stop -- Stop a pattern playback for a given pattern static string Ublink1PatternStop(HttpRequest request, Blink1Server blink1Server) { string pname = request.Query.Get("pname"); string statusstr = "no pattern by that name"; if (pname != null) { Blink1Pattern patt = null; if (blink1Server.patterns.TryGetValue(pname, out patt)) { patt.stop(); statusstr = "pattern '" + pname + "' stopped"; } } Dictionary <string, object> result = new Dictionary <string, object>(); result.Add("status", statusstr); return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings)); }
// /blink1/pattern/del -- Remove color pattern from color pattern list static string Ublink1PatternDel(HttpRequest request, Blink1Server blink1Server) { string pname = request.Query.Get("pname"); string statusstr = "no pattern by that name"; Blink1Pattern patt = null; if (pname != null) { patt = blink1Server.patterns[pname]; patt.stop(); blink1Server.patterns.Remove(pname); statusstr = "pattern '" + pname + "' removed"; } blink1Server.saveSettings(); Dictionary <string, object> result = new Dictionary <string, object>(); result.Add("status", statusstr); return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings)); }
// /blink1/pattern/add -- Add color pattern to color pattern list static string Ublink1PatternAdd(HttpRequest request, Blink1Server blink1Server) { string pname = request.Query.Get("pname"); string patternstr = request.Query.Get("pattern"); string statusstr = "pattern add"; Blink1Pattern pattern = null; if (pname != null && patternstr != null) { pattern = new Blink1Pattern(pname); Boolean goodpattern = pattern.parsePatternStr(patternstr); if (goodpattern) { blink1Server.patterns[pname] = pattern; // NOTE: this replaces pattern if already exists } else { statusstr = "error: pattern badly formatted"; } } else { statusstr = "error: need 'pname' and 'pattern' (e.g. '2,#ff00ff,0.5,#00ff00,0.5') argument"; } blink1Server.saveSettings(); Dictionary<string, object> result = new Dictionary<string, object>(); result.Add("status", statusstr); result.Add("pattern", pattern); return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings); }