92 lines
2.1 KiB
C++
92 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include "Things/RelativeEncoder.h"
|
|
#include "Things/TouchSensor.h"
|
|
|
|
namespace RoboidControl {
|
|
namespace Arduino {
|
|
|
|
/// @brief A digital input represents the stat of a digital GPIO pin
|
|
class DigitalInput : public Thing {
|
|
public:
|
|
/// @brief Create a new digital input
|
|
/// @param participant The participant to use
|
|
/// @param pin The digital pin
|
|
DigitalInput(Participant* participant, unsigned char pin);
|
|
// DigitalInput(Thing* parent, unsigned char pin);
|
|
DigitalInput(unsigned char pin, Thing& parent);
|
|
|
|
bool isHigh = false;
|
|
bool isLow = false;
|
|
|
|
/// @copydoc RoboidControl::Thing::Update(unsigned long currentTimeMs)
|
|
virtual void Update(bool recursive = false) override;
|
|
|
|
protected:
|
|
/// @brief The pin used for digital input
|
|
unsigned char pin = 0;
|
|
|
|
public:
|
|
class TouchSensor;
|
|
class RelativeEncoder;
|
|
};
|
|
|
|
#pragma region Touch sensor
|
|
|
|
class DigitalInput::TouchSensor : public RoboidControl::TouchSensor {
|
|
public:
|
|
TouchSensor(unsigned char pin, Thing& parent);
|
|
|
|
/// @copydoc RoboidControl::Thing::Update(unsigned long currentTimeMs)
|
|
virtual void Update(bool recurse = false) override;
|
|
|
|
protected:
|
|
DigitalInput digitalInput;
|
|
};
|
|
|
|
#pragma endregion Touch sensor
|
|
|
|
#pragma region Incremental encoder
|
|
|
|
class DigitalInput::RelativeEncoder : public RoboidControl::RelativeEncoder {
|
|
public:
|
|
struct Configuration {
|
|
unsigned char pin;
|
|
unsigned char pulsesPerRevolution;
|
|
};
|
|
|
|
RelativeEncoder(Configuration config, Thing& parent = Thing::LocalRoot());
|
|
|
|
unsigned char pulsesPerRevolution;
|
|
|
|
/// @brief The current pulse frequency in Hz
|
|
float pulseFrequency = 0;
|
|
|
|
/// @copydoc RoboidControl::Thing::Update()
|
|
virtual void Update(bool recurse = false) override;
|
|
|
|
protected:
|
|
DigitalInput digitalInput;
|
|
|
|
int interruptIx = 0;
|
|
|
|
static int interruptCount;
|
|
|
|
volatile static int pulseCount0;
|
|
static void PulseInterrupt0();
|
|
|
|
volatile static int pulseCount1;
|
|
static void PulseInterrupt1();
|
|
|
|
int GetPulseCount();
|
|
long netPulseCount = 0;
|
|
unsigned long lastUpdateTime = 0;
|
|
|
|
private:
|
|
void Start();
|
|
};
|
|
|
|
#pragma endregion Incremental encoder
|
|
|
|
} // namespace Arduino
|
|
} // namespace RoboidControl
|