Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
super().__init__(moduleNumber)
self.channel = channel
SensorUtil.checkSolenoidModule(moduleNumber)
SensorUtil.checkSolenoidChannel(channel)
portHandle = hal.getPortWithModule(moduleNumber, channel)
self.solenoidHandle = hal.initializeSolenoidPort(portHandle)
hal.report(hal.UsageReporting.kResourceType_Solenoid, channel, moduleNumber)
self.setName("Solenoid", self.moduleNumber, self.channel)
self.__finalizer = weakref.finalize(self, _freeSolenoid, self.solenoidHandle)
# Need this to free on unit test wpilib reset
Resource._add_global_resource(self)
trigger. Treated as an AnalogInput if the provided object has a
getChannel function.
"""
super().__init__()
if not hasattr(channel, "getChannel"):
self.analogInput = AnalogInput(channel)
self.ownsAnalog = True
self.addChild(self.analogInput)
else:
self.analogInput = channel
self.port, self.index = hal.initializeAnalogTrigger(self.analogInput.port)
self.__finalizer = weakref.finalize(self, _freeAnalogTrigger, self.port)
# Need this to free on unit test wpilib reset
Resource._add_global_resource(self)
hal.report(hal.UsageReporting.kResourceType_AnalogTrigger, channel)
self.setName("AnalogTrigger", self.analogInput.getChannel())
self.distanceEntry = None
self.distancePerTickEntry = None
self.encoder = hal.initializeEncoder(
aSource.getPortHandleForRouting(),
aSource.getAnalogTriggerTypeForRouting(),
bSource.getPortHandleForRouting(),
bSource.getAnalogTriggerTypeForRouting(),
reverseDirection,
encodingType,
)
self.__finalizer = weakref.finalize(self, _freeEncoder, self.encoder)
# Need this to free on unit test wpilib reset
Resource._add_global_resource(self)
if self.indexSource is not None:
self.setIndexSource(self.indexSource)
self.index = self.getFPGAIndex()
hal.report(hal.UsageReporting.kResourceType_Encoder, self.index, encodingType)
self.setName("Encoder", self.index)
#: appropriate interval.
self._handler = run
# Whether we are calling the handler just once or periodically.
self._periodic = False
#: If periodic, the period of the calling; if just once, stores how long it
#: is until we call the handler.
self._period = 0
#: The thread waiting on the HAL alarm
self._thread = threading.Thread(target=self._run, name="Notifier", daemon=True)
self._thread.start()
# python-specific
Resource._add_global_resource(self)
self.controlEnabled = True
receivedFirmwareVersion = False
# Request firmware and hardware version only once
self.requestMessage(frccan.CAN_IS_FRAME_REMOTE |
_cj.CAN_MSGID_API_FIRMVER)
self.requestMessage(_cj.LM_API_HWVER)
# Establish finalizer
self.__finalizer = weakref.finalize(self, _freeJaguar,
self.deviceNumber,
self.controlMode)
# Need this to free on unit test wpilib reset
Resource._add_global_resource(self)
# Wait until we've gotten all of the status data at least once.
for i in range(CANJaguar.kReceiveStatusAttempts):
Timer.delay(0.001)
self.setupPeriodicStatus()
self.updatePeriodicStatus()
if not receivedFirmwareVersion:
try:
data = self.getMessage(_cj.CAN_MSGID_API_FIRMVER,
_cj.CAN_MSGID_FULL_M)
self.firmwareVersion = _unpackINT32(data)
receivedFirmwareVersion = True
except frccan.CANMessageNotFound:
pass
self.valueEntry = None
# set up counter for this sensor
self.counter = Counter(self.echoChannel)
self.counter.setMaxPeriod(1.0)
self.counter.setSemiPeriodMode(True)
self.counter.reset()
isAutomatic = Ultrasonic.isAutomaticMode()
self.setAutomaticMode(False)
Ultrasonic.sensors.add(self)
if isAutomatic:
self.setAutomaticMode(True)
Resource._add_global_resource(self)
Ultrasonic.instances += 1
hal.report(hal.UsageReporting.kResourceType_Ultrasonic, Ultrasonic.instances)
self.setName("Ultrasonic", echoChannel.getChannel())
try:
portHandle = hal.getPortWithModule(moduleNumber, reverseChannel)
self.reverseHandle = hal.initializeSolenoidPort(portHandle)
except Exception:
# free the forward handle on exception, then rethrow
hal.freeSolenoidPort(self.forwardHandle)
self.forwardHandle = None
self.reverseHandle = None
raise
self.forwardMask = 1 << forwardChannel
self.reverseMask = 1 << reverseChannel
# Need this to free on unit test wpilib reset
Resource._add_global_resource(self)
hal.report(
hal.UsageReporting.kResourceType_Solenoid, forwardChannel, moduleNumber
)
hal.report(
hal.UsageReporting.kResourceType_Solenoid, reverseChannel, moduleNumber
)
self.setName("DoubleSolenoid", moduleNumber, forwardChannel)
self.__finalizer = weakref.finalize(
self, _freeSolenoid, self.forwardHandle, self.reverseHandle
)