Skip to content

Bug in _write_num creates issues with set_track_index and set_volume #2

@Jeronimo59

Description

@Jeronimo59

Hello,

Many thanks for this useful work.

When playing with it, I came up with strange behavior when using set_track_index() (wrong track was being played) and set_volume() (behavior not consistent).

It turns out that the _write_num() function does not work properly with some values such as 30 (that results into '3' being sent instead of '3', '0' ).
Hence I propose the following fix, that introduces a num0 variable that keeps the original value of 'num' :

void Mp3PlayerModuleWire::_write_num(uint16_t num)  
{  
   int num0 = num;
   for (uint16_t i = 10000; i > 0; i /= 10)  
   {  
      if (num0>= i)  
      {  
         _write_byte(num / i);  
         num %= i;  
      }  
   }  
}  

HTH

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions