From 8e5fa2bb9287df927ef899fd1e0ea337b70fb385 Mon Sep 17 00:00:00 2001 From: Jonathan Perret Date: Sat, 17 Aug 2024 17:38:53 +0200 Subject: [PATCH] tester: don't beep on encoder edges, set LEDs instead --- src/ayab/global_tester.cpp | 4 ++-- src/ayab/tester.cpp | 20 ++++++++++---------- src/ayab/tester.h | 6 +++--- test/test_com.cpp | 4 +--- test/test_tester.cpp | 4 +--- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/ayab/global_tester.cpp b/src/ayab/global_tester.cpp index 45dba8fc0..cef5676e2 100644 --- a/src/ayab/global_tester.cpp +++ b/src/ayab/global_tester.cpp @@ -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 diff --git a/src/ayab/tester.cpp b/src/ayab/tester.cpp index 59e93fcab..92613fc4c 100644 --- a/src/ayab/tester.cpp +++ b/src/ayab/tester.cpp @@ -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); } /*! @@ -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 @@ -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; diff --git a/src/ayab/tester.h b/src/ayab/tester.h index 61fcf476c..71a8d71db 100644 --- a/src/ayab/tester.h +++ b/src/ayab/tester.h @@ -51,7 +51,7 @@ class TesterInterface { virtual void stopCmd() = 0; virtual void quitCmd() = 0; #ifndef AYAB_TESTS - virtual void encoderAChange(); + virtual void encoderChange(); #endif }; @@ -84,7 +84,7 @@ class GlobalTester final { static void stopCmd(); static void quitCmd(); #ifndef AYAB_TESTS - static void encoderAChange(); + static void encoderChange(); #endif }; @@ -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: diff --git a/test/test_com.cpp b/test/test_com.cpp index 2c34d391d..be6119933 100644 --- a/test/test_com.cpp +++ b/test/test_com.cpp @@ -249,12 +249,10 @@ TEST_F(ComTest, test_stopCmd) { TEST_F(ComTest, test_quitCmd) { uint8_t buffer[] = {static_cast(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)); } diff --git a/test/test_tester.cpp b/test/test_tester.cpp index 70f78dc82..7d8a225e3 100644 --- a/test/test_tester.cpp +++ b/test/test_tester.cpp @@ -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)); }