Program Listing for File BlackBox_Lock.hpp¶
↰ Return to documentation for file (include/library/BlackBox_Lock.hpp
)
#pragma once
#include "library/BlackBox_pinout.hpp"
#include "driver/gpio.h"
#include "driver/ledc.h"
#include <mutex>
namespace BlackBox {
class Lock {
private:
const char* m_tag = "Lock";
bool m_isLocked;
static constexpr int s_locked = 1;
mutable std::recursive_mutex m_mutex;
gpio_num_t m_motor;
gpio_num_t m_encoderA;
gpio_num_t m_encoderB;
ledc_timer_config_t m_timerConfig;
ledc_channel_config_t m_channelConfig;
gpio_config_t m_encoderConfig;
void drive(bool locked, int duty = 0b110); // FIXME: test maximum reliable speed and use it
void readState();
public:
~Lock() = default;
Lock(gpio_num_t motor = Pins::Lock::Motor,
gpio_num_t encoderA = Pins::Lock::A,
gpio_num_t encoderB = Pins::Lock::B,
ledc_timer_t timer = LEDC_TIMER_0,
ledc_channel_t channel = LEDC_CHANNEL_0);
void init();
void lock();
void unlock();
bool locked();
};
} // namespace BlackBox