Skip to content
Snippets Groups Projects
Commit 653179fb authored by Paul-Winpenny's avatar Paul-Winpenny
Browse files

Added the drawable pane, now I need to make it draw graphs very nicely.

parent f58b5311
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@
</PropertyGroup>
<ItemGroup>
<MauiIcon Include="Resources\AppIcon\robobinlogo.png"/>
<MauiIcon Include="Resources\AppIcon\robobinlogo.png" />
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />
......@@ -39,6 +39,8 @@
<PackageReference Include="Shiny" Version="2.7.3" />
<PackageReference Include="Shiny.BluetoothLE" Version="3.3.3" />
<PackageReference Include="Shiny.Hosting.Maui" Version="3.3.3" />
<PackageReference Include="SkiaSharp.Views.Maui.Controls" Version="2.88.8" />
<PackageReference Include="SkiaSharp.Views.Maui.Core" Version="2.88.8" />
</ItemGroup>
<ItemGroup>
......@@ -54,6 +56,9 @@
<MauiXaml Update="LeftBox.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\CentreGraph.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\ConnectionPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
......
......@@ -20,6 +20,9 @@
</AppxManifest>
</ItemGroup>
<ItemGroup>
<MauiXaml Update="Views\CentreGraph.xaml">
<SubType>Designer</SubType>
</MauiXaml>
<MauiXaml Update="Views\ConnectionPage.xaml">
<SubType>Designer</SubType>
</MauiXaml>
......
......@@ -150,7 +150,7 @@ namespace RobobinApp.ViewModels
CheckAndRequestBluetoothPermissions();
}
private void OnSendWifiInfo(object obj)
private async void OnSendWifiInfo(object obj)
{
try
{
......@@ -162,7 +162,18 @@ namespace RobobinApp.ViewModels
var SSID = SelectedWifiNetwork.SSID;
var result = WriteOperationAsync("CONNECT", SSID + "," + password);
Debug.WriteLine($"Result: {result}");
await Task.Delay(5000);
//var successfulConnect = await ReadOperationAsync();
var successfulConnect = "SUCCESS";
Debug.WriteLine($"Result: {successfulConnect}");
if (successfulConnect.Equals("SUCCESS"))
{
Application.Current.MainPage.DisplayAlert("SUCCESS",$"RoboBin is now connected to {SelectedWifiNetwork.SSID}!","Great :)");
await OnGoHome();
}
}
catch (Exception e)
{
......@@ -172,15 +183,20 @@ namespace RobobinApp.ViewModels
private async Task PingPiASyncAsync()
{
if (tempUnit.Equals("C"))
await WriteOperationAsync("PING");
await Task.Delay(5000);
var result = await ReadOperationAsync();
Debug.WriteLine($"Result: {result}");
if (result == "PING_RETURN")
{
tempUnit = "F";
Debug.WriteLine("Ping verify succeeded");
}
else
{
tempUnit = "C";
Debug.WriteLine("Ping return could not be verified, please check the connection");
}
await WriteOperationAsync(tempUnit);
}
......@@ -273,6 +289,7 @@ namespace RobobinApp.ViewModels
public async Task OnGoHome()
{
Debug.WriteLine("Navigating to home page.");
ResetState();
await Application.Current.MainPage.Navigation.PushAsync(new MainPage());
}
......@@ -311,18 +328,21 @@ namespace RobobinApp.ViewModels
private void OnDeviceDiscovered(object? sender, DeviceEventArgs e)
{
Debug.WriteLine($"Discovered device: {e.Device.Name ?? e.Device.Id.ToString()}");
var bluetoothDevice = new BluetoothDevice(
string.IsNullOrWhiteSpace(e.Device.Name) ? e.Device.Id.ToString() : e.Device.Name,
e.Device.Id.ToString()
);
// Check if the device is already in the list
if (!BluetoothDevices.Any(d => d.MacAddress == bluetoothDevice.MacAddress))
if (e.Device.Name.Equals("RoboBin-BT"))
{
// Device is new, add it
Microsoft.Maui.Controls.Device.BeginInvokeOnMainThread(() => BluetoothDevices.Add(bluetoothDevice));
var bluetoothDevice = new BluetoothDevice(
string.IsNullOrWhiteSpace(e.Device.Name) ? e.Device.Id.ToString() : e.Device.Name,
e.Device.Id.ToString()
);
// Check if the device is already in the list
if (!BluetoothDevices.Any(d => d.MacAddress == bluetoothDevice.MacAddress))
{
// Device is new, add it
Microsoft.Maui.Controls.Device.BeginInvokeOnMainThread(() => BluetoothDevices.Add(bluetoothDevice));
}
}
}
private void RemoveUnavailableDevices(IEnumerable<IDevice> availableDevices)
......@@ -441,10 +461,10 @@ namespace RobobinApp.ViewModels
try
{
Debug.WriteLine($"Attempt {attempt}: Reading from characteristic");
var temperatureData = await ReadCharacteristic.ReadAsync();
var temperatureValue = Encoding.UTF8.GetString(temperatureData.data);
Debug.WriteLine($"Temperature Value: {temperatureValue}");
return temperatureValue;
var retrievedData = await ReadCharacteristic.ReadAsync();
var retrievedValue = Encoding.UTF8.GetString(retrievedData.data);
Debug.WriteLine($"Read Value: {retrievedValue}");
return retrievedValue;
}
catch (Exception ex)
{
......@@ -460,9 +480,6 @@ namespace RobobinApp.ViewModels
Debug.WriteLine("Reconnection failed. Returning failure.");
return "Failure";
}
// Wait before the next attempt
await Task.Delay(1000);
}
return "Failure"; // This will only be reached if all attempts failed without reconnection
}
......@@ -501,9 +518,6 @@ namespace RobobinApp.ViewModels
Debug.WriteLine("Reconnection failed. Returning failure.");
return "Failure";
}
// Wait before the next attempt
await Task.Delay(1000);
}
return "Failure"; // This will only be reached if all attempts failed without reconnection
}
......
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Robobin.Views.CentreGraph">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ContentView>
using Microsoft.Maui.Graphics;
namespace RobobinApp.Views
{
public class GraphicsDrawable : IDrawable
{
public void Draw(ICanvas canvas, RectF dirtyRect)
{
// Set the background color
canvas.FillColor = Colors.LightPink; // Change to your desired color
canvas.FillRectangle(dirtyRect);
// Draw some graphics (for example, a circle)
canvas.FillColor = Colors.Red;
canvas.FillCircle(dirtyRect.Center.X, dirtyRect.Center.Y, 50);
// Example of drawing text
canvas.FontSize = 24;
canvas.FillColor = Colors.Black;
canvas.DrawString("Hello, GraphicsView!", dirtyRect.Center.X, dirtyRect.Center.Y, HorizontalAlignment.Center);
}
}
}
......@@ -2,10 +2,9 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:RobobinApp.Views"
xmlns:viewModels="clr-namespace:RobobinApp.ViewModels"
x:Class="RobobinApp.Views.MainPage"
xmlns:drawable="clr-namespace:RobobinApp.Views"
x:Class="RobobinApp.Views.MainPage"
Title="">
<ContentPage.BindingContext>
<viewModels:MainPageViewModel />
......@@ -13,11 +12,11 @@
<ContentPage.Resources>
<ResourceDictionary>
<drawable:GraphicsDrawable x:Key="drawable" />
<StyleSheet Source="/Resources/Styles/appstyle.css" />
</ResourceDictionary>
</ContentPage.Resources>
<Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
......@@ -29,37 +28,34 @@
</Grid.ColumnDefinitions>
<VerticalStackLayout StyleClass="sideFrame"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
Grid.Column="0" Grid.Row="0">
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Grid.Column="0" Grid.Row="0">
<HorizontalStackLayout HorizontalOptions="Start" VerticalOptions="End">
<Button Text="Admin" HorizontalOptions="Start" VerticalOptions="Start" Command="{Binding ConnectToRobobinCommand}"/>
<Button Text="Setup" HorizontalOptions="Start" VerticalOptions="Start" Command="{Binding ConnectToRobobinCommand}"/>
<Button Text="Admin" Command="{Binding ConnectToRobobinCommand}"/>
<Button Text="Setup" Command="{Binding ConnectToRobobinCommand}"/>
</HorizontalStackLayout>
<local:SideBox Grid.Column="0" Grid.Row="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
<local:SideBox Grid.Column="0" Grid.Row="1" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" HeaderTitle= "Status:" />
<local:SideBox HeaderTitle="Status:" />
</VerticalStackLayout>
<Frame StyleClass="mainFrame"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Grid.Column="1" Grid.Row="0">
<Label Text="{Binding StatusMessage}" HorizontalOptions="Center" VerticalOptions="Center"/>
<GraphicsView Drawable="{StaticResource drawable}"
HeightRequest="300"
WidthRequest="400" />
</Frame>
<VerticalStackLayout StyleClass="sideFrame"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
Grid.Column="2" Grid.Row="0">
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Grid.Column="2" Grid.Row="0">
<HorizontalStackLayout HorizontalOptions="Start" VerticalOptions="End">
<Button Text="Info" HorizontalOptions="Start" VerticalOptions="Start" />
<Button Text="Info" />
</HorizontalStackLayout>
<local:SideBox Grid.Column="0" Grid.Row="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" HeaderTitle= "Mode:" />
<local:SideBox Grid.Column="0" Grid.Row="1" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" HeaderTitle= "Admin:" />
<local:SideBox HeaderTitle="Mode:" />
</VerticalStackLayout>
</Grid>
</ContentPage>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment