36 lines
919 B
C#
36 lines
919 B
C#
|
|
using Assets.Scripts.Ble.Commands;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace Assets.Scripts.Commands
|
|||
|
|
{
|
|||
|
|
public static class CommandFactory
|
|||
|
|
{
|
|||
|
|
public static Command GetBatteryLevel(Action<CommandResponseStatus, int?> action = null)
|
|||
|
|
{
|
|||
|
|
return new Command(CommandType.GetBatteryLevel, CommandFactory.InjectCommandAction<int>(action));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static CommandAction InjectCommandAction<T>(Action<CommandResponseStatus, T?> action) where T : struct
|
|||
|
|
{
|
|||
|
|
if (action == null)
|
|||
|
|
{
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
return delegate (CommandResponseStatus status, object data)
|
|||
|
|
{
|
|||
|
|
T? arg = data as T?;
|
|||
|
|
if (data != null && arg == null)
|
|||
|
|
{
|
|||
|
|
action(new CommandResponseStatus(status.Type, CommandResponseCode.TypeMismatch), null);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
action(status, arg);
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|