Skip to content

Commit ff0b21f

Browse files
committed
Fix compilation errors for non-AVR chips (#300)
1 parent 06cf76d commit ff0b21f

File tree

4 files changed

+85
-40
lines changed

4 files changed

+85
-40
lines changed

NodeManager.ino

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,33 @@
2020
2121
DESCRIPTION
2222
23-
NodeManager is intended to take care on your behalf of all those common tasks that a MySensors node has to accomplish, speeding up the development cycle of your projects.
24-
Consider it as a sort of frontend for your MySensors projects. When you need to add a sensor (which requires just uncommeting a single line),
25-
NodeManager will take care of importing the required library, presenting the sensor to the gateway/controller, executing periodically the main function of the sensor
26-
(e.g. measure a temperature, detect a motion, etc.), allowing you to interact with the sensor and even configuring it remotely.
23+
NodeManager is intended to take care on your behalf of all those common tasks that a
24+
MySensors node has to accomplish, speeding up the development cycle of your projects.
25+
Consider it as a sort of frontend for your MySensors projects. When you need to add
26+
a sensor (which requires just uncommeting a single line),
27+
NodeManager will take care of importing the required library, presenting the sensor
28+
to the gateway/controller, executing periodically the main function of the sensor
29+
(e.g. measure a temperature, detect a motion, etc.), allowing you to interact with
30+
the sensor and even configuring it remotely.
2731
2832
Documentation available on: https://github.com/mysensors/NodeManager
29-
NodeManager provides built-in implementation of a number of sensors through ad-hoc classes.
33+
NodeManager provides built-in implementation of a number of sensors through ad-hoc
34+
classes.
3035
3136
To use a buil-in sensor:
3237
* Install the required library if any
3338
* Enable the corresponding module (uncomment it) in the main sketch
3439
* Declare the sensor (uncomment it) in the main sketch
3540
36-
Once created, the sensor will automatically present one or more child to the gateway and controller.
37-
A list of buil-in sensors, module to enable, required dependencies and the number of child automatically created is presented below:
41+
Once created, the sensor will automatically present one or more child to the gateway
42+
and controller. A list of buil-in sensors, module to enable, required dependencies
43+
and the number of child automatically created is presented below:
3844
3945
Sensor Name |#Child | Module to enable | Description | Dependencies
4046
--------------------|-------|--------------------|---------------------------------------------------------------------------------------------------|----------------------------------------------------------
41-
SensorBattery | 1 | - | Built-in sensor for automatic battery reporting | -
42-
SensorSignal | 1 | - | Built-in sensor for automatic signal level reporting | -
43-
SensorConfiguration | 1 | - | Built-in sensor for OTA remote configuration of any registered sensor | -
47+
SensorBattery | 1 | USE_BATTERY | Built-in sensor for automatic battery reporting | -
48+
SensorSignal | 1 | USE_SIGNAL | Built-in sensor for automatic signal level reporting | -
49+
SensorConfiguration | 1 | USE_CONFIGURATION | Built-in sensor for OTA remote configuration of any registered sensor | -
4450
SensorAnalogInput | 1 | USE_ANALOG_INPUT | Generic analog sensor, return a pin's analog value or its percentage | -
4551
SensorLDR | 1 | USE_ANALOG_INPUT | LDR sensor, return the light level of an attached light resistor in percentage | -
4652
SensorRain | 1 | USE_ANALOG_INPUT | Rain sensor, return the percentage of rain from an attached analog sensor | -
@@ -89,10 +95,11 @@ SensorServo | 1 | USE_SERVO | Control a generic Servo motor
8995
SensorAPDS9960 | 1 | USE_APDS9960 | SparkFun RGB and Gesture Sensor | https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor
9096
SensorNeopixel | 1 | USE_NEOPIXEL | Control a Neopixel LED | https://github.com/adafruit/Adafruit_NeoPixel
9197
92-
NodeManager provides useful built-in features which can be disabled if you need to save some storage for your code.
93-
To enable/disable a buil-in feature:
98+
NodeManager provides useful built-in features which can be disabled if you need
99+
to save some storage for your code. To enable/disable a buil-in feature:
94100
* Install the required library if any
95-
* Enable the corresponding feature by setting it to ON in the main sketch. To disable it, set it to OFF
101+
* Enable the corresponding feature by setting it to ON in the main sketch. To
102+
disable it, set it to OFF
96103
97104
A list of buil-in features and the required dependencies is presented below:
98105
@@ -236,6 +243,9 @@ FEATURE_HOOKING | OFF | allow custom code to be hooked in the ou
236243
* NodeManager modules for supported sensors
237244
*/
238245

246+
//#define USE_BATTERY
247+
//#define USE_SIGNAL
248+
//#define USE_CONFIGURATION
239249
//#define USE_ANALOG_INPUT
240250
//#define USE_THERMISTOR
241251
//#define USE_ML8511

NodeManagerLibrary.h

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,29 @@
3838
#define EEPROM_SLEEP_3 7
3939
#define EEPROM_USER_START 100
4040

41+
/***********************************
42+
Chip type
43+
*/
44+
// 168 and 328 Arduinos
45+
#if defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
46+
#define CHIP_TINYX4
47+
#endif
48+
#if defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
49+
#define CHIP_TINYX5
50+
#endif
51+
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
52+
#define CHIP_MEGA
53+
#endif
54+
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
55+
#define CHIP_STM32
56+
#endif
57+
#if defined(ESP8266) || defined(MY_GATEWAY_ESP8266)
58+
#define CHIP_ESP8266
59+
#endif
60+
#if !defined(CHIP_ESP8266) && !defined(CHIP_STM32)
61+
#define CHIP_AVR
62+
#endif
63+
4164
/***********************************
4265
Default configuration settings
4366
*/
@@ -105,13 +128,16 @@
105128
#ifdef MY_USE_UDP
106129
#include <WiFiUdp.h>
107130
#endif
108-
#ifdef MY_GATEWAY_ESP8266
131+
#ifdef CHIP_ESP8266
109132
#include <ESP8266WiFi.h>
110133
#endif
111134
// load MySensors library
112135
#include <MySensors.h>
113136

114137
// include third party libraries
138+
#ifdef USE_SIGNAL
139+
#define MY_SIGNAL_REPORT_ENABLED
140+
#endif
115141
#ifdef USE_DHT
116142
#include <DHT.h>
117143
#endif
@@ -610,6 +636,7 @@ class Sensor {
610636
#endif
611637
};
612638

639+
#ifdef USE_BATTERY
613640
/*
614641
SensorBattery: report battery level
615642
*/
@@ -637,8 +664,9 @@ class SensorBattery: public Sensor {
637664
int _battery_pin = -1;
638665
float _battery_volts_per_bit = 0.003363075;
639666
};
667+
#endif
640668

641-
#ifdef MY_SIGNAL_REPORT_ENABLED
669+
#ifdef USE_SIGNAL
642670
/*
643671
SensorSignal: report RSSI signal strength from the radio
644672
*/
@@ -655,6 +683,7 @@ class SensorSignal: public Sensor {
655683
};
656684
#endif
657685

686+
#ifdef USE_CONFIGURATION
658687
/*
659688
SensorConfiguration: allow remote configuration of the board and any configured sensor
660689
*/
@@ -668,6 +697,7 @@ class SensorConfiguration: public Sensor {
668697
void onReceive(MyMessage* message);
669698
protected:
670699
};
700+
#endif
671701

672702
#ifdef USE_ANALOG_INPUT
673703
/*

NodeManagerLibrary.ino

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -711,10 +711,11 @@ void Sensor::onLoop(Child* child){}
711711
void Sensor::onReceive(MyMessage* message){}
712712
void Sensor::onInterrupt(){}
713713

714+
715+
#ifdef USE_BATTERY
714716
/*
715717
SensorBattery
716718
*/
717-
#ifndef MY_GATEWAY_ESP8266
718719
// contructor
719720
SensorBattery::SensorBattery(NodeManager& node_manager, int child_id): Sensor(node_manager) {
720721
_name = "BATTERY";
@@ -741,13 +742,15 @@ void SensorBattery::setBatteryVoltsPerBit(float value) {
741742

742743
// what to do during setup
743744
void SensorBattery::onSetup() {
745+
#ifdef CHIP_AVR
744746
// when measuring the battery from a pin, analog reference must be internal
745747
if (! _battery_internal_vcc && _battery_pin > -1)
746-
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
748+
#ifdef CHIP_MEGA
747749
analogReference(INTERNAL1V1);
748750
#else
749751
analogReference(INTERNAL);
750752
#endif
753+
#endif
751754
}
752755

753756
// what to do during loop
@@ -780,11 +783,10 @@ void SensorBattery::onReceive(MyMessage* message) {
780783
}
781784
#endif
782785

783-
#ifdef MY_SIGNAL_REPORT_ENABLED
786+
#ifdef USE_SIGNAL
784787
/*
785788
SensorSignal
786789
*/
787-
#ifndef MY_GATEWAY_ESP8266
788790
// contructor
789791
SensorSignal::SensorSignal(NodeManager& node_manager, int child_id): Sensor(node_manager) {
790792
_name = "SIGNAL";
@@ -816,7 +818,6 @@ void SensorSignal::onReceive(MyMessage* message) {
816818
if (message->getCommand() == C_REQ && message->type == child->type) onLoop(child);
817819
}
818820
#endif
819-
#endif
820821

821822
#ifdef USE_ANALOG_INPUT
822823
/*
@@ -882,7 +883,7 @@ void SensorAnalogInput::onReceive(MyMessage* message) {
882883

883884
// read the analog input
884885
int SensorAnalogInput::_getAnalogRead() {
885-
#ifndef MY_GATEWAY_ESP8266
886+
#ifdef CHIP_AVR
886887
// set the reference
887888
if (_reference != -1) {
888889
analogReference(_reference);
@@ -4003,6 +4004,7 @@ void SensorNeopixel::setColor(char* string) {
40034004

40044005
#endif
40054006

4007+
#ifdef USE_CONFIGURATION
40064008
/*
40074009
SensorConfiguration
40084010
*/
@@ -4045,7 +4047,7 @@ void SensorConfiguration::onReceive(MyMessage* message) {
40454047
case 20: _node->setSleepBetweenSend(request.getValueInt()); break;
40464048
case 9: _node->wakeup(); break;
40474049
#endif
4048-
#ifndef MY_GATEWAY_ESP8266
4050+
#ifdef CHIP_AVR
40494051
case 6: _node->reboot(); return;
40504052
#endif
40514053
#if FEATURE_EEPROM == ON
@@ -4104,8 +4106,8 @@ void SensorConfiguration::onReceive(MyMessage* message) {
41044106
default: return;
41054107
}
41064108
} else {
4107-
#ifndef MY_GATEWAY_ESP8266
41084109
// the message is for a function specific to a sensor
4110+
#ifdef USE_BATTERY
41094111
if (strcmp(sensor->getName(),"BATTERY") == 0) {
41104112
SensorBattery* custom_sensor = (SensorBattery*)sensor;
41114113
switch(function) {
@@ -4117,7 +4119,8 @@ void SensorConfiguration::onReceive(MyMessage* message) {
41174119
default: return;
41184120
}
41194121
}
4120-
#ifdef MY_SIGNAL_REPORT_ENABLED
4122+
#endif
4123+
#ifdef USE_SIGNAL
41214124
if (strcmp(sensor->getName(),"SIGNAL") == 0) {
41224125
SensorSignal* custom_sensor = (SensorSignal*)sensor;
41234126
switch(function) {
@@ -4126,7 +4129,6 @@ void SensorConfiguration::onReceive(MyMessage* message) {
41264129
}
41274130
}
41284131
#endif
4129-
#endif
41304132
#ifdef USE_ANALOG_INPUT
41314133
if (strcmp(sensor->getName(),"ANALOG_I") == 0 || strcmp(sensor->getName(),"LDR") == 0 || strcmp(sensor->getName(),"RAIN") == 0 || strcmp(sensor->getName(),"SOIL") == 0) {
41324134
SensorAnalogInput* custom_sensor = (SensorAnalogInput*)sensor;
@@ -4336,6 +4338,7 @@ void SensorConfiguration::onReceive(MyMessage* message) {
43364338
}
43374339
_node->sendMessage(CONFIGURATION_CHILD_ID,V_CUSTOM,function);
43384340
}
4341+
#endif
43394342

43404343
/*******************************************
43414344
NodeManager
@@ -4655,7 +4658,7 @@ void NodeManager::receive(const MyMessage &message) {
46554658
powerOn();
46564659
#endif
46574660
// call the sensor's receive()
4658-
sensor->receive(&message);
4661+
sensor->receive((MyMessage*) &message);
46594662
// turn off the pin powering all the sensors
46604663
#if FEATURE_POWER_MANAGER == ON
46614664
powerOff();
@@ -4693,7 +4696,7 @@ void NodeManager::hello() {
46934696

46944697
// reboot the board
46954698
void NodeManager::reboot() {
4696-
#ifndef MY_GATEWAY_ESP8266
4699+
#ifdef CHIP_AVR
46974700
#if FEATURE_DEBUG == ON
46984701
Serial.println(F("REBOOT"));
46994702
#endif
@@ -4708,7 +4711,7 @@ void NodeManager::reboot() {
47084711
// Infinite loop until watchdog reset after 16 ms
47094712
while(true){}
47104713
}
4711-
#endif
4714+
#endif
47124715
}
47134716

47144717
#if FEATURE_EEPROM == ON
@@ -4749,13 +4752,13 @@ void NodeManager::setSmartSleep(bool value) {
47494752

47504753
// return vcc in V
47514754
float NodeManager::getVcc() {
4752-
#ifndef MY_GATEWAY_ESP8266
4755+
#ifdef CHIP_AVR
47534756
// Measure Vcc against 1.1V Vref
4754-
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
4757+
#if defined(CHIP_MEGA)
47554758
ADMUX = (_BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1));
4756-
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
4759+
#elif defined (CHIP_TINYX4)
47574760
ADMUX = (_BV(MUX5) | _BV(MUX0));
4758-
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
4761+
#elif defined (CHIP_TINYX5)
47594762
ADMUX = (_BV(MUX3) | _BV(MUX2));
47604763
#else
47614764
ADMUX = (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1));
@@ -4767,9 +4770,9 @@ float NodeManager::getVcc() {
47674770
while (bit_is_set(ADCSRA, ADSC)) {};
47684771
// return Vcc in mV
47694772
return (float)((1125300UL) / ADC) / 1000;
4770-
#else
4773+
#else
47714774
return (float)0;
4772-
#endif
4775+
#endif
47734776
}
47744777

47754778
#if FEATURE_INTERRUPTS == ON
@@ -4848,12 +4851,12 @@ void NodeManager::setRebootPin(int value) {
48484851

48494852
// turn the ADC off so to save 0.2 mA
48504853
void NodeManager::setADCOff() {
4851-
#ifndef MY_GATEWAY_ESP8266
4854+
#ifdef CHIP_AVR
48524855
// Disable the ADC by setting the ADEN bit (bit 7) to zero
48534856
ADCSRA = ADCSRA & B01111111;
48544857
// Disable the analog comparator by setting the ACD bit (bit 7) to one
48554858
ACSR = B10000000;
4856-
#endif
4859+
#endif
48574860
}
48584861

48594862
// sleep if the node is a battery powered or wait if it is not for the given number of milliseconds
@@ -4913,7 +4916,7 @@ void NodeManager::_onInterrupt_2() {
49134916
// send a message by providing the source child, type of the message and value
49144917
void NodeManager::sendMessage(int child_id, int type, int value) {
49154918
_message.clear();
4916-
_message.set(value);
4919+
_message.set((uint32_t) value);
49174920
_sendMessage(child_id,type);
49184921
}
49194922
void NodeManager::sendMessage(int child_id, int type, float value, int precision) {

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# NodeManager
2+
13
NodeManager is intended to take care on your behalf of all those common tasks that a MySensors node has to accomplish, speeding up the development cycle of your projects.
24
Consider it as a sort of frontend for your MySensors projects. When you need to add a sensor (which requires just uncommeting a single line),
35
NodeManager will take care of importing the required library, presenting the sensor to the gateway/controller, executing periodically the main function of the sensor
@@ -31,9 +33,9 @@ A list of buil-in sensors, module to enable, required dependencies and the numbe
3133

3234
Sensor Name |#Child | Module to enable | Description | Dependencies
3335
--------------------|-------|--------------------|---------------------------------------------------------------------------------------------------|----------------------------------------------------------
34-
SensorBattery | 1 | - | Built-in sensor for automatic battery reporting | -
35-
SensorSignal | 1 | - | Built-in sensor for automatic signal level reporting | -
36-
SensorConfiguration | 1 | - | Built-in sensor for OTA remote configuration of any registered sensor | -
36+
SensorBattery | 1 | USE_BATTERY | Built-in sensor for automatic battery reporting | -
37+
SensorSignal | 1 | USE_SIGNAL | Built-in sensor for automatic signal level reporting | -
38+
SensorConfiguration | 1 | USE_CONFIGURATION | Built-in sensor for OTA remote configuration of any registered sensor | -
3739
SensorAnalogInput | 1 | USE_ANALOG_INPUT | Generic analog sensor, return a pin's analog value or its percentage | -
3840
SensorLDR | 1 | USE_ANALOG_INPUT | LDR sensor, return the light level of an attached light resistor in percentage | -
3941
SensorRain | 1 | USE_ANALOG_INPUT | Rain sensor, return the percentage of rain from an attached analog sensor | -

0 commit comments

Comments
 (0)