Skip to content

Commit

Permalink
v1.6 - New stopwatch features
Browse files Browse the repository at this point in the history
- `Clear file on reset` mode is awesome for making the text "Disappear" from the stream on reset
- 🆕 `Lap Mode` - Every press records the timestamp when pressed. A long press will reset the timer and copy all the laps to the clipboard (Ctrl-V to see them)
  • Loading branch information
BarRaider committed Sep 1, 2019
1 parent 5322cc3 commit 4a1dff2
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 45 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -3,6 +3,10 @@ A C# Stopwatch implementation for the Elgato Stream Deck device.

**Author's website and contact information:** [https://barraider.github.io](https://barraider.github.io)

## New in v1.6
- `Clear file on reset` mode is awesome for making the text "Disappear" from the stream on reset
- :new: `Lap Mode` - Every press records the timestamp when pressed. A long press will reset the timer and copy all the laps to the clipboard (`Ctrl-V` to see them)

## New in v1.5
- Time is written to a file of your choice so you can display the elapsed time on your stream
- File is now created immediately when you press the "Save" button
Expand Down
1 change: 1 addition & 0 deletions Stopwatch/Program.cs
Expand Up @@ -7,6 +7,7 @@ namespace Stopwatch
{
class Program
{
[STAThreadAttribute]
static void Main(string[] args)
{
// Uncomment this line of code to allow for debugging
Expand Down
24 changes: 21 additions & 3 deletions Stopwatch/PropertyInspector/Stopwatch/Index.html
Expand Up @@ -13,28 +13,46 @@
<details class="message info">
<summary>For feedback/suggestions contact me at <span class="linkspan" onclick="openWebsite()">https://BarRaider.github.io</span> </summary>
</details>
<details class="message">
<summary>Tip: Long press resets the stopwatch</summary>
</details>
<div class="sdpi-item" id="dvFileName">
<div class="sdpi-item-label">File Name</div>
<input class="sdpi-item-value sdProperty" placeholder="c:\temp\timer.txt" value="" id="fileName">
<button class="sdpi-item-value max20 minmargin" onclick="setSettings()">Save</button>
</div>
<div type="checkbox" class="sdpi-item" id="MultilineStopwatch">
<div type="checkbox" class="sdpi-item" id="dvClearFileOnReset">
<div class="sdpi-item-label">Clear on Reset</div>
<div class="sdpi-item-value">
<input id="clearFileOnReset" type="checkbox" value="" class="sdProperty sdCheckbox" oninput="setSettings()">
<label for="clearFileOnReset" class="sdpi-item-label"><span></span>Clear text file on reset</label>
</div>
</div>
<div type="checkbox" class="sdpi-item" id="dvMultilineStopwatch">
<div class="sdpi-item-label">Multiline</div>
<div class="sdpi-item-value">
<input id="multiline" type="checkbox" value="" class="sdProperty sdCheckbox" oninput="setSettings()">
<label for="multiline" class="sdpi-item-label"><span></span>3 different lines</label>
</div>
</div>
<div type="checkbox" class="sdpi-item" id="ClickResume">
<div type="checkbox" class="sdpi-item" id="dvClickResume">
<div class="sdpi-item-label">Resume on click</div>
<div class="sdpi-item-value">
<input id="resumeOnClick" type="checkbox" value="" class="sdProperty sdCheckbox" oninput="setSettings()">
<label for="resumeOnClick" class="sdpi-item-label"><span></span>Unpausing does not reset</label>
</div>
</div>
<div type="checkbox" class="sdpi-item" id="dvLapMode">
<div class="sdpi-item-label">Lap Mode</div>
<div class="sdpi-item-value">
<input id="lapMode" type="checkbox" value="" class="sdProperty sdCheckbox" oninput="setSettings()">
<label for="lapMode" class="sdpi-item-label"><span></span>&nbsp;</label>
</div>
</div>
<details class="message">
<summary>Long press the key to reset the stopwatch</summary>
<summary>In Lap mode, each press records a lap, Long press stops. After a long press, all laps are copied to clipboard</summary>
</details>

</div>
<script src="../sdtools.common.js"></script>
</body>
Expand Down
2 changes: 2 additions & 0 deletions Stopwatch/Stopwatch.csproj
Expand Up @@ -59,6 +59,7 @@
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -70,6 +71,7 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StopwatchManager.cs" />
<Compile Include="StopwatchSettings.cs" />
<Compile Include="StopwatchStatus.cs" />
<Compile Include="StopwatchTimerAction.cs" />
</ItemGroup>
Expand Down
51 changes: 36 additions & 15 deletions Stopwatch/StopwatchManager.cs
Expand Up @@ -56,19 +56,14 @@ private StopwatchManager()

#region Public Methods

public void StartStopwatch(string stopwatchId, bool resetOnStart, string fileName)
public void StartStopwatch(StopwatchSettings settings)
{
if (!dicCounters.ContainsKey(stopwatchId))
{
dicCounters[stopwatchId] = new StopwatchStatus();
}

dicCounters[stopwatchId].Filename = fileName;
if (resetOnStart)
InitializeStopwatch(settings);
if (settings.ResetOnStart)
{
ResetStopwatch(stopwatchId, fileName);
ResetStopwatch(settings);
}
dicCounters[stopwatchId].IsEnabled = true;
dicCounters[settings.StopwatchId].IsEnabled = true;
}

public void StopStopwatch(string stopwatchId)
Expand All @@ -79,14 +74,27 @@ public void StopStopwatch(string stopwatchId)
}
}

public void ResetStopwatch(string stopwatchId, string fileName)
public void ResetStopwatch(StopwatchSettings settings)
{
if (!dicCounters.ContainsKey(stopwatchId))
InitializeStopwatch(settings);
dicCounters[settings.StopwatchId].Counter = 0;
dicCounters[settings.StopwatchId].Laps.Clear();

// Clear file contents
if (settings.ClearFileOnReset)
{
dicCounters[stopwatchId] = new StopwatchStatus();
SaveTimerToFile(settings.FileName, "");
}
dicCounters[stopwatchId].Counter = 0;
dicCounters[stopwatchId].Filename = fileName;
}

public void RecordLap(string stopwatchId)
{
dicCounters[stopwatchId].Laps.Add(dicCounters[stopwatchId].Counter);
}

public List<long> GetLaps(string stopwatchId)
{
return dicCounters[stopwatchId].Laps;
}

public long GetStopwatchTime(string stopwatchId)
Expand Down Expand Up @@ -165,6 +173,19 @@ private void SaveTimerToFile(string fileName, string text)
}
}

