Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NodeManager_GasSensor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SmartHome
NodeManager_GasSensor
Commits
97585d55
Commit
97585d55
authored
8 years ago
by
user2684
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Move isMetric in a function and allow users to set it manually from the sketch #115
parent
cccba366
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
NodeManager.cpp
+28
-12
28 additions, 12 deletions
NodeManager.cpp
NodeManager.h
+9
-0
9 additions, 0 deletions
NodeManager.h
README.md
+7
-0
7 additions, 0 deletions
README.md
with
44 additions
and
12 deletions
NodeManager.cpp
+
28
−
12
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"
));
...
...
This diff is collapsed.
Click to expand it.
NodeManager.h
+
9
−
0
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
This diff is collapsed.
Click to expand it.
README.md
+
7
−
0
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment