2019-06-01 23:31:32 +00:00
|
|
|
//
|
|
|
|
// DriveSpeedAccumulator.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 01/06/2019.
|
|
|
|
// Copyright © 2019 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2024-01-17 04:34:46 +00:00
|
|
|
#pragma once
|
2019-06-01 23:31:32 +00:00
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
|
2023-05-10 21:02:18 +00:00
|
|
|
namespace Apple::Macintosh {
|
2019-06-01 23:31:32 +00:00
|
|
|
|
|
|
|
class DriveSpeedAccumulator {
|
2024-12-05 03:29:08 +00:00
|
|
|
public:
|
|
|
|
/*!
|
|
|
|
Accepts fetched motor control values.
|
|
|
|
*/
|
|
|
|
void post_sample(uint8_t sample);
|
2019-06-01 23:31:32 +00:00
|
|
|
|
2024-12-05 03:29:08 +00:00
|
|
|
struct Delegate {
|
|
|
|
virtual void drive_speed_accumulator_set_drive_speed(DriveSpeedAccumulator *, float speed) = 0;
|
|
|
|
};
|
|
|
|
/*!
|
|
|
|
Sets the delegate to receive drive speed changes.
|
|
|
|
*/
|
|
|
|
void set_delegate(Delegate *delegate) {
|
|
|
|
delegate_ = delegate;
|
|
|
|
}
|
2019-07-30 19:08:55 +00:00
|
|
|
|
2024-12-05 03:29:08 +00:00
|
|
|
private:
|
|
|
|
static constexpr int samples_per_bucket = 20;
|
|
|
|
int sample_count_ = 0;
|
|
|
|
int sample_total_ = 0;
|
|
|
|
Delegate *delegate_ = nullptr;
|
2019-06-01 23:31:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|