|
|
|
@ -15,22 +15,17 @@ |
|
|
|
/* vars */ |
|
|
|
/* vars */ |
|
|
|
static dict_t **flapDict; |
|
|
|
static dict_t **flapDict; |
|
|
|
static uint8_t addedFlaps = 0; |
|
|
|
static uint8_t addedFlaps = 0; |
|
|
|
static const uint8_t BYTES_PER_KEY = 3; |
|
|
|
static char flapKeys[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'}; // TODO improve
|
|
|
|
static char* flapKeys[10]; // TODO improve
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* function declarations */ |
|
|
|
|
|
|
|
void initFlapKeys(uint8_t numberOfFlaps); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************/ |
|
|
|
/**********************/ |
|
|
|
/* INIT / DEINIT */ |
|
|
|
/* INIT / DEINIT */ |
|
|
|
/**********************/ |
|
|
|
/**********************/ |
|
|
|
void MultiSplitFlap_Init(uint8_t numFlaps){ |
|
|
|
void MultiSplitFlap_Init(){ |
|
|
|
addedFlaps = 0; |
|
|
|
addedFlaps = 0; |
|
|
|
flapDict = dictAlloc(); |
|
|
|
flapDict = dictAlloc(); |
|
|
|
((dict_t*)flapDict)->key=NULL; |
|
|
|
((dict_t*)flapDict)->key=NULL; |
|
|
|
((dict_t*)flapDict)->value=NULL; |
|
|
|
((dict_t*)flapDict)->value=NULL; |
|
|
|
((dict_t*)flapDict)->next=NULL; |
|
|
|
((dict_t*)flapDict)->next=NULL; |
|
|
|
initFlapKeys(numFlaps); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void MultiSplitFlap_Deinit(void){ |
|
|
|
void MultiSplitFlap_Deinit(void){ |
|
|
|
@ -43,18 +38,19 @@ void MultiSplitFlap_Deinit(void){ |
|
|
|
/**********************/ |
|
|
|
/**********************/ |
|
|
|
void MultiSplitFlap_AddFlap(SF_Handle_t splitflap){ |
|
|
|
void MultiSplitFlap_AddFlap(SF_Handle_t splitflap){ |
|
|
|
McuLog_info("Adding split flap to multi splitflap combination..."); |
|
|
|
McuLog_info("Adding split flap to multi splitflap combination..."); |
|
|
|
addItem(flapDict, flapKeys[addedFlaps], (SF_Handle_t*)splitflap); |
|
|
|
addItem(flapDict, &flapKeys[addedFlaps], (SF_Handle_t*)splitflap); |
|
|
|
McuLog_info("Added flap nr. %i/%i.", addedFlaps+1, NUM_FLAPS); |
|
|
|
McuLog_info("Added flap nr. %i/%i.", addedFlaps+1, NUM_MAX_AMOUNT_FLAPS); |
|
|
|
addedFlaps++; |
|
|
|
addedFlaps++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool MultiSplitFlap_MoveAllToZeroPosition(void){ |
|
|
|
bool MultiSplitFlap_MoveAllToZeroPosition(void){ |
|
|
|
|
|
|
|
uint8_t numCurrentlyAddedSplitflaps = MultiSplitFlap_GetAmountOfAddedSplitFlaps(); |
|
|
|
McuLog_info("MultiSplitFlap_MoveAllToZeroPosition: Initializing split flap motors."); |
|
|
|
McuLog_info("MultiSplitFlap_MoveAllToZeroPosition: Initializing split flap motors."); |
|
|
|
|
|
|
|
|
|
|
|
// start all inits
|
|
|
|
// start all inits
|
|
|
|
for (uint8_t num = 0; num < NUM_FLAPS; ++num) { |
|
|
|
for (uint8_t num = 0; num < numCurrentlyAddedSplitflaps; ++num) { |
|
|
|
// get handle
|
|
|
|
// get handle
|
|
|
|
SF_Handle_t sfHandle = (SF_Handle_t)(getItem(*flapDict, flapKeys[num])); |
|
|
|
SF_Handle_t sfHandle = (SF_Handle_t)(getItem(*flapDict, &flapKeys[num])); |
|
|
|
// start init
|
|
|
|
// start init
|
|
|
|
SF_MoveMotorToZeroPositionAsync(sfHandle); |
|
|
|
SF_MoveMotorToZeroPositionAsync(sfHandle); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -65,9 +61,9 @@ bool MultiSplitFlap_MoveAllToZeroPosition(void){ |
|
|
|
initSuccess = true; |
|
|
|
initSuccess = true; |
|
|
|
vTaskDelay(pdMS_TO_TICKS(50)); |
|
|
|
vTaskDelay(pdMS_TO_TICKS(50)); |
|
|
|
// check each splitflap if it is finished with init
|
|
|
|
// check each splitflap if it is finished with init
|
|
|
|
for (uint8_t num = 0; num < NUM_FLAPS; ++num) { |
|
|
|
for (uint8_t num = 0; num < numCurrentlyAddedSplitflaps; ++num) { |
|
|
|
// get handle
|
|
|
|
// get handle
|
|
|
|
SF_Handle_t sfHandle = (SF_Handle_t)(getItem(*flapDict, flapKeys[num])); |
|
|
|
SF_Handle_t sfHandle = (SF_Handle_t)(getItem(*flapDict, &flapKeys[num])); |
|
|
|
// check if init done
|
|
|
|
// check if init done
|
|
|
|
if(SF_IS_RDY_TO_MOVE(sfHandle) == false){ |
|
|
|
if(SF_IS_RDY_TO_MOVE(sfHandle) == false){ |
|
|
|
initSuccess = false; |
|
|
|
initSuccess = false; |
|
|
|
@ -84,10 +80,11 @@ bool MultiSplitFlap_MoveAllToZeroPosition(void){ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool MultiSplitFlap_Display(char sentence[]){ |
|
|
|
bool MultiSplitFlap_Display(char sentence[]){ |
|
|
|
|
|
|
|
uint8_t numCurrentlyAddedSplitflaps = MultiSplitFlap_GetAmountOfAddedSplitFlaps(); |
|
|
|
// Start movements
|
|
|
|
// Start movements
|
|
|
|
for (uint8_t num = 0; num < NUM_FLAPS; ++num) { |
|
|
|
for (uint8_t num = 0; num < numCurrentlyAddedSplitflaps; ++num) { |
|
|
|
// get handle
|
|
|
|
// get handle
|
|
|
|
SF_Handle_t sfHandle = (SF_Handle_t)(getItem(*flapDict, flapKeys[num])); |
|
|
|
SF_Handle_t sfHandle = (SF_Handle_t)(getItem(*flapDict, &flapKeys[num])); |
|
|
|
char letter = sentence[num]; |
|
|
|
char letter = sentence[num]; |
|
|
|
SF_MoveToFlapAsync(sfHandle, letter); |
|
|
|
SF_MoveToFlapAsync(sfHandle, letter); |
|
|
|
McuLog_info("Multi splitflap: Commanded Flap nr. %i to letter '%c'.", num+1, letter); |
|
|
|
McuLog_info("Multi splitflap: Commanded Flap nr. %i to letter '%c'.", num+1, letter); |
|
|
|
@ -101,8 +98,9 @@ bool MultiSplitFlap_Display(char sentence[]){ |
|
|
|
|
|
|
|
|
|
|
|
done = true; // default is successful
|
|
|
|
done = true; // default is successful
|
|
|
|
// go through all splitflaps
|
|
|
|
// go through all splitflaps
|
|
|
|
for (uint8_t num = 0; num < NUM_FLAPS; ++num) { |
|
|
|
|
|
|
|
SF_Handle_t sfHandle = (SF_Handle_t)(getItem(*flapDict, flapKeys[num])); |
|
|
|
for (uint8_t num = 0; num < numCurrentlyAddedSplitflaps; ++num) { |
|
|
|
|
|
|
|
SF_Handle_t sfHandle = (SF_Handle_t)(getItem(*flapDict, &flapKeys[num])); |
|
|
|
if(SF_GetCurrentState(sfHandle) == SF_STATE_MOVING){ |
|
|
|
if(SF_GetCurrentState(sfHandle) == SF_STATE_MOVING){ |
|
|
|
done = false; |
|
|
|
done = false; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -114,7 +112,7 @@ bool MultiSplitFlap_Display(char sentence[]){ |
|
|
|
|
|
|
|
|
|
|
|
bool MultiSplitFlap_SetHardwareIdentifier(SetupIdentifier_t id, HardwareIdentifier_t hwId){ |
|
|
|
bool MultiSplitFlap_SetHardwareIdentifier(SetupIdentifier_t id, HardwareIdentifier_t hwId){ |
|
|
|
// number too high (not that many split flaps can be added to the combination)
|
|
|
|
// number too high (not that many split flaps can be added to the combination)
|
|
|
|
if(id >= NUM_FLAPS){ |
|
|
|
if(id >= NUM_MAX_AMOUNT_FLAPS){ |
|
|
|
McuLog_error("MultiSplitFlap_SetHardwareIdentifier failed because splitflap with setup id <%i> cannot exist.", id); |
|
|
|
McuLog_error("MultiSplitFlap_SetHardwareIdentifier failed because splitflap with setup id <%i> cannot exist.", id); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -130,7 +128,7 @@ bool MultiSplitFlap_SetHardwareIdentifier(SetupIdentifier_t id, HardwareIdentifi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get handle
|
|
|
|
// get handle
|
|
|
|
SF_Handle_t sfHandle = (SF_Handle_t)(getItem(*flapDict, flapKeys[id])); |
|
|
|
SF_Handle_t sfHandle = (SF_Handle_t)(getItem(*flapDict, &flapKeys[id])); |
|
|
|
// set hardware identifier
|
|
|
|
// set hardware identifier
|
|
|
|
SF_SetHardwareIdentifier(sfHandle, hwId); |
|
|
|
SF_SetHardwareIdentifier(sfHandle, hwId); |
|
|
|
// log
|
|
|
|
// log
|
|
|
|
@ -146,16 +144,18 @@ uint8_t MultiSplitFlap_GetAmountOfAddedSplitFlaps(void){ |
|
|
|
/**********************/ |
|
|
|
/**********************/ |
|
|
|
/* INTERNAL FUNCTIONS */ |
|
|
|
/* INTERNAL FUNCTIONS */ |
|
|
|
/**********************/ |
|
|
|
/**********************/ |
|
|
|
|
|
|
|
/* UNUSED
|
|
|
|
void initFlapKeys(uint8_t numberOfFlaps){ |
|
|
|
void initFlapKeys(uint8_t numberOfFlaps){ |
|
|
|
for (uint8_t i = 0; i < numberOfFlaps; ++i) { |
|
|
|
for (uint8_t i = 0; i < numberOfFlaps; ++i) { |
|
|
|
/* get a memory place for the key */ |
|
|
|
get a memory place for the key |
|
|
|
#if SPLITFLAP_CONFIG_USE_FREERTOS_HEAP |
|
|
|
#if SPLITFLAP_CONFIG_USE_FREERTOS_HEAP |
|
|
|
flapKeys[i] = pvPortMalloc(sizeof(BYTES_PER_KEY)); |
|
|
|
flapKeys[i] = pvPortMalloc(sizeof(BYTES_PER_KEY)); |
|
|
|
#else |
|
|
|
#else |
|
|
|
if((flapKeys[i] = malloc(BYTES_PER_KEY)) == NULL){ |
|
|
|
if((flapKeys[i] = malloc(BYTES_PER_KEY)) == NULL){ |
|
|
|
McuLog_error("Reserving memory for flap num. %i failed!:", i); |
|
|
|
McuLog_error("Reserving memory for flap num. %i failed!:", i); |
|
|
|
} |
|
|
|
} |
|
|
|
sprintf(flapKeys[i], "%i", i); |
|
|
|
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
sprintf(flapKeys[i], "%i", i); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|