@@ -19,7 +19,6 @@ public class Hcsr04 : IDisposable
1919    { 
2020        ReceiverChannel  _rxChannel ; 
2121        TransmitterChannel  _txChannel ; 
22-         RmtCommand  _txPulse ; 
2322        long  _lastMeasurment ; 
2423
2524        const  double  _speedOfSound  =  340.29 ; 
@@ -39,26 +38,37 @@ public Hcsr04(int trigger, int echo)
3938        { 
4039            // Set-up TX & RX channels 
4140            // We need to send a 10us pulse to initiate measurement 
42-             _txChannel  =  new  TransmitterChannel ( trigger ) ; 
41+             var  txChannelSettings  =  new  TransmitChannelSettings ( pinNumber :  trigger ) 
42+             { 
43+                 // 1us clock ( 80Mhz / 80 ) = 1Mhz 
44+                 ClockDivider  =  80 , 
45+                 EnableCarrierWave  =  true , 
46+                 IdleLevel  =  false , 
47+             } ; 
48+ 
49+             _txChannel  =  new  TransmitterChannel ( txChannelSettings ) ; 
4350            // we only need 1 pulse of 10 us high 
4451            _txChannel . AddCommand ( new  RmtCommand ( 10 ,  true ,  0 ,  false ) ) ; 
4552
46-             _txChannel . ClockDivider  =  80 ; 
47-             _txChannel . CarrierEnabled  =  false ; 
48-             _txChannel . IdleLevel  =  false ; 
49- 
5053            // The received echo pulse width represents the distance to obstacle 
5154            // 150us to 38ms 
52-             _rxChannel  =  new  ReceiverChannel ( echo ) ; 
53- 
54-             // 1us clock ( 80Mhz / 80 ) = 1Mhz 
55-             _rxChannel . ClockDivider  =  80 ; 
56-             // filter out 200Us / noise  
57-             _rxChannel . EnableFilter ( true ,  200 ) ; 
58-             // 40ms based on 1us clock 
59-             _rxChannel . SetIdleThresold ( 40000 ) ; 
60-             // 100 millisecond timeout is enough 
61-             _rxChannel . ReceiveTimeout  =  TimeSpan . FromMilliseconds ( 100 ) ; 
55+             var  rxChannelSettings  =  new  ReceiverChannelSettings ( pinNumber :  echo ) 
56+             { 
57+                 // 1us clock ( 80Mhz / 80 ) = 1Mhz 
58+                 ClockDivider  =  80 , 
59+ 
60+                 // filter out 200Us / noise 
61+                 EnableFilter  =  true , 
62+                 FilterThreshold  =  200 , 
63+ 
64+                 // 40ms based on 1us clock 
65+                 IdleThreshold  =  40_000 , 
66+ 
67+                 // 100 millisecond timeout is enough 
68+                 ReceiveTimeout  =  TimeSpan . FromMilliseconds ( 100 ) 
69+             } ; 
70+ 
71+             _rxChannel  =  new  ReceiverChannel ( rxChannelSettings ) ; 
6272        } 
6373
6474        /// <summary> 
0 commit comments