From c8fe4acff6adc04b8e7668ec30c2019d7d3e27bd Mon Sep 17 00:00:00 2001 From: J0EK3R Date: Thu, 11 Jun 2026 15:00:26 +0200 Subject: [PATCH 01/15] InfraredDevice as manual device --- .../DI/DeviceManagementModule.cs | 5 ++-- .../DeviceManagement/DeviceManager.cs | 11 +++----- .../IInfraredDeviceManager.cs | 2 +- .../InfraRedDevice/InfraRedDeviceVendor.cs | 26 +++++++++++++++++++ .../{ => InfraRedDevice}/InfraredDevice.cs | 9 ++++--- .../InfraredDeviceManager.cs | 2 +- 6 files changed, 41 insertions(+), 14 deletions(-) rename BrickController2/BrickController2/DeviceManagement/{ => InfraRedDevice}/IInfraredDeviceManager.cs (84%) create mode 100644 BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs rename BrickController2/BrickController2/DeviceManagement/{ => InfraRedDevice}/InfraredDevice.cs (84%) rename BrickController2/BrickController2/DeviceManagement/{ => InfraRedDevice}/InfraredDeviceManager.cs (99%) diff --git a/BrickController2/BrickController2/DeviceManagement/DI/DeviceManagementModule.cs b/BrickController2/BrickController2/DeviceManagement/DI/DeviceManagementModule.cs index f9e9d3741..c4a82ce88 100644 --- a/BrickController2/BrickController2/DeviceManagement/DI/DeviceManagementModule.cs +++ b/BrickController2/BrickController2/DeviceManagement/DI/DeviceManagementModule.cs @@ -2,7 +2,10 @@ using BrickController2.DeviceManagement.Vendors; using BrickController2.Extensions; using BrickController2.UI.Images; +using Microsoft.Maui.Controls; using System; +using System.Net; +using System.Numerics; namespace BrickController2.DeviceManagement.DI { @@ -11,13 +14,11 @@ public class DeviceManagementModule : Module protected override void Load(ContainerBuilder builder) { builder.RegisterType().As().SingleInstance(); - builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); - builder.RegisterType().Keyed(DeviceType.Infrared); builder.RegisterType().Keyed(DeviceType.CircuitCubes); builder.RegisterType().Keyed(DeviceType.PfxBrick); diff --git a/BrickController2/BrickController2/DeviceManagement/DeviceManager.cs b/BrickController2/BrickController2/DeviceManagement/DeviceManager.cs index e542dccb8..836b022da 100644 --- a/BrickController2/BrickController2/DeviceManagement/DeviceManager.cs +++ b/BrickController2/BrickController2/DeviceManagement/DeviceManager.cs @@ -1,4 +1,5 @@ -using BrickController2.Helpers; +using BrickController2.DeviceManagement.InfraredDevice; +using BrickController2.Helpers; using BrickController2.UI.Services.MainThread; using Microsoft.Extensions.Logging; using System; @@ -12,7 +13,6 @@ namespace BrickController2.DeviceManagement internal class DeviceManager : NotifyPropertyChangedSource, IDeviceManager { private readonly IBluetoothDeviceManager _bluetoothDeviceManager; - private readonly IInfraredDeviceManager _infraredDeviceManager; private readonly IDeviceRepository _deviceRepository; private readonly DeviceFactory _deviceFactory; private readonly IMainThreadService _uiThreadService; @@ -25,14 +25,12 @@ internal class DeviceManager : NotifyPropertyChangedSource, IDeviceManager public DeviceManager( IBluetoothDeviceManager bluetoothDeviceManager, - IInfraredDeviceManager infraredDeviceManager, IDeviceRepository deviceRepository, DeviceFactory deviceFactory, IMainThreadService uiThreadService, ILogger logger) { _bluetoothDeviceManager = bluetoothDeviceManager; - _infraredDeviceManager = infraredDeviceManager; _deviceRepository = deviceRepository; _deviceFactory = deviceFactory; _uiThreadService = uiThreadService; @@ -88,12 +86,11 @@ public async Task ScanAsync(CancellationToken token) try { - var infraScan = _infraredDeviceManager.ScanAsync(CreateDeviceAsync!, token); var bluetoothScan = _bluetoothDeviceManager.ScanAsync(CreateDeviceAsync!, token); - await Task.WhenAll(infraScan, bluetoothScan); + await Task.WhenAll(bluetoothScan); - return infraScan.Result && bluetoothScan.Result; + return bluetoothScan.Result; } catch (Exception) { diff --git a/BrickController2/BrickController2/DeviceManagement/IInfraredDeviceManager.cs b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/IInfraredDeviceManager.cs similarity index 84% rename from BrickController2/BrickController2/DeviceManagement/IInfraredDeviceManager.cs rename to BrickController2/BrickController2/DeviceManagement/InfraRedDevice/IInfraredDeviceManager.cs index 9602ba020..90522c93a 100644 --- a/BrickController2/BrickController2/DeviceManagement/IInfraredDeviceManager.cs +++ b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/IInfraredDeviceManager.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace BrickController2.DeviceManagement +namespace BrickController2.DeviceManagement.InfraredDevice { internal interface IInfraredDeviceManager : IDeviceScanner { diff --git a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs new file mode 100644 index 000000000..59b97c50c --- /dev/null +++ b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs @@ -0,0 +1,26 @@ +using Autofac; +using BrickController2.DeviceManagement.DI; +using BrickController2.DeviceManagement.Vendors; + +namespace BrickController2.DeviceManagement.InfraredDevice; + +/// +/// fake Vendor for infrared devices +/// +internal class InfraRedDeviceVendor : Vendor +{ + public override string VendorName => "IRDevice"; + + protected override void Register(VendorBuilder builder) + { + // device manager + builder.ContainerBuilder.RegisterType().As().SingleInstance(); + + // manually added devices + builder.RegisterDevice() + .WithDeviceFactory($"{0}", $"PF Infra {1}", null) + .WithDeviceFactory($"{1}", $"PF Infra {2}", null) + .WithDeviceFactory($"{2}", $"PF Infra {3}", null) + .WithDeviceFactory($"{3}", $"PF Infra {4}", null); + } +} diff --git a/BrickController2/BrickController2/DeviceManagement/InfraredDevice.cs b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDevice.cs similarity index 84% rename from BrickController2/BrickController2/DeviceManagement/InfraredDevice.cs rename to BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDevice.cs index 03ecd0f1f..2bf58b406 100644 --- a/BrickController2/BrickController2/DeviceManagement/InfraredDevice.cs +++ b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDevice.cs @@ -3,9 +3,9 @@ using System.Threading; using System.Threading.Tasks; -namespace BrickController2.DeviceManagement +namespace BrickController2.DeviceManagement.InfraredDevice { - internal class InfraredDevice : Device + internal class InfraredDevice : Device, IDeviceType { private readonly IInfraredDeviceManager _infraredDeviceManager; @@ -15,7 +15,10 @@ public InfraredDevice(string name, string address, byte[] deviceData, IInfraredD _infraredDeviceManager = infraredDeviceManager; } - public override DeviceType DeviceType => DeviceType.Infrared; + public static DeviceType Type => DeviceType.Infrared; + + public static string TypeName => "InfraredDevice"; + public override DeviceType DeviceType => Type; public override int NumberOfChannels => 2; public override async Task ConnectAsync( diff --git a/BrickController2/BrickController2/DeviceManagement/InfraredDeviceManager.cs b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDeviceManager.cs similarity index 99% rename from BrickController2/BrickController2/DeviceManagement/InfraredDeviceManager.cs rename to BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDeviceManager.cs index 2b2cd24eb..ba091ea24 100644 --- a/BrickController2/BrickController2/DeviceManagement/InfraredDeviceManager.cs +++ b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDeviceManager.cs @@ -4,7 +4,7 @@ using BrickController2.PlatformServices.Infrared; using BrickController2.Helpers; -namespace BrickController2.DeviceManagement +namespace BrickController2.DeviceManagement.InfraredDevice { internal class InfraredDeviceManager : IInfraredDeviceManager { From c58a050a60b3863625df553bdd71815b7e0b8300 Mon Sep 17 00:00:00 2001 From: J0EK3R Date: Mon, 15 Jun 2026 12:54:03 +0200 Subject: [PATCH 02/15] Manual devices are shown only if IDeviceFactoryData.IsAvailable is true --- .../DeviceManagement/DeviceFactoryData.cs | 1 + .../DeviceManagement/IDeviceFactoryData.cs | 1 + .../InfraRedDevice/InfraRedDeviceVendor.cs | 10 ++++++++++ .../DeviceManagement/Vendors/Vendor.cs | 2 ++ .../UI/ViewModels/ManualDeviceListPageViewModel.cs | 1 + 5 files changed, 15 insertions(+) diff --git a/BrickController2/BrickController2/DeviceManagement/DeviceFactoryData.cs b/BrickController2/BrickController2/DeviceManagement/DeviceFactoryData.cs index cd94e88f2..72183f18b 100644 --- a/BrickController2/BrickController2/DeviceManagement/DeviceFactoryData.cs +++ b/BrickController2/BrickController2/DeviceManagement/DeviceFactoryData.cs @@ -19,6 +19,7 @@ public DeviceFactoryData(TVendor vendor, string name, string address, byte[] dev public DeviceType DeviceType => TDevice.Type; + public bool IsAvailable => Vendor.IsAvailable; public TVendor Vendor { get; } public string Name { get; } public string Address { get; } diff --git a/BrickController2/BrickController2/DeviceManagement/IDeviceFactoryData.cs b/BrickController2/BrickController2/DeviceManagement/IDeviceFactoryData.cs index 5af67008b..4441d3d4d 100644 --- a/BrickController2/BrickController2/DeviceManagement/IDeviceFactoryData.cs +++ b/BrickController2/BrickController2/DeviceManagement/IDeviceFactoryData.cs @@ -5,6 +5,7 @@ namespace BrickController2.DeviceManagement { public interface IDeviceFactoryData { + bool IsAvailable { get; } DeviceType DeviceType { get; } string Name { get; } string Address { get; } diff --git a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs index 59b97c50c..badc9392d 100644 --- a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs +++ b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs @@ -1,6 +1,7 @@ using Autofac; using BrickController2.DeviceManagement.DI; using BrickController2.DeviceManagement.Vendors; +using BrickController2.PlatformServices.Infrared; namespace BrickController2.DeviceManagement.InfraredDevice; @@ -9,13 +10,22 @@ namespace BrickController2.DeviceManagement.InfraredDevice; /// internal class InfraRedDeviceVendor : Vendor { + private IInfraredService? _infraredService; + public override string VendorName => "IRDevice"; + public override bool IsAvailable => _infraredService?.IsInfraredSupported ?? false; + protected override void Register(VendorBuilder builder) { // device manager builder.ContainerBuilder.RegisterType().As().SingleInstance(); + builder.ContainerBuilder.RegisterBuildCallback(scope => + { + _infraredService = scope.Resolve(); + }); + // manually added devices builder.RegisterDevice() .WithDeviceFactory($"{0}", $"PF Infra {1}", null) diff --git a/BrickController2/BrickController2/DeviceManagement/Vendors/Vendor.cs b/BrickController2/BrickController2/DeviceManagement/Vendors/Vendor.cs index 76cd92c49..24fd0b357 100644 --- a/BrickController2/BrickController2/DeviceManagement/Vendors/Vendor.cs +++ b/BrickController2/BrickController2/DeviceManagement/Vendors/Vendor.cs @@ -12,6 +12,8 @@ public abstract class Vendor : Module, IVendorModule { public abstract string VendorName { get; } + public virtual bool IsAvailable => true; + protected abstract void Register(VendorBuilder builder); protected sealed override void Load(ContainerBuilder builder) diff --git a/BrickController2/BrickController2/UI/ViewModels/ManualDeviceListPageViewModel.cs b/BrickController2/BrickController2/UI/ViewModels/ManualDeviceListPageViewModel.cs index ddf253ca1..627f0425c 100644 --- a/BrickController2/BrickController2/UI/ViewModels/ManualDeviceListPageViewModel.cs +++ b/BrickController2/BrickController2/UI/ViewModels/ManualDeviceListPageViewModel.cs @@ -56,6 +56,7 @@ public ManualDeviceListPageViewModel( var groups = manualDeviceManager.FactoryDataList // apply ordering per vendor and device type + .Where(o => o.IsAvailable) .OrderBy(o => o.VendorName) .ThenBy(o => o.DeviceTypeName) .GroupBy(o => (o.VendorName, o.DeviceType, o.DeviceTypeName), x => new DeviceEntry(x, GetDeviceInstance(x))); From bf3da4e24a26648b7a4002a759661128d8578fe2 Mon Sep 17 00:00:00 2001 From: J0EK3R Date: Mon, 15 Jun 2026 13:10:26 +0200 Subject: [PATCH 03/15] Available if _infraredService.IsCarrierFrequencySupported(InfraredDeviceManager.IR_FREQUENCY) --- .../DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs | 2 +- .../DeviceManagement/InfraRedDevice/InfraredDeviceManager.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs index badc9392d..91286dd42 100644 --- a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs +++ b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs @@ -14,7 +14,7 @@ internal class InfraRedDeviceVendor : Vendor public override string VendorName => "IRDevice"; - public override bool IsAvailable => _infraredService?.IsInfraredSupported ?? false; + public override bool IsAvailable => _infraredService != null && _infraredService.IsInfraredSupported && _infraredService.IsCarrierFrequencySupported(InfraredDeviceManager.IR_FREQUENCY); protected override void Register(VendorBuilder builder) { diff --git a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDeviceManager.cs b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDeviceManager.cs index ba091ea24..2952333b0 100644 --- a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDeviceManager.cs +++ b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDeviceManager.cs @@ -8,7 +8,7 @@ namespace BrickController2.DeviceManagement.InfraredDevice { internal class InfraredDeviceManager : IInfraredDeviceManager { - private const int IR_FREQUENCY = 38000; + public const int IR_FREQUENCY = 38000; private const int IR_MARK_US = 158; private const int IR_START_GAP_US = 1026; From 367c81b778dcf002a309e5b3ec2bb096a62099df Mon Sep 17 00:00:00 2001 From: J0EK3R Date: Mon, 15 Jun 2026 13:12:34 +0200 Subject: [PATCH 04/15] removed IDeviceScanner from IInfraredDeviceManager --- .../InfraRedDevice/IInfraredDeviceManager.cs | 2 +- .../InfraRedDevice/InfraredDeviceManager.cs | 21 ------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/IInfraredDeviceManager.cs b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/IInfraredDeviceManager.cs index 90522c93a..015ce1d49 100644 --- a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/IInfraredDeviceManager.cs +++ b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/IInfraredDeviceManager.cs @@ -2,7 +2,7 @@ namespace BrickController2.DeviceManagement.InfraredDevice { - internal interface IInfraredDeviceManager : IDeviceScanner + internal interface IInfraredDeviceManager { Task ConnectDevice(InfraredDevice device); Task DisconnectDevice(InfraredDevice device); diff --git a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDeviceManager.cs b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDeviceManager.cs index 2952333b0..3fc859b34 100644 --- a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDeviceManager.cs +++ b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDeviceManager.cs @@ -34,27 +34,6 @@ public InfraredDeviceManager(IInfraredService infraredService) _infraredService = infraredService; } - public async Task ScanAsync(Func deviceFoundCallback, CancellationToken token) - { - using (await _asyncLock.LockAsync()) - { - if (_infraredService.IsInfraredSupported && _infraredService.IsCarrierFrequencySupported(IR_FREQUENCY)) - { - for (int i = 0; i < 4; i++) - { - if (token.IsCancellationRequested) - { - break; - } - - await deviceFoundCallback(DeviceType.Infrared, $"PF Infra {i + 1}", $"{i}", null); - } - } - } - - return true; - } - public async Task ConnectDevice(InfraredDevice device) { using (await _asyncLock.LockAsync()) From 01e6fc2fd658a030601469265931f1982d3f837b Mon Sep 17 00:00:00 2001 From: J0EK3R Date: Tue, 16 Jun 2026 05:55:49 +0200 Subject: [PATCH 05/15] Simplify Bluetooth scan logic in DeviceManager --- .../BrickController2/DeviceManagement/DeviceManager.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/BrickController2/BrickController2/DeviceManagement/DeviceManager.cs b/BrickController2/BrickController2/DeviceManagement/DeviceManager.cs index 836b022da..0202ce5e7 100644 --- a/BrickController2/BrickController2/DeviceManagement/DeviceManager.cs +++ b/BrickController2/BrickController2/DeviceManagement/DeviceManager.cs @@ -86,11 +86,7 @@ public async Task ScanAsync(CancellationToken token) try { - var bluetoothScan = _bluetoothDeviceManager.ScanAsync(CreateDeviceAsync!, token); - - await Task.WhenAll(bluetoothScan); - - return bluetoothScan.Result; + return await _bluetoothDeviceManager.ScanAsync(CreateDeviceAsync!, token); } catch (Exception) { From c806ce98ead5ae2f62b9bceaa5984b2897994871 Mon Sep 17 00:00:00 2001 From: J0EK3R Date: Tue, 16 Jun 2026 05:57:35 +0200 Subject: [PATCH 06/15] Clean up unused using directives in DeviceManagementModule Removed unused using directives for Microsoft.Maui.Controls, System.Net, and System.Numerics. --- .../DeviceManagement/DI/DeviceManagementModule.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/BrickController2/BrickController2/DeviceManagement/DI/DeviceManagementModule.cs b/BrickController2/BrickController2/DeviceManagement/DI/DeviceManagementModule.cs index c4a82ce88..24c17c5c5 100644 --- a/BrickController2/BrickController2/DeviceManagement/DI/DeviceManagementModule.cs +++ b/BrickController2/BrickController2/DeviceManagement/DI/DeviceManagementModule.cs @@ -2,10 +2,7 @@ using BrickController2.DeviceManagement.Vendors; using BrickController2.Extensions; using BrickController2.UI.Images; -using Microsoft.Maui.Controls; using System; -using System.Net; -using System.Numerics; namespace BrickController2.DeviceManagement.DI { From 64daab4be104b74cc9e68b20a49453f4cbe19903 Mon Sep 17 00:00:00 2001 From: J0EK3R Date: Tue, 16 Jun 2026 06:01:17 +0200 Subject: [PATCH 07/15] Refactor device factory registrations for InfraRedDevice --- .../InfraRedDevice/InfraRedDeviceVendor.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs index 91286dd42..30a648f58 100644 --- a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs +++ b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs @@ -28,9 +28,9 @@ protected override void Register(VendorBuilder builder) // manually added devices builder.RegisterDevice() - .WithDeviceFactory($"{0}", $"PF Infra {1}", null) - .WithDeviceFactory($"{1}", $"PF Infra {2}", null) - .WithDeviceFactory($"{2}", $"PF Infra {3}", null) - .WithDeviceFactory($"{3}", $"PF Infra {4}", null); + .WithDeviceFactory("0", "PF Infra 1") + .WithDeviceFactory("1", "PF Infra 2") + .WithDeviceFactory("2", "PF Infra 3") + .WithDeviceFactory("3", "PF Infra 4"); } } From e73790d5df9ad12ae175e726f200180231dae7ba Mon Sep 17 00:00:00 2001 From: J0EK3R Date: Tue, 16 Jun 2026 15:22:15 +0200 Subject: [PATCH 08/15] removed unused using --- .../BrickController2/DeviceManagement/DeviceManager.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/BrickController2/BrickController2/DeviceManagement/DeviceManager.cs b/BrickController2/BrickController2/DeviceManagement/DeviceManager.cs index 0202ce5e7..406cb30b4 100644 --- a/BrickController2/BrickController2/DeviceManagement/DeviceManager.cs +++ b/BrickController2/BrickController2/DeviceManagement/DeviceManager.cs @@ -1,5 +1,4 @@ -using BrickController2.DeviceManagement.InfraredDevice; -using BrickController2.Helpers; +using BrickController2.Helpers; using BrickController2.UI.Services.MainThread; using Microsoft.Extensions.Logging; using System; From 87cd776590d736ce668fcb891bf62e4a7c8e5184 Mon Sep 17 00:00:00 2001 From: J0EK3R Date: Fri, 19 Jun 2026 06:19:02 +0200 Subject: [PATCH 09/15] Introduce IBluetoothDevice to avoid directly checks against DeviceType.Infrared --- .../DeviceManagement/BluetoothAdvertisingDevice.cs | 2 +- .../BrickController2/DeviceManagement/BluetoothDevice.cs | 2 +- .../BrickController2/DeviceManagement/IBluetoothDevice.cs | 6 ++++++ .../UI/ViewModels/ChannelSetupPageViewModel.cs | 2 +- .../BrickController2/UI/ViewModels/DevicePageViewModel.cs | 2 +- .../BrickController2/UI/ViewModels/PlayerPageViewModel.cs | 2 +- 6 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 BrickController2/BrickController2/DeviceManagement/IBluetoothDevice.cs diff --git a/BrickController2/BrickController2/DeviceManagement/BluetoothAdvertisingDevice.cs b/BrickController2/BrickController2/DeviceManagement/BluetoothAdvertisingDevice.cs index 2620908b3..1e192bb35 100644 --- a/BrickController2/BrickController2/DeviceManagement/BluetoothAdvertisingDevice.cs +++ b/BrickController2/BrickController2/DeviceManagement/BluetoothAdvertisingDevice.cs @@ -9,7 +9,7 @@ namespace BrickController2.DeviceManagement /// /// Baseclass of Bluetooth LE Advertising devices /// - internal abstract class BluetoothAdvertisingDevice : Device + internal abstract class BluetoothAdvertisingDevice : Device, IBluetoothDevice { /// /// BluetoothAdvertisingDeviceHandler diff --git a/BrickController2/BrickController2/DeviceManagement/BluetoothDevice.cs b/BrickController2/BrickController2/DeviceManagement/BluetoothDevice.cs index 2b1e3d8fc..f25c4c35c 100644 --- a/BrickController2/BrickController2/DeviceManagement/BluetoothDevice.cs +++ b/BrickController2/BrickController2/DeviceManagement/BluetoothDevice.cs @@ -6,7 +6,7 @@ namespace BrickController2.DeviceManagement { - internal abstract class BluetoothDevice : Device + internal abstract class BluetoothDevice : Device, IBluetoothDevice { protected readonly IBluetoothLEService _bleService; diff --git a/BrickController2/BrickController2/DeviceManagement/IBluetoothDevice.cs b/BrickController2/BrickController2/DeviceManagement/IBluetoothDevice.cs new file mode 100644 index 000000000..9e2ccbba6 --- /dev/null +++ b/BrickController2/BrickController2/DeviceManagement/IBluetoothDevice.cs @@ -0,0 +1,6 @@ +namespace BrickController2.DeviceManagement +{ + internal interface IBluetoothDevice + { + } +} diff --git a/BrickController2/BrickController2/UI/ViewModels/ChannelSetupPageViewModel.cs b/BrickController2/BrickController2/UI/ViewModels/ChannelSetupPageViewModel.cs index 4f1c08ddc..bff63327e 100644 --- a/BrickController2/BrickController2/UI/ViewModels/ChannelSetupPageViewModel.cs +++ b/BrickController2/BrickController2/UI/ViewModels/ChannelSetupPageViewModel.cs @@ -101,7 +101,7 @@ public override async void OnAppearing() _isDisappearing = false; base.OnAppearing(); - if (Device.DeviceType != DeviceType.Infrared) + if (Device is IBluetoothDevice) { if (!await _deviceManager.IsBluetoothOnAsync()) { diff --git a/BrickController2/BrickController2/UI/ViewModels/DevicePageViewModel.cs b/BrickController2/BrickController2/UI/ViewModels/DevicePageViewModel.cs index 710220d36..baa1c040b 100644 --- a/BrickController2/BrickController2/UI/ViewModels/DevicePageViewModel.cs +++ b/BrickController2/BrickController2/UI/ViewModels/DevicePageViewModel.cs @@ -88,7 +88,7 @@ public override async void OnAppearing() _isDisappearing = false; base.OnAppearing(); - if (Device.DeviceType != DeviceType.Infrared) + if (Device is IBluetoothDevice) { if (!await _deviceManager.IsBluetoothOnAsync()) { diff --git a/BrickController2/BrickController2/UI/ViewModels/PlayerPageViewModel.cs b/BrickController2/BrickController2/UI/ViewModels/PlayerPageViewModel.cs index aa671f200..6c0de58d0 100644 --- a/BrickController2/BrickController2/UI/ViewModels/PlayerPageViewModel.cs +++ b/BrickController2/BrickController2/UI/ViewModels/PlayerPageViewModel.cs @@ -101,7 +101,7 @@ public override async void OnAppearing() _isDisappearing = false; base.OnAppearing(); - if (_devices.Any(d => d.DeviceType != DeviceType.Infrared) && !await _deviceManager.IsBluetoothOnAsync()) + if (_devices.Any(d => d is IBluetoothDevice) && !await _deviceManager.IsBluetoothOnAsync()) { await _dialogService.ShowMessageBoxAsync( Translate("Warning"), From 1795f4b7333a3b87ffd35f95c925abef6b999d5f Mon Sep 17 00:00:00 2001 From: J0EK3R Date: Fri, 19 Jun 2026 07:16:00 +0200 Subject: [PATCH 10/15] renaming of "InfraredDevice" to "PowerFunctions" including files, DeviceType, xaml and images --- .../Infrared/InfraredService.cs | 2 +- .../BusinessLogic/PlayLogic.cs | 2 +- .../DeviceManagement/DeviceType.cs | 2 +- .../InfraRedDevice/IInfraredDeviceManager.cs | 12 ----------- .../PowerFunctions/IPowerFunctionsManager.cs | 12 +++++++++++ .../PowerFunctions.cs} | 20 +++++++++--------- .../PowerFunctionsManager.cs} | 12 +++++------ .../PowerFunctionsVendor.cs} | 16 +++++++------- .../UI/Controls/DeviceChannelLabel.cs | 2 +- .../UI/Controls/DeviceChannelSelector.xaml | 10 ++++----- .../UI/Controls/DeviceChannelSelector.xaml.cs | 10 ++++----- ...red_image.png => powerfunctions_image.png} | Bin ...all.png => powerfunctions_image_small.png} | Bin 13 files changed, 50 insertions(+), 50 deletions(-) delete mode 100644 BrickController2/BrickController2/DeviceManagement/InfraRedDevice/IInfraredDeviceManager.cs create mode 100644 BrickController2/BrickController2/DeviceManagement/PowerFunctions/IPowerFunctionsManager.cs rename BrickController2/BrickController2/DeviceManagement/{InfraRedDevice/InfraredDevice.cs => PowerFunctions/PowerFunctions.cs} (65%) rename BrickController2/BrickController2/DeviceManagement/{InfraRedDevice/InfraredDeviceManager.cs => PowerFunctions/PowerFunctionsManager.cs} (95%) rename BrickController2/BrickController2/DeviceManagement/{InfraRedDevice/InfraRedDeviceVendor.cs => PowerFunctions/PowerFunctionsVendor.cs} (60%) rename BrickController2/BrickController2/UI/Images/{infrared_image.png => powerfunctions_image.png} (100%) rename BrickController2/BrickController2/UI/Images/{infrared_image_small.png => powerfunctions_image_small.png} (100%) diff --git a/BrickController2/BrickController2.Android/PlatformServices/Infrared/InfraredService.cs b/BrickController2/BrickController2.Android/PlatformServices/Infrared/InfraredService.cs index 4e461fed7..c5d358797 100644 --- a/BrickController2/BrickController2.Android/PlatformServices/Infrared/InfraredService.cs +++ b/BrickController2/BrickController2.Android/PlatformServices/Infrared/InfraredService.cs @@ -47,7 +47,7 @@ public Task SendPacketAsync(int carrierFrequency, int[] packet) { if (_irManager == null) { - throw new InvalidOperationException("Infrared is not supported."); + throw new InvalidOperationException("PowerFunctions is not supported."); } return _irManager.TransmitAsync(carrierFrequency, packet); diff --git a/BrickController2/BrickController2/BusinessLogic/PlayLogic.cs b/BrickController2/BrickController2/BusinessLogic/PlayLogic.cs index 875a88a7b..3068aafc9 100644 --- a/BrickController2/BrickController2/BusinessLogic/PlayLogic.cs +++ b/BrickController2/BrickController2/BusinessLogic/PlayLogic.cs @@ -423,7 +423,7 @@ private float GetAccelarationStep(DeviceType deviceType) { case DeviceType.BuWizz: case DeviceType.BuWizz2: - case DeviceType.Infrared: + case DeviceType.PowerFunctions: case DeviceType.SBrick: return 1F / 7; diff --git a/BrickController2/BrickController2/DeviceManagement/DeviceType.cs b/BrickController2/BrickController2/DeviceManagement/DeviceType.cs index 13e7c1a8d..8452e7bfa 100644 --- a/BrickController2/BrickController2/DeviceManagement/DeviceType.cs +++ b/BrickController2/BrickController2/DeviceManagement/DeviceType.cs @@ -6,7 +6,7 @@ public enum DeviceType SBrick, BuWizz, BuWizz2, - Infrared, + PowerFunctions, Boost, PoweredUp, TechnicHub, diff --git a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/IInfraredDeviceManager.cs b/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/IInfraredDeviceManager.cs deleted file mode 100644 index 015ce1d49..000000000 --- a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/IInfraredDeviceManager.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Threading.Tasks; - -namespace BrickController2.DeviceManagement.InfraredDevice -{ - internal interface IInfraredDeviceManager - { - Task ConnectDevice(InfraredDevice device); - Task DisconnectDevice(InfraredDevice device); - - void SetOutput(InfraredDevice device, int channel, int value); - } -} diff --git a/BrickController2/BrickController2/DeviceManagement/PowerFunctions/IPowerFunctionsManager.cs b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/IPowerFunctionsManager.cs new file mode 100644 index 000000000..8d023fe75 --- /dev/null +++ b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/IPowerFunctionsManager.cs @@ -0,0 +1,12 @@ +using System.Threading.Tasks; + +namespace BrickController2.DeviceManagement.PowerFunctions +{ + internal interface IPowerFunctionsManager + { + Task ConnectDevice(PowerFunctions device); + Task DisconnectDevice(PowerFunctions device); + + void SetOutput(PowerFunctions device, int channel, int value); + } +} diff --git a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDevice.cs b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctions.cs similarity index 65% rename from BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDevice.cs rename to BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctions.cs index 2bf58b406..8ab832040 100644 --- a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDevice.cs +++ b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctions.cs @@ -3,21 +3,21 @@ using System.Threading; using System.Threading.Tasks; -namespace BrickController2.DeviceManagement.InfraredDevice +namespace BrickController2.DeviceManagement.PowerFunctions { - internal class InfraredDevice : Device, IDeviceType + internal class PowerFunctions : Device, IDeviceType { - private readonly IInfraredDeviceManager _infraredDeviceManager; + private readonly IPowerFunctionsManager _powerFunctionsManager; - public InfraredDevice(string name, string address, byte[] deviceData, IInfraredDeviceManager infraredDeviceManager, IDeviceRepository deviceRepository) + public PowerFunctions(string name, string address, byte[] deviceData, IPowerFunctionsManager powerFunctionsManager, IDeviceRepository deviceRepository) : base(name, address, deviceRepository) { - _infraredDeviceManager = infraredDeviceManager; + _powerFunctionsManager = powerFunctionsManager; } - public static DeviceType Type => DeviceType.Infrared; + public static DeviceType Type => DeviceType.PowerFunctions; - public static string TypeName => "InfraredDevice"; + public static string TypeName => "Power Functions"; public override DeviceType DeviceType => Type; public override int NumberOfChannels => 2; @@ -31,7 +31,7 @@ public override async Task ConnectAsync( { DeviceState = DeviceState.Connecting; - var result = await _infraredDeviceManager.ConnectDevice(this); + var result = await _powerFunctionsManager.ConnectDevice(this); DeviceState = result == DeviceConnectionResult.Ok ? DeviceState.Connected : DeviceState.Disconnected; return result; @@ -41,7 +41,7 @@ public override async Task DisconnectAsync() { DeviceState = DeviceState.Disconnecting; - await _infraredDeviceManager.DisconnectDevice(this); + await _powerFunctionsManager.DisconnectDevice(this); DeviceState = DeviceState.Disconnected; } @@ -52,7 +52,7 @@ public override void SetOutput(int channel, float value) value = CutOutputValue(value); var intValue = (int)(7 * value); - _infraredDeviceManager.SetOutput(this, channel, intValue); + _powerFunctionsManager.SetOutput(this, channel, intValue); } } } diff --git a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDeviceManager.cs b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsManager.cs similarity index 95% rename from BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDeviceManager.cs rename to BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsManager.cs index 3fc859b34..4fefa5df6 100644 --- a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraredDeviceManager.cs +++ b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsManager.cs @@ -4,9 +4,9 @@ using BrickController2.PlatformServices.Infrared; using BrickController2.Helpers; -namespace BrickController2.DeviceManagement.InfraredDevice +namespace BrickController2.DeviceManagement.PowerFunctions { - internal class InfraredDeviceManager : IInfraredDeviceManager + internal class PowerFunctionsManager : IPowerFunctionsManager { public const int IR_FREQUENCY = 38000; @@ -29,12 +29,12 @@ internal class InfraredDeviceManager : IInfraredDeviceManager private Task? _irTask; private CancellationTokenSource? _irTaskCancelationTokenSource; - public InfraredDeviceManager(IInfraredService infraredService) + public PowerFunctionsManager(IInfraredService infraredService) { _infraredService = infraredService; } - public async Task ConnectDevice(InfraredDevice device) + public async Task ConnectDevice(PowerFunctions device) { using (await _asyncLock.LockAsync()) { @@ -53,7 +53,7 @@ public async Task ConnectDevice(InfraredDevice device) } } - public async Task DisconnectDevice(InfraredDevice device) + public async Task DisconnectDevice(PowerFunctions device) { using (await _asyncLock.LockAsync()) { @@ -70,7 +70,7 @@ public async Task DisconnectDevice(InfraredDevice device) } } - public void SetOutput(InfraredDevice device, int channel, int value) + public void SetOutput(PowerFunctions device, int channel, int value) { if (int.TryParse(device.Address, out int address)) { diff --git a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsVendor.cs similarity index 60% rename from BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs rename to BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsVendor.cs index 30a648f58..df7dd530f 100644 --- a/BrickController2/BrickController2/DeviceManagement/InfraRedDevice/InfraRedDeviceVendor.cs +++ b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsVendor.cs @@ -3,23 +3,23 @@ using BrickController2.DeviceManagement.Vendors; using BrickController2.PlatformServices.Infrared; -namespace BrickController2.DeviceManagement.InfraredDevice; +namespace BrickController2.DeviceManagement.PowerFunctions; /// -/// fake Vendor for infrared devices +/// Vendor for Power Functions devices /// -internal class InfraRedDeviceVendor : Vendor +internal class PowerFunctionsVendor : Vendor { private IInfraredService? _infraredService; - public override string VendorName => "IRDevice"; + public override string VendorName => "LEGO"; - public override bool IsAvailable => _infraredService != null && _infraredService.IsInfraredSupported && _infraredService.IsCarrierFrequencySupported(InfraredDeviceManager.IR_FREQUENCY); + public override bool IsAvailable => _infraredService != null && _infraredService.IsInfraredSupported && _infraredService.IsCarrierFrequencySupported(PowerFunctionsManager.IR_FREQUENCY); - protected override void Register(VendorBuilder builder) + protected override void Register(VendorBuilder builder) { // device manager - builder.ContainerBuilder.RegisterType().As().SingleInstance(); + builder.ContainerBuilder.RegisterType().As().SingleInstance(); builder.ContainerBuilder.RegisterBuildCallback(scope => { @@ -27,7 +27,7 @@ protected override void Register(VendorBuilder builder) }); // manually added devices - builder.RegisterDevice() + builder.RegisterDevice() .WithDeviceFactory("0", "PF Infra 1") .WithDeviceFactory("1", "PF Infra 2") .WithDeviceFactory("2", "PF Infra 3") diff --git a/BrickController2/BrickController2/UI/Controls/DeviceChannelLabel.cs b/BrickController2/BrickController2/UI/Controls/DeviceChannelLabel.cs index 5d0a90d05..9c7b46683 100644 --- a/BrickController2/BrickController2/UI/Controls/DeviceChannelLabel.cs +++ b/BrickController2/BrickController2/UI/Controls/DeviceChannelLabel.cs @@ -79,7 +79,7 @@ private void SetChannelText() SetChannelText(_buwizz3ChannelLetters); break; - case DeviceType.Infrared: + case DeviceType.PowerFunctions: Text = Channel == 0 ? TranslationHelper.Translate("Blue") : TranslationHelper.Translate("Red"); diff --git a/BrickController2/BrickController2/UI/Controls/DeviceChannelSelector.xaml b/BrickController2/BrickController2/UI/Controls/DeviceChannelSelector.xaml index 530242b2b..ffd71672f 100644 --- a/BrickController2/BrickController2/UI/Controls/DeviceChannelSelector.xaml +++ b/BrickController2/BrickController2/UI/Controls/DeviceChannelSelector.xaml @@ -132,8 +132,8 @@ - - + + @@ -141,13 +141,13 @@ - + - + - + diff --git a/BrickController2/BrickController2/UI/Controls/DeviceChannelSelector.xaml.cs b/BrickController2/BrickController2/UI/Controls/DeviceChannelSelector.xaml.cs index 04a3fa1dd..e60f5e802 100644 --- a/BrickController2/BrickController2/UI/Controls/DeviceChannelSelector.xaml.cs +++ b/BrickController2/BrickController2/UI/Controls/DeviceChannelSelector.xaml.cs @@ -29,8 +29,8 @@ public DeviceChannelSelector() BuWizz3Channel3.Command = new SafeCommand(() => SelectedChannel = 3); BuWizz3Channel4.Command = new SafeCommand(() => SelectedChannel = 4); BuWizz3Channel5.Command = new SafeCommand(() => SelectedChannel = 5); - InfraredChannel0.Command = new SafeCommand(() => SelectedChannel = 0); - InfraredChannel1.Command = new SafeCommand(() => SelectedChannel = 1); + PowerFunctionsChannel0.Command = new SafeCommand(() => SelectedChannel = 0); + PowerFunctionsChannel1.Command = new SafeCommand(() => SelectedChannel = 1); PoweredUpChannel0.Command = new SafeCommand(() => SelectedChannel = 0); PoweredUpChannel1.Command = new SafeCommand(() => SelectedChannel = 1); BoostChannelA.Command = new SafeCommand(() => SelectedChannel = 0); @@ -173,7 +173,7 @@ private void OnDeviceChanged(Device device) SbrickLightSection.IsVisible = deviceType == DeviceType.SBrickLight; BuWizzSection.IsVisible = deviceType == DeviceType.BuWizz || deviceType == DeviceType.BuWizz2; BuWizz3Section.IsVisible = deviceType == DeviceType.BuWizz3; - InfraredSection.IsVisible = deviceType == DeviceType.Infrared; + PowerFunctionsSection.IsVisible = deviceType == DeviceType.PowerFunctions; PoweredUpSection.IsVisible = deviceType == DeviceType.PoweredUp; BoostSection.IsVisible = deviceType == DeviceType.Boost; TechnicHubSection.IsVisible = deviceType == DeviceType.TechnicHub; @@ -222,8 +222,8 @@ private void OnSelectedChannelChanged(int selectedChannel) BuWizz3Channel3.SelectedChannel = selectedChannel; BuWizz3Channel4.SelectedChannel = selectedChannel; BuWizz3Channel5.SelectedChannel = selectedChannel; - InfraredChannel0.SelectedChannel = selectedChannel; - InfraredChannel1.SelectedChannel = selectedChannel; + PowerFunctionsChannel0.SelectedChannel = selectedChannel; + PowerFunctionsChannel1.SelectedChannel = selectedChannel; PoweredUpChannel0.SelectedChannel = selectedChannel; PoweredUpChannel1.SelectedChannel = selectedChannel; BoostChannelA.SelectedChannel = selectedChannel; diff --git a/BrickController2/BrickController2/UI/Images/infrared_image.png b/BrickController2/BrickController2/UI/Images/powerfunctions_image.png similarity index 100% rename from BrickController2/BrickController2/UI/Images/infrared_image.png rename to BrickController2/BrickController2/UI/Images/powerfunctions_image.png diff --git a/BrickController2/BrickController2/UI/Images/infrared_image_small.png b/BrickController2/BrickController2/UI/Images/powerfunctions_image_small.png similarity index 100% rename from BrickController2/BrickController2/UI/Images/infrared_image_small.png rename to BrickController2/BrickController2/UI/Images/powerfunctions_image_small.png From 8466af353f65228f90bd967615518637bebf42ac Mon Sep 17 00:00:00 2001 From: J0EK3R Date: Sat, 20 Jun 2026 05:20:53 +0200 Subject: [PATCH 11/15] step back "PowerFunctions is not supported." -> "Infrared is not supported." --- .../PlatformServices/Infrared/InfraredService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BrickController2/BrickController2.Android/PlatformServices/Infrared/InfraredService.cs b/BrickController2/BrickController2.Android/PlatformServices/Infrared/InfraredService.cs index c5d358797..4e461fed7 100644 --- a/BrickController2/BrickController2.Android/PlatformServices/Infrared/InfraredService.cs +++ b/BrickController2/BrickController2.Android/PlatformServices/Infrared/InfraredService.cs @@ -47,7 +47,7 @@ public Task SendPacketAsync(int carrierFrequency, int[] packet) { if (_irManager == null) { - throw new InvalidOperationException("PowerFunctions is not supported."); + throw new InvalidOperationException("Infrared is not supported."); } return _irManager.TransmitAsync(carrierFrequency, packet); From fc37dd4da8a0e00678859c13d32b4c33c25330f5 Mon Sep 17 00:00:00 2001 From: J0EK3R Date: Sat, 20 Jun 2026 05:40:39 +0200 Subject: [PATCH 12/15] Revert: rename DeviceType.PowerFunction -> DeviceType.Infrared --- BrickController2/BrickController2/BusinessLogic/PlayLogic.cs | 2 +- .../BrickController2/DeviceManagement/DeviceType.cs | 2 +- .../DeviceManagement/PowerFunctions/PowerFunctions.cs | 2 +- .../BrickController2/UI/Controls/DeviceChannelLabel.cs | 2 +- .../BrickController2/UI/Controls/DeviceChannelSelector.xaml | 4 ++-- .../UI/Controls/DeviceChannelSelector.xaml.cs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/BrickController2/BrickController2/BusinessLogic/PlayLogic.cs b/BrickController2/BrickController2/BusinessLogic/PlayLogic.cs index 3068aafc9..875a88a7b 100644 --- a/BrickController2/BrickController2/BusinessLogic/PlayLogic.cs +++ b/BrickController2/BrickController2/BusinessLogic/PlayLogic.cs @@ -423,7 +423,7 @@ private float GetAccelarationStep(DeviceType deviceType) { case DeviceType.BuWizz: case DeviceType.BuWizz2: - case DeviceType.PowerFunctions: + case DeviceType.Infrared: case DeviceType.SBrick: return 1F / 7; diff --git a/BrickController2/BrickController2/DeviceManagement/DeviceType.cs b/BrickController2/BrickController2/DeviceManagement/DeviceType.cs index 8452e7bfa..13e7c1a8d 100644 --- a/BrickController2/BrickController2/DeviceManagement/DeviceType.cs +++ b/BrickController2/BrickController2/DeviceManagement/DeviceType.cs @@ -6,7 +6,7 @@ public enum DeviceType SBrick, BuWizz, BuWizz2, - PowerFunctions, + Infrared, Boost, PoweredUp, TechnicHub, diff --git a/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctions.cs b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctions.cs index 8ab832040..fe28a6216 100644 --- a/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctions.cs +++ b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctions.cs @@ -15,7 +15,7 @@ public PowerFunctions(string name, string address, byte[] deviceData, IPowerFunc _powerFunctionsManager = powerFunctionsManager; } - public static DeviceType Type => DeviceType.PowerFunctions; + public static DeviceType Type => DeviceType.Infrared; public static string TypeName => "Power Functions"; public override DeviceType DeviceType => Type; diff --git a/BrickController2/BrickController2/UI/Controls/DeviceChannelLabel.cs b/BrickController2/BrickController2/UI/Controls/DeviceChannelLabel.cs index 9c7b46683..5d0a90d05 100644 --- a/BrickController2/BrickController2/UI/Controls/DeviceChannelLabel.cs +++ b/BrickController2/BrickController2/UI/Controls/DeviceChannelLabel.cs @@ -79,7 +79,7 @@ private void SetChannelText() SetChannelText(_buwizz3ChannelLetters); break; - case DeviceType.PowerFunctions: + case DeviceType.Infrared: Text = Channel == 0 ? TranslationHelper.Translate("Blue") : TranslationHelper.Translate("Red"); diff --git a/BrickController2/BrickController2/UI/Controls/DeviceChannelSelector.xaml b/BrickController2/BrickController2/UI/Controls/DeviceChannelSelector.xaml index ffd71672f..dd974e99b 100644 --- a/BrickController2/BrickController2/UI/Controls/DeviceChannelSelector.xaml +++ b/BrickController2/BrickController2/UI/Controls/DeviceChannelSelector.xaml @@ -141,13 +141,13 @@ - + - + diff --git a/BrickController2/BrickController2/UI/Controls/DeviceChannelSelector.xaml.cs b/BrickController2/BrickController2/UI/Controls/DeviceChannelSelector.xaml.cs index e60f5e802..5f1c68c2b 100644 --- a/BrickController2/BrickController2/UI/Controls/DeviceChannelSelector.xaml.cs +++ b/BrickController2/BrickController2/UI/Controls/DeviceChannelSelector.xaml.cs @@ -173,7 +173,7 @@ private void OnDeviceChanged(Device device) SbrickLightSection.IsVisible = deviceType == DeviceType.SBrickLight; BuWizzSection.IsVisible = deviceType == DeviceType.BuWizz || deviceType == DeviceType.BuWizz2; BuWizz3Section.IsVisible = deviceType == DeviceType.BuWizz3; - PowerFunctionsSection.IsVisible = deviceType == DeviceType.PowerFunctions; + PowerFunctionsSection.IsVisible = deviceType == DeviceType.Infrared; PoweredUpSection.IsVisible = deviceType == DeviceType.PoweredUp; BoostSection.IsVisible = deviceType == DeviceType.Boost; TechnicHubSection.IsVisible = deviceType == DeviceType.TechnicHub; From 7e18bc6d7a46696e1c98fe11e2bc35210686c2c3 Mon Sep 17 00:00:00 2001 From: J0EK3R Date: Sat, 20 Jun 2026 15:58:05 +0200 Subject: [PATCH 13/15] Explicitly register image names for PowerFunctions --- .../DeviceManagement/PowerFunctions/PowerFunctionsVendor.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsVendor.cs b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsVendor.cs index df7dd530f..8422b556b 100644 --- a/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsVendor.cs +++ b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsVendor.cs @@ -28,6 +28,7 @@ protected override void Register(VendorBuilder builder) // manually added devices builder.RegisterDevice() + .WithImages("powerfunctions_image.png", "powerfunctions_image_small.png") .WithDeviceFactory("0", "PF Infra 1") .WithDeviceFactory("1", "PF Infra 2") .WithDeviceFactory("2", "PF Infra 3") From db5c16b7e03f785e09e5224d9d960a0a10e11717 Mon Sep 17 00:00:00 2001 From: J0EK3R Date: Tue, 23 Jun 2026 05:41:48 +0200 Subject: [PATCH 14/15] renamed PowerFunctions -> PowerFunctionsDevice and PowerFunctionsVendor -> PowerFunctions --- .../PowerFunctions/IPowerFunctionsManager.cs | 6 +- .../PowerFunctions/PowerFunctions.cs | 79 +++++++------------ .../PowerFunctions/PowerFunctionsDevice.cs | 58 ++++++++++++++ .../PowerFunctions/PowerFunctionsManager.cs | 6 +- .../PowerFunctions/PowerFunctionsVendor.cs | 37 --------- 5 files changed, 93 insertions(+), 93 deletions(-) create mode 100644 BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsDevice.cs delete mode 100644 BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsVendor.cs diff --git a/BrickController2/BrickController2/DeviceManagement/PowerFunctions/IPowerFunctionsManager.cs b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/IPowerFunctionsManager.cs index 8d023fe75..baaabe278 100644 --- a/BrickController2/BrickController2/DeviceManagement/PowerFunctions/IPowerFunctionsManager.cs +++ b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/IPowerFunctionsManager.cs @@ -4,9 +4,9 @@ namespace BrickController2.DeviceManagement.PowerFunctions { internal interface IPowerFunctionsManager { - Task ConnectDevice(PowerFunctions device); - Task DisconnectDevice(PowerFunctions device); + Task ConnectDevice(PowerFunctionsDevice device); + Task DisconnectDevice(PowerFunctionsDevice device); - void SetOutput(PowerFunctions device, int channel, int value); + void SetOutput(PowerFunctionsDevice device, int channel, int value); } } diff --git a/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctions.cs b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctions.cs index fe28a6216..07a4e511b 100644 --- a/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctions.cs +++ b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctions.cs @@ -1,58 +1,37 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; +using Autofac; +using BrickController2.DeviceManagement.DI; +using BrickController2.DeviceManagement.Vendors; +using BrickController2.PlatformServices.Infrared; -namespace BrickController2.DeviceManagement.PowerFunctions -{ - internal class PowerFunctions : Device, IDeviceType - { - private readonly IPowerFunctionsManager _powerFunctionsManager; - - public PowerFunctions(string name, string address, byte[] deviceData, IPowerFunctionsManager powerFunctionsManager, IDeviceRepository deviceRepository) - : base(name, address, deviceRepository) - { - _powerFunctionsManager = powerFunctionsManager; - } - - public static DeviceType Type => DeviceType.Infrared; - - public static string TypeName => "Power Functions"; - public override DeviceType DeviceType => Type; - public override int NumberOfChannels => 2; - - public override async Task ConnectAsync( - bool reconnect, - Action onDeviceDisconnected, - IEnumerable channelConfigurations, - bool startOutputProcessing, - bool requestDeviceInformation, - CancellationToken token) - { - DeviceState = DeviceState.Connecting; - - var result = await _powerFunctionsManager.ConnectDevice(this); +namespace BrickController2.DeviceManagement.PowerFunctions; - DeviceState = result == DeviceConnectionResult.Ok ? DeviceState.Connected : DeviceState.Disconnected; - return result; - } - - public override async Task DisconnectAsync() - { - DeviceState = DeviceState.Disconnecting; +/// +/// Vendor for Power Functions devices +/// +internal class PowerFunctions : Vendor +{ + private IInfraredService? _infraredService; + + public override string VendorName => "LEGO"; - await _powerFunctionsManager.DisconnectDevice(this); + public override bool IsAvailable => _infraredService != null && _infraredService.IsInfraredSupported && _infraredService.IsCarrierFrequencySupported(PowerFunctionsManager.IR_FREQUENCY); - DeviceState = DeviceState.Disconnected; - } + protected override void Register(VendorBuilder builder) + { + // device manager + builder.ContainerBuilder.RegisterType().As().SingleInstance(); - public override void SetOutput(int channel, float value) + builder.ContainerBuilder.RegisterBuildCallback(scope => { - CheckChannel(channel); - value = CutOutputValue(value); - - var intValue = (int)(7 * value); - _powerFunctionsManager.SetOutput(this, channel, intValue); - } + _infraredService = scope.Resolve(); + }); + + // manually added devices + builder.RegisterDevice() + .WithImages("powerfunctions_image.png", "powerfunctions_image_small.png") + .WithDeviceFactory("0", "PF Infra 1") + .WithDeviceFactory("1", "PF Infra 2") + .WithDeviceFactory("2", "PF Infra 3") + .WithDeviceFactory("3", "PF Infra 4"); } } diff --git a/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsDevice.cs b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsDevice.cs new file mode 100644 index 000000000..a54452922 --- /dev/null +++ b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsDevice.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace BrickController2.DeviceManagement.PowerFunctions +{ + internal class PowerFunctionsDevice : Device, IDeviceType + { + private readonly IPowerFunctionsManager _powerFunctionsManager; + + public PowerFunctionsDevice(string name, string address, byte[] deviceData, IPowerFunctionsManager powerFunctionsManager, IDeviceRepository deviceRepository) + : base(name, address, deviceRepository) + { + _powerFunctionsManager = powerFunctionsManager; + } + + public static DeviceType Type => DeviceType.Infrared; + + public static string TypeName => "Power Functions"; + public override DeviceType DeviceType => Type; + public override int NumberOfChannels => 2; + + public override async Task ConnectAsync( + bool reconnect, + Action onDeviceDisconnected, + IEnumerable channelConfigurations, + bool startOutputProcessing, + bool requestDeviceInformation, + CancellationToken token) + { + DeviceState = DeviceState.Connecting; + + var result = await _powerFunctionsManager.ConnectDevice(this); + + DeviceState = result == DeviceConnectionResult.Ok ? DeviceState.Connected : DeviceState.Disconnected; + return result; + } + + public override async Task DisconnectAsync() + { + DeviceState = DeviceState.Disconnecting; + + await _powerFunctionsManager.DisconnectDevice(this); + + DeviceState = DeviceState.Disconnected; + } + + public override void SetOutput(int channel, float value) + { + CheckChannel(channel); + value = CutOutputValue(value); + + var intValue = (int)(7 * value); + _powerFunctionsManager.SetOutput(this, channel, intValue); + } + } +} diff --git a/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsManager.cs b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsManager.cs index 4fefa5df6..22a07696d 100644 --- a/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsManager.cs +++ b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsManager.cs @@ -34,7 +34,7 @@ public PowerFunctionsManager(IInfraredService infraredService) _infraredService = infraredService; } - public async Task ConnectDevice(PowerFunctions device) + public async Task ConnectDevice(PowerFunctionsDevice device) { using (await _asyncLock.LockAsync()) { @@ -53,7 +53,7 @@ public async Task ConnectDevice(PowerFunctions device) } } - public async Task DisconnectDevice(PowerFunctions device) + public async Task DisconnectDevice(PowerFunctionsDevice device) { using (await _asyncLock.LockAsync()) { @@ -70,7 +70,7 @@ public async Task DisconnectDevice(PowerFunctions device) } } - public void SetOutput(PowerFunctions device, int channel, int value) + public void SetOutput(PowerFunctionsDevice device, int channel, int value) { if (int.TryParse(device.Address, out int address)) { diff --git a/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsVendor.cs b/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsVendor.cs deleted file mode 100644 index 8422b556b..000000000 --- a/BrickController2/BrickController2/DeviceManagement/PowerFunctions/PowerFunctionsVendor.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Autofac; -using BrickController2.DeviceManagement.DI; -using BrickController2.DeviceManagement.Vendors; -using BrickController2.PlatformServices.Infrared; - -namespace BrickController2.DeviceManagement.PowerFunctions; - -/// -/// Vendor for Power Functions devices -/// -internal class PowerFunctionsVendor : Vendor -{ - private IInfraredService? _infraredService; - - public override string VendorName => "LEGO"; - - public override bool IsAvailable => _infraredService != null && _infraredService.IsInfraredSupported && _infraredService.IsCarrierFrequencySupported(PowerFunctionsManager.IR_FREQUENCY); - - protected override void Register(VendorBuilder builder) - { - // device manager - builder.ContainerBuilder.RegisterType().As().SingleInstance(); - - builder.ContainerBuilder.RegisterBuildCallback(scope => - { - _infraredService = scope.Resolve(); - }); - - // manually added devices - builder.RegisterDevice() - .WithImages("powerfunctions_image.png", "powerfunctions_image_small.png") - .WithDeviceFactory("0", "PF Infra 1") - .WithDeviceFactory("1", "PF Infra 2") - .WithDeviceFactory("2", "PF Infra 3") - .WithDeviceFactory("3", "PF Infra 4"); - } -} From 8d73325064a06383cc3858daa63fe756e8152803 Mon Sep 17 00:00:00 2001 From: J0EK3R Date: Tue, 23 Jun 2026 05:49:35 +0200 Subject: [PATCH 15/15] fix: explicitly add DeviceType.Infrared to DeviceImageRegistry to fix UnitTests --- .../UI/Images/DeviceImagesResourceTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/BrickController2/BrickController2.Tests/UI/Images/DeviceImagesResourceTests.cs b/BrickController2/BrickController2.Tests/UI/Images/DeviceImagesResourceTests.cs index 5c4044f1e..1d691a228 100644 --- a/BrickController2/BrickController2.Tests/UI/Images/DeviceImagesResourceTests.cs +++ b/BrickController2/BrickController2.Tests/UI/Images/DeviceImagesResourceTests.cs @@ -76,6 +76,7 @@ private static DeviceImageRegistry CreateRegistry() var registry = new DeviceImageRegistry(); registry.Register(DeviceType.BuWizz2, "buwizz_image.png", "buwizz_image_small.png"); registry.Register(DeviceType.RemoteControl, "remotecontrol_image_small.png", "remotecontrol_image_small.png"); + registry.Register(DeviceType.Infrared, "powerfunctions_image.png", "powerfunctions_image_small.png"); return registry; } }