Exemplo n.º 1
0
        public static IEnumerable<IKeypadButtonState> ConvertButtons(byte[] data)
        {
            var relevantBytes = data.Skip(3).Take(4);

            var row = 1;
            var column = 'A';

            foreach (var chunk in relevantBytes)
            {
                byte mask = 1;

                for (byte i = 0; i < 6; i++)
                {
                    var id = "" + column + row;
                    var pressed = (chunk & mask) > 0;

                    var buttonState = new ReadOnlyKeypadButtonState(id, pressed);

                    yield return buttonState;

                    row++;
                    mask *= 2;
                }

                row = 1;
                column++;
            }
        }
Exemplo n.º 2
0
        public static ReadOnlyKeypadButtonState CopyFrom(IKeypadButtonState source)
        {
            var result = new ReadOnlyKeypadButtonState
            {
                Id      = source.Id,
                Pressed = source.Pressed
            };

            return(result);
        }
Exemplo n.º 3
0
        public static ReadOnlyKeypadButtonState CopyFrom(IKeypadButtonState source)
        {
            var result = new ReadOnlyKeypadButtonState
            {
                Id = source.Id,
                Pressed = source.Pressed
            };

            return result;
        }
Exemplo n.º 4
0
        public static IEnumerable <IKeypadButtonState> Changes(this IEnumerable <IKeypadButtonState> newState, IEnumerable <IKeypadButtonState> oldState)
        {
            var result = newState.Where(@new =>
            {
                var old = oldState.FirstOrDefault(x => x.Id == @new.Id);

                if (old == null)
                {
                    old = new ReadOnlyKeypadButtonState(@new.Id, null);
                }

                return(@new.Changed(old));
            }).ToArray();

            return(result);
        }
Exemplo n.º 5
0
        public static IEnumerable<IKeypadButtonState> Changes(this IEnumerable<IKeypadButtonState> newState, IEnumerable<IKeypadButtonState> oldState)
        {
            var result = newState.Where(@new =>
                {
                    var old = oldState.FirstOrDefault(x => x.Id == @new.Id);

                    if (old == null)
                    {
                        old = new ReadOnlyKeypadButtonState(@new.Id, null);
                    }

                    return @new.Changed(old);
                }).ToArray();

            return result;
        }
Exemplo n.º 6
0
        public static ReadOnlyKeypadButtonState FromXElement(XElement element)
        {
            var id      = element.GetAttributeStringValue("Id");
            var pressed = element.GetAttributeStringValue("Pressed");

            var result = new ReadOnlyKeypadButtonState
            {
                Id = id
            };

            if (pressed != null)
            {
                result.Pressed = Convert.ToBoolean(pressed);
            }

            return(result);
        }
Exemplo n.º 7
0
        public static ReadOnlyKeypadButtonState FromXElement(XElement element)
        {
            var id = element.GetAttributeStringValue("Id");
            var pressed = element.GetAttributeStringValue("Pressed");

            var result = new ReadOnlyKeypadButtonState
            {
                Id = id
            };

            if (pressed != null)
            {
                result.Pressed = Convert.ToBoolean(pressed);
            }

            return result;
        }
Exemplo n.º 8
0
 public static IKeypadButtonState ToButton(this XElement element)
 {
     return(ReadOnlyKeypadButtonState.FromXElement(element));
 }
Exemplo n.º 9
0
 public static IKeypadButtonState Copy(this IKeypadButtonState state)
 {
     return(ReadOnlyKeypadButtonState.CopyFrom(state));
 }