2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
/* Copyright (c) FIRST 2008-2016. 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
|
|
|
|
2016-05-25 22:38:11 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
2016-07-09 00:24:26 -07:00
|
|
|
#include "AnalogTriggerType.h"
|
2016-05-25 22:38:11 -07:00
|
|
|
#include "HAL/Interrupts.h"
|
2016-05-20 17:30:37 -07:00
|
|
|
#include "SensorBase.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
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
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
InterruptableSensorBase();
|
2015-06-24 01:06:29 -07:00
|
|
|
virtual ~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;
|
2015-06-25 15:07:55 -04:00
|
|
|
virtual void RequestInterrupts(
|
2016-09-05 07:31:51 -07:00
|
|
|
HAL_InterruptHandlerFunction handler,
|
2016-05-20 17:30:37 -07:00
|
|
|
void* param); ///< Asynchronus handler version.
|
2015-06-25 15:07:55 -04:00
|
|
|
virtual void RequestInterrupts(); ///< Synchronus Wait version.
|
|
|
|
|
virtual void
|
|
|
|
|
CancelInterrupts(); ///< Free up the underlying chipobject functions.
|
|
|
|
|
virtual WaitResult WaitForInterrupt(
|
2016-05-20 17:30:37 -07:00
|
|
|
float timeout,
|
|
|
|
|
bool ignorePrevious = true); ///< Synchronus version.
|
2015-06-25 15:07:55 -04:00
|
|
|
virtual void
|
|
|
|
|
EnableInterrupts(); ///< Enable interrupts - after finishing setup.
|
|
|
|
|
virtual void DisableInterrupts(); ///< Disable, but don't deallocate.
|
|
|
|
|
virtual double ReadRisingTimestamp(); ///< Return the timestamp for the
|
2016-05-20 17:30:37 -07:00
|
|
|
/// rising interrupt that occurred.
|
2015-06-25 15:07:55 -04:00
|
|
|
virtual double ReadFallingTimestamp(); ///< Return the timestamp for the
|
2016-05-20 17:30:37 -07:00
|
|
|
/// falling interrupt that occurred.
|
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
|
|
|
};
|