Skip to content

Commit

Permalink
Remove pin_t. Use uint8_t instead.
Browse files Browse the repository at this point in the history
It looks nicer in Arduino IDE's tooltips.
  • Loading branch information
bblanchon committed Aug 7, 2023
1 parent 9cf299a commit 12edf95
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
```


Expand Down
9 changes: 4 additions & 5 deletions src/ContinuousStepper/OutputPin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -31,7 +30,7 @@ class OutputPin {
}

private:
pin_t _pin;
uint8_t _pin;
uint8_t _level = 2; // i.e. neither HIGH nor LOW
};

Expand Down
6 changes: 2 additions & 4 deletions src/ContinuousStepper/StepperInterfaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

namespace ArduinoContinuousStepper {

typedef uint8_t pin_t;

class StepperBase {
protected:
StepperBase(StepperListener *listener) : _listener(listener) {}
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/ContinuousStepper/Tickers/AnalogWriteFrequency.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ArduinoContinuousStepper {

class AwfOscillator {
public:
void init(pin_t pin) {
void init(uint8_t pin) {
pinMode(pin, OUTPUT);
_pin = pin;
}
Expand All @@ -26,7 +26,7 @@ class AwfOscillator {

private:
bool _active = false;
pin_t _pin = NULL_PIN;
uint8_t _pin = NULL_PIN;
};

using AwfTicker = OscillatorTicker<AwfOscillator>;
Expand Down
4 changes: 2 additions & 2 deletions src/ContinuousStepper/Tickers/OscillatorTicker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -58,7 +58,7 @@ class ContinuousStepper<StepperDriver, OscillatorTicker<TOscillator>>
using TBase = ContinuousStepperImpl<StepperDriver, TTicker>;

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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ContinuousStepper/Tickers/Tone.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ArduinoContinuousStepper {

class ToneOscillator {
public:
void init(pin_t pin) {
void init(uint8_t pin) {
pinMode(pin, OUTPUT);
_pin = pin;
}
Expand All @@ -20,7 +20,7 @@ class ToneOscillator {
}

private:
pin_t _pin = NULL_PIN;
uint8_t _pin = NULL_PIN;
};

using ToneTicker = OscillatorTicker<ToneOscillator>;
Expand Down
2 changes: 1 addition & 1 deletion src/ContinuousStepperImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ContinuousStepperImpl : public TTicker, TickListener, public TStepper, Ste
template <typename... Args>
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;
Expand Down

0 comments on commit 12edf95

Please sign in to comment.