Add acceleration speed slider to main page
This commit is contained in:
parent
4fe9bc7d87
commit
b1a414ba90
6 changed files with 215 additions and 34 deletions
9
Models/VariablesModel.cs
Normal file
9
Models/VariablesModel.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace TestingRoom_NN_Kajk_UI.Models
|
||||
{
|
||||
public class VariablesModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Value { get; set; }
|
||||
public bool IsDefault { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
@page "/variables"
|
||||
|
||||
<PageTitle>Counter</PageTitle>
|
||||
|
||||
<h1>Counter</h1>
|
||||
|
||||
<p role="status">Current count: @currentCount</p>
|
||||
|
||||
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
|
||||
|
||||
@code {
|
||||
private int currentCount = 0;
|
||||
|
||||
private void IncrementCount()
|
||||
{
|
||||
currentCount++;
|
||||
}
|
||||
}
|
115
Pages/Home.razor
115
Pages/Home.razor
|
@ -2,6 +2,7 @@
|
|||
|
||||
@using TestingRoom_NN_Kajk_UI.Models
|
||||
@inject HttpClient HttpClient
|
||||
@implements IDisposable
|
||||
|
||||
<PageTitle>Control</PageTitle>
|
||||
|
||||
|
@ -11,14 +12,14 @@
|
|||
<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/>
|
||||
<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()))" />
|
||||
<input class="form-control text-center" type="number" min="0" max="@RPM_Max" value="@RPM_Requested" @onchange="(x) => SetRPMRequested(float.Parse(x.Value.ToString()))" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
@ -30,7 +31,7 @@
|
|||
<button class="btn btn-primary" @onclick="() => AddRPMRequested(100)">+100</button>
|
||||
</div>
|
||||
|
||||
<h6/>
|
||||
<h6 />
|
||||
|
||||
<div>
|
||||
@foreach (int i in RPM_Presets)
|
||||
|
@ -39,7 +40,13 @@
|
|||
}
|
||||
</div>
|
||||
</div>
|
||||
<h3/>
|
||||
<h3 />
|
||||
</div>
|
||||
|
||||
<div class="col-sm-12 col-xl-6 col-xxl-4">
|
||||
<h2><b>Rychlost náběhu: @(Math.Round(RPM_Acceleration_speed * 1000, 0)) </b></h2>
|
||||
<input type="range" class="form-range" min="1" max="1000" step="1" value="@(Math.Round(RPM_Acceleration_speed * 1000, 0).ToString())" @onchange="(x) => PostRPMAcceleration(float.Parse(x.Value.ToString()))" />
|
||||
<h3 />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
@ -49,18 +56,23 @@
|
|||
|
||||
|
||||
|
||||
@code{
|
||||
@code {
|
||||
string RPM_Actual_Variable_Name = "actual_rpm";
|
||||
string RPM_Requested_Variable_Name = "requested_rpm";
|
||||
string RPM_Max_Variable_Name = "max_rpm";
|
||||
string RPM_Acceleration_Variable_Name = "control_step_U";
|
||||
|
||||
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
|
||||
float RPM_Acceleration_speed = 0;
|
||||
|
||||
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
|
||||
private System.Timers.Timer? RPM_Max_Timer = new System.Timers.Timer(10000); //max RPM reader timer
|
||||
private System.Timers.Timer? RPM_Acceleration_Timer = new System.Timers.Timer(1000); //Acceleration RPM reader timer
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
|
@ -71,22 +83,42 @@
|
|||
RPM_Actual_Timer.Elapsed += RequestActualRPM;
|
||||
RPM_Actual_Timer.Start();
|
||||
|
||||
RequestRequestedRPM(null, null);
|
||||
GetRPMMax(null, null);
|
||||
GetRPMAcceleration(null, null);
|
||||
|
||||
//requested RPM request timer
|
||||
RPM_Requested_Timer.AutoReset = true;
|
||||
RPM_Requested_Timer.Elapsed += RequestRequestedRPM;
|
||||
RPM_Requested_Timer.Start();
|
||||
|
||||
//max RPM request timer
|
||||
RPM_Max_Timer.AutoReset = true;
|
||||
RPM_Max_Timer.Elapsed += GetRPMMax;
|
||||
RPM_Max_Timer.Start();
|
||||
|
||||
//acceleration RPM request timer
|
||||
RPM_Acceleration_Timer.AutoReset = true;
|
||||
RPM_Acceleration_Timer.Elapsed += GetRPMAcceleration;
|
||||
RPM_Acceleration_Timer.Start();
|
||||
}
|
||||
|
||||
private void SetRPMRequested(int rpm)
|
||||
private void SetRPMRequested(float rpm)
|
||||
{
|
||||
if (RPM_Requested_Timer == null)
|
||||
return;
|
||||
|
||||
RPM_Requested_Timer.Stop();
|
||||
RPM_Requested = rpm;
|
||||
SetRPMRequested();
|
||||
RPM_Requested_Timer.Start();
|
||||
}
|
||||
|
||||
private void AddRPMRequested(int add)
|
||||
private void AddRPMRequested(float add)
|
||||
{
|
||||
if (RPM_Requested_Timer == null)
|
||||
return;
|
||||
|
||||
RPM_Requested_Timer.Stop();
|
||||
RPM_Requested += add;
|
||||
|
||||
|
@ -101,26 +133,79 @@
|
|||
|
||||
private async void RequestActualRPM(object? sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
//RPM_Actual = float.Parse(await HttpClient.GetStringAsync($"/api/variables/{RPM_Actual_Variable_Name}"));
|
||||
string response = await HttpClient.GetStringAsync($"/api/variables/{RPM_Actual_Variable_Name}");
|
||||
if (float.TryParse(response.Replace("\"", "").Replace(".", ","), out float result))
|
||||
{
|
||||
RPM_Actual = result;
|
||||
}
|
||||
else
|
||||
{
|
||||
RPM_Actual = -1;
|
||||
}
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async void RequestRequestedRPM(object? sender, System.Timers.ElapsedEventArgs e)
|
||||
private async void RequestRequestedRPM(object? sender, System.Timers.ElapsedEventArgs? e)
|
||||
{
|
||||
//RPM_Requested = int.Parse(await HttpClient.GetStringAsync($"/api/variables/{RPM_Requested_Variable_Name}"));
|
||||
RPM_Requested = int.Parse((await HttpClient.GetStringAsync($"/api/variables/{RPM_Requested_Variable_Name}")).Replace("\"", "").Replace(".", ","));
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async void SetRPMRequested()
|
||||
{
|
||||
//await HttpClient.PostAsJsonAsync($"/api/variables/{RPM_Requested_Variable_Name}", new VariablePostModel { data = RPM_Requested.ToString(), Isdefault = false });
|
||||
await HttpClient.PostAsJsonAsync($"/api/variables/{RPM_Requested_Variable_Name}", new VariablePostModel { data = RPM_Requested.ToString(), Isdefault = false });
|
||||
}
|
||||
|
||||
private async void GetRPMMax()
|
||||
private async void GetRPMMax(object? sender, System.Timers.ElapsedEventArgs? e)
|
||||
{
|
||||
//RPM_Max = int.Parse(await HttpClient.GetStringAsync($"/api/variables/{RPM_Requested_Variable_Name}"));
|
||||
RPM_Max = float.Parse((await HttpClient.GetStringAsync($"/api/variables/{RPM_Max_Variable_Name}")).Replace("\"", "").Replace(".", ","));
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
|
||||
private async void PostRPMAcceleration(float value)
|
||||
{
|
||||
if (RPM_Acceleration_Timer == null)
|
||||
return;
|
||||
|
||||
RPM_Acceleration_Timer.Stop();
|
||||
|
||||
RPM_Acceleration_speed = value / 1000;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await HttpClient.PostAsJsonAsync($"/api/variables/{RPM_Acceleration_Variable_Name}", new VariablePostModel { data = RPM_Acceleration_speed.ToString().Replace(",", "."), Isdefault = false });
|
||||
RPM_Acceleration_Timer.Start();
|
||||
}
|
||||
|
||||
private async void GetRPMAcceleration(object? sender, System.Timers.ElapsedEventArgs? e)
|
||||
{
|
||||
RPM_Acceleration_speed = float.Parse((await HttpClient.GetStringAsync($"/api/variables/{RPM_Acceleration_Variable_Name}")).Replace("\"", "").Replace(".", ","));
|
||||
}
|
||||
|
||||
|
||||
|
||||
private bool disposed;
|
||||
public void Dispose()
|
||||
{
|
||||
if (disposed) return;
|
||||
|
||||
disposed = true;
|
||||
|
||||
RPM_Actual_Timer.Stop();
|
||||
RPM_Actual_Timer.Dispose();
|
||||
RPM_Actual_Timer = null;
|
||||
|
||||
RPM_Requested_Timer.Stop();
|
||||
RPM_Requested_Timer.Dispose();
|
||||
RPM_Requested_Timer = null;
|
||||
|
||||
RPM_Max_Timer.Stop();
|
||||
RPM_Max_Timer.Dispose();
|
||||
RPM_Max_Timer = null;
|
||||
|
||||
RPM_Acceleration_Timer.Stop();
|
||||
RPM_Acceleration_Timer.Dispose();
|
||||
RPM_Acceleration_Timer = null;
|
||||
|
||||
this.Dispose();
|
||||
}
|
||||
}
|
103
Pages/Variables.razor
Normal file
103
Pages/Variables.razor
Normal file
|
@ -0,0 +1,103 @@
|
|||
@page "/variables"
|
||||
|
||||
@using Newtonsoft.Json
|
||||
@using TestingRoom_NN_Kajk_UI.Models
|
||||
|
||||
@inject HttpClient HttpClient
|
||||
|
||||
<PageTitle>Variables</PageTitle>
|
||||
<div class="row">
|
||||
<div class="text-center align-content-center align-items-center align-self-center justify-content-center">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Proměnná</th>
|
||||
<th>Hodnota</th>
|
||||
<th>Ulož</th>
|
||||
<th>Výchozí?</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (VariablesModel s in VariableDetails)
|
||||
{
|
||||
<tr class="text-center align-content-center align-items-center align-self-center justify-content-center">
|
||||
<td>@s.Name</td>
|
||||
|
||||
<td>
|
||||
@if (float.TryParse(s.Value.Replace(".", ","), out float parsed2))
|
||||
{
|
||||
<input type="number" step="0.001" class="form-control text-center" value="@s.Value" @onchange="(x) => s.Value = x.Value.ToString()" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<input type="text" class="form-control text-center" @bind="s.Value" />
|
||||
}
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<button class="btn btn-primary" @onclick="() => PostVariableData(s)">Ulož</button>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<div class="form-check form-switch">
|
||||
<input type="checkbox" class="form-check-input" role="switch" @bind="s.IsDefault" />
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@code {
|
||||
private List<VariablesModel> VariableDetails = new List<VariablesModel>();
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
|
||||
GetVariablesDerails();
|
||||
}
|
||||
|
||||
private async Task<List<string>> GetVariablesNames()
|
||||
{
|
||||
string str = await HttpClient.GetStringAsync("/api/variables/");
|
||||
Console.WriteLine(str);
|
||||
List<string> list = JsonConvert.DeserializeObject<List<string>>(str);
|
||||
list.Sort();
|
||||
return list;
|
||||
}
|
||||
|
||||
private async void GetVariablesDerails()
|
||||
{
|
||||
List<string> VariableNames = await GetVariablesNames();
|
||||
Console.WriteLine($"Variable Count: {VariableNames.Count}");
|
||||
foreach (string name in VariableNames)
|
||||
{
|
||||
Console.WriteLine(name);
|
||||
VariableDetails.Add(new VariablesModel
|
||||
{
|
||||
Name = name,
|
||||
IsDefault = false,
|
||||
Value = (await HttpClient.GetStringAsync($"/api/variables/{name}")).Replace("\"", "")
|
||||
});
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private async void PostVariableData(VariablesModel variables)
|
||||
{
|
||||
await HttpClient.PostAsJsonAsync($"/api/variables/{variables.Name}", new VariablePostModel { data = variables.Value, Isdefault = variables.IsDefault });
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -6,6 +6,7 @@ var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
|||
builder.RootComponents.Add<App>("#app");
|
||||
builder.RootComponents.Add<HeadOutlet>("head::after");
|
||||
|
||||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
|
||||
//builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
|
||||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://10.0.0.190") });
|
||||
|
||||
await builder.Build().RunAsync();
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.0" PrivateAssets="all" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
Loading…
Add table
Reference in a new issue