Unwrapping measurements from Adxl345 accelerometer
The reconstruction you are looking for is called unwrapping. I have implemented this in C++ with good results last year when measuring the total revolution of a car wheel. In matlab:
link

Q = unwrap(P,tol)


The "roll over" observed (actually, a wrapping) is not caused by register overflow, but by the signal change of measured gravity acceleration. The tolerance tol should be half the peak-to-peak amplitude observed.

In C, it would be something like this (haven't tested this, but the idea is here):

void unwrap(int *P, int tol, int len)
{
    for (int index = 1; index &lt; len; index++)
    {
        // Upwards wrapping
        while (P[index-1] - P[index] &gt; tol)
        {
            P[index] += 2*tol;
        }
        // Downwards wrapping
        while (P[index] - P[index-1] &gt; tol)
        {
            P[index] -= 2*tol;
        }
    }
}