51 lines
837 B
C++
51 lines
837 B
C++
#ifndef ROTARY_ENCODER_DRIVER_H
|
|
#define ROTARY_ENCODER_DRIVER_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "digital_in.h"
|
|
//#include "digital_out.h"
|
|
#include "timer_usec.h"
|
|
|
|
class RotaryEncoderDriver {
|
|
static const uint8_t HIST_LEN = 4; // 4 x 4 ms = 16 ms gluggi fyrir rpm-utreikning
|
|
|
|
volatile uint8_t cycle;
|
|
volatile int16_t count;
|
|
volatile int16_t prev_count;
|
|
volatile bool speed_ready;
|
|
|
|
volatile int16_t history[HIST_LEN];
|
|
volatile uint8_t hist_idx;
|
|
|
|
//Digital_out led;
|
|
|
|
Digital_in eA;
|
|
Digital_in eB;
|
|
|
|
Timer_usec timer;
|
|
|
|
public:
|
|
volatile int16_t delta;
|
|
|
|
RotaryEncoderDriver();
|
|
|
|
void begin();
|
|
|
|
void update();
|
|
|
|
int position();
|
|
|
|
void update_delta();
|
|
|
|
float count_per_sec();
|
|
|
|
float rpm();
|
|
|
|
bool new_speed_available();
|
|
|
|
void reset_speed_measurement();
|
|
|
|
};
|
|
#endif
|