Skip to content

Commit

Permalink
Merge branch 'Development' into 'main'
Browse files Browse the repository at this point in the history
MAUI: update hio monitor app

See merge request tools/hio-dotnet!6
  • Loading branch information
fyziktom committed Dec 12, 2024
2 parents a49b2a9 + 5765973 commit 512855f
Show file tree
Hide file tree
Showing 20 changed files with 1,310 additions and 458 deletions.
14 changes: 14 additions & 0 deletions hio-dotnet.Demos.HardwarioMonitor/AppConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace hio_dotnet.Demos.HardwarioMonitor
{
public class AppConfig
{
public string AppName { get; set; } = string.Empty;
public string AppVersion { get; set; } = string.Empty;
}
}
103 changes: 103 additions & 0 deletions hio-dotnet.Demos.HardwarioMonitor/Components/Layout/Footer.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
@using Services

@inject ConsoleService ConsoleService

<RadzenRow Style=@getLeftMargin>
<RadzenColumn>
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Start" JustifyContent="JustifyContent.Left">
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Start">
@if (ConsoleService.IsConsoleListening)
{
<div style="margin-top:-2px;">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<circle cx="8" cy="8" r="7" fill="green" />
</svg>
</div>
}
else
{
<div style="margin-top:-2px;">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<circle cx="8" cy="8" r="7" fill="red" />
</svg>
</div>
}
<RadzenText Text="@connectionStatus" style="margin-left:5px;" />
</RadzenStack>

<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Start">
@if (ConsoleService.IsPPK2Connected())
{
<div style="margin-top:-2px;">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<circle cx="8" cy="8" r="7" fill="green" />
</svg>
</div>
}
else
{
<div style="margin-top:-2px;">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<circle cx="8" cy="8" r="7" fill="red" />
</svg>
</div>
}
<RadzenText Text="@ppkconnectionStatus" style="margin-left:5px;" />
</RadzenStack>

<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Start">
@if (ConsoleService.IsDeviceOn)
{
<div style="margin-top:-2px;">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<circle cx="8" cy="8" r="7" fill="green" />
</svg>
</div>
}
else
{
<div style="margin-top:-2px;">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<circle cx="8" cy="8" r="7" fill="red" />
</svg>
</div>
}
<RadzenText Text="@ppkVoltageStatus" style="margin-left:5px;" />
</RadzenStack>
</RadzenStack>
</RadzenColumn>
</RadzenRow>

@code {
[Parameter] public int LeftMargin { get; set; } = 5;

string getLeftMargin => $"margin-left:{LeftMargin}px;";
bool sidebarExpanded = true;

public string connectionStatus => ConsoleService.IsConsoleListening ? $"JLink Connection Status: Connected" : "JLink Connection Status: Not Connected";
public string ppkconnectionStatus => ConsoleService.IsPPK2Connected() ? $"PPK2 Connection Status: Connected" : "PPK2 Connection Status: Not Connected";
public string ppkVoltageStatus => ConsoleService.IsDeviceOn ? $"PPK2 Voltage On: {ConsoleService.DeviceVoltage} mV " : "PPK2 Voltage Off";

protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();

ConsoleService.OnIsJLinkConnected += Refresh;
ConsoleService.OnIsJLinkDisconnected += Refresh;
ConsoleService.OnIsPPKConnected += Refresh;
ConsoleService.OnIsPPKDisconnected += Refresh;
ConsoleService.OnIsPPKVoltageOutputConnected += Refresh;
ConsoleService.OnIsPPKVoltageOutputDisconnected += Refresh;
}

private void Refresh(object sender, bool e)
{
InvokeAsync(StateHasChanged);
}

public async Task ChangeLeftMargin(int margin)
{
LeftMargin = margin;
await InvokeAsync(StateHasChanged);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,70 @@
@inherits LayoutComponentBase

<div class="page">
<div class="sidebar">
<NavMenu />
</div>
@inject TooltipService TooltipService

<main>
<div class="top-row px-4">
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
</div>
<RadzenLayout>
<RadzenHeader>
<RadzenRow>
<RadzenColumn>
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" Gap="0" JustifyContent="JustifyContent.Start">
<RadzenSidebarToggle Click="@sidebarToggle" Style="margin-left:4px;" />
<img src="resources/hw_logo_pos.svg" alt="HARDWARIO" style="width:100px;height:100%;" />
</RadzenStack>
</RadzenColumn>
</RadzenRow>
</RadzenHeader>
<RadzenSidebar Responsive="false" Style="width: max-content;height:100%;">
<RadzenStack Orientation="Orientation.Vertical" Style="height:100%;">
<RadzenRow>
<RadzenColumn Style="height:100%;">
<RadzenPanelMenu DisplayStyle="@(sidebarExpanded ? MenuItemDisplayStyle.IconAndText : MenuItemDisplayStyle.Icon)" ShowArrow="false">
<RadzenPanelMenuItem Text="Home" Icon="home" Path="/" MouseEnter="@(args => ShowTooltip(args, new TooltipOptions() { Text = "Home", Position = TooltipPosition.Right }) )" />
<RadzenPanelMenuItem Text="Graph" Icon="monitoring" Path="/graph" MouseEnter="@(args => ShowTooltip(args, new TooltipOptions() { Text = "Counter", Position = TooltipPosition.Right }) )" />
<RadzenPanelMenuItem Text="Configs" Icon="manufacturing" Path="/configs" MouseEnter="@(args => ShowTooltip(args, new TooltipOptions() { Text = "Configs", Position = TooltipPosition.Right }) )" />
</RadzenPanelMenu>
</RadzenColumn>
</RadzenRow>
@if (sidebarExpanded)
{
<RadzenRow Style="height:100%;">
<RadzenColumn Style="height:100%;">
<RadzenStack Style="height: 100%;" Orientation="Orientation.Horizontal" AlignItems="AlignItems.End" JustifyContent="JustifyContent.Center">
<RadzenText Text="@GetVersion()" />
</RadzenStack>
</RadzenColumn>
</RadzenRow>
}
</RadzenStack>
</RadzenSidebar>
<RadzenBody Style="padding:0px;">
@Body
</RadzenBody>
<RadzenFooter>
<Footer @ref=footerRef />
</RadzenFooter>
</RadzenLayout>

<article class="content px-4">
@Body
</article>
</main>
</div>
<RadzenComponents />

@code {
bool sidebarExpanded = true;
Footer? footerRef;

public string GetVersion()
{
return $"Version: {MainDataContext.Config.AppVersion}";
}

private async Task sidebarToggle()
{
sidebarExpanded = !sidebarExpanded;
}

void ShowTooltip(ElementReference elementReference, TooltipOptions options = null)
{
if (!sidebarExpanded)
{
TooltipService.Open(elementReference, options.Text, options);
}
}
}
166 changes: 166 additions & 0 deletions hio-dotnet.Demos.HardwarioMonitor/Components/Pages/Configs.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
@using Services
@page "/configs"

@inject ConsoleService ConsoleService

<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center">
<!-- Loading overlay -->
@if (isBusy)
{
<RadzenCard Style="z-index: 3; text-align: center; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0, 0, 0, .5)">
<div style="display: flex; justify-content: center; align-items: center; height: 100%; width: 100%;">
<RadzenProgressBarCircular ShowValue="true" Mode="ProgressBarMode.Indeterminate" Size="ProgressBarCircularSize.Medium">
<Template>Wait</Template>
</RadzenProgressBarCircular>
</div>
</RadzenCard>
}
</RadzenStack>

<RadzenLayout Style="height: 100%; grid-template-rows: 1fr; grid-template-columns: 1fr auto; grid-template-areas: 'rz-body rz-sidebar'">
<RadzenSidebar Style="padding: 5px;">

@if (!ConsoleService.IsConsoleListening)
{
<RadzenButton Click="OnInitConsoleHandler" Style="margin-top: 5px; width: 100%;">Init Console</RadzenButton>
}
else
{
<RadzenButton Click="OnInitConsoleHandler" Disabled="true" Style="margin-top: 5px; width: 100%;">Init Console</RadzenButton>
}

<RadzenButton Click="LoadConfigFromDevice" Disabled="@isDisabled" Style="margin-top: 5px; width: 100%;">Load Config From Device</RadzenButton>

</RadzenSidebar>
<RadzenBody>
<RadzenRow Style="height: 100%;">
<RadzenColumn Style="height: 100%;">

<RadzenRow>
<RadzenColumn>
<hio_dotnet.UI.BlazorComponents.Radzen.CHESTER.Configs.LoRa.LoRaWANConfigCompleteForm @ref=LoRaConfigFormRef Config="@ConsoleService.LoRaWANConfig" />
</RadzenColumn>
</RadzenRow>
<RadzenRow>
<RadzenColumn>
<RadzenButton Disabled="@isDisabled" Click="ApplyLoRaSettings">Apply LoRa Settings</RadzenButton>
</RadzenColumn>
</RadzenRow>

</RadzenColumn>
<RadzenColumn Style="height: 100%;">

<RadzenRow>
<RadzenColumn>
<hio_dotnet.UI.BlazorComponents.Radzen.CHESTER.Configs.LTE.LTEConfigCompleteForm @ref=LTEConfigFormRef Config="@ConsoleService.LTEConfig" />
</RadzenColumn>
</RadzenRow>
<RadzenRow>
<RadzenColumn>
<RadzenButton Disabled="@isDisabled" Click="ApplyLTESettings">Apply LTE Settings</RadzenButton>
</RadzenColumn>
</RadzenRow>

</RadzenColumn>
</RadzenRow>
</RadzenBody>
</RadzenLayout>


@code {
private bool isBusy = false;
private bool isDisabled = false;

hio_dotnet.UI.BlazorComponents.Radzen.CHESTER.Configs.LoRa.LoRaWANConfigCompleteForm? LoRaConfigFormRef;
hio_dotnet.UI.BlazorComponents.Radzen.CHESTER.Configs.LTE.LTEConfigCompleteForm? LTEConfigFormRef;


public int Voltage { get; set; } = 3300;

protected override void OnInitialized()
{
ConsoleService.InitArrays();
ConsoleService.NewRTTMessageLineReceived += NewLineReceived;
ConsoleService.OnIsBusy += (s, e) =>
{
isBusy = e;
Refresh();
};

ConsoleService.OnIsJLinkConnected += (s, e) =>
{
isDisabled = false;
InvokeAsync(StateHasChanged);
};
ConsoleService.OnIsJLinkDisconnected += (s, e) =>
{
isDisabled = true;
InvokeAsync(StateHasChanged);
};

if (ConsoleService.IsConsoleListening)
{
isDisabled = false;
}
else
{
isDisabled = true;
}
}

protected override async Task OnParametersSetAsync()
{
if (ConsoleService.IsConsoleListening)
{
isDisabled = false;
}
else
{
isDisabled = true;
}
await base.OnParametersSetAsync();
}

public async Task Refresh()
{
await InvokeAsync(StateHasChanged);
}

public async Task OnInitConsoleHandler()
{
await ConsoleService.StartListening();
}


public void NewLineReceived(object sender, Tuple<string, MultiRTTClientBase> data)
{
if (data?.Item2.Channel == 0)
{
InvokeAsync(async () =>
{
await InvokeAsync(StateHasChanged);
});
}
}

private async Task ApplyLoRaSettings()
{
await ConsoleService.ApplyLoRaSettings();
}

private async Task ApplyLTESettings()
{
await ConsoleService.ApplyLTESettings();
}

private async Task HandleSendCommand(string command)
{
await ConsoleService.SendCommand(command.ToLower().Trim() + "\n");
}

private async Task LoadConfigFromDevice()
{
await ConsoleService.SendCommand("config show\n");
}

}
16 changes: 0 additions & 16 deletions hio-dotnet.Demos.HardwarioMonitor/Components/Pages/Counter.razor

This file was deleted.

Loading

0 comments on commit 512855f

Please sign in to comment.