I added the following function to the MO2Sensor.mc example code to allow it to pair to a new sensor after it has already been paired to one.
function setPair()
{
closeSensor();
GenericChannel.release();
GenericChannel.initialize(method(:onMessage), chanAssign);
pairing = true;
deviceCfg = new Ant.DeviceConfig( {
:deviceNumber => 0, //Wildcard our search for pairing
:deviceType => DEVICE_TYPE,
:transmissionType => 0,
:messagePeriod => PERIOD,
:radioFrequency => 57, //Ant+ Frequency
:searchTimeoutLowPriority => 10, //Timeout in 25s
:searchTimeoutHighPriority => 2, //Timeout in 5s
:searchThreshold => 1} ); //Turn on Proximity Pairing
GenericChannel.setDeviceConfig(deviceCfg);
searching = true;
}
When the function is called repeatedly, the memory used grows by 243 bytes every time that GenericChannel.initialize is called.
Is this the correct way to pair to a new sensor or is there a better way that would not cause the memory used to grow like this? Is there something additional that needs to be closed out to prevent this?
I can send in more code if that would be helpful.