def calc_offset(actpre, actcount):
    """
    compute offset in ADC counts from a pressure reading and known
    barometric pressure.  actpre is in kPa and actcount is corresponding
    adc count.  Recall:

    y = mx + b

    where:
    y is the pressure in the units of choice
    x is the ADC reading
    m is the slope
    b is the y offset

    54mv/kpa from data sheet but that is scaled for a 5.1V supply so adjust
    94kPa measured pressure
    209 ADC count

      sensitivity = 54mv/kPa * 5V/5.1V = 52.94 mV/kPa

    converting to ADC counts...

      52.94 mV/kPa * 255 counts/5,000mV = 2.7counts/kPa

    We really want the inverse of that or 0.37037 kPa/count so we have:

      y = 5000mV / 255counts / sensitivity * x + b

      5000mv / 255 counts = 0.37037 kpA/count

      94 kPa = 0.37037 kpA/count * 209 counts + b

      b = y - mx
    """

    sensitivity = 54 * 5 / 5.1  # mv/kPa
    m = 5000 / 255 / sensitivity  # kPa/count
    b = actpre - m * actcount  # kPa

    offset = b / m  # count

    return offset