# validated: 2018-01-05 EN d376a57d7f94 java/src/com/ctre/phoenix/motorcontrol/can/TalonSRX.java
#----------------------------------------------------------------------------
#  Software License Agreement
#
# Copyright (C) Cross The Road Electronics.  All rights
# reserved.
# 
# Cross The Road Electronics (CTRE) licenses to you the right to 
# use, publish, and distribute copies of CRF (Cross The Road) firmware files (*.crf) and Software
# API Libraries ONLY when in use with Cross The Road Electronics hardware products.
# 
# THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
# WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
# LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
# CROSS THE ROAD ELECTRONICS BE LIABLE FOR ANY INCIDENTAL, SPECIAL, 
# INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
# PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
# BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
# THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
# SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
# (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE
#----------------------------------------------------------------------------
import hal
from .basemotorcontroller import BaseMotorController
from ._impl import MotController


__all__ = ['TalonSRX']


class TalonSRX(BaseMotorController):
    """CTRE Talon SRX Motor Controller when used on CAN Bus.
    
    Don't use this directly, use :class:`.WPI_TalonSRX`"""

    def __init__(self, deviceNumber):
        super().__init__(deviceNumber | 0x02040000)
        hal.report(hal.UsageReporting.kResourceType_CANTalonSRX, deviceNumber + 1)

    def configForwardLimitSwitchSource(self, type, normalOpenOrClose, timeoutMs: int):
        """
        Configures a limit switch for a local/remote source.

        For example, a CAN motor controller may need to monitor the Limit-R pin
        of another Talon, CANifier, or local Gadgeteer feedback connector.

        If the sensor is remote, a device ID of zero is assumed.
        If that's not desired, use the four parameter version of this function.

        :param type:
            Limit switch source.
            User can choose between the feedback connector, remote Talon SRX, CANifier, or deactivate the feature.
        :param normalOpenOrClose:
            Setting for normally open, normally closed, or disabled. This setting
            matches the web-based configuration drop down.
        :param timeoutMs:
            Timeout value in ms. If nonzero, function will wait for
            config success and report an error if it times out.
            If zero, no blocking or checking is performed.
        :returns: Error Code generated by function. 0 indicates no error.
        """
        return super().configForwardLimitSwitchSource(type, normalOpenOrClose, 0x00000000, timeoutMs)

    def configReverseLimitSwitchSource(self, type, normalOpenOrClose, timeoutMs: int):
        """
        Configures a limit switch for a local/remote source.
        
        For example, a CAN motor controller may need to monitor the Limit-R pin
        of another Talon, CANifier, or local Gadgeteer feedback connector.
        
        If the sensor is remote, a device ID of zero is assumed. If that's not
        desired, use the four parameter version of this function.
        
        :param type:
            Limit switch source. See :class:`.LimitSwitchSource` User can choose
            between the feedback connector, remote Talon SRX, CANifier, or
            deactivate the feature.
        :param normalOpenOrClose:
            Setting for normally open, normally closed, or disabled. This
            setting matches the web-based configuration drop down.
        :param timeoutMs:
            Timeout value in ms. If nonzero, function will wait for config
            success and report an error if it times out. If zero, no
            blocking or checking is performed.
        :returns: Error Code generated by function. 0 indicates no error.
        """
        return super().configReverseLimitSwitchSource(type, normalOpenOrClose, 0x00000000, timeoutMs)
