Note that the algorithm I posted has a possibility of incorrect behavior. I wrote it for compression only, assuming that (L1-x1) would always be a positive value. That is, I didn't look at the possibility that the the spring/tire would be stretched. That could occur if the car goes airborne and the suspension stretches where D > sum of static lengths.
However, looks like you're getting something useable.