Skip to content

Commit

Permalink
tester: don't beep on encoder edges, set LEDs instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanperret committed Aug 17, 2024
1 parent 7432e76 commit 8e5fa2b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
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
20 changes: 10 additions & 10 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 @@ -211,13 +214,10 @@ void Tester::setUp() {
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;
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
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 8e5fa2b

Please sign in to comment.