2022-02-16 22:06:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "pico/stdlib.h"
|
|
|
|
#include "hardware/clocks.h"
|
|
|
|
#include "common/pimoroni_common.hpp"
|
|
|
|
#include "calibration.hpp"
|
|
|
|
|
|
|
|
namespace servo {
|
|
|
|
|
|
|
|
class ServoState {
|
|
|
|
//--------------------------------------------------
|
|
|
|
// Variables
|
|
|
|
//--------------------------------------------------
|
|
|
|
private:
|
|
|
|
//uint pin;
|
|
|
|
float servo_value = 0.0f;
|
|
|
|
float last_enabled_pulse = 0.0f;
|
|
|
|
bool enabled = false;
|
|
|
|
|
|
|
|
Converter converter;
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------
|
|
|
|
// Constructors/Destructor
|
|
|
|
//--------------------------------------------------
|
|
|
|
public:
|
|
|
|
ServoState(/*uint pin, */Type type = ANGULAR);
|
|
|
|
|
|
|
|
//--------------------------------------------------
|
|
|
|
// Methods
|
|
|
|
//--------------------------------------------------
|
|
|
|
public:
|
|
|
|
bool init();
|
|
|
|
|
|
|
|
float enable();
|
|
|
|
float disable();
|
2022-02-17 17:59:09 +00:00
|
|
|
bool is_enabled();
|
2022-02-16 22:06:07 +00:00
|
|
|
|
|
|
|
float get_value();
|
|
|
|
float set_value(float value);
|
|
|
|
|
|
|
|
float get_pulse();
|
|
|
|
float set_pulse(float pulse);
|
|
|
|
|
|
|
|
float to_min();
|
|
|
|
float to_mid();
|
|
|
|
float to_max();
|
|
|
|
float to_percent(float in, float in_min, float in_max);
|
|
|
|
float to_percent(float in, float in_min, float in_max, float value_min, float value_max);
|
|
|
|
|
2022-02-17 17:59:09 +00:00
|
|
|
float get_min_value();
|
|
|
|
float get_mid_value();
|
|
|
|
float get_max_value();
|
|
|
|
|
2022-02-16 22:06:07 +00:00
|
|
|
Calibration& calibration();
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|