mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-02-04 19:48:11 +00:00
CABELL: code optimization
This commit is contained in:
parent
13add5b9f2
commit
9e0684b6cb
@ -292,11 +292,12 @@ static void __attribute__((unused)) CABELL_getChannelSequence (uint8_t outArray[
|
||||
* this routine constrains the value.
|
||||
*/
|
||||
uint8_t i; //iterator counts numChannels
|
||||
uint64_t indexOfNextSequenceValue;
|
||||
uint64_t numChannelsFactorial=1;
|
||||
uint32_t indexOfNextSequenceValue;
|
||||
uint32_t numChannelsFactorial=1;
|
||||
uint32_t perm32 ;
|
||||
uint8_t sequenceValue;
|
||||
|
||||
numChannels = constrain(numChannels,1,20);
|
||||
numChannels = constrain(numChannels,1,9);
|
||||
|
||||
for (i = 1; i <= numChannels;i++)
|
||||
{
|
||||
@ -304,14 +305,18 @@ static void __attribute__((unused)) CABELL_getChannelSequence (uint8_t outArray[
|
||||
outArray[i-1] = i-1; // Initialize array with the sequence
|
||||
}
|
||||
|
||||
permutation = (permutation % numChannelsFactorial) + 1; // permutation must be between 1 and n! or this algorithm will infinite loop
|
||||
perm32 = permutation >> 8 ; // Shift 40 bit input to 32 bit
|
||||
perm32 = (perm32 % numChannelsFactorial); // permutation must be between 1 and n! or this algorithm will infinite loop
|
||||
perm32 <<= 8 ; // Shift back 8 bits
|
||||
perm32 += permutation & 0x00FF ; // Tack on least 8 bits
|
||||
perm32 = (perm32 % numChannelsFactorial) + 1; // permutation must be between 1 and n! or this algorithm will infinite loop
|
||||
|
||||
//Rearrange the array elements based on the permutation selected
|
||||
for (i=0, permutation--; i<numChannels; i++ )
|
||||
for (i=0, perm32--; i<numChannels; i++ )
|
||||
{
|
||||
numChannelsFactorial /= ((uint64_t)numChannels)-i;
|
||||
indexOfNextSequenceValue = i+(permutation/numChannelsFactorial);
|
||||
permutation %= numChannelsFactorial;
|
||||
numChannelsFactorial /= numChannels-i;
|
||||
indexOfNextSequenceValue = i+(perm32/numChannelsFactorial);
|
||||
perm32 %= numChannelsFactorial;
|
||||
|
||||
//Copy the value in the selected array position
|
||||
sequenceValue = outArray[indexOfNextSequenceValue];
|
||||
|
@ -19,7 +19,7 @@
|
||||
#define VERSION_MAJOR 1
|
||||
#define VERSION_MINOR 3
|
||||
#define VERSION_REVISION 2
|
||||
#define VERSION_PATCH_LEVEL 71
|
||||
#define VERSION_PATCH_LEVEL 72
|
||||
|
||||
#define MODE_SERIAL 0
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user