diff --git a/src/ayab/knitter.cpp b/src/ayab/knitter.cpp index 4539bc1ef..2a58e40d5 100644 --- a/src/ayab/knitter.cpp +++ b/src/ayab/knitter.cpp @@ -64,6 +64,8 @@ void Knitter::init() { setUpInterrupt(); // explicitly initialize members + + // job parameters m_machineType = NoMachine; m_startNeedle = 0U; m_stopNeedle = 0U; @@ -79,8 +81,6 @@ void Knitter::init() { #ifdef DBG_NOMACHINE m_prevState = false; #endif - m_solenoidToSet = 0U; - m_pixelToSet = 0U; } void Knitter::setUpInterrupt() { @@ -163,7 +163,8 @@ void Knitter::encodePosition() { } } -// return true -> move from state `s_init` to `s_ready` +// if this function returns true then +// the FSM will move from state `s_init` to `s_ready` bool Knitter::isReady() { #ifdef DBG_NOMACHINE bool state = digitalRead(DBG_BTN_PIN); @@ -171,8 +172,12 @@ bool Knitter::isReady() { // TODO(who?): check if debounce is needed if (m_prevState && !state) { #else - // machine is initialized when left hall sensor is passed in Right direction - if (Right == m_direction && Left == m_hallActive) { + // Machine is initialized when left Hall sensor is passed in Right direction + // New feature (August 2020): the machine is also initialized + // when the right Hall sensor is passed in Left direction. + if ((Right == m_direction and Left == m_hallActive) or + (Left == m_direction and Right == m_hallActive)) { + #endif // DBG_NOMACHINE GlobalSolenoids::setSolenoids(SOLENOIDS_BITMASK); indState(true); diff --git a/test/test_knitter.cpp b/test/test_knitter.cpp index f0b394086..74cab462a 100644 --- a/test/test_knitter.cpp +++ b/test/test_knitter.cpp @@ -116,7 +116,7 @@ class KnitterTest : public ::testing::Test { } void expect_isr(Direction_t dir, Direction_t hall) { - expect_isr(1, dir, hall, Regular, Garter); + expect_isr(1, dir, hall, Regular, Knit); } void expected_isr(Direction_t dir, Direction_t hall) { @@ -151,10 +151,10 @@ class KnitterTest : public ::testing::Test { } void get_to_ready() { - // machine is initialized when left hall sensor - // is passed in Right direction inside active needles + // Machine is initialized when Left hall sensor + // is passed in Right direction inside active needles. Machine_t m = knitter->getMachineType(); - expected_isr(40 + END_OF_LINE_OFFSET_L[m] + 1); + expected_isr(40 + END_OF_LINE_OFFSET_L[m] + 1, Right, Left, Regular, Knit); // initialize EXPECT_CALL(*solenoidsMock, setSolenoids(0xFFFF)); @@ -355,7 +355,7 @@ TEST_F(KnitterTest, test_knit_Kh910) { expected_knit(false); // no useful position calculated by `calculatePixelAndSolenoid()` - expected_isr(100, NoDirection, Right, Shifted, Garter); + expected_isr(100, NoDirection, Right, Shifted, Knit); EXPECT_CALL(*solenoidsMock, setSolenoid).Times(0); expect_indState(); expected_knit(false); @@ -670,7 +670,8 @@ TEST_F(KnitterTest, test_fsm_init_RR) { } TEST_F(KnitterTest, test_fsm_init_RL) { - // ready + // Machine is initialized when Left hall sensor + // is passed in Right direction inside active needles. expected_isr(Right, Left); EXPECT_CALL(*solenoidsMock, setSolenoids(0xFFFF)); expect_indState(); @@ -682,3 +683,18 @@ TEST_F(KnitterTest, test_fsm_init_RL) { ASSERT_TRUE(Mock::VerifyAndClear(comMock)); ASSERT_TRUE(Mock::VerifyAndClear(encodersMock)); } + +TEST_F(KnitterTest, test_fsm_init_LR) { + // New feature (August 2020): the machine is also initialized + // when the right Hall sensor is passed in the Left direction. + expected_isr(Left, Right); + EXPECT_CALL(*solenoidsMock, setSolenoids(0xFFFF)); + expect_indState(); + expected_fsm(); + ASSERT_EQ(fsm->getState(), s_ready); + + // test expectations without destroying instance + ASSERT_TRUE(Mock::VerifyAndClear(solenoidsMock)); + ASSERT_TRUE(Mock::VerifyAndClear(comMock)); + ASSERT_TRUE(Mock::VerifyAndClear(encodersMock)); +}