Skip to content

Commit

Permalink
Add Knitter:quit()
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mpr1c3 committed Mar 9, 2024
1 parent 378e055 commit abfe4b2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/ayab/com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include "com.h"
#include "fsm.h"
#include "knitter.h"
#include "tester.h"

Expand Down Expand Up @@ -184,8 +185,15 @@ void Com::onPacketReceived(const uint8_t *buffer, size_t size) {
break;

case static_cast<uint8_t>(AYAB_API::quitCmd):
GlobalTester::quitCmd();
break;
if (GlobalFsm::getState() == OpState::knit) {
GlobalKnitter::quit();
break;
}
if (GlobalFsm::getState() == OpState::test) {
GlobalTester::quitCmd();
break;
}
// fallthrough

default:
h_unrecognized();
Expand Down
5 changes: 5 additions & 0 deletions src/ayab/global_knitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ void GlobalKnitter::setLastLine() {
void GlobalKnitter::setMachineType(Machine_t machineType) {
m_instance->setMachineType(machineType);
}

void GlobalKnitter::quit() const {
m_instance->quit();
}

11 changes: 11 additions & 0 deletions src/ayab/knitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@ void Knitter::setMachineType(Machine_t machineType) {
m_machineType = machineType;
}

/*!
* \brief Cancel knitting procedure.
*/
void Knitter::quit() const {
GlobalFsm::setState(OpState::init);
GlobalSolenoids::setSolenoids(SOLENOIDS_BITMASK);

// detaching ENC_PIN_A, Interrupt #0
/* detachInterrupt(digitalPinToInterrupt(ENC_PIN_A)); */
}

// private methods

/*!
Expand Down
3 changes: 3 additions & 0 deletions src/ayab/knitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class KnitterInterface {
virtual bool setNextLine(uint8_t lineNumber) = 0;
virtual void setLastLine() = 0;
virtual void setMachineType(Machine_t) = 0;
virtual void quit() const = 0;
};

// Singleton container class for static methods.
Expand Down Expand Up @@ -86,6 +87,7 @@ class GlobalKnitter final {
static bool setNextLine(uint8_t lineNumber);
static void setLastLine();
static void setMachineType(Machine_t);
static void quit();
};

class Knitter : public KnitterInterface {
Expand All @@ -106,6 +108,7 @@ class Knitter : public KnitterInterface {
bool setNextLine(uint8_t lineNumber) final;
void setLastLine() final;
void setMachineType(Machine_t) final;
void quit() const final;

private:
void reqLine(uint8_t lineNumber);
Expand Down

0 comments on commit abfe4b2

Please sign in to comment.