Skip to content

Commit

Permalink
pointers -> references
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mpr1c3 committed Oct 2, 2023
1 parent 4748717 commit 3823fdd
Show file tree
Hide file tree
Showing 44 changed files with 789 additions and 784 deletions.
6 changes: 3 additions & 3 deletions src/ayab/analogReadAsyncWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AnalogReadAsyncWrapperInterface {
};

// Container class for the static method analogReadAsync.
// Dependency injection is enabled using a pointer to a global instance of
// Dependency injection is enabled using a reference to a global instance of
// either `AnalogReadAsyncWrapper` or `AnalogReadAsyncWrapperMock`,
// both of which classes implement the
// pure virtual methods of `AnalogReadAsyncWrapperInterface`.
Expand All @@ -47,8 +47,8 @@ class GlobalAnalogReadAsyncWrapper final {
GlobalAnalogReadAsyncWrapper() = default;

public:
// pointer to global instance whose methods are implemented
static AnalogReadAsyncWrapperInterface *m_instance;
// reference to global instance whose methods are implemented
static AnalogReadAsyncWrapperInterface& m_instance;

static void analogReadAsyncWrapped(uint8_t pin, analogReadCompleteCallback_t cb = nullptr, const void *data = nullptr);
};
Expand Down
6 changes: 3 additions & 3 deletions src/ayab/beeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BeeperInterface {
};

// Container class for the static methods that control the beeper.
// Dependency injection is enabled using a pointer to a global instance of
// Dependency injection is enabled using a reference to a global instance of
// either `Beeper` or `BeeperMock`, both of which classes implement the
// pure virtual methods of `BeeperInterface`.

