forked from JFF-Bohdan/msp430intertempsensor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinternaltempsensor.cpp
More file actions
46 lines (33 loc) · 976 Bytes
/
internaltempsensor.cpp
File metadata and controls
46 lines (33 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "internaltempsensor.h"
InternalTempSensor::InternalTempSensor()
{
}
InternalTempSensor::~InternalTempSensor()
{
//
}
int32_t InternalTempSensor::update(const boolean onlyIntegerPart, const int measurementsQty)
{
analogReference(INTERNAL1V5);
//first measuring contains wrong data
analogRead(TEMPSENSOR);
int i = 0;
m_Average = 0;
for(i=0; i<measurementsQty; ++i) {
// Formula: http://www.43oh.com/forum/viewtopic.php?p=18248#p18248
m_Average += ((int32_t)analogRead(TEMPSENSOR)*27069 - 18169625) *10 >> 16;
}
m_Average = (m_Average / measurementsQty);
return temperature(onlyIntegerPart);
}
int32_t InternalTempSensor::temperature(const boolean onlyIntegerPart) const
{
if(onlyIntegerPart)
return m_Average / 10;
return m_Average;
}
float InternalTempSensor::temperatureFloat() const
{
return (float)((m_Average/10)) + (m_Average%10)/10.0;
}
InternalTempSensor MSPTemp;