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
b0312ff3
Commit
b0312ff3
authored
8 years ago
by
user2684
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Backport of 1.5.1 hotfix for maximum allocated sensors
parent
ea9596ec
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
NodeManager.cpp
+11
-6
11 additions, 6 deletions
NodeManager.cpp
NodeManager.h
+1
-1
1 addition, 1 deletion
NodeManager.h
with
12 additions
and
7 deletions
NodeManager.cpp
+
11
−
6
View file @
b0312ff3
...
@@ -2747,6 +2747,7 @@ int NodeManager::registerSensor(int sensor_type, int pin, int child_id) {
...
@@ -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
// attach a built-in or custom sensor to this manager
int
NodeManager
::
registerSensor
(
Sensor
*
sensor
)
{
int
NodeManager
::
registerSensor
(
Sensor
*
sensor
)
{
if
(
sensor
->
getChildId
()
>
MAX_SENSORS
)
return
;
#if DEBUG == 1
#if DEBUG == 1
Serial
.
print
(
F
(
"REG I="
));
Serial
.
print
(
F
(
"REG I="
));
Serial
.
print
(
sensor
->
getChildId
());
Serial
.
print
(
sensor
->
getChildId
());
...
@@ -2769,12 +2770,14 @@ int NodeManager::registerSensor(Sensor* sensor) {
...
@@ -2769,12 +2770,14 @@ int NodeManager::registerSensor(Sensor* sensor) {
// un-register a sensor to this manager
// un-register a sensor to this manager
void
NodeManager
::
unRegisterSensor
(
int
sensor_index
)
{
void
NodeManager
::
unRegisterSensor
(
int
sensor_index
)
{
if
(
sensor_index
>
MAX_SENSORS
)
return
;
// unlink the pointer to this sensor
// unlink the pointer to this sensor
_sensors
[
sensor_index
]
==
0
;
_sensors
[
sensor_index
]
==
0
;
}
}
// return a sensor given its index
// return a sensor given its index
Sensor
*
NodeManager
::
get
(
int
child_id
)
{
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 a pointer to the sensor from the given child_id
return
_sensors
[
child_id
];
return
_sensors
[
child_id
];
}
}
...
@@ -2784,6 +2787,7 @@ Sensor* NodeManager::getSensor(int child_id) {
...
@@ -2784,6 +2787,7 @@ Sensor* NodeManager::getSensor(int child_id) {
// assign a different child id to a sensor'
// assign a different child id to a sensor'
bool
NodeManager
::
renameSensor
(
int
old_child_id
,
int
new_child_id
)
{
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
// ensure the old id exists and the new is available
if
(
_sensors
[
old_child_id
]
==
0
||
_sensors
[
new_child_id
]
!=
0
)
return
false
;
if
(
_sensors
[
old_child_id
]
==
0
||
_sensors
[
new_child_id
]
!=
0
)
return
false
;
// assign the sensor to new id
// assign the sensor to new id
...
@@ -2851,7 +2855,7 @@ void NodeManager::before() {
...
@@ -2851,7 +2855,7 @@ void NodeManager::before() {
_battery_report_timer
.
start
();
_battery_report_timer
.
start
();
#endif
#endif
// setup individual sensors
// setup individual sensors
for
(
int
i
=
0
;
i
<
MAX_SENSORS
;
i
++
)
{
for
(
int
i
=
1
;
i
<
=
MAX_SENSORS
;
i
++
)
{
if
(
_sensors
[
i
]
==
0
)
continue
;
if
(
_sensors
[
i
]
==
0
)
continue
;
// call each sensor's setup()
// call each sensor's setup()
_sensors
[
i
]
->
before
();
_sensors
[
i
]
->
before
();
...
@@ -2875,7 +2879,7 @@ void NodeManager::presentation() {
...
@@ -2875,7 +2879,7 @@ void NodeManager::presentation() {
batteryReport
();
batteryReport
();
#endif
#endif
// present each sensor
// present each sensor
for
(
int
i
=
0
;
i
<
MAX_SENSORS
;
i
++
)
{
for
(
int
i
=
1
;
i
<
=
MAX_SENSORS
;
i
++
)
{
if
(
_sensors
[
i
]
==
0
)
continue
;
if
(
_sensors
[
i
]
==
0
)
continue
;
// call each sensor's presentation()
// call each sensor's presentation()
if
(
_sleep_between_send
>
0
)
sleep
(
_sleep_between_send
);
if
(
_sleep_between_send
>
0
)
sleep
(
_sleep_between_send
);
...
@@ -2902,7 +2906,7 @@ void NodeManager::setup() {
...
@@ -2902,7 +2906,7 @@ void NodeManager::setup() {
_send
(
_msg
.
set
(
"STARTED"
));
_send
(
_msg
.
set
(
"STARTED"
));
#endif
#endif
// run setup for all the registered sensors
// 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
;
if
(
_sensors
[
i
]
==
0
)
continue
;
// call each sensor's setup()
// call each sensor's setup()
_sensors
[
i
]
->
setup
();
_sensors
[
i
]
->
setup
();
...
@@ -2935,7 +2939,7 @@ void NodeManager::loop() {
...
@@ -2935,7 +2939,7 @@ void NodeManager::loop() {
if
(
_auto_power_pins
)
powerOn
();
if
(
_auto_power_pins
)
powerOn
();
#endif
#endif
// run loop for all the registered sensors
// 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
// skip not configured sensors
if
(
_sensors
[
i
]
==
0
)
continue
;
if
(
_sensors
[
i
]
==
0
)
continue
;
// if waking up from an interrupt skip all the sensor without that interrupt configured
// if waking up from an interrupt skip all the sensor without that interrupt configured
...
@@ -2975,7 +2979,7 @@ void NodeManager::receive(const MyMessage &message) {
...
@@ -2975,7 +2979,7 @@ void NodeManager::receive(const MyMessage &message) {
#endif
#endif
}
}
// dispatch the message to the registered sensor
// 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
#if POWER_MANAGER == 1
// turn on the pin powering all the sensors
// turn on the pin powering all the sensors
if
(
_auto_power_pins
)
powerOn
();
if
(
_auto_power_pins
)
powerOn
();
...
@@ -3285,12 +3289,13 @@ void NodeManager::_present(int child_id, int type) {
...
@@ -3285,12 +3289,13 @@ void NodeManager::_present(int child_id, int type) {
// return the next available child_id
// return the next available child_id
int
NodeManager
::
_getAvailableChildId
()
{
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
==
CONFIGURATION_CHILD_ID
)
continue
;
if
(
i
==
BATTERY_CHILD_ID
)
continue
;
if
(
i
==
BATTERY_CHILD_ID
)
continue
;
// empty place, return it
// empty place, return it
if
(
_sensors
[
i
]
==
0
)
return
i
;
if
(
_sensors
[
i
]
==
0
)
return
i
;
}
}
return
MAX_SENSORS
;
}
}
// guess the initial value of a digital output based on the configured interrupt mode
// guess the initial value of a digital output based on the configured interrupt mode
...
...
This diff is collapsed.
Click to expand it.
NodeManager.h
+
1
−
1
View file @
b0312ff3
...
@@ -1295,7 +1295,7 @@ class NodeManager {
...
@@ -1295,7 +1295,7 @@ class NodeManager {
int
_interrupt_2_pull
=
-
1
;
int
_interrupt_2_pull
=
-
1
;
int
_last_interrupt_pin
=
-
1
;
int
_last_interrupt_pin
=
-
1
;
long
_timestamp
=
-
1
;
long
_timestamp
=
-
1
;
Sensor
*
_sensors
[
MAX_SENSORS
]
=
{
0
};
Sensor
*
_sensors
[
MAX_SENSORS
+
1
]
=
{
0
};
bool
_ack
=
false
;
bool
_ack
=
false
;
void
_sleep
();
void
_sleep
();
void
_present
(
int
child_id
,
int
type
);
void
_present
(
int
child_id
,
int
type
);
...
...
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