# Path: ripyl/util/enum.py
# class Enum(object):
#     '''Base class for enumeration classes
#     
#     This provides a name() class method that will return the string
#     attribute name for an encoded enumeration value.
#     
#     e.g.
#     
#     >>> class Colors(Enum):
#     ...     blue = 1
#     ...     red = 2
#     ...     green = 3
#         
#     >>> Colors.name(Colors.red)
#     'red'
#     
#     >>> Colors.name(1, full_name=True)
#     'Colors.blue'
# 
#     "Instantiating" the Enum sub-class calls the name() method as well:
#     
#     >>> Colors(3, full_name=False)
#     'green'
#     
#     If necesssary you can use non-integers as the values as long as they are hashable:
#     
#     >>> class MathConst(Enum):
#     ...     pi = 3.2     # in certain US states :)
#     ...     e = 2.71828
#         
#     >>> MathConst.pi
#     3.2
#     
#     '''
# 
#     @classmethod
#     def name(cls, value, full_name=False):
#         '''Lookup the enumeration name with the provided value
# 
#         value (hashable)
#             A hashable Enum value (typically int) to find a name for.
# 
#         full_name (bool)
#             Include full name of Enum object in result
# 
#         Returns a string for the Enum attribute associated with value.
#         '''
#         
#         try:
#             enum_lookup = cls._enum_lookup
#         except AttributeError:
#             # Build inverse dict of class attributes with their values as key
#             enum_lookup = dict((v, k) for k, v in cls.__dict__.items() if k[0] != '_')
#             cls._enum_lookup = enum_lookup
#         
#         try:
#             aname = enum_lookup[value]
#             prefix = cls.__name__ + '.' if full_name else ''
#             return prefix + aname
# 
#         except KeyError:
#             return 'unknown'
# 
#     def __new__(cls, value, full_name=False):
#         '''Override class instantitation to perform name lookup instead'''
#         return cls.name(value, full_name)
# 
# Path: ripyl/sigproc.py
# def remove_excess_edges(edges):
#     '''Remove incorrect edge transitions from an edge stream
#     
#     This is a generator function.
#     
#     This function is most useful for conditioning the outputs of the protocol
#     synthesizers. For those protocols with multiple signals, the synthesizers
#     myst yield a new output set for *all* signals when any *one* of them changes.
#     This results in non-conforming edge streams that contain multiple consecutive
#     pairs with a non-changing value.
#     
#     edges (iterable of (float, int) tuples)
#         An edge stream to filter for extraneous non-edges
#         
#     Yields an edge stream.
#     '''
#     prev_state = None
#     last_e = None
#     for e in edges:
#         if prev_state is None:
#             prev_state = e[1]
#             yield e
#         else:
#             if e[1] != prev_state:
#                 prev_state = e[1]
#                 last_e = None
#                 yield e
#             else: # Save last edge so we can yield it at the end
#                 last_e = e
#         
#     if last_e is not None:
#         yield last_e


import itertools
import ripyl.streaming as stream
from ripyl.util.enum import Enum
from ripyl.decode import *
from ripyl.util.bitops import *
from ripyl.sigproc import remove_excess_edges

# Copyright © 2013 Kevin Thibedeau

# This file is part of Ripyl.

# Ripyl is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.

# Ripyl is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with Ripyl. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function, division



class PS2StreamStatus(Enum):
    '''Enumeration of PS/2 status codes'''
    FramingError = stream.StreamStatus.Error + 1
    ParityError = stream.StreamStatus.Error + 2
    AckError = stream.StreamStatus.Error + 3
    TimingError = stream.StreamStatus.Error + 4



# Path: ripyl/util/enum.py
# class Enum(object):
#     '''Base class for enumeration classes
#     
#     This provides a name() class method that will return the string
#     attribute name for an encoded enumeration value.
#     
#     e.g.
#     
#     >>> class Colors(Enum):
#     ...     blue = 1
#     ...     red = 2
#     ...     green = 3
#         
#     >>> Colors.name(Colors.red)
#     'red'
#     
#     >>> Colors.name(1, full_name=True)
#     'Colors.blue'
# 
#     "Instantiating" the Enum sub-class calls the name() method as well:
#     
#     >>> Colors(3, full_name=False)
#     'green'
#     
#     If necesssary you can use non-integers as the values as long as they are hashable:
#     
#     >>> class MathConst(Enum):
#     ...     pi = 3.2     # in certain US states :)
#     ...     e = 2.71828
#         
#     >>> MathConst.pi
#     3.2
#     
#     '''
# 
#     @classmethod
#     def name(cls, value, full_name=False):
#         '''Lookup the enumeration name with the provided value
# 
#         value (hashable)
#             A hashable Enum value (typically int) to find a name for.
# 
#         full_name (bool)
#             Include full name of Enum object in result
# 
#         Returns a string for the Enum attribute associated with value.
#         '''
#         
#         try:
#             enum_lookup = cls._enum_lookup
#         except AttributeError:
#             # Build inverse dict of class attributes with their values as key
#             enum_lookup = dict((v, k) for k, v in cls.__dict__.items() if k[0] != '_')
#             cls._enum_lookup = enum_lookup
#         
#         try:
#             aname = enum_lookup[value]
#             prefix = cls.__name__ + '.' if full_name else ''
#             return prefix + aname
# 
#         except KeyError:
#             return 'unknown'
# 
#     def __new__(cls, value, full_name=False):
#         '''Override class instantitation to perform name lookup instead'''
#         return cls.name(value, full_name)
# 
# Path: ripyl/sigproc.py
# def remove_excess_edges(edges):
#     '''Remove incorrect edge transitions from an edge stream
#     
#     This is a generator function.
#     
#     This function is most useful for conditioning the outputs of the protocol
#     synthesizers. For those protocols with multiple signals, the synthesizers
#     myst yield a new output set for *all* signals when any *one* of them changes.
#     This results in non-conforming edge streams that contain multiple consecutive
#     pairs with a non-changing value.
#     
#     edges (iterable of (float, int) tuples)
#         An edge stream to filter for extraneous non-edges
#         
#     Yields an edge stream.
#     '''
#     prev_state = None
#     last_e = None
#     for e in edges:
#         if prev_state is None:
#             prev_state = e[1]
#             yield e
#         else:
#             if e[1] != prev_state:
#                 prev_state = e[1]
#                 last_e = None
#                 yield e
#             else: # Save last edge so we can yield it at the end
#                 last_e = e
#         
#     if last_e is not None:
#         yield last_e


# Path: ripyl/protocol/ps2.py
import itertools
import ripyl.streaming as stream
from ripyl.util.enum import Enum
from ripyl.decode import *
from ripyl.util.bitops import *
from ripyl.sigproc import remove_excess_edges


# Copyright © 2013 Kevin Thibedeau

# This file is part of Ripyl.

# Ripyl is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.

# Ripyl is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with Ripyl. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function, division



class PS2StreamStatus(Enum):
    '''Enumeration of PS/2 status codes'''
    FramingError = stream.StreamStatus.Error + 1
    ParityError = stream.StreamStatus.Error + 2
    AckError = stream.StreamStatus.Error + 3
    TimingError = stream.StreamStatus.Error + 4



class PS2Dir(Enum):