From 12edf95a636ceb6dcf5fea5d19b1d77d7167fa6b Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Mon, 7 Aug 2023 10:24:12 +0200 Subject: [PATCH] Remove `pin_t`. Use `uint8_t` instead. It looks nicer in Arduino IDE's tooltips. --- README.md | 6 +++--- src/ContinuousStepper/OutputPin.hpp | 9 ++++----- src/ContinuousStepper/StepperInterfaces.hpp | 6 ++---- src/ContinuousStepper/Tickers/AnalogWriteFrequency.hpp | 4 ++-- src/ContinuousStepper/Tickers/OscillatorTicker.hpp | 4 ++-- src/ContinuousStepper/Tickers/Tone.hpp | 4 ++-- src/ContinuousStepperImpl.hpp | 2 +- 7 files changed, 16 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 38eb315..d4220a2 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ public: // Configures the "enable" pin. // You can pass LOW as the second argument to invert the logic. // The pin is set to its active level unless powerOff() was called. - void setEnablePin(pin_t pinNumber, bool activeLevel = HIGH); + void setEnablePin(uint8_t pinNumber, bool activeLevel = HIGH); // Updates the status of the step and dir pins. // You must call this function as frequently as possible. @@ -161,10 +161,10 @@ The `begin()` function forwards its arguments to the `TStepper::begin()`, such a ```c++ // For stepper drivers, the arguments are step and dir pins numbers. -void StepperDriver::begin(pin_t stepPin, pin_t dirPin); +void StepperDriver::begin(uint8_t stepPin, uint8_t dirPin); // For four-wire stepper motors, the arguments are the four pins numbers. -void FourWireStepper::begin(pin_t pin1, pin_t pin2, pin_t pin3, pin_t pin4); +void FourWireStepper::begin(uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4); ``` diff --git a/src/ContinuousStepper/OutputPin.hpp b/src/ContinuousStepper/OutputPin.hpp index 4c5182b..20a23ba 100644 --- a/src/ContinuousStepper/OutputPin.hpp +++ b/src/ContinuousStepper/OutputPin.hpp @@ -4,18 +4,17 @@ namespace ArduinoContinuousStepper { -typedef uint8_t pin_t; -constexpr pin_t NULL_PIN = 255; +constexpr uint8_t NULL_PIN = 255; class OutputPin { public: OutputPin() : _pin(NULL_PIN) {} - OutputPin(pin_t pin) : _pin(pin) { + OutputPin(uint8_t pin) : _pin(pin) { pinMode(pin, OUTPUT); } - operator pin_t() const { + operator uint8_t() const { return _pin; } @@ -31,7 +30,7 @@ class OutputPin { } private: - pin_t _pin; + uint8_t _pin; uint8_t _level = 2; // i.e. neither HIGH nor LOW }; diff --git a/src/ContinuousStepper/StepperInterfaces.hpp b/src/ContinuousStepper/StepperInterfaces.hpp index 084bcb1..fbae521 100644 --- a/src/ContinuousStepper/StepperInterfaces.hpp +++ b/src/ContinuousStepper/StepperInterfaces.hpp @@ -7,8 +7,6 @@ namespace ArduinoContinuousStepper { -typedef uint8_t pin_t; - class StepperBase { protected: StepperBase(StepperListener *listener) : _listener(listener) {} @@ -23,7 +21,7 @@ class StepperBase { class StepperDriver : StepperBase { public: - void begin(pin_t stepPin, pin_t dirPin) { + void begin(uint8_t stepPin, uint8_t dirPin) { _stepPin = stepPin; _dirPin = dirPin; stepperInitialized(); @@ -56,7 +54,7 @@ class StepperDriver : StepperBase { class FourWireStepper : StepperBase { public: - void begin(pin_t pin1, pin_t pin2, pin_t pin3, pin_t pin4) { + void begin(uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4) { _pins[0] = pin1; _pins[1] = pin2; _pins[2] = pin3; diff --git a/src/ContinuousStepper/Tickers/AnalogWriteFrequency.hpp b/src/ContinuousStepper/Tickers/AnalogWriteFrequency.hpp index 14d21d2..83d1b4c 100644 --- a/src/ContinuousStepper/Tickers/AnalogWriteFrequency.hpp +++ b/src/ContinuousStepper/Tickers/AnalogWriteFrequency.hpp @@ -6,7 +6,7 @@ namespace ArduinoContinuousStepper { class AwfOscillator { public: - void init(pin_t pin) { + void init(uint8_t pin) { pinMode(pin, OUTPUT); _pin = pin; } @@ -26,7 +26,7 @@ class AwfOscillator { private: bool _active = false; - pin_t _pin = NULL_PIN; + uint8_t _pin = NULL_PIN; }; using AwfTicker = OscillatorTicker; diff --git a/src/ContinuousStepper/Tickers/OscillatorTicker.hpp b/src/ContinuousStepper/Tickers/OscillatorTicker.hpp index 2288bac..2e7aa92 100644 --- a/src/ContinuousStepper/Tickers/OscillatorTicker.hpp +++ b/src/ContinuousStepper/Tickers/OscillatorTicker.hpp @@ -27,7 +27,7 @@ class OscillatorTicker : StepperTicker { void init() {} - void setPin(pin_t pin) { + void setPin(uint8_t pin) { pinMode(pin, OUTPUT); _oscillator.init(pin); } @@ -58,7 +58,7 @@ class ContinuousStepper> using TBase = ContinuousStepperImpl; public: - void begin(pin_t stepPin, pin_t dirPin) { + void begin(uint8_t stepPin, uint8_t dirPin) { TTicker::setPin(stepPin); TBase::begin(NULL_PIN, dirPin); } diff --git a/src/ContinuousStepper/Tickers/Tone.hpp b/src/ContinuousStepper/Tickers/Tone.hpp index 441fda5..64be522 100644 --- a/src/ContinuousStepper/Tickers/Tone.hpp +++ b/src/ContinuousStepper/Tickers/Tone.hpp @@ -6,7 +6,7 @@ namespace ArduinoContinuousStepper { class ToneOscillator { public: - void init(pin_t pin) { + void init(uint8_t pin) { pinMode(pin, OUTPUT); _pin = pin; } @@ -20,7 +20,7 @@ class ToneOscillator { } private: - pin_t _pin = NULL_PIN; + uint8_t _pin = NULL_PIN; }; using ToneTicker = OscillatorTicker; diff --git a/src/ContinuousStepperImpl.hpp b/src/ContinuousStepperImpl.hpp index 741b6ca..57d4942 100644 --- a/src/ContinuousStepperImpl.hpp +++ b/src/ContinuousStepperImpl.hpp @@ -23,7 +23,7 @@ class ContinuousStepperImpl : public TTicker, TickListener, public TStepper, Ste template ContinuousStepperImpl(Args &&...args) : TTicker(this, args...), TStepper(this) {} - void setEnablePin(pin_t enablePin, bool activeLevel = HIGH) { + void setEnablePin(uint8_t enablePin, bool activeLevel = HIGH) { _enablePin = OutputPin(enablePin); _enablePin.set((_status == OFF) ^ activeLevel); _enablePinActiveLevel = activeLevel;