libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
encoder.h
Go to the documentation of this file.
1#pragma once
2#ifndef DSY_ENCODER_H
3#define DSY_ENCODER_H
4#include "daisy_core.h"
5#include "per/gpio.h"
6#include "hid/switch.h"
7
8namespace daisy
9{
18{
19 public:
22
29 float update_rate = 0.f);
33 void Debounce();
34
36 inline int32_t Increment() const { return updated_ ? inc_ : 0; }
37
39 inline bool RisingEdge() const { return sw_.RisingEdge(); }
40
42 inline bool FallingEdge() const { return sw_.FallingEdge(); }
43
45 inline bool Pressed() const { return sw_.Pressed(); }
46
48 inline float TimeHeldMs() const { return sw_.TimeHeldMs(); }
49
53 inline void SetUpdateRate(float update_rate) {}
54
55 private:
56 uint32_t last_update_;
57 bool updated_;
58 Switch sw_;
59 dsy_gpio hw_a_, hw_b_;
60 uint8_t a_, b_;
61 int32_t inc_;
62};
63} // namespace daisy
64#endif
Generic Class for handling Quadrature Encoders Inspired/influenced by Mutable Instruments (pichenet...
Definition encoder.h:18
float TimeHeldMs() const
Definition encoder.h:48
bool Pressed() const
Definition encoder.h:45
Encoder()
Definition encoder.h:20
void SetUpdateRate(float update_rate)
Definition encoder.h:53
~Encoder()
Definition encoder.h:21
bool FallingEdge() const
Definition encoder.h:42
bool RisingEdge() const
Definition encoder.h:39
int32_t Increment() const
Definition encoder.h:36
void Init(dsy_gpio_pin a, dsy_gpio_pin b, dsy_gpio_pin click, float update_rate=0.f)
Definition leddriver.h:33
Definition switch.h:18
float TimeHeldMs() const
Definition switch.h:88
bool RisingEdge() const
Definition switch.h:70
bool Pressed() const
Definition switch.h:79
bool FallingEdge() const
Definition switch.h:73
Hardware defines and helpers for daisy field platform.
Definition index.h:2
Definition daisy_core.h:205
Definition gpio.h:175