I don't think that this code affects the built-in compass.
You can calibrate built-in compass:
start compass app or gps app that shows compass information.
take your phone with one hand.
put it horizontal then "draw" a horizontal half circle
after this draw a vertical half circle above your head.
and put your phone vertical and roll one circle
order is not important, but after do this compass sensor is calibrated.
look this:
it works on my samsung galaxy mini