@@ -83,10 +83,66 @@ void test_threshold(void) {
8383 TEST_ASSERT_EQUAL (2 , logIndex);
8484}
8585
86+ void test_offset (void ) {
87+ byte servoId = 3 ;
88+ Servo servo (servoId, move);
89+ servo.setOffset (10 );
90+
91+ TEST_ASSERT_TRUE (servo.isNeutral ());
92+
93+ servo.move (340 );
94+
95+ TEST_ASSERT_EQUAL (servoId, positions[0 ].servoId );
96+ TEST_ASSERT_EQUAL (350 , positions[0 ].position );
97+
98+ servo.move (330 );
99+
100+ TEST_ASSERT_EQUAL (servoId, positions[1 ].servoId );
101+ TEST_ASSERT_EQUAL (340 , positions[1 ].position );
102+
103+ servo.setOffset (-10 );
104+ servo.move (320 );
105+
106+ TEST_ASSERT_EQUAL (servoId, positions[2 ].servoId );
107+ TEST_ASSERT_EQUAL (310 , positions[2 ].position );
108+
109+ TEST_ASSERT_EQUAL (3 , logIndex);
110+ }
111+
112+ void test_move_towards_neutral_with_offset (void ) {
113+ byte servoId = 123 ;
114+ Servo servo (servoId, move, 10 );
115+ servo.setOffset (10 );
116+
117+ servo.move (350 );
118+
119+ TEST_ASSERT_EQUAL (servoId, positions[0 ].servoId );
120+ TEST_ASSERT_EQUAL (360 , positions[0 ].position );
121+ TEST_ASSERT_TRUE (servo.isNeutral ());
122+
123+ servo.move (340 );
124+
125+ TEST_ASSERT_EQUAL (servoId, positions[1 ].servoId );
126+ TEST_ASSERT_EQUAL (350 , positions[1 ].position );
127+ TEST_ASSERT_FALSE (servo.isNeutral ());
128+
129+ for (int i = 0 ; i < 10 ; i++) {
130+ servo.moveTowardsNeutral ();
131+
132+ TEST_ASSERT_EQUAL (servoId, positions[2 + i].servoId );
133+ TEST_ASSERT_EQUAL (351 + i, positions[2 + i].position );
134+ }
135+
136+ TEST_ASSERT_TRUE (servo.isNeutral ());
137+ TEST_ASSERT_EQUAL (12 , logIndex);
138+ }
139+
86140int main (int argc, char **argv) {
87141 UNITY_BEGIN ();
88- RUN_TEST (test_move);
89- RUN_TEST (test_move_towards_neutral);
90- RUN_TEST (test_threshold);
142+ // RUN_TEST(test_move);
143+ // RUN_TEST(test_move_towards_neutral);
144+ // RUN_TEST(test_threshold);
145+ // RUN_TEST(test_offset);
146+ RUN_TEST (test_move_towards_neutral_with_offset);
91147 UNITY_END ();
92148}
0 commit comments