@Override
    public void tick(Object context, long timeStamp)
    {
        synchronized(buf)
        {
            buf.add(timeStamp);
            if(buf.size() > WINDOW_SIZE)
                buf.remove(0);
        }

        // Energy expenditure estimation
        float rpm = getRPM();
        if(last_rpm != 0 && last_rpm_time != -1)
        {
            long dt = timeStamp - last_rpm_time;
            float avgRPM = (last_rpm + rpm) / 2;
            float cal_per_hour = 18.7f * avgRPM - 1132f;
            if(cal_per_hour > 0 && dt > 0)
                calories += (cal_per_hour / (60l * 60l * 1000l)) * dt;
        }

        last_rpm = rpm;
        last_rpm_time = timeStamp;
        if(state == State.RUNNING)
            ticks++;
    }