Nýjir kóðar og uppfærðir gamlir kóðar fyrir arduino yfir í zephyr

This commit is contained in:
2026-10-08 15:18:32 +00:00
parent 53091f68df
commit c2d8780478
24 changed files with 922 additions and 338 deletions
+40 -13
View File
@@ -2,8 +2,9 @@
#define ROTARY_ENCODER_DRIVER_H
#include <stdint.h>
#include <zephyr/drivers/gpio.h>
#include "digital_in.h"
//#include "digital_in.h"
#include "timer_usec.h"
class RotaryEncoderDriver {
@@ -11,6 +12,19 @@ public:
static constexpr uint16_t SAMPLE_PERIOD_US = 4000; // Ts = 4 ms
static constexpr float COUNTS_PER_REV = 1050.0f;
RotaryEncoderDriver();
// Returns 0 on success, or a negative Zephyr error code.
int begin();
void update();
int32_t position();
void update_delta();
float count_per_sec();
float rpm();
bool new_speed_available();
void reset_speed_measurement();
private:
static const uint8_t HIST_LEN = 4; // 4 x Ts = 16 ms gluggi fyrir rpm-utreikning
@@ -21,29 +35,42 @@ private:
volatile int32_t history[HIST_LEN];
volatile uint8_t hist_idx;
Digital_in eA;
Digital_in eB;
//Digital_in eA;
//Digital_in eB;
struct gpio_callback encoder_c1_callback;
Timer_usec timer;
public:
RotaryEncoderDriver();
static void gpio_edge_handler(
const structdevice *dev,
struct gpio_callback *callback,
uint32_t pins);
void begin();
static void timer_expired(void *context);
void update();
// public:
// RotaryEncoderDriver();
int32_t position();
// void begin();
void update_delta();
// void update();
float count_per_sec();
// int32_t position();
float rpm();
// void update_delta();
// float count_per_sec();
// float rpm();
// bool new_speed_available();
// void reset_speed_measurement();
bool new_speed_available();
void reset_speed_measurement();
};
#endif