SHIP:Data Types:Temperature

From Serious Documentation
Revision as of 16:21, 1 February 2013 by NickW-Serious (talk | contribs)
Jump to: navigation, search


The Temperature datatype is returned by the pcbTemp portvar with a variable format configured by setting tempPrecision.

Data Type Description
Temperature 16 bit fixed-point-integer interpreted as an 8-bit value in whole degrees followed by a tempPrecision-bit value in 1/256ths of a degree. Set shipCelsius to true for Celsius, or false for Fahrenheit.

The following are examples on how to properly interpret a Temperature value:

If tempPrecision is 0 (default):

SIMTempWhole = GPIO.pcbTemp;  // the value is good as-is
SIMTempFrac  = 0;             // unnecessary

Otherwise (if your GUI does not change tempPrecision, replace with constant values):

SIMTempWhole = (GPIO.pcbTemp >> GPIO.tempPrecision);                  // get rid of the fractional bits
SIMTempFrac  = (GPIO.pcbTemp & (0x00FF >> (8 - GPIO.tempPrecision))); // get rid of the degree bits
SIMTempFrac  = (SIMTempFrac << (8 - GPIO.tempPrecision));             // re-adjust the fractional bits
SIMTempFrac  = (SIMTempFrac*100)/256;                                 // fix up the value to be a proper fraction (currently it is from 0/256 to 255/256 of a degree)

Note: SIMTempWhole and SIMTempFrac only need to be of type Byte to fit the highest possible values