Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SmartHome
NodeManager_BME280_EasyPCB
Commits
b0312ff3
Commit
b0312ff3
authored
Jul 09, 2017
by
user2684
Committed by
GitHub
Jul 09, 2017
Browse files
Backport of 1.5.1 hotfix for maximum allocated sensors
parent
ea9596ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
NodeManager.cpp
View file @
b0312ff3
...
...
@@ -2747,6 +2747,7 @@ int NodeManager::registerSensor(int sensor_type, int pin, int child_id) {
// attach a built-in or custom sensor to this manager
int
NodeManager
::
registerSensor
(
Sensor
*
sensor
)
{
if
(
sensor
->
getChildId
()
>
MAX_SENSORS
)
return
;
#if DEBUG == 1
Serial
.
print
(
F
(
"REG I="
));
Serial
.
print
(
sensor
->
getChildId
());
...
...
@@ -2769,12 +2770,14 @@ int NodeManager::registerSensor(Sensor* sensor) {
// un-register a sensor to this manager
void
NodeManager
::
unRegisterSensor
(
int
sensor_index
)
{
if
(
sensor_index
>
MAX_SENSORS
)
return
;
// unlink the pointer to this sensor
_sensors
[
sensor_index
]
==
0
;
}
// return a sensor given its index
Sensor
*
NodeManager
::
get
(
int
child_id
)
{
if
(
child_id
>
MAX_SENSORS
)
return
0
;
// return a pointer to the sensor from the given child_id
return
_sensors
[
child_id
];
}
...
...
@@ -2784,6 +2787,7 @@ Sensor* NodeManager::getSensor(int child_id) {
// assign a different child id to a sensor'
bool
NodeManager
::
renameSensor
(
int
old_child_id
,
int
new_child_id
)
{
if
(
old_child_id
>
MAX_SENSORS
||
new_child_id
>
MAX_SENSORS
)
return
;
// ensure the old id exists and the new is available
if
(
_sensors
[
old_child_id
]
==
0
||
_sensors
[
new_child_id
]
!=
0
)
return
false
;
// assign the sensor to new id
...
...
@@ -2851,7 +2855,7 @@ void NodeManager::before() {
_battery_report_timer
.
start
();
#endif
// setup individual sensors
for
(
int
i
=
0
;
i
<
MAX_SENSORS
;
i
++
)
{
for
(
int
i
=
1
;
i
<
=
MAX_SENSORS
;
i
++
)
{
if
(
_sensors
[
i
]
==
0
)
continue
;
// call each sensor's setup()
_sensors
[
i
]
->
before
();
...
...
@@ -2875,7 +2879,7 @@ void NodeManager::presentation() {
batteryReport
();
#endif
// present each sensor
for
(
int
i
=
0
;
i
<
MAX_SENSORS
;
i
++
)
{
for
(
int
i
=
1
;
i
<
=
MAX_SENSORS
;
i
++
)
{
if
(
_sensors
[
i
]
==
0
)
continue
;
// call each sensor's presentation()
if
(
_sleep_between_send
>
0
)
sleep
(
_sleep_between_send
);
...
...
@@ -2902,7 +2906,7 @@ void NodeManager::setup() {
_send
(
_msg
.
set
(
"STARTED"
));
#endif
// run setup for all the registered sensors
for
(
int
i
=
0
;
i
<
MAX_SENSORS
;
i
++
)
{
for
(
int
i
=
1
;
i
<
=
MAX_SENSORS
;
i
++
)
{
if
(
_sensors
[
i
]
==
0
)
continue
;
// call each sensor's setup()
_sensors
[
i
]
->
setup
();
...
...
@@ -2935,7 +2939,7 @@ void NodeManager::loop() {
if
(
_auto_power_pins
)
powerOn
();
#endif
// run loop for all the registered sensors
for
(
int
i
=
0
;
i
<
MAX_SENSORS
;
i
++
)
{
for
(
int
i
=
1
;
i
<
=
MAX_SENSORS
;
i
++
)
{
// skip not configured sensors
if
(
_sensors
[
i
]
==
0
)
continue
;
// if waking up from an interrupt skip all the sensor without that interrupt configured
...
...
@@ -2975,7 +2979,7 @@ void NodeManager::receive(const MyMessage &message) {
#endif
}
// dispatch the message to the registered sensor
else
if
(
_sensors
[
message
.
sensor
]
!=
0
)
{
else
if
(
message
.
sensor
<=
MAX_SENSORS
&&
_sensors
[
message
.
sensor
]
!=
0
)
{
#if POWER_MANAGER == 1
// turn on the pin powering all the sensors
if
(
_auto_power_pins
)
powerOn
();
...
...
@@ -3285,12 +3289,13 @@ void NodeManager::_present(int child_id, int type) {
// return the next available child_id
int
NodeManager
::
_getAvailableChildId
()
{
for
(
int
i
=
1
;
i
<
MAX_SENSORS
;
i
++
)
{
for
(
int
i
=
1
;
i
<
=
MAX_SENSORS
;
i
++
)
{
if
(
i
==
CONFIGURATION_CHILD_ID
)
continue
;
if
(
i
==
BATTERY_CHILD_ID
)
continue
;
// empty place, return it
if
(
_sensors
[
i
]
==
0
)
return
i
;
}
return
MAX_SENSORS
;
}
// guess the initial value of a digital output based on the configured interrupt mode
...
...
NodeManager.h
View file @
b0312ff3
...
...
@@ -1295,7 +1295,7 @@ class NodeManager {
int
_interrupt_2_pull
=
-
1
;
int
_last_interrupt_pin
=
-
1
;
long
_timestamp
=
-
1
;
Sensor
*
_sensors
[
MAX_SENSORS
]
=
{
0
};
Sensor
*
_sensors
[
MAX_SENSORS
+
1
]
=
{
0
};
bool
_ack
=
false
;
void
_sleep
();
void
_present
(
int
child_id
,
int
type
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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