Expand All @@ -63,8 +63,8 @@ class GlobalBeeper final {
GlobalBeeper() = default;

public:
// pointer to global instance whose methods are implemented
static BeeperInterface *m_instance;
// reference to global instance whose methods are implemented
static BeeperInterface& m_instance;

static void init(bool enabled);
static void update();
Expand Down
13 changes: 4 additions & 9 deletions src/ayab/com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void Com::send_indState(Err_t error) const {
send(static_cast<uint8_t *>(payload), INDSTATE_LEN);
}

/*! GCOVR_EXCL_START
/*!
*
* \brief Callback for PacketSerial.
* \param buffer A pointer to a data buffer.
Expand All @@ -161,7 +161,6 @@ void Com::send_indState(Err_t error) const {
void Com::onPacketReceived(const uint8_t *buffer, size_t size) {
GlobalController::getState()->com(buffer, size);
}
// GCOVR_EXCL_STOP

// Serial command handling

Expand Down Expand Up @@ -191,7 +190,7 @@ void Com::h_reqInit(const uint8_t *buffer, size_t size) {
}

GlobalController::setMachineType(machineType);
GlobalController::setState(GlobalOpInit::m_instance);
GlobalController::setState(&GlobalOpInit::m_instance);
send_cnfInit(Err_t::Success);
}

Expand Down Expand Up @@ -277,8 +276,6 @@ void Com::h_cnfLine(const uint8_t *buffer, size_t size) {

/*!
* \brief Handle `reqInfo` (request information) command.
* \param buffer A pointer to a data buffer.
* \param size The number of bytes in the data buffer.
*/
void Com::h_reqInfo() const {
send_cnfInfo();
Expand All @@ -288,22 +285,21 @@ void Com::h_reqInfo() const {
* \brief Handle `reqTest` (request hardware test) command.
*/
void Com::h_reqTest() const {
GlobalController::setState(GlobalOpTest::m_instance);
GlobalController::setState(&GlobalOpTest::m_instance);
send_cnfTest(Err_t::Success);
}

/*!
* \brief Handle `quitCmd` (cancel) command.
*/
void Com::h_quitCmd() const {
GlobalController::setState(GlobalOpInit::m_instance);
GlobalController::setState(&GlobalOpInit::m_instance);
}

/*!
* \brief Handle unrecognized command.
*/
void Com::h_unrecognized() const {
// do nothing
}

/*!
Expand Down Expand Up @@ -334,7 +330,6 @@ void Com::send_cnfInit(Err_t error) const {
send(payload, 2);
}


/*!
* \brief Send `cnfStart` message.
* \param error Error code (0 = success, other values = error).
Expand Down
6 changes: 3 additions & 3 deletions src/ayab/com.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ComInterface {
};

// Container class for the static methods that implement the serial API.
// Dependency injection is enabled using a pointer to a global instance of
// Dependency injection is enabled using a reference to a global instance of
// either `Com` or `ComMock`, both of which classes implement the
// pure virtual methods of `ComInterface`.

Expand All @@ -112,8 +112,8 @@ class GlobalCom final {
GlobalCom() = default;

public:
// pointer to global instance whose methods are implemented
static ComInterface *m_instance;
// reference to global instance whose methods are implemented
static ComInterface& m_instance;

static void init();
static void update();
Expand Down
6 changes: 3 additions & 3 deletions src/ayab/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ void Controller::init() {
m_hallActive = Direction_t::NoDirection;
m_beltShift = BeltShift_t::Unknown;
m_position = 0;
m_currentState = GlobalOpIdle::m_instance;
m_nextState = GlobalOpIdle::m_instance;
m_currentState = &GlobalOpIdle::m_instance;
m_nextState = &GlobalOpIdle::m_instance;
}

/*!
Expand Down Expand Up @@ -109,7 +109,7 @@ void Controller::setState(OpInterface *state) {
* \brief Get machine state.
* \return Current state of Finite State Machine.
*/
OpInterface *Controller::getState() {
OpInterface* Controller::getState() {
return m_currentState;
}

Expand Down
12 changes: 6 additions & 6 deletions src/ayab/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ControllerInterface {
virtual void update() = 0;
virtual void cacheEncoders() = 0;
virtual void setState(OpInterface *state) = 0;
virtual OpInterface *getState() = 0;
virtual OpInterface* getState() = 0;
virtual void setMachineType(Machine_t) = 0;
virtual Machine_t getMachineType() = 0;
virtual BeltShift_t getBeltShift() = 0;
Expand All @@ -49,7 +49,7 @@ class ControllerInterface {
};

// Singleton container class for static methods.
// Dependency injection is enabled using a pointer
// Dependency injection is enabled using a reference
// to a global instance of either `Controller` or `ControllerMock`
// both of which classes implement the pure virtual methods
// of the `ControllerInterface` class.
Expand All @@ -60,14 +60,14 @@ class GlobalController final {
GlobalController() = default;

public:
// pointer to global instance whose methods are implemented
static ControllerInterface *m_instance;
// reference to global instance whose methods are implemented
static ControllerInterface& m_instance;

static void init();
static void update();
static void cacheEncoders();
static void setState(OpInterface *state);
static OpInterface *getState();
static OpInterface* getState();
static void setMachineType(Machine_t);
static Machine_t getMachineType();
static BeltShift_t getBeltShift();
Expand All @@ -83,7 +83,7 @@ class Controller : public ControllerInterface {
void update() final;
void cacheEncoders() final;
void setState(OpInterface *state) final;
OpInterface *getState() final;
OpInterface* getState() final;
void setMachineType(Machine_t) final;
Machine_t getMachineType() final;
BeltShift_t getBeltShift() final;
Expand Down
6 changes: 3 additions & 3 deletions src/ayab/encoders.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class EncodersInterface {
};

// Container class for the static methods for the encoders.
// Dependency injection is enabled using a pointer to a global instance of
// Dependency injection is enabled using a reference to a global instance of
// either `Encoders` or `EncodersMock`, both of which classes implement the
// pure virtual methods of `EncodersInterface`.

Expand All @@ -145,8 +145,8 @@ class GlobalEncoders final {
GlobalEncoders() = default;

public:
// pointer to global instance whose methods are implemented
static EncodersInterface *m_instance;
// reference to global instance whose methods are implemented
static EncodersInterface& m_instance;

static void init(Machine_t machineType);
static void setUpInterrupt();
Expand Down
12 changes: 6 additions & 6 deletions src/ayab/global_OpError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@
// static member functions

OpState_t GlobalOpError::state() {
return m_instance->state();
return m_instance.state();
}

void GlobalOpError::init() {
m_instance->init();
m_instance.init();
}

void GlobalOpError::begin() {
m_instance->begin();
m_instance.begin();
}

void GlobalOpError::update() {
m_instance->update();
m_instance.update();
}

void GlobalOpError::com(const uint8_t *buffer, size_t size) {
m_instance->com(buffer, size);
m_instance.com(buffer, size);
}

void GlobalOpError::end() {
m_instance->end();
m_instance.end();
}
12 changes: 6 additions & 6 deletions src/ayab/global_OpIdle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@
// static member functions

OpState_t GlobalOpIdle::state() {
return m_instance->state();
return m_instance.state();
}

void GlobalOpIdle::init() {
m_instance->init();
m_instance.init();
}

void GlobalOpIdle::begin() {
m_instance->begin();
m_instance.begin();
}

void GlobalOpIdle::update() {
m_instance->update();
m_instance.update();
}

void GlobalOpIdle::com(const uint8_t *buffer, size_t size) {
m_instance->com(buffer, size);
m_instance.com(buffer, size);
}

void GlobalOpIdle::end() {
m_instance->end();
m_instance.end();
}
14 changes: 7 additions & 7 deletions src/ayab/global_OpInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,30 @@
// static member functions

OpState_t GlobalOpInit::state() {
return m_instance->state();
return m_instance.state();
}

void GlobalOpInit::init() {
m_instance->init();
m_instance.init();
}

void GlobalOpInit::begin() {
m_instance->begin();
m_instance.begin();
}

void GlobalOpInit::update() {
m_instance->update();
m_instance.update();
}

void GlobalOpInit::com(const uint8_t *buffer, size_t size) {
m_instance->com(buffer, size);
m_instance.com(buffer, size);
}

void GlobalOpInit::end() {
m_instance->end();
m_instance.end();

}

bool GlobalOpInit::isReady() {
return m_instance->isReady();
return m_instance.isReady();
}
24 changes: 12 additions & 12 deletions src/ayab/global_OpKnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,53 +28,53 @@
// static member functions

OpState_t GlobalOpKnit::state() {
return m_instance->state();
return m_instance.state();
}

void GlobalOpKnit::init() {
m_instance->init();
m_instance.init();
}

void GlobalOpKnit::begin() {
m_instance->begin();
m_instance.begin();
}

void GlobalOpKnit::update() {
m_instance->update();
m_instance.update();
}

void GlobalOpKnit::com(const uint8_t *buffer, size_t size) {
m_instance->com(buffer, size);
m_instance.com(buffer, size);
}

void GlobalOpKnit::end() {
m_instance->end();
m_instance.end();
}


Err_t GlobalOpKnit::startKnitting(uint8_t startNeedle,
uint8_t stopNeedle, uint8_t *pattern_start,
bool continuousReportingEnabled) {
return m_instance->startKnitting(startNeedle, stopNeedle,
return m_instance.startKnitting(startNeedle, stopNeedle,
pattern_start, continuousReportingEnabled);
}

void GlobalOpKnit::encodePosition() {
m_instance->encodePosition();
m_instance.encodePosition();
}

void GlobalOpKnit::knit() {
m_instance->knit();
m_instance.knit();
}

uint8_t GlobalOpKnit::getStartOffset(const Direction_t direction) {
return m_instance->getStartOffset(direction);
return m_instance.getStartOffset(direction);
}

bool GlobalOpKnit::setNextLine(uint8_t lineNumber) {
return m_instance->setNextLine(lineNumber);
return m_instance.setNextLine(lineNumber);
}

void GlobalOpKnit::setLastLine() {
m_instance->setLastLine();
m_instance.setLastLine();
}
Loading

0 comments on commit 3823fdd

Please sign in to comment.