Smartcar Shield
BrushedMotor.hpp
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <stdint.h> // NOLINT(modernize-deprecated-headers)
13 
14 #include "../../../runtime/Runtime.hpp"
15 #include "../../Motor.hpp"
16 
21 {
29  BrushedMotorPins(uint8_t forwardPin, uint8_t backwardPin, uint8_t enablePin)
30  : forward{ forwardPin }
31  , backward{ backwardPin }
32  , enable{ enablePin }
33  {
34  }
35 
36  const uint8_t forward; // NOLINT: It's OK for these to be public
37  const uint8_t backward; // NOLINT
38  const uint8_t enable; // NOLINT
39 };
40 
41 class BrushedMotor : public Motor
42 {
43 public:
57  BrushedMotor(Runtime& runtime, uint8_t forwardPin, uint8_t backwardPin, uint8_t enablePin);
58 
70  BrushedMotor(Runtime& runtime, BrushedMotorPins pins);
71 
72  /* Check `Motor` interface for documentation */
73  void setSpeed(int speed) override;
74 
75 private:
76  void attach();
77  const uint8_t kForwardPin;
78  const uint8_t kBackwardPin;
79  const uint8_t kEnablePin;
80  Runtime& mRuntime;
81  const uint8_t kOutput;
82  const uint8_t kLow;
83  const uint8_t kHigh;
84  bool mAttached{ false };
85 };
BrushedMotorPins
Helper class to represent brushed motor pins.
Definition: BrushedMotor.hpp:20
BrushedMotor::BrushedMotor
BrushedMotor(Runtime &runtime, uint8_t forwardPin, uint8_t backwardPin, uint8_t enablePin)
Constructs a brushed DC motor instance.
Definition: BrushedMotor.cpp:13
BrushedMotor
Definition: BrushedMotor.hpp:41
Runtime
Definition: Runtime.hpp:35
Motor
Definition: Motor.hpp:22
BrushedMotorPins::backward
const uint8_t backward
Definition: BrushedMotor.hpp:37
BrushedMotorPins::enable
const uint8_t enable
Definition: BrushedMotor.hpp:38
BrushedMotorPins::BrushedMotorPins
BrushedMotorPins(uint8_t forwardPin, uint8_t backwardPin, uint8_t enablePin)
Construct a BrushedMotorPins object.
Definition: BrushedMotor.hpp:29
BrushedMotorPins::forward
const uint8_t forward
Definition: BrushedMotor.hpp:36
BrushedMotor::setSpeed
void setSpeed(int speed) override
Sets the motor speed and direction as the percentage of the maximum possible speed,...
Definition: BrushedMotor.cpp:32