27 lines
677 B
C++
27 lines
677 B
C++
#pragma once
|
|
#include "types.hpp"
|
|
#include "gpio.hpp"
|
|
|
|
class Encoder {
|
|
public:
|
|
Encoder(int pwm_channel, int dir_gpio, int direction_polarity);
|
|
~Encoder();
|
|
|
|
void update();
|
|
float getRPS() const { return _rps; }
|
|
int getDirection() const;
|
|
|
|
private:
|
|
int _channel;
|
|
GPIO _dir_gpio;
|
|
int _polarity; // 1 或 -1
|
|
volatile uint32* _reg_base;
|
|
int _mem_fd;
|
|
float _rps;
|
|
uint32 _last_period;
|
|
static constexpr unsigned int REG_OFFSET = 0x0100;
|
|
void _mmapRegs();
|
|
void _munmapRegs();
|
|
uint32 _readRegister(unsigned int offset) const;
|
|
};
|