private void InitializeStopwatch(StopwatchSettings settings)
{
string stopwatchId = settings.StopwatchId;
if (!dicCounters.ContainsKey(stopwatchId))
{
dicCounters[stopwatchId] = new StopwatchStatus();
}

dicCounters[stopwatchId].Filename = settings.FileName;
dicCounters[stopwatchId].ClearFileOnReset = settings.ClearFileOnReset;
dicCounters[stopwatchId].LapMode = settings.LapMode;
}

#endregion
}
}
21 changes: 21 additions & 0 deletions Stopwatch/StopwatchSettings.cs
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Stopwatch
{
internal class StopwatchSettings
{
internal string StopwatchId { get; set; }

internal bool ResetOnStart { get; set; }

internal bool ClearFileOnReset { get; set; }

internal bool LapMode { get; set; }

internal string FileName { get; set; }
}
}
8 changes: 8 additions & 0 deletions Stopwatch/StopwatchStatus.cs
Expand Up @@ -14,11 +14,19 @@ public class StopwatchStatus

public string Filename { get; set; }

public bool LapMode { get; set; }

public bool ClearFileOnReset { get; set; }

public List<long> Laps { get; set; }

public StopwatchStatus()
{
Counter = 0;
IsEnabled = false;
Filename = String.Empty;
ClearFileOnReset = false;
Laps = new List<long>();
}
}
}

0 comments on commit 4a1dff2

Please sign in to comment.