diff --git a/GLedApiDotNet/LedSettings/FlashLedSetting.cs b/GLedApiDotNet/LedSettings/FlashLedSetting.cs
index 1ac79c3..0938d87 100644
--- a/GLedApiDotNet/LedSettings/FlashLedSetting.cs
+++ b/GLedApiDotNet/LedSettings/FlashLedSetting.cs
@@ -68,5 +68,16 @@ public FlashLedSetting(Color color, byte maxBrightness, byte minBrightness, Time
CheckRanges();
}
+
+ public TimeSpan OnOffTime => TimeSpan0;
+ public TimeSpan IntervalTime => TimeSpan1;
+ public TimeSpan CycleTime => TimeSpan2;
+ public byte Count => CtrlValue0;
+
+ public override string ToString()
+ {
+ return string.Format("Flash: Color={0}, MaxBrightness={1}, MinBrightness={2}, OnOffTime={3}s, IntervalTime={4}s, CycleTime={5}s, Count={6}",
+ Color, MaxBrightness, MinBrightness, OnOffTime.TotalSeconds, IntervalTime.TotalSeconds, CycleTime.TotalSeconds, Count);
+ }
}
}
diff --git a/RGBFusionTool/Application.cs b/RGBFusionTool/Application.cs
index 12f268a..763dd7c 100644
--- a/RGBFusionTool/Application.cs
+++ b/RGBFusionTool/Application.cs
@@ -102,6 +102,7 @@ public Application(IRGBFusionMotherboard motherboardLEDs, TextWriter stdout, Tex
new StaticColorArgParser(),
new ColorCycleArgParser(),
new PulseArgParser(),
+ new FlashArgParser(),
new OffArgParser()
};
diff --git a/RGBFusionTool/ArgParsers/FlashArgParser.cs b/RGBFusionTool/ArgParsers/FlashArgParser.cs
new file mode 100644
index 0000000..c4035ae
--- /dev/null
+++ b/RGBFusionTool/ArgParsers/FlashArgParser.cs
@@ -0,0 +1,89 @@
+// Copyright (C) 2018 Tyler Szabo
+//
+// This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along with this program. If not, see .
+
+using GLedApiDotNet.LedSettings;
+using Mono.Options;
+using System;
+using System.Collections.Generic;
+
+namespace RGBFusionTool.ArgParsers
+{
+ class FlashArgParser : LedSettingArgParser
+ {
+ private class FlashArgParserContext : ArgParserContext
+ {
+ public byte MaxBrightness { get; set; }
+ public byte MinBrightness { get; set; }
+ public double OnOff { get; set; }
+ public double Interval { get; set; }
+ public double Cycle { get; set; }
+ public byte Count { get; set; }
+
+ private string colorString;
+ public string ColorString
+ {
+ get => colorString; set
+ {
+ Valid = true;
+ colorString = value;
+ }
+ }
+
+ protected override void SetDefaults()
+ {
+ colorString = null;
+ MaxBrightness = 100;
+ MinBrightness = 0;
+ OnOff = 0.25;
+ Interval = 1;
+ Cycle = 5;
+ Count = 3;
+ }
+ }
+
+ FlashArgParserContext context;
+
+ private FlashArgParser(FlashArgParserContext context) : base(context)
+ {
+ this.context = context;
+ }
+
+ public FlashArgParser() : this(new FlashArgParserContext ())
+ {
+ RequiredOptions = new OptionSet
+ {
+ { "Flash" },
+ { "flash=", "flash color {COLOR}", v => context.ColorString = v },
+ };
+ ExtraOptions = new OptionSet
+ {
+ { "maxbrightness=", "(optional) max brightness (0-100)", (byte b) => context.MaxBrightness = b },
+ { "minbrightness=", "(optional) min brightness (0-100)", (byte b) => context.MinBrightness = b },
+ { "time=", "(optional) {SECONDS} to flash for", (double d) => context.OnOff = d },
+ { "interval=", "(optional) {SECONDS} in a flash interval", (double d) => context.Interval = d },
+ { "flashcycle=", "(optional) {SECONDS} in a cycle", (double d) => context.Cycle = d },
+ { "count=", "(optional) flash {COUNT} intervals in a cycle", (byte b) => context.Count = b },
+ { "<>", v => throw new InvalidOperationException(string.Format("Unsupported option {0}", v)) }
+ };
+ }
+
+ public override LedSetting TryParse(IEnumerable args)
+ {
+ if (!PopulateContext(args))
+ {
+ return null;
+ }
+
+ TimeSpan onoff = TimeSpan.FromSeconds(context.OnOff);
+ TimeSpan interval = TimeSpan.FromSeconds(context.Interval);
+ TimeSpan cycle = TimeSpan.FromSeconds(context.Cycle);
+
+ return new FlashLedSetting(GetColor(context.ColorString), context.MaxBrightness, context.MinBrightness, onoff, interval, cycle, context.Count);
+ }
+ }
+}
diff --git a/RGBFusionTool/RGBFusionTool.csproj b/RGBFusionTool/RGBFusionTool.csproj
index 990bd9b..0bcb019 100644
--- a/RGBFusionTool/RGBFusionTool.csproj
+++ b/RGBFusionTool/RGBFusionTool.csproj
@@ -77,6 +77,7 @@ You should have received a copy of the GNU General Public License along with thi
+
diff --git a/RGBFusionToolTests/RGBFusionToolExeTests.cs b/RGBFusionToolTests/RGBFusionToolExeTests.cs
index bca11f8..6a10ccc 100644
--- a/RGBFusionToolTests/RGBFusionToolExeTests.cs
+++ b/RGBFusionToolTests/RGBFusionToolExeTests.cs
@@ -72,6 +72,7 @@ public void Help(string[] args)
"static",
"colorcycle",
"pulse",
+ "flash",
"off",
"verbose",
@@ -381,6 +382,41 @@ public void Pulse_verbose(string[] args)
GLedApiv1_0_0Mock.DEFAULT_MAXDIVISIONS);
}
+ [DataRow(new string[] { "--flash=Blue", "--maxbrightness=100", "--minbrightness=10", "--time=0.3", "--interval=1", "--flashcycle=4", "--count=3" }, DisplayName = "--flash=Blue --maxbrightness=100 --minbrightness=10 --time=0.3 --interval=1 --flashcycle=4 --count=3")]
+ [DataTestMethod]
+ public void Flash(string[] args)
+ {
+ rgbFusionTool.Main(args);
+
+ StringAssert.DoesNotMatch(stderr.ToString(), ANY, "Expect stderr is empty");
+ StringAssert.DoesNotMatch(stdout.ToString(), ANY, "Expect stdout is empty");
+
+ TestHelper.AssertAllLeds(mock,
+ GLedApiDotNetTests.Tests.LedSettingTests.SettingByteArrays.FlashC,
+ GLedApiv1_0_0Mock.DEFAULT_MAXDIVISIONS);
+ }
+
+ [DataRow(new string[] { "--verbose", "--flash=Blue", "--maxbrightness=100", "--minbrightness=10", "--time=0.3", "--interval=1", "--flashcycle=4", "--count=3" }, DisplayName = "--verbose --flash=Blue --maxbrightness=100 --minbrightness=10 --time=0.3 --interval=1 --flashcycle=4 --count=3")]
+ [DataTestMethod]
+ public void Flash_verbose(string[] args)
+ {
+ rgbFusionTool.Main(args);
+
+ StringAssert.DoesNotMatch(stderr.ToString(), ANY, "Expect stderr is empty");
+ StringAssert.Matches(stdout.ToString(), new Regex("\\bflash\\b", RegexOptions.IgnoreCase),"Expect stdout includes flash config");
+ StringAssert.Matches(stdout.ToString(), new Regex("\\bblue\\b", RegexOptions.IgnoreCase), "Expect stdout includes color");
+ StringAssert.Matches(stdout.ToString(), new Regex("\\b100\\b", RegexOptions.IgnoreCase),"Expect stdout includes max brightness");
+ StringAssert.Matches(stdout.ToString(), new Regex("\\b10\\b", RegexOptions.IgnoreCase),"Expect stdout includes min brightness");
+ StringAssert.Matches(stdout.ToString(), new Regex("\\b0?\\.3(0*)?\\s?s\\b", RegexOptions.IgnoreCase),"Expect stdout includes on/off time");
+ StringAssert.Matches(stdout.ToString(), new Regex("\\b1(\\.0*)?\\s?s\\b", RegexOptions.IgnoreCase),"Expect stdout includes interval time");
+ StringAssert.Matches(stdout.ToString(), new Regex("\\b4(\\.0*)?\\s?s\\b", RegexOptions.IgnoreCase),"Expect stdout includes cycle time");
+ StringAssert.Matches(stdout.ToString(), new Regex("\\b2\\b", RegexOptions.IgnoreCase),"Expect stdout includes flash count");
+
+ TestHelper.AssertAllLeds(mock,
+ GLedApiDotNetTests.Tests.LedSettingTests.SettingByteArrays.FlashC,
+ GLedApiv1_0_0Mock.DEFAULT_MAXDIVISIONS);
+ }
+
[DataRow(new string[] { "--off" }, DisplayName = "--off")]
[DataTestMethod]
public void Off(string[] args)