Skip to content

Commit b346214

Browse files
authored
Allow flash strings in present() to save RAM (#1198)
1 parent 1c33609 commit b346214

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

core/MySensorsCore.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,20 @@ bool present(const uint8_t childSensorId, const uint8_t sensorType, const char *
355355
const bool ack)
356356
{
357357
return _sendRoute(build(_msgTmp, GATEWAY_ADDRESS, childSensorId, C_PRESENTATION, sensorType,
358-
ack).set(childSensorId==NODE_SENSOR_ID?MYSENSORS_LIBRARY_VERSION:description));
358+
ack).set(childSensorId == NODE_SENSOR_ID ? MYSENSORS_LIBRARY_VERSION : description));
359359
}
360360

361+
#if !defined(__linux__)
362+
bool present(const uint8_t childSensorId, const uint8_t sensorType,
363+
const __FlashStringHelper *description,
364+
const bool ack)
365+
{
366+
return _sendRoute(build(_msgTmp, GATEWAY_ADDRESS, childSensorId, C_PRESENTATION, sensorType,
367+
ack).set(childSensorId == NODE_SENSOR_ID ? F(" MYSENSORS_LIBRARY_VERSION "): description));
368+
}
369+
#endif
370+
371+
361372
bool sendSketchInfo(const char *name, const char *version, const bool ack)
362373
{
363374
bool result = true;

core/MySensorsCore.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,14 @@ void presentNode(void);
137137
*/
138138
bool present(const uint8_t sensorId, const uint8_t sensorType, const char *description="",
139139
const bool ack = false);
140-
140+
#if !defined(__linux__)
141+
bool present(const uint8_t childSensorId, const uint8_t sensorType,
142+
const __FlashStringHelper *description,
143+
const bool ack = false);
144+
#endif
141145
/**
142146
* Sends sketch meta information to the gateway. Not mandatory but a nice thing to do.
143-
* @param name String containing a short Sketch name or NULL if not applicable
147+
* @param name String containing a short Sketch name or NULL if not applicable
144148
* @param version String containing a short Sketch version or NULL if not applicable
145149
* @param ack Set this to true if you want destination node to send ack back to this node. Default is not to request any ack.
146150
* @return true Returns true if message reached the first stop on its way to destination.
@@ -153,7 +157,6 @@ bool sendSketchInfo(const __FlashStringHelper *name, const __FlashStringHelper *
153157

154158
/**
155159
* Sends a message to gateway or one of the other nodes in the radio network
156-
*
157160
* @param msg Message to send
158161
* @param ack Set this to true if you want destination node to send ack back to this node. Default is not to request any ack.
159162
* @return true Returns true if message reached the first stop on its way to destination.

0 commit comments

Comments
 (0)