Implementato sdk honeywell e metodi per lo scanner barcode

This commit is contained in:
2026-02-24 17:49:25 +01:00
parent e8adb76256
commit 7fa96eeb09
27 changed files with 477 additions and 53 deletions

View File

@@ -0,0 +1,140 @@
using Android.OS;
using Com.Honeywell.Aidc;
using SteUp.Shared.Core.BarcodeReader.Dto;
namespace SteUp.Maui.Core.System;
public partial class HoneywellScannerService
{
private AidcManager? _aidcManager;
private BarcodeReader? _barcodeReader;
private static readonly List<string> CompatibleModels = ["EDA50", "EDA51", "EDA52", "CT60"];
public partial bool IsRightAdapter()
{
return CompatibleModels.Contains(Build.Model ?? string.Empty);
}
public partial string GetAdapterName() => "Honeywell";
public partial void Init(Action onDeviceReady)
{
if (!IsRightAdapter())
throw new Exception($"Adapter non trovato per il modello: {Build.Model}");
AidcManager.Create(
Android.App.Application.Context,
new AidcCreatedCallback(this, onDeviceReady)
);
}
public partial void Deinit()
{
_barcodeReader?.Close();
_barcodeReader = null;
_aidcManager?.Close();
_aidcManager = null;
}
public partial void OnKeyEvent(object keyEvent)
{
// Honeywell gestisce il trigger hardware internamente, non serve implementazione
}
public partial void ChangeSettings(List<(string Key, object Value)> settings)
{
if (_barcodeReader == null) return;
var properties = GetDefaultProperties();
foreach (var (key, value) in settings)
{
switch (key)
{
case "TRIGGER_SCAN_MODE":
var scanMode = (string)value switch
{
"ONE_SHOT" => BarcodeReader.TriggerScanModeOneshot,
"CONTINUOUS" => BarcodeReader.TriggerScanModeContinuous,
"READ_ON_SECOND_TRIGGER_PRESS" => BarcodeReader.TriggerScanModeReadOnSecondTriggerPress,
"READ_ON_RELEASE" => BarcodeReader.TriggerScanModeReadOnRelease,
_ => BarcodeReader.TriggerScanModeOneshot
};
properties[BarcodeReader.PropertyTriggerScanMode] = scanMode!;
break;
case "TRIGGER_SCAN_DELAY":
properties[BarcodeReader.PropertyTriggerScanDelay] = int.Parse((string)value);
break;
}
}
_barcodeReader.SetProperties(properties);
try { _barcodeReader.Claim(); }
catch (ScannerUnavailableException ex) { OnScanFailed?.Invoke(ex); }
}
private void RegisterListenersInternal()
{
_barcodeReader?.AddBarcodeListener(new BarcodeEventListener(this));
}
private void DispatchEvent(BarcodeReadEvent e)
{
var dto = new BarcodeScanDto
{
StringValue = e.BarcodeData,
Type = e.CodeId,
Name = e.CodeId
};
OnScanSuccessful?.Invoke(dto);
}
private static Dictionary<string, Java.Lang.Object> GetDefaultProperties() => new()
{
{ BarcodeReader.PropertyEan8Enabled, true },
{ BarcodeReader.PropertyEan13Enabled, true },
{ BarcodeReader.PropertyCode39Enabled, true },
{ BarcodeReader.PropertyCode128Enabled, true },
{ BarcodeReader.PropertyGs1128Enabled, true },
{ BarcodeReader.PropertyUpcAEnable, true },
{ BarcodeReader.PropertyEan8CheckDigitTransmitEnabled, true },
{ BarcodeReader.PropertyEan13CheckDigitTransmitEnabled, true },
{ BarcodeReader.PropertyUpcACheckDigitTransmitEnabled, true }
};
private class AidcCreatedCallback(HoneywellScannerService service, Action onDeviceReady)
: Java.Lang.Object, AidcManager.ICreatedCallback
{
public void OnCreated(AidcManager? manager)
{
service._aidcManager = manager;
try
{
if (manager == null) throw new Exception("AidcManager null");
service._barcodeReader = manager.CreateBarcodeReader();
service.RegisterListenersInternal();
}
catch (Exception ex)
{
service.OnScanFailed?.Invoke(ex);
}
onDeviceReady.Invoke();
}
}
private class BarcodeEventListener(HoneywellScannerService service)
: Java.Lang.Object, BarcodeReader.IBarcodeListener
{
public void OnBarcodeEvent(BarcodeReadEvent? e) => service.DispatchEvent(e!);
public void OnFailureEvent(BarcodeFailureEvent? e) =>
service.OnScanFailed?.Invoke(new Exception($"Scan failure: {e}"));
}
}

View File

@@ -0,0 +1,17 @@
namespace SteUp.Maui.Core.System;
public partial class HoneywellScannerService
{
public partial bool IsRightAdapter() => false;
public partial void Init(Action onDeviceReady) =>
throw new NotSupportedException("Honeywell SDK non disponibile su iOS.");
public partial void Deinit() { }
public partial string GetAdapterName() => "Honeywell";
public partial void OnKeyEvent(object keyEvent) { }
public partial void ChangeSettings(List<(string Key, object Value)> settings) { }
}