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_GasSensor
Commits
69f2705c
Commit
69f2705c
authored
Jun 06, 2017
by
user2684
Committed by
GitHub
Jun 06, 2017
Browse files
PowerManager allows Vcc only to be set
parent
00ae05a8
Changes
3
Hide whitespace changes
Inline
Side-by-side
NodeManager.cpp
View file @
69f2705c
...
...
@@ -4,36 +4,6 @@
#include "NodeManager.h"
/***************************************
Global functions
*/
// return vcc in V
float
getVcc
()
{
#ifndef MY_GATEWAY_ESP8266
// Measure Vcc against 1.1V Vref
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
ADMUX
=
(
_BV
(
REFS0
)
|
_BV
(
MUX4
)
|
_BV
(
MUX3
)
|
_BV
(
MUX2
)
|
_BV
(
MUX1
));
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ADMUX
=
(
_BV
(
MUX5
)
|
_BV
(
MUX0
));
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
ADMUX
=
(
_BV
(
MUX3
)
|
_BV
(
MUX2
));
#else
ADMUX
=
(
_BV
(
REFS0
)
|
_BV
(
MUX3
)
|
_BV
(
MUX2
)
|
_BV
(
MUX1
));
#endif
// Vref settle
wait
(
70
);
// Do conversion
ADCSRA
|=
_BV
(
ADSC
);
while
(
bit_is_set
(
ADCSRA
,
ADSC
))
{};
// return Vcc in mV
return
(
float
)((
1125300UL
)
/
ADC
)
/
1000
;
#else
return
(
float
)
0
;
#endif
}
/***************************************
PowerManager
*/
...
...
@@ -46,26 +16,26 @@ void PowerManager::setPowerPins(int ground_pin, int vcc_pin, int wait_time) {
Serial
.
print
(
F
(
" V="
));
Serial
.
println
(
vcc_pin
);
#endif
// configure the vcc pin as output and initialize to high (power on)
_vcc_pin
=
vcc_pin
;
pinMode
(
_vcc_pin
,
OUTPUT
);
digitalWrite
(
_vcc_pin
,
HIGH
);
// configure the ground pin as output and initialize to low
_ground_pin
=
ground_pin
;
pinMode
(
_ground_pin
,
OUTPUT
);
digitalWrite
(
_ground_pin
,
LOW
);
if
(
_ground_pin
>
0
)
{
// configure the ground pin as output and initialize to low
_ground_pin
=
ground_pin
;
pinMode
(
_ground_pin
,
OUTPUT
);
digitalWrite
(
_ground_pin
,
LOW
);
}
if
(
_vcc_pin
>
0
)
{
// configure the vcc pin as output and initialize to high (power on)
_vcc_pin
=
vcc_pin
;
pinMode
(
_vcc_pin
,
OUTPUT
);
digitalWrite
(
_vcc_pin
,
HIGH
);
}
// save wait time
_wait
=
wait_time
;
}
// return true if power pins have been configured
bool
PowerManager
::
isConfigured
()
{
if
(
_vcc_pin
!=
-
1
&&
_ground_pin
!=
-
1
)
return
true
;
return
false
;
}
// turn on the sensor by activating its power pins
void
PowerManager
::
powerOn
()
{
if
(
!
isConfigured
()
)
return
;
if
(
_vcc_pin
==
-
1
)
return
;
#if DEBUG == 1
Serial
.
print
(
F
(
"ON P="
));
Serial
.
println
(
_vcc_pin
);
...
...
@@ -78,7 +48,7 @@ void PowerManager::powerOn() {
// turn off the sensor
void
PowerManager
::
powerOff
()
{
if
(
!
isConfigured
()
)
return
;
if
(
_vcc_pin
==
-
1
)
return
;
#if DEBUG == 1
Serial
.
print
(
F
(
"OFF P="
));
Serial
.
println
(
_vcc_pin
);
...
...
@@ -768,7 +738,7 @@ void SensorML8511::onSetup() {
void
SensorML8511
::
onLoop
()
{
// read the voltage
int
uvLevel
=
analogRead
(
_pin
);
int
refLevel
=
getVcc
()
*
1024
/
3.3
;
int
refLevel
=
_node_manager
->
getVcc
()
*
1024
/
3.3
;
//Use the 3.3V power pin as a reference to get a very accurate output value from sensor
float
outputVoltage
=
3.3
/
refLevel
*
uvLevel
;
//Convert the voltage to a UV intensity level
...
...
@@ -2997,6 +2967,31 @@ void NodeManager::saveToMemory(int index, int value) {
saveState
(
index
+
EEPROM_USER_START
,
value
);
}
// return vcc in V
float
NodeManager
::
getVcc
()
{
#ifndef MY_GATEWAY_ESP8266
// Measure Vcc against 1.1V Vref
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
ADMUX
=
(
_BV
(
REFS0
)
|
_BV
(
MUX4
)
|
_BV
(
MUX3
)
|
_BV
(
MUX2
)
|
_BV
(
MUX1
));
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ADMUX
=
(
_BV
(
MUX5
)
|
_BV
(
MUX0
));
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
ADMUX
=
(
_BV
(
MUX3
)
|
_BV
(
MUX2
));
#else
ADMUX
=
(
_BV
(
REFS0
)
|
_BV
(
MUX3
)
|
_BV
(
MUX2
)
|
_BV
(
MUX1
));
#endif
// Vref settle
wait
(
70
);
// Do conversion
ADCSRA
|=
_BV
(
ADSC
);
while
(
bit_is_set
(
ADCSRA
,
ADSC
))
{};
// return Vcc in mV
return
(
float
)((
1125300UL
)
/
ADC
)
/
1000
;
#else
return
(
float
)
0
;
#endif
}
// send a message to the network
void
NodeManager
::
_send
(
MyMessage
&
message
)
{
// send the message, multiple times if requested
...
...
NodeManager.h
View file @
69f2705c
...
...
@@ -332,10 +332,6 @@ class PowerManager {
void
powerOn
();
// turns the power pins on
void
powerOff
();
// returns the Vcc voltge
float
getVcc
();
// turns true if power pins are configured
bool
isConfigured
();
private:
int
_vcc_pin
=
-
1
;
int
_ground_pin
=
-
1
;
...
...
@@ -1205,6 +1201,8 @@ class NodeManager {
int
loadFromMemory
(
int
index
);
// [27] save the given index of the EEPROM the provided value
void
saveToMemory
(
int
index
,
int
value
);
// return vcc in V
float
getVcc
();
// hook into the main sketch functions
void
before
();
void
presentation
();
...
...
@@ -1221,7 +1219,6 @@ class NodeManager {
bool
_battery_internal_vcc
=
true
;
int
_battery_pin
=
-
1
;
float
_battery_volts_per_bit
=
0.003363075
;
float
_getVcc
();
#endif
#if POWER_MANAGER == 1
// to optionally controller power pins
...
...
README.md
View file @
69f2705c
...
...
@@ -290,6 +290,8 @@ Node Manager comes with a reasonable default configuration. If you want/need to
int
loadFromMemory
(
int
index
);
// [27] save the given index of the EEPROM the provided value
void
saveToMemory
(
int
index
,
int
value
);
// return vcc in V
float
getVcc
();
~~~
For example
...
...
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