74 lines
1.5 KiB
C
Raw Normal View History

2023-04-10 13:04:38 +02:00
#ifndef _PERIPHERALS_DRUM_H_
#define _PERIPHERALS_DRUM_H_
#include "utils/InputState.h"
#include <map>
#include <stdint.h>
namespace Doncon::Peripherals {
class Drum {
public:
struct Config {
struct Thresholds {
uint16_t don_left;
uint16_t ka_left;
uint16_t don_right;
uint16_t ka_right;
};
2023-04-10 13:04:38 +02:00
struct {
2023-05-13 15:27:43 +02:00
uint8_t don_left;
uint8_t ka_left;
uint8_t don_right;
uint8_t ka_right;
2023-04-10 13:04:38 +02:00
} pins;
Thresholds trigger_thresholds;
uint8_t trigger_threshold_scale_level;
2023-07-02 23:48:33 +02:00
uint8_t sample_count;
2023-05-13 15:27:43 +02:00
uint16_t debounce_delay_ms;
2023-04-10 13:04:38 +02:00
};
private:
enum class Id {
2023-05-13 15:27:43 +02:00
DON_LEFT,
KA_LEFT,
DON_RIGHT,
KA_RIGHT,
2023-04-10 13:04:38 +02:00
};
class Pad {
private:
2023-05-13 15:27:43 +02:00
uint8_t pin;
2023-04-10 13:04:38 +02:00
uint32_t last_change;
bool active;
public:
Pad(uint8_t pin);
2023-05-13 15:27:43 +02:00
uint8_t getPin() const { return pin; };
2023-04-10 13:04:38 +02:00
bool getState() const { return active; };
2023-05-13 15:27:43 +02:00
void setState(bool state, uint16_t debounce_delay);
2023-04-10 13:04:38 +02:00
};
Config m_config;
std::map<Id, Pad> m_pads;
2023-05-13 15:27:43 +02:00
private:
2023-07-02 23:48:33 +02:00
std::map<Id, uint16_t> sampleInputs();
2023-05-13 15:27:43 +02:00
2023-04-10 13:04:38 +02:00
public:
Drum(const Config &config);
void updateInputState(Utils::InputState &input_state);
void setThresholds(const Config::Thresholds& thresholds);
void setThresholdScaleLevel(const uint8_t threshold_scale_level);
2023-04-10 13:04:38 +02:00
};
} // namespace Doncon::Peripherals
#endif // _PERIPHERALS_DRUM_H_