Skip to content
GitLab
About GitLab
GitLab: the DevOps platform
Explore GitLab
Install GitLab
How GitLab compares
Get started
GitLab docs
GitLab Learn
Pricing
Talk to an expert
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Projects
Groups
Snippets
Sign up now
Login
Sign in
Toggle navigation
Menu
Open sidebar
SmartHome
NodeManager_BME280_EasyPCB
Commits
97585d55
Commit
97585d55
authored
May 31, 2017
by
user2684
Committed by
GitHub
May 31, 2017
Browse files
Move isMetric in a function and allow users to set it manually from the sketch #115
parent
cccba366
Changes
3
Hide whitespace changes
Inline
Side-by-side
NodeManager.cpp
View file @
97585d55
...
...
@@ -466,7 +466,7 @@ void SensorThermistor::onLoop() {
temperature
+=
1.0
/
(
_nominal_temperature
+
273.15
);
// + (1/To)
temperature
=
1.0
/
temperature
;
// Invert
temperature
-=
273.15
;
// convert to C
if
(
!
getControllerConfig
().
isMetric
)
temperature
=
temperature
*
1.8
+
32
;
temperature
=
_node_manager
->
celsiusToFahrenheit
(
temperature
)
;
#if DEBUG == 1
Serial
.
print
(
F
(
"THER I="
));
Serial
.
print
(
_child_id
);
...
...
@@ -474,8 +474,6 @@ void SensorThermistor::onLoop() {
Serial
.
print
(
adc
);
Serial
.
print
(
F
(
" T="
));
Serial
.
print
(
temperature
);
Serial
.
print
(
F
(
" M="
));
Serial
.
println
(
getControllerConfig
().
isMetric
);
#endif
// store the value
_value_float
=
temperature
;
...
...
@@ -1038,7 +1036,7 @@ void SensorDHT::onLoop() {
// read the temperature
float
temperature
=
_dht
->
readTemperature
();
// convert it
if
(
!
getControllerConfig
().
isMetric
)
temperature
=
temperature
*
1.8
+
32
;
temperature
=
_node_manager
->
celsiusToFahrenheit
(
temperature
)
;
#if DEBUG == 1
Serial
.
print
(
F
(
"DHT I="
));
Serial
.
print
(
_child_id
);
...
...
@@ -1109,7 +1107,7 @@ void SensorSHT21::onLoop() {
// read the temperature
float
temperature
=
SHT2x
.
GetTemperature
();
// convert it
if
(
!
getControllerConfig
().
isMetric
)
temperature
=
temperature
*
1.8
+
32
;
temperature
=
_node_manager
->
celsiusToFahrenheit
(
temperature
)
;
#if DEBUG == 1
Serial
.
print
(
F
(
"SHT I="
));
Serial
.
print
(
_child_id
);
...
...
@@ -1272,7 +1270,7 @@ void SensorDs18b20::onLoop() {
// read the temperature
float
temperature
=
_sensors
->
getTempCByIndex
(
_index
);
// convert it
if
(
!
getControllerConfig
().
isMetric
)
temperature
=
temperature
*
1.8
+
32
;
temperature
=
_node_manager
->
celsiusToFahrenheit
(
temperature
)
;
#if DEBUG == 1
Serial
.
print
(
F
(
"DS18B20 I="
));
Serial
.
print
(
_child_id
);
...
...
@@ -1376,7 +1374,7 @@ void SensorMLX90614::onSetup() {
void
SensorMLX90614
::
onLoop
()
{
float
temperature
=
_sensor_type
==
SensorMLX90614
::
TEMPERATURE_OBJECT
?
_mlx
->
readAmbientTempC
()
:
_mlx
->
readObjectTempC
();
// convert it
if
(
!
getControllerConfig
().
isMetric
)
temperature
=
temperature
*
1.8
+
32
;
temperature
=
_node_manager
->
celsiusToFahrenheit
(
temperature
)
;
#if DEBUG == 1
Serial
.
print
(
F
(
"MLX I="
));
Serial
.
print
(
_child_id
);
...
...
@@ -1573,7 +1571,7 @@ void SensorBME280::onLoop() {
// read the temperature
float
temperature
=
_bme
->
readTemperature
();
// convert it
if
(
!
getControllerConfig
().
isMetric
)
temperature
=
temperature
*
1.8
+
32
;
temperature
=
_node_manager
->
celsiusToFahrenheit
(
temperature
)
;
#if DEBUG == 1
Serial
.
print
(
F
(
"BME I="
));
Serial
.
print
(
_child_id
);
...
...
@@ -1637,7 +1635,7 @@ void SensorBMP085::onLoop() {
// read the temperature
float
temperature
=
_bmp
->
readTemperature
();
// convert it
if
(
!
getControllerConfig
().
isMetric
)
temperature
=
temperature
*
1.8
+
32
;
temperature
=
_node_manager
->
celsiusToFahrenheit
(
temperature
)
;
#if DEBUG == 1
Serial
.
print
(
F
(
"BMP I="
));
Serial
.
print
(
_child_id
);
...
...
@@ -1807,7 +1805,7 @@ void SensorHCSR04::onSetup() {
// what to do during loop
void
SensorHCSR04
::
onLoop
()
{
int
distance
=
getControllerConfig
().
i
sMetric
?
_sonar
->
ping_cm
()
:
_sonar
->
ping_in
();
int
distance
=
_node_manager
->
getI
sMetric
()
?
_sonar
->
ping_cm
()
:
_sonar
->
ping_in
();
#if DEBUG == 1
Serial
.
print
(
F
(
"HC I="
));
Serial
.
print
(
_child_id
);
...
...
@@ -1847,7 +1845,7 @@ void SensorMCP9808::onSetup() {
void
SensorMCP9808
::
onLoop
()
{
float
temperature
=
_mcp
->
readTempC
();
// convert it
if
(
!
getControllerConfig
().
isMetric
)
temperature
=
temperature
*
1.8
+
32
;
temperature
=
_node_manager
->
celsiusToFahrenheit
(
temperature
)
;
#if DEBUG == 1
Serial
.
print
(
F
(
"MCP I="
));
Serial
.
print
(
_child_id
);
...
...
@@ -1951,6 +1949,22 @@ void NodeManager::setSleepBetweenSend(int value) {
void
NodeManager
::
setAck
(
bool
value
)
{
_ack
=
value
;
}
void
NodeManager
::
setGetControllerConfig
(
bool
value
)
{
_get_controller_config
=
value
;
}
void
NodeManager
::
setIsMetric
(
bool
value
)
{
_is_metric
=
value
;
}
bool
NodeManager
::
getIsMetric
()
{
return
_is_metric
;
}
// Convert a temperature from celsius to fahrenheit depending on how isMetric is set
float
NodeManager
::
celsiusToFahrenheit
(
float
temperature
)
{
if
(
_is_metric
)
return
temperature
;
// convert the temperature from C to F
return
temperature
*
1.8
+
32
;
}
// register a sensor to this manager
int
NodeManager
::
registerSensor
(
int
sensor_type
,
int
pin
,
int
child_id
)
{
...
...
@@ -2283,11 +2297,13 @@ void NodeManager::presentation() {
// setup NodeManager
void
NodeManager
::
setup
()
{
// retrieve and store isMetric from the controller
if
(
_get_controller_config
)
_is_metric
=
getControllerConfig
().
isMetric
;
#if DEBUG == 1
Serial
.
print
(
F
(
"MY I="
));
Serial
.
print
(
getNodeId
());
Serial
.
print
(
F
(
" M="
));
Serial
.
println
(
getControllerConfig
().
isM
etric
);
Serial
.
println
(
_is_m
etric
);
#endif
#if SERVICE_MESSAGES == 1
_send
(
_msg
.
set
(
"STARTED"
));
...
...
NodeManager.h
View file @
97585d55
...
...
@@ -1056,6 +1056,13 @@ class NodeManager {
void
setAck
(
bool
value
);
// request and return the current timestamp from the controller
long
getTimestamp
();
// Request the controller's configuration on startup (default: true)
void
setGetControllerConfig
(
bool
value
);
// Manually set isMetric setting
void
setIsMetric
(
bool
value
);
bool
getIsMetric
();
// Convert a temperature from celsius to fahrenheit depending on how isMetric is set
float
celsiusToFahrenheit
(
float
temperature
);
// hook into the main sketch functions
void
before
();
void
presentation
();
...
...
@@ -1101,6 +1108,8 @@ class NodeManager {
void
_present
(
int
child_id
,
int
type
);
int
_getAvailableChildId
();
int
_getInterruptInitialValue
(
int
mode
);
bool
_get_controller_config
=
true
;
int
_is_metric
=
1
;
};
#endif
README.md
View file @
97585d55
...
...
@@ -256,6 +256,13 @@ Node Manager comes with a reasonable default configuration. If you want/need to
void
setAck
(
bool
value
);
// request and return the current timestamp from the controller
long
getTimestamp
();
// Request the controller's configuration on startup (default: true)
void
setGetControllerConfig
(
bool
value
);
// Manually set isMetric setting
void
setIsMetric
(
bool
value
);
bool
getIsMetric
();
// Convert a temperature from celsius to fahrenheit depending on how isMetric is set
float
celsiusToFahrenheit
(
float
temperature
);
~~~
For example
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment