@user2684 I have looked at the changes in https://github.com/mysensors/NodeManager/pull/174 which incorporates an alternative improved implementation for the _LoadConfig/_SaveConfig functions (interesting that using an intermediate union requires less code than my shifting version- presumably due to differences in the way the GCC optimiser works for an AVR target).
I spotted a coupld of minor points and was also able to further reduce the code size.
Firstly as we are writing C++ rather than C the declaration of the union should just be
// Local union used to split _sleep_time into bytes
union tLongByteArrayCombo{
long long_value;
uint8_t byte_array[4];
} ;
(The typedef systax, although valid C++ is unnecessary - a simple union declaration is sufficient.)
There is also a typo - the original had a member called byte_arrray instead of byte_array.
You can also save 24 bytes of code by avoiding the use of a local union variable and simply aliasing _sleep_time as the union type. So instead of _load_config doing -
tLongByteArrayCombo c;
c.byte_array[0] = loadState(EEPROM_SLEEP_1);
c.byte_array[1] = loadState(EEPROM_SLEEP_2);
c.byte_array[2] = loadState(EEPROM_SLEEP_3);
c.byte_array[3] = 0;
_sleep_time = c.long_value;
You can do
(((tLongByteArrayCombo&)_sleep_time).byte_array )[0] = loadState(EEPROM_SLEEP_1);
(((tLongByteArrayCombo&)_sleep_time).byte_array )[1] = loadState(EEPROM_SLEEP_2);
(((tLongByteArrayCombo&)_sleep_time).byte_array )[2] = loadState(EEPROM_SLEEP_3);
(((tLongByteArrayCombo&)_sleep_time).byte_array )[3] = 0;
And in _save_config instead of
tLongByteArrayCombo c;
c.long_value = _sleep_time;
saveState(EEPROM_SLEEP_1, c.byte_array[0]);
saveState(EEPROM_SLEEP_2, c.byte_array[1]);
saveState(EEPROM_SLEEP_3, c.byte_array[2]);
you can use
saveState(EEPROM_SLEEP_1, (((tLongByteArrayCombo&)_sleep_time).byte_array )[0] );
saveState(EEPROM_SLEEP_2, (((tLongByteArrayCombo&)_sleep_time).byte_array )[1] );
saveState(EEPROM_SLEEP_3, (((tLongByteArrayCombo&)_sleep_time).byte_array )[2] );
In my specific sample sketch I had the following code sizes
Original NodeManager.cpp 28242 Bytes
NodeManager with patch from pull rq 174 - 28154 Bytes (saving of 88 Bytes of code(
Patched NodeManager with additional changes above - 28130 Bytes ( saving another 24 Bytes of code)