Skip to content

Commit

Permalink
Added SpinUp offsets for each fan speed, TrayIcon tweaks, 0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nicko88 committed Apr 4, 2022
1 parent 01676cc commit adde710
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 96 deletions.
19 changes: 15 additions & 4 deletions FanTrayIcon/TrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public TrayIcon(string IP)
ShowWindow(handle, SW_HIDE);

trayIcon = new NotifyIcon();
trayIcon.Text = "HTFanControl";
trayIcon.Text = "HTFanControl (Right Click For Menu)";
trayIcon.Icon = new Icon(GetType(), "htfancontrol.ico");
trayIcon.Click += new EventHandler(trayIcon_Click);
trayIcon.MouseClick += new MouseEventHandler(trayIcon_MouseClick);
trayIcon.DoubleClick += new EventHandler(trayIcon_DoubleClick);

ToolStripMenuItem itemWebUI = new ToolStripMenuItem();
itemWebUI.Text = "Open Web UI";
Expand Down Expand Up @@ -76,12 +77,22 @@ public TrayIcon(string IP)
Application.Run();
}

private void trayIcon_Click(object sender, EventArgs e)
private void trayIcon_MouseClick(object sender, MouseEventArgs e)
{
Point position = Cursor.Position;
position.X -= 253;
position.Y -= 100;

trayIcon.ContextMenuStrip.Show(position);
if (e.Button == MouseButtons.Right)
{
trayIcon.ContextMenuStrip.Show(position);
}
}

private void trayIcon_DoubleClick(object sender, EventArgs e)
{
trayIcon.ContextMenuStrip.Hide();
itemWebUI_Click(sender, e);
}

