1+ use std:: time:: Duration ;
2+
13fn test_device ( d : & jabi:: Device ) -> Result < ( ) , jabi:: Error > {
24 // Metadata
35 println ! (
@@ -21,7 +23,7 @@ fn test_device(d: &jabi::Device) -> Result<(), jabi::Error> {
2123 d. can_write ( i, & jabi:: CANMessage :: new_rtr ( 0x69420 , 2 , true ) ) ?;
2224 println ! ( "\t Sent some messages" ) ;
2325
24- std:: thread:: sleep ( std :: time :: Duration :: from_millis ( 500 ) ) ;
26+ std:: thread:: sleep ( Duration :: from_millis ( 500 ) ) ;
2527 println ! ( "\t Printing received messages" ) ;
2628 while let Some ( msg) = d. can_read ( i) ? {
2729 println ! ( "\t {msg}" ) ;
@@ -41,21 +43,32 @@ fn test_device(d: &jabi::Device) -> Result<(), jabi::Error> {
4143 }
4244 println ! ( ) ;
4345
46+ // PWM (GPIO overrides it until reset)
47+ for i in 0 ..d. num_inst ( jabi:: InstID :: PWM ) ? {
48+ println ! ( "\t Flashing PWM {i} at 1Hz" ) ;
49+ d. pwm_write ( i, Duration :: from_millis ( 500 ) , Duration :: from_millis ( 1000 ) ) ?;
50+ std:: thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
51+ }
52+ if d. num_inst ( jabi:: InstID :: PWM ) ? > 0 {
53+ std:: thread:: sleep ( Duration :: from_secs ( 3 ) ) ;
54+ }
55+
4456 // GPIO
4557 for i in 0 ..d. num_inst ( jabi:: InstID :: GPIO ) ? {
4658 println ! ( "\t Flashing GPIO {i}" ) ;
4759 d. gpio_set_mode ( i, jabi:: GPIODir :: Output , jabi:: GPIOPull :: None , false ) ?;
4860 for _ in 0 ..6 {
4961 d. gpio_write ( i, false ) ?;
50- std:: thread:: sleep ( std :: time :: Duration :: from_millis ( 25 ) ) ;
62+ std:: thread:: sleep ( Duration :: from_millis ( 25 ) ) ;
5163 d. gpio_write ( i, true ) ?;
52- std:: thread:: sleep ( std :: time :: Duration :: from_millis ( 25 ) ) ;
64+ std:: thread:: sleep ( Duration :: from_millis ( 25 ) ) ;
5365 }
5466 }
5567 for i in 0 ..d. num_inst ( jabi:: InstID :: GPIO ) ? {
5668 d. gpio_set_mode ( i, jabi:: GPIODir :: Input , jabi:: GPIOPull :: Up , false ) ?;
5769 println ! ( "\t Read GPIO {i} w/ pullups: {}" , d. gpio_read( i) ?) ;
5870 }
71+ println ! ( ) ;
5972
6073 Ok ( ( ) )
6174}
0 commit comments