This repository was archived by the owner on Jun 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAtlasStampTemperatureCompensated.cpp
More file actions
58 lines (48 loc) · 1.78 KB
/
Copy pathAtlasStampTemperatureCompensated.cpp
File metadata and controls
58 lines (48 loc) · 1.78 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
#include "AtlasStampTemperatureCompensated.h"
AtlasStampTemperatureCompensated::AtlasStampTemperatureCompensated(uint8_t address, char* unit, uint8_t unit_len, float min_value, float max_value, uint8_t max_num_fields_in_response) :
AtlasStamp(address, unit, unit_len, min_value, max_value, max_num_fields_in_response), _current_temperature(-2048.0)
{
}
void AtlasStampTemperatureCompensated::info(Stream& output)
{
output.printf("ADDRESS:[0x%02x] VERSION:[%s] READY:[%d] BUSY:[%d] MIN:[%4.3f] MAX:[%4.3f] UNIT:[%s] TMP:[%4.2f] VCC:[%4.4f]\n",_address, stamp_version, ready(), busy(), get_min_value(), get_max_value(), get_unit(), _current_temperature, get_vcc());
}
float const AtlasStampTemperatureCompensated::get_temperature()
{
return _current_temperature;
}
bool const AtlasStampTemperatureCompensated::_load_temperature()
{
if (ATLAS_SUCCESS_RESPONSE == _command(ATLAS_TEMPERATURE_READ_COMAND, 300))
{
// Buffer holds "?T,19.5".
if (_bytes_in_buffer() >= 5)
{
char* res_buff = (char*)(_get_response_buffer() + 3);
_current_temperature = atof(res_buff);
#ifdef ATLAS_DEBUG
Serial.printf("AtlasStampTemperatureCompensated::temperature buffer [%s] current float [%4.2f]\n", res_buff, _current_temperature);
#endif
return true;
}
}
return false;
}
bool const AtlasStampTemperatureCompensated::set_temperature(float temp, float max_divergence)
{
if ((!busy()) && (abs(temp - _current_temperature) >= max_divergence))
{
return set_temperature(temp);
}
return false;
}
bool const AtlasStampTemperatureCompensated::set_temperature(float temp)
{
sprintf(_command_buffer, "T,%4.2f", temp);
if (ATLAS_SUCCESS_RESPONSE == _command(_command_buffer, 300))
{
_current_temperature = temp;
return true;
}
return false;
}