Skip to content

Commit

Permalink
Merge branch 'clholgat/garter_carriage' of https://github.com/clholga…
Browse files Browse the repository at this point in the history
…t/ayab-firmware into clholgat/garter_carriage
  • Loading branch information
clholgat committed Sep 5, 2024
2 parents 030c5f3 + 67affda commit 52cd583
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 32 deletions.
3 changes: 0 additions & 3 deletions src/ayab/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ constexpr uint8_t DBG_BTN_PIN = 7; // DEBUG BUTTON
constexpr uint8_t I2Caddr_sol1_8 = 0x0U; ///< I2C Address of solenoids 1 - 8
constexpr uint8_t I2Caddr_sol9_16 = 0x1U; ///< I2C Address of solenoids 9 - 16

// TODO(Who?): Optimize Delay for various Arduino Models
constexpr uint16_t START_KNITTING_DELAY = 2000U; // ms

// Determine board type
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
// Arduino Uno
Expand Down
4 changes: 2 additions & 2 deletions src/ayab/global_tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void GlobalTester::quitCmd() {
}

#ifndef AYAB_TESTS
void GlobalTester::encoderAChange() {
m_instance->encoderAChange();
void GlobalTester::encoderChange() {
m_instance->encoderChange();
}
#endif // AYAB_TESTS
3 changes: 0 additions & 3 deletions src/ayab/knitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ bool Knitter::isReady() {
void Knitter::knit() {
if (m_firstRun) {
m_firstRun = false;
// TODO(who?): optimize delay for various Arduino models
delay(START_KNITTING_DELAY);
GlobalBeeper::finishedLine();
++m_currentLineNumber;
reqLine(m_currentLineNumber);
Expand Down Expand Up @@ -398,7 +396,6 @@ bool Knitter::calculatePixelAndSolenoid() {
// magic numbers from machine manual
case Direction_t::Right:
startOffset = getStartOffset(Direction_t::Left);


// The Lace carriage is special
// See page 7 of the 930 service manual https://mkmanuals.com/downloadable/download/sample/sample_id/27/
Expand Down
31 changes: 18 additions & 13 deletions src/ayab/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ void Tester::stopCmd() {
* \brief Quit command handler.
*/
void Tester::quitCmd() {
GlobalFsm::setState(OpState::init);
GlobalKnitter::setUpInterrupt();
detachInterrupt(digitalPinToInterrupt(ENC_PIN_A));
detachInterrupt(digitalPinToInterrupt(ENC_PIN_B));

GlobalFsm::setState(OpState::wait_for_machine);
}

/*!
Expand Down Expand Up @@ -190,8 +192,9 @@ void Tester::loop() {
/*!
* \brief Interrupt service routine for encoder A.
*/
void Tester::encoderAChange() {
beep();
void Tester::encoderChange() {
digitalWrite(LED_PIN_A, digitalRead(ENC_PIN_A));
digitalWrite(LED_PIN_B, digitalRead(ENC_PIN_B));
}
#endif // AYAB_TESTS

Expand All @@ -203,27 +206,29 @@ void Tester::encoderAChange() {
void Tester::setUp() {
// Print welcome message
GlobalCom::sendMsg(AYAB_API::testRes, "AYAB Hardware Test, ");
snprintf(buf, BUFFER_LEN, "Firmware v%hhu", FW_VERSION_MAJ);
GlobalCom::sendMsg(AYAB_API::testRes, buf);
snprintf(buf, BUFFER_LEN, ".%hhu", FW_VERSION_MIN);
snprintf(buf, BUFFER_LEN, "Firmware v%hhu.%hhu.%hhu", FW_VERSION_MAJ, FW_VERSION_MIN, FW_VERSION_PATCH);
GlobalCom::sendMsg(AYAB_API::testRes, buf);
if (*FW_VERSION_SUFFIX != '\0') {
snprintf(buf, BUFFER_LEN, "-%s", FW_VERSION_SUFFIX);
GlobalCom::sendMsg(AYAB_API::testRes, buf);
}
snprintf(buf, BUFFER_LEN, " API v%hhu\n\n", API_VERSION);
GlobalCom::sendMsg(AYAB_API::testRes, buf);
helpCmd();

// attach interrupt for ENC_PIN_A(=2), interrupt #0
detachInterrupt(digitalPinToInterrupt(ENC_PIN_A));
#ifndef AYAB_TESTS
// Attaching ENC_PIN_A, Interrupt #0
// This interrupt cannot be enabled until
// the machine type has been validated.
attachInterrupt(digitalPinToInterrupt(ENC_PIN_A), GlobalTester::encoderAChange, RISING);
// Attach interrupts for both encoder pins
attachInterrupt(digitalPinToInterrupt(ENC_PIN_A), GlobalTester::encoderChange, CHANGE);
attachInterrupt(digitalPinToInterrupt(ENC_PIN_B), GlobalTester::encoderChange, CHANGE);
#endif // AYAB_TESTS

m_autoReadOn = false;
m_autoTestOn = false;
m_lastTime = millis();
m_timerEventOdd = false;

// Enable beeper so that it can be tested
GlobalBeeper::init(true);
}

/*!
Expand Down
6 changes: 3 additions & 3 deletions src/ayab/tester.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TesterInterface {
virtual void stopCmd() = 0;
virtual void quitCmd() = 0;
#ifndef AYAB_TESTS
virtual void encoderAChange();
virtual void encoderChange();
#endif
};

Expand Down Expand Up @@ -84,7 +84,7 @@ class GlobalTester final {
static void stopCmd();
static void quitCmd();
#ifndef AYAB_TESTS
static void encoderAChange();
static void encoderChange();
#endif
};

Expand All @@ -104,7 +104,7 @@ class Tester : public TesterInterface {
void stopCmd() final;
void quitCmd() final;
#ifndef AYAB_TESTS
void encoderAChange() final;
void encoderChange() final;
#endif

private:
Expand Down
4 changes: 1 addition & 3 deletions test/test_com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,10 @@ TEST_F(ComTest, test_stopCmd) {

TEST_F(ComTest, test_quitCmd) {
uint8_t buffer[] = {static_cast<uint8_t>(AYAB_API::quitCmd)};
EXPECT_CALL(*knitterMock, setUpInterrupt);
EXPECT_CALL(*fsmMock, setState(OpState::init));
EXPECT_CALL(*fsmMock, setState(OpState::wait_for_machine));
com->onPacketReceived(buffer, sizeof(buffer));

// test expectations without destroying instance
ASSERT_TRUE(Mock::VerifyAndClear(knitterMock));
ASSERT_TRUE(Mock::VerifyAndClear(fsmMock));
}

Expand Down
1 change: 0 additions & 1 deletion test/test_fsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ class FsmTest : public ::testing::Test {
}

void expect_first_knit() {
EXPECT_CALL(*arduinoMock, delay(START_KNITTING_DELAY));
EXPECT_CALL(*beeperMock, finishedLine);
expect_reqLine();
}
Expand Down
1 change: 0 additions & 1 deletion test/test_knitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ class KnitterTest : public ::testing::Test {
}

void expect_first_knit() {
EXPECT_CALL(*arduinoMock, delay(START_KNITTING_DELAY));
EXPECT_CALL(*beeperMock, finishedLine);
expect_reqLine();
}
Expand Down
4 changes: 1 addition & 3 deletions test/test_tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,10 @@ TEST_F(TesterTest, test_autoTestCmd) {
}

TEST_F(TesterTest, test_quitCmd) {
EXPECT_CALL(*knitterMock, setUpInterrupt);
EXPECT_CALL(*fsmMock, setState(OpState::init));
EXPECT_CALL(*fsmMock, setState(OpState::wait_for_machine));
tester->quitCmd();

// test expectations without destroying instance
ASSERT_TRUE(Mock::VerifyAndClear(knitterMock));
ASSERT_TRUE(Mock::VerifyAndClear(fsmMock));
}

Expand Down

0 comments on commit 52cd583

Please sign in to comment.