private void itemWebUI_Click(object sender, EventArgs e)
Expand Down
12 changes: 6 additions & 6 deletions HTFanControl/HTFanControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<ApplicationIcon>htfancontrol.ico</ApplicationIcon>
<Configurations>Debug;ReleaseWin;ReleaseLinux</Configurations>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<AssemblyVersion>0.3.0.0</AssemblyVersion>
<FileVersion>0.3.0.0</FileVersion>
<Version>0.3.0</Version>
<AssemblyVersion>0.3.1.0</AssemblyVersion>
<FileVersion>0.3.1.0</FileVersion>
<Version>0.3.1</Version>
<Description>4D Theater Wind Effect - DIY Home Theater Project</Description>
<Copyright>nicko88</Copyright>
<Authors>nicko88</Authors>
Expand Down Expand Up @@ -76,9 +76,9 @@
<PackageReference Include="HtmlAgilityPack" Version="1.11.42" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="MQTTnet" Version="3.1.2" />
<PackageReference Include="OpenTK.OpenAL" Version="4.6.7" />
<PackageReference Include="SoundFingerprinting" Version="8.4.0" />
<PackageReference Include="SoundFingerprinting.Emy" Version="8.3.0" />
<PackageReference Include="OpenTK.OpenAL" Version="4.7.1" />
<PackageReference Include="SoundFingerprinting" Version="8.5.1" />
<PackageReference Include="SoundFingerprinting.Emy" Version="8.5.1" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWin|AnyCPU' Or '$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
68 changes: 41 additions & 27 deletions HTFanControl/Main/HTFanControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,54 +286,44 @@ private string GetWindtrackFilePath(string fileName, string filePath)
{
string validFilePath = null;

//look for windtrack .txt in tmp folder
//LEGACY look in windtrack folder for .txt
try
{
if (File.Exists(Path.Combine(ConfigHelper._rootPath, "tmp", fileName + ".txt")))
if (string.IsNullOrEmpty(validFilePath) && File.Exists(Path.Combine(ConfigHelper._rootPath, "windtracks", fileName + ".txt")))
{
validFilePath = Path.Combine(ConfigHelper._rootPath, "tmp", fileName + ".txt");
validFilePath = Path.Combine(ConfigHelper._rootPath, "windtracks", fileName + ".txt");
}
}
catch { }

//look for windtrack .zip archive in windtracks folder
//LEGACY check the active video's folder for .txt
try
{
if (string.IsNullOrEmpty(validFilePath) && File.Exists(Path.Combine(ConfigHelper._rootPath, "windtracks", fileName + ".zip")))
if (string.IsNullOrEmpty(validFilePath) && File.Exists(Path.Combine(filePath, fileName + ".txt")))
{
ExtractWindtrack(Path.Combine(ConfigHelper._rootPath, "windtracks", fileName + ".zip"), false);
validFilePath = Path.Combine(ConfigHelper._rootPath, "tmp", fileName + ".txt");
validFilePath = Path.Combine(filePath, fileName + ".txt");
}
}
catch { }

//if not found, look in the active video's folder
//look for windtrack .zip archive in windtracks folder
try
{
if (string.IsNullOrEmpty(validFilePath) && File.Exists(Path.Combine(filePath, fileName + ".zip")))
if (string.IsNullOrEmpty(validFilePath) && File.Exists(Path.Combine(ConfigHelper._rootPath, "windtracks", fileName + ".zip")))
{
ExtractWindtrack(Path.Combine(filePath, fileName + ".zip"), false);
ExtractWindtrack(Path.Combine(ConfigHelper._rootPath, "windtracks", fileName + ".zip"), false);
validFilePath = Path.Combine(ConfigHelper._rootPath, "tmp", fileName + ".txt");
}
}
catch { }

//LEGACY look in windtrack folder
try
{
if (string.IsNullOrEmpty(validFilePath) && File.Exists(Path.Combine(ConfigHelper._rootPath, "windtracks", fileName + ".txt")))
{
validFilePath = Path.Combine(ConfigHelper._rootPath, "windtracks", fileName + ".txt");
}
}
catch { }

//check the active video's folder
//if not found, look in the active video's folder
try
{
if (string.IsNullOrEmpty(validFilePath) && File.Exists(Path.Combine(filePath, fileName + ".txt")))
if (string.IsNullOrEmpty(validFilePath) && File.Exists(Path.Combine(filePath, fileName + ".zip")))
{
validFilePath = Path.Combine(filePath, fileName + ".txt");
ExtractWindtrack(Path.Combine(filePath, fileName + ".zip"), false);
validFilePath = Path.Combine(ConfigHelper._rootPath, "tmp", fileName + ".txt");
}
}
catch { }
Expand Down Expand Up @@ -451,7 +441,22 @@ private void LoadVideoTimecodes(string fileName, string filePath)
//if command comes after OFF, add spinup offset
if (lastCmd.Contains("OFF"))
{
timeCode -= _settings.SpinupOffsetMS;
if(lineData[1].Contains("ECO"))
{
timeCode -= _settings.ECOSpinupOffsetMS;
}
else if (lineData[1].Contains("LOW"))
{
timeCode -= _settings.LOWSpinupOffsetMS;
}
else if (lineData[1].Contains("MED"))
{
timeCode -= _settings.MEDSpinupOffsetMS;
}
else if (lineData[1].Contains("HIGH"))
{
timeCode -= _settings.HIGHSpinupOffsetMS;
}
}
//if command is OFF, add spindown offset
else if (lineData[1].Contains("OFF"))
Expand Down Expand Up @@ -506,11 +511,20 @@ private void LoadVideoTimecodes(string fileName, string filePath)

private void ExtractWindtrack(string filePath, bool extractFingerprint)
{
DirectoryInfo tmp = new DirectoryInfo(Path.Combine(ConfigHelper._rootPath, "tmp"));
foreach (FileInfo file in tmp.GetFiles())
try
{
file.Delete();
DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(ConfigHelper._rootPath, "tmp"));

foreach (FileInfo file in directoryInfo.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo dir in directoryInfo.GetDirectories())
{
dir.Delete(true);
}
}
catch { }

string fileName = Path.GetFileNameWithoutExtension(filePath);

Expand Down
20 changes: 13 additions & 7 deletions HTFanControl/Main/WebUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace HTFanControl.Main
{
class WebUI
{
private readonly string _version = Assembly.GetExecutingAssembly().GetName().Version.ToString(3);
private readonly string _version = Assembly.GetExecutingAssembly().GetName().Version.ToString().TrimEnd(new char[] { '.', '0' });
private readonly Thread _httpThread;
private readonly HTFanControl _HTFanCtrl;
private bool _webUIEnabled = true;
Expand Down Expand Up @@ -338,7 +338,7 @@ private string SettingsPage()
{
if (_waitForFile)
{
Thread.Sleep(250);
Thread.Sleep(500);
_waitForFile = false;
}

Expand Down Expand Up @@ -441,7 +441,10 @@ private string SettingsPage()
}

html = html.Replace("{GlobalOffset}", _HTFanCtrl._settings.GlobalOffsetMS.ToString());
html = html.Replace("{SpinupOffset}", _HTFanCtrl._settings.SpinupOffsetMS.ToString());
html = html.Replace("{ECOSpinupOffset}", _HTFanCtrl._settings.ECOSpinupOffsetMS.ToString());
html = html.Replace("{LOWSpinupOffset}", _HTFanCtrl._settings.LOWSpinupOffsetMS.ToString());
html = html.Replace("{MEDSpinupOffset}", _HTFanCtrl._settings.MEDSpinupOffsetMS.ToString());
html = html.Replace("{HIGHSpinupOffset}", _HTFanCtrl._settings.HIGHSpinupOffsetMS.ToString());
html = html.Replace("{SpindownOffset}", _HTFanCtrl._settings.SpindownOffsetMS.ToString());

html = html.Replace("{version}", @$"Version: {_version} <a href=""checkupdate"">(Check For Update)</a>");
Expand Down Expand Up @@ -478,7 +481,10 @@ private void SaveSettings(HttpListenerRequest request)
_HTFanCtrl._settings.MediaPlayerIP = data.RootElement.GetProperty("MediaPlayerIP").GetString();
_HTFanCtrl._settings.MediaPlayerPort = int.TryParse(data.RootElement.GetProperty("MediaPlayerPort").GetString(), out int MediaPlayerPort) ? MediaPlayerPort : 0;
_HTFanCtrl._settings.GlobalOffsetMS = int.TryParse(data.RootElement.GetProperty("GlobalOffset").GetString(), out int GlobalOffset) ? GlobalOffset : 0;
_HTFanCtrl._settings.SpinupOffsetMS = int.TryParse(data.RootElement.GetProperty("SpinupOffset").GetString(), out int SpinupOffset) ? SpinupOffset : 0;
_HTFanCtrl._settings.ECOSpinupOffsetMS = int.TryParse(data.RootElement.GetProperty("ECOSpinupOffset").GetString(), out int ECOSpinupOffset) ? ECOSpinupOffset : 0;
_HTFanCtrl._settings.LOWSpinupOffsetMS = int.TryParse(data.RootElement.GetProperty("LOWSpinupOffset").GetString(), out int LOWSpinupOffset) ? LOWSpinupOffset : 0;
_HTFanCtrl._settings.MEDSpinupOffsetMS = int.TryParse(data.RootElement.GetProperty("MEDSpinupOffset").GetString(), out int MEDSpinupOffset) ? MEDSpinupOffset : 0;
_HTFanCtrl._settings.HIGHSpinupOffsetMS = int.TryParse(data.RootElement.GetProperty("HIGHSpinupOffset").GetString(), out int HIGHSpinupOffset) ? HIGHSpinupOffset : 0;
_HTFanCtrl._settings.SpindownOffsetMS = int.TryParse(data.RootElement.GetProperty("SpindownOffset").GetString(), out int SpindownOffset) ? SpindownOffset : 0;
_HTFanCtrl._settings.MediaPlayerType = data.RootElement.GetProperty("MediaPlayer").GetString();
_HTFanCtrl._settings.PlexToken = data.RootElement.GetProperty("PlexToken").GetString();
Expand All @@ -499,9 +505,9 @@ private string CheckUpdatePage()
sb.AppendLine($"<b>Current Version:</b> {_version}");
sb.AppendLine("</br>");

HttpClient httpClient = new HttpClient();
using HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("User-Agent", ".netapp");
string releaseJSON = httpClient.GetAsync("https://api.github.com/repos/nicko88/htfancontrol/releases/latest").Result.Content.ReadAsStringAsync().Result;
string releaseJSON = httpClient.GetStringAsync("https://api.github.com/repos/nicko88/htfancontrol/releases/latest").Result;
using JsonDocument data = JsonDocument.Parse(releaseJSON);
string latest = data.RootElement.GetProperty("tag_name").GetString();
string latesturl = data.RootElement.GetProperty("html_url").GetString();
Expand Down Expand Up @@ -635,7 +641,7 @@ private string ManagePage()
{
if(_waitForFile)
{
Thread.Sleep(500);
Thread.Sleep(750);
_waitForFile = false;
}
string html = GetHtml("manage");
Expand Down
10 changes: 8 additions & 2 deletions HTFanControl/Util/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ class Settings
public string PlexClientPort { get; set; }
public string PlexClientGUID { get; set; }
public int GlobalOffsetMS { get; set; }
public int SpinupOffsetMS { get; set; }
public int ECOSpinupOffsetMS { get; set; }
public int LOWSpinupOffsetMS { get; set; }
public int MEDSpinupOffsetMS { get; set; }
public int HIGHSpinupOffsetMS { get; set; }
public int SpindownOffsetMS { get; set; }

public static Settings LoadSettings()
Expand Down Expand Up @@ -72,7 +75,10 @@ public static Settings LoadSettings()
settings.MQTT_HIGH_Topic = "cmnd/HTFan/EVENT";
settings.MQTT_HIGH_Payload = "s4";
settings.GlobalOffsetMS = 2000;
settings.SpinupOffsetMS = 750;
settings.ECOSpinupOffsetMS = 1400;
settings.LOWSpinupOffsetMS = 1200;
settings.MEDSpinupOffsetMS = 1000;
settings.HIGHSpinupOffsetMS = 800;
settings.SpindownOffsetMS = 250;
}

Expand Down
Loading

0 comments on commit adde710

Please sign in to comment.