Files
mozc-devices/mozc-dial/firmware/common/motor_controller.h
Shun Ikejima 994d22bb71 Add mozc-dial nine dial edition.
Co-authored-by: Takashi Toyoshima <toyoshim@google.com>
Co-authored-by: Shun Ikejima <ikejima@google.com>
2025-10-28 18:19:10 +09:00

40 lines
1.1 KiB
C++

// Copyright 2025 Google Inc.
// Use of this source code is governed by an Apache License that can be found
// in the LICENSE file.
#ifndef COMMON_MOTOR_CONTROLLER_H_
#define COMMON_MOTOR_CONTROLLER_H_
#include <cstdint>
#include <memory>
#include "pico/time.h"
class MotorController final {
public:
enum class Mode { k1Motor, k9Motor };
enum class Direction { kForward, kBackward };
explicit MotorController(Mode = Mode::k9Motor, Direction = Direction::kForward);
MotorController(const MotorController&) = delete;
MotorController& operator=(const MotorController&) = delete;
~MotorController();
void Start(uint8_t index);
void Stop(uint8_t index);
private:
class Decoder;
static bool OnAlarm(repeating_timer* t);
void Step();
static constexpr size_t kNumOfPhases = 4;
static constexpr size_t kNumOfMotors = 9;
std::unique_ptr<Decoder> decoder_[kNumOfPhases];
bool started_[kNumOfMotors] = { false };
uint8_t phase_ = 0;
repeating_timer timer_;
Direction direction_ = Direction::kForward;
};
#endif // COMMON_MOTOR_CONTROLLER_H_