Difference between revisions of "SHIP:Data Types:Temperature"

From Serious Documentation
Jump to: navigation, search
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
*'''[[SHIP:Node|Node Home]]'''
+
== See Also ==
*'''[[SHIP:Data_Types|All Data Types]]'''
+
*[[SHIP:Node|Node Home]]
 
+
*[[SHIP:Data_Types|All Data Types]]
 +
== {{DataType|Temperature}} (SHIPv4 Only) ==
 +
<onlyinclude>
 +
In SHIPv4 the {{DataType|Temperature}} datatype is returned by the {{Portvar|gpio|pcbTemperature}} portvar with a variable format configured by setting {{Portvar|gpio|tempPrecision}}.  In SHIPv5, this variable is renamed {{Portvar|gpio|pcbTemp}} and is a normal {{DataType|Float}}.
 
{{DataTypeTableStart|}}
 
{{DataTypeTableStart|}}
 
|-
 
|-
|<onlyinclude>{{DataType|Temperature}}||16 bit fixed-point-integer in which the upper portion is in whole degrees and the lower portion is in 256ths of a degree. Set {{SysVar|shipCelsius}} to {{Reserved|true}} for Celsius, or {{Reserved|false}} for Fahrenheit.</onlyinclude>
+
|{{DataType|Temperature}}||16 bit fixed-point-integer interpreted as an 8-bit value in whole degrees followed by a {{Portvar|gpio|tempPrecision}}-bit value in 1/256ths of a degree. Set '''shipCelsius''' <!--- Remove link until page exist {{SysVar|shipCelsius}}---> to {{Reserved|true}} for Celsius, or {{Reserved|false}} for Fahrenheit.
|}
+
|}</onlyinclude>
  
The {{DataType|Temperature}} datatype is returned by the {{Port|gpio|pcbTemp}} portvar (the exact format is configured by setting {{Port|gpio|tempPrecision}}). Generically, the value read from {{Port|gpio|pcbTemp}} is an 8-bit value in whole degrees followed by a <code>tempPrecision</code>-bit value in 1/256ths of a degree. The following are examples on how to properly interpret a {{DataType|Temperature}} value:
+
== Examples==
 +
The following are examples on how to properly interpret a {{DataType|Temperature}} value:
  
By default {{Port|gpio|tempPrecision}} is <code>0</code>:
+
If {{Portvar|gpio|tempPrecision}} is <code>0</code> (default):
  <code>SIMTempWhole = GPIO.pcbTemp;  // the value is good as-is
+
  <code>SIMTempWhole = GPIO.pcbTemperature;  // the value is good as-is
 
  SIMTempFrac  = 0;            // unnecessary</code>
 
  SIMTempFrac  = 0;            // unnecessary</code>
  
For handling any other value of {{Port|gpio|tempPrecision}}:
+
Otherwise (if your GUI does not change {{Portvar|gpio|tempPrecision}}, replace with constant values):
  <code>SIMTempWhole = (GPIO.pcbTemp >> GPIO.tempPrecision);                  // once the fractional bits are gone, the value is correct
+
  <code>SIMTempWhole = (GPIO.pcbTemperature >> GPIO.tempPrecision);                  // get rid of the fractional bits
  SIMTempFrac  = (GPIO.pcbTemp & (0x00FF >> (8 - GPIO.tempPrecision))); // get rid of the degree bits
+
  SIMTempFrac  = (GPIO.pcbTemperature & (0x00FF >> (8 - GPIO.tempPrecision))); // get rid of the degree bits
 
  SIMTempFrac  = (SIMTempFrac << (8 - GPIO.tempPrecision));            // re-adjust the fractional 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)</code>
 
  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)</code>
  
 
'''''Note:''' ''<code>SIMTempWhole</code>'' and ''<code>SIMTempFrac</code>'' only need to be of type ''{{DataType|Byte}}'' to fit the highest possible values''
 
'''''Note:''' ''<code>SIMTempWhole</code>'' and ''<code>SIMTempFrac</code>'' only need to be of type ''{{DataType|Byte}}'' to fit the highest possible values''

Latest revision as of 10:22, 26 October 2016

See Also

Temperature (SHIPv4 Only)

In SHIPv4 the Temperature datatype is returned by the pcbTemperature portvar with a variable format configured by setting tempPrecision. In SHIPv5, this variable is renamed pcbTemp and is a normal Float.

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.

Examples

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

If tempPrecision is 0 (default):

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

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

SIMTempWhole = (GPIO.pcbTemperature >> GPIO.tempPrecision);                  // get rid of the fractional bits
SIMTempFrac  = (GPIO.pcbTemperature & (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