Files
Vision/ModuleWeather/Module.cs
2026-03-20 21:10:28 +02:00

67 lines
1.7 KiB
C#

using Avalonia.Controls;
using VisionAsist.SDK;
using System.IO.Ports;
namespace ModuleWeather;
public class WeatherModule : IModule
{
public SerialPort myPort = new ();
public static string port;
public WeatherModule()
{
}
public string Name => "Прогноз Погоды";
public string[] GetCommands() => new[] { "погода", "поверни на *", "верни *" };
public void Settings(object[] args)
{
// args[0] — это родительское окно из Ядра
var parentWindow = args != null && args.Length > 0 ? args[0] as Window : null;
var win = new Window
{
Title = "Настройки",
Content = new WeatherView(), // Вставляем наш контрол
Width = 350,
Height = 250,
WindowStartupLocation = WindowStartupLocation.CenterOwner
};
if (parentWindow != null) win.Show(parentWindow);
else win.Show();
}
public object Execute(string command)
{
myPort.Close();
myPort = new SerialPort(port, 9600);
myPort.Open();
switch (command)
{
case "погода":
return "Погода хорошая!";
case "поверни на *":
myPort.WriteLine("178");
return "Повернул на 180";
case "верни *":
myPort.WriteLine("0");
return "Вернул в 0";
default:
return "Команда не найдена";
}
}
}