@@ -381,23 +381,13 @@ do_take_reading(State) ->
381381% % @private
382382to_reading (Bin , Mode , MtReg ) ->
383383 <<Reading :16 /big -unsigned >> = Bin ,
384- X = multiply ({ 1 , { 2 , 10 }}, { 69 , MtReg } ),
384+ X = 1.2 * ( 69 / MtReg ),
385385 Y = case Mode of
386386 high2 ->
387- multiply ( X , 2 ) ;
387+ X * 2 ;
388388 _ -> X
389389 end ,
390- divide (Reading , Y ).
391-
392- % % @private
393- multiply (A , B ) ->
394- rational :simplify (rational :reduce (rational :multiply (A , B ))).
395-
396- % % @private
397- divide (0 , _B ) ->
398- {0 , {0 , 1 }};
399- divide (A , B ) ->
400- rational :to_decimal (rational :reduce (rational :divide (A , B )), 2 ).
390+ Reading / Y .
401391
402392% % @private
403393do_start_continuous_reading (State ) ->
@@ -442,13 +432,8 @@ do_powerdown(State) ->
442432
443433% % @private
444434send_command (I2CBus , Address , Command ) ->
445- % ok = i2c_bus:begin_transmission(I2CBus, Address),
446- % ok = i2c_bus:write_byte(I2CBus, Command),
447- % ok = i2c_bus:end_transmission(I2CBus).
448435 ? TRACE (" sending command to bus ~p using address ~p command ~p ..." , [I2CBus , Address , Command ]),
449- ok = i2c_bus :enqueue (I2CBus , Address , [
450- fun (Port , _Address ) -> ok = i2c :write_byte (Port , Command ) end
451- ]).
436+ i2c_bus :write_bytes (I2CBus , Address , Command ).
452437
453438% % @private
454439get_command (one_time , high ) ->
@@ -467,22 +452,10 @@ get_command(continuous, low) ->
467452% % @private
468453get_sleep_ms (Resolution , MtReg ) ->
469454 Base = get_sleep_ms (Resolution ),
470- Sleep = multiply ( Base , divide (MtReg , 69 ) ),
471- round_sleep (Sleep ).
455+ Sleep = Base * (MtReg / 69 ),
456+ erlang : round (Sleep ).
472457
473458% % @private
474459get_sleep_ms (high ) -> 120 ;
475460get_sleep_ms (high2 ) -> 120 ;
476461get_sleep_ms (low ) -> 16 .
477-
478- % % @private
479- round_sleep ({I , {_N , _D } = F }) ->
480- I + round_sleep (F );
481- round_sleep ({0 , _D }) ->
482- 0 ;
483- round_sleep ({N , D }) ->
484- case N > (D bsr 1 ) of
485- true -> 1 ;
486- _ -> 0
487- end ;
488- round_sleep (I ) when is_integer (I ) -> I .
0 commit comments