2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2014-05-02 17:54:01 -04:00
|
|
|
#pragma once
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2017-08-27 00:11:52 -07:00
|
|
|
#include <HAL/Interrupts.h>
|
|
|
|
|
|
2016-07-09 00:24:26 -07:00
|
|
|
#include "AnalogTriggerType.h"
|
2016-05-20 17:30:37 -07:00
|
|
|
#include "SensorBase.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
namespace frc {
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
class InterruptableSensorBase : public SensorBase {
|
|
|
|
|
public:
|
|
|
|
|
enum WaitResult {
|
|
|
|
|
kTimeout = 0x0,
|
|
|
|
|
kRisingEdge = 0x1,
|
|
|
|
|
kFallingEdge = 0x100,
|
|
|
|
|
kBoth = 0x101,
|
|
|
|
|
};
|
2014-10-05 17:17:59 -04:00
|
|
|
|
2017-08-07 17:36:34 -07:00
|
|
|
InterruptableSensorBase() = default;
|
|
|
|
|
|
2016-07-09 00:24:26 -07:00
|
|
|
virtual HAL_Handle GetPortHandleForRouting() const = 0;
|
2016-07-07 21:43:55 -07:00
|
|
|
virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0;
|
2017-11-16 00:33:51 -08:00
|
|
|
|
|
|
|
|
// Asynchronous handler version.
|
|
|
|
|
virtual void RequestInterrupts(HAL_InterruptHandlerFunction handler,
|
|
|
|
|
void* param);
|
|
|
|
|
|
|
|
|
|
// Synchronous wait version.
|
|
|
|
|
virtual void RequestInterrupts();
|
|
|
|
|
|
|
|
|
|
// Free up the underlying ChipObject functions.
|
|
|
|
|
virtual void CancelInterrupts();
|
|
|
|
|
|
|
|
|
|
// Synchronous version.
|
|
|
|
|
virtual WaitResult WaitForInterrupt(double timeout,
|
|
|
|
|
bool ignorePrevious = true);
|
|
|
|
|
|
|
|
|
|
// Enable interrupts - after finishing setup.
|
|
|
|
|
virtual void EnableInterrupts();
|
|
|
|
|
|
|
|
|
|
// Disable, but don't deallocate.
|
|
|
|
|
virtual void DisableInterrupts();
|
|
|
|
|
|
|
|
|
|
// Return the timestamp for the rising interrupt that occurred.
|
|
|
|
|
virtual double ReadRisingTimestamp();
|
|
|
|
|
|
|
|
|
|
// Return the timestamp for the falling interrupt that occurred.
|
|
|
|
|
virtual double ReadFallingTimestamp();
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
|
2014-08-06 09:46:50 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
protected:
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_InterruptHandle m_interrupt = HAL_kInvalidHandle;
|
2015-06-25 15:07:55 -04:00
|
|
|
void AllocateInterrupts(bool watcher);
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|
2016-11-01 22:33:12 -07:00
|
|
|
|
|
|
|
|
} // namespace frc
|