2025-01-16 14:43:19 +01:00
|
|
|
@page "/"
|
|
|
|
|
2025-01-16 18:54:15 +01:00
|
|
|
@using TestingRoom_NN_Kajk_UI.Models
|
|
|
|
@inject HttpClient HttpClient
|
2025-01-16 14:43:19 +01:00
|
|
|
|
2025-01-16 18:54:15 +01:00
|
|
|
<PageTitle>Control</PageTitle>
|
2025-01-16 14:43:19 +01:00
|
|
|
|
2025-01-16 18:54:15 +01:00
|
|
|
<div class="row align-content-center text-center align-items-center">
|
|
|
|
<div class="col-sm-12 col-xl-6 col-xxl-4">
|
|
|
|
<h2><b>Otáčky: @RPM_Actual RPM</b></h2>
|
|
|
|
<div class="progress" role="progressbar" aria-label="Basic example" aria-valuenow="@RPM_Actual" aria-valuemin="0" aria-valuemax="@RPM_Max">
|
|
|
|
<div class="progress-bar" style="width: @($"{Math.Round((RPM_Actual / RPM_Max), 2) * 100}%")"></div>
|
|
|
|
</div>
|
|
|
|
<h3/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="col-sm-12 col-xl-6 col-xxl-4">
|
|
|
|
<div class="align-content-center">
|
|
|
|
<h4><b>Žádané otáčky:</b></h4>
|
|
|
|
<div class="input-group mb-3">
|
|
|
|
<input class="form-control text-center" type="number" min="0" max="@RPM_Max" value="@RPM_Requested" @onchange="(x) => SetRPMRequested(int.Parse(x.Value.ToString()))" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<button class="btn btn-primary" @onclick="() => AddRPMRequested(-1)">-1</button>
|
|
|
|
<button class="btn btn-primary" @onclick="() => AddRPMRequested(+1)">+1</button>
|
|
|
|
<button class="btn btn-primary" @onclick="() => AddRPMRequested(-10)">-10</button>
|
|
|
|
<button class="btn btn-primary" @onclick="() => AddRPMRequested(+10)">+10</button>
|
|
|
|
<button class="btn btn-primary" @onclick="() => AddRPMRequested(-100)">-100</button>
|
|
|
|
<button class="btn btn-primary" @onclick="() => AddRPMRequested(100)">+100</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<h6/>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
@foreach (int i in RPM_Presets)
|
|
|
|
{
|
|
|
|
<button class="btn btn-primary" @onclick="() => SetRPMRequested(i)">@i RPM</button>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<h3/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@code{
|
|
|
|
string RPM_Actual_Variable_Name = "actual_rpm";
|
|
|
|
string RPM_Requested_Variable_Name = "requested_rpm";
|
|
|
|
string RPM_Max_Variable_Name = "max_rpm";
|
|
|
|
|
|
|
|
float RPM_Actual = 0;
|
|
|
|
float RPM_Max = 1900;
|
|
|
|
float RPM_Requested = 0;
|
|
|
|
List<int> RPM_Presets = new() { 0, 1500, 1800 };
|
|
|
|
|
|
|
|
private System.Timers.Timer RPM_Actual_Timer = new System.Timers.Timer(500); //actual RPM reader timer
|
|
|
|
private System.Timers.Timer RPM_Requested_Timer = new System.Timers.Timer(5000); //requested RPM reader timer
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
{
|
|
|
|
base.OnInitialized();
|
|
|
|
|
|
|
|
//actual RPM request timer
|
|
|
|
RPM_Actual_Timer.AutoReset = true;
|
|
|
|
RPM_Actual_Timer.Elapsed += RequestActualRPM;
|
|
|
|
RPM_Actual_Timer.Start();
|
|
|
|
|
|
|
|
//requested RPM request timer
|
|
|
|
RPM_Requested_Timer.AutoReset = true;
|
|
|
|
RPM_Requested_Timer.Elapsed += RequestRequestedRPM;
|
|
|
|
RPM_Requested_Timer.Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetRPMRequested(int rpm)
|
|
|
|
{
|
|
|
|
RPM_Requested_Timer.Stop();
|
|
|
|
RPM_Requested = rpm;
|
|
|
|
SetRPMRequested();
|
|
|
|
RPM_Requested_Timer.Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void AddRPMRequested(int add)
|
|
|
|
{
|
|
|
|
RPM_Requested_Timer.Stop();
|
|
|
|
RPM_Requested += add;
|
|
|
|
|
|
|
|
if (RPM_Requested < 0)
|
|
|
|
RPM_Requested = 0;
|
|
|
|
if (RPM_Requested > RPM_Max)
|
|
|
|
RPM_Requested = RPM_Max;
|
|
|
|
|
|
|
|
SetRPMRequested();
|
|
|
|
RPM_Requested_Timer.Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
private async void RequestActualRPM(object? sender, System.Timers.ElapsedEventArgs e)
|
|
|
|
{
|
|
|
|
//RPM_Actual = float.Parse(await HttpClient.GetStringAsync($"/api/variables/{RPM_Actual_Variable_Name}"));
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
private async void RequestRequestedRPM(object? sender, System.Timers.ElapsedEventArgs e)
|
|
|
|
{
|
|
|
|
//RPM_Requested = int.Parse(await HttpClient.GetStringAsync($"/api/variables/{RPM_Requested_Variable_Name}"));
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
private async void SetRPMRequested()
|
|
|
|
{
|
|
|
|
//await HttpClient.PostAsJsonAsync($"/api/variables/{RPM_Requested_Variable_Name}", new VariablePostModel { data = RPM_Requested.ToString(), Isdefault = false });
|
|
|
|
}
|
|
|
|
|
|
|
|
private async void GetRPMMax()
|
|
|
|
{
|
|
|
|
//RPM_Max = int.Parse(await HttpClient.GetStringAsync($"/api/variables/{RPM_Requested_Variable_Name}"));
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|