@@ -190,5 +190,71 @@ def test_analogWrite(self):
190190 build_cmd_str ('aw' , (pin , value )))
191191
192192
193+ class TestServos (ArduinoTestCase ):
194+
195+ def test_attach (self ):
196+ from Arduino .arduino import build_cmd_str
197+ pin = 10
198+ position = 0
199+ self .mock_serial .push_line (position )
200+ servo_min = 544
201+ servo_max = 2400
202+ self .board .Servos .attach (pin , min = servo_min , max = servo_max )
203+ self .assertEquals (self .mock_serial .output [0 ],
204+ build_cmd_str ('sva' , (pin , servo_min , servo_max )))
205+
206+ def test_detach (self ):
207+ from Arduino .arduino import build_cmd_str
208+ pin = 10
209+ position = 0
210+ # Attach first.
211+ self .mock_serial .push_line (position )
212+ self .board .Servos .attach (pin )
213+ self .mock_serial .reset_mock ()
214+ self .board .Servos .detach (pin )
215+ self .assertEquals (self .mock_serial .output [0 ],
216+ build_cmd_str ('svd' , (position ,)))
217+
218+ def test_write (self ):
219+ from Arduino .arduino import build_cmd_str
220+ pin = 10
221+ position = 0
222+ angle = 90
223+ # Attach first.
224+ self .mock_serial .push_line (position )
225+ self .board .Servos .attach (pin )
226+ self .mock_serial .reset_mock ()
227+ self .board .Servos .write (pin , angle )
228+ self .assertEquals (self .mock_serial .output [0 ],
229+ build_cmd_str ("svw" , (position , angle )))
230+
231+ def test_writeMicroseconds (self ):
232+ from Arduino .arduino import build_cmd_str
233+ pin = 10
234+ position = 0
235+ microseconds = 1500
236+ # Attach first.
237+ self .mock_serial .push_line (position )
238+ self .board .Servos .attach (pin )
239+ self .mock_serial .reset_mock ()
240+ self .board .Servos .writeMicroseconds (pin , microseconds )
241+ self .assertEquals (self .mock_serial .output [0 ],
242+ build_cmd_str ("svwm" , (position , microseconds )))
243+
244+ def test_read (self ):
245+ from Arduino .arduino import build_cmd_str
246+ pin = 10
247+ position = 0
248+ angle = 90
249+ # Attach first.
250+ self .mock_serial .push_line (position )
251+ self .board .Servos .attach (pin )
252+ self .mock_serial .reset_mock ()
253+ self .mock_serial .push_line (angle )
254+ self .assertEquals (self .board .Servos .read (pin ), angle )
255+ self .assertEquals (self .mock_serial .output [0 ],
256+ build_cmd_str ("svr" , (position ,)))
257+
258+
193259if __name__ == '__main__' :
194260 unittest .main ()
0 commit comments