|
|
|
|
@ -5,41 +5,63 @@ |
|
|
|
|
* Author: jonas |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <stdbool.h> |
|
|
|
|
#include "multi-splitflap.h" |
|
|
|
|
#include "fsl_debug_console.h" |
|
|
|
|
|
|
|
|
|
static dict_t **flapDict; |
|
|
|
|
static uint8_t amountOfFlaps = 0; |
|
|
|
|
static uint8_t numberOfFlaps = 0; |
|
|
|
|
static uint8_t addedFlaps = 0; |
|
|
|
|
static const uint8_t BYTES_PER_KEY = 3; |
|
|
|
|
static char* flapKeys[] = {}; |
|
|
|
|
|
|
|
|
|
void MultiSplitFlap_Init(void){ |
|
|
|
|
amountOfFlaps = 0; |
|
|
|
|
void initFlapKeys(uint8_t numberOfFlaps); |
|
|
|
|
|
|
|
|
|
void MultiSplitFlap_Init(uint8_t numOfFlaps){ |
|
|
|
|
numberOfFlaps = numOfFlaps; |
|
|
|
|
addedFlaps = 0; |
|
|
|
|
flapDict = dictAlloc(); |
|
|
|
|
((dict_t*)flapDict)->key=NULL; |
|
|
|
|
((dict_t*)flapDict)->value=NULL; |
|
|
|
|
((dict_t*)flapDict)->next=NULL; |
|
|
|
|
initFlapKeys(numberOfFlaps); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void initFlapKeys(uint8_t numberOfFlaps){ |
|
|
|
|
for (uint8_t i = 0; i < numberOfFlaps; ++i) { |
|
|
|
|
/* get a memory place for the key */ |
|
|
|
|
#if SPLITFLAP_CONFIG_USE_FREERTOS_HEAP |
|
|
|
|
flapKeys[i] = pvPortMalloc(sizeof(BYTES_PER_KEY)); |
|
|
|
|
#else |
|
|
|
|
if((flapKeys[i] = malloc(BYTES_PER_KEY)) == NULL){ |
|
|
|
|
PRINTF("Reserving memory for flap num. %i failed!:\n", i); |
|
|
|
|
} |
|
|
|
|
sprintf(flapKeys[i], "%i", i); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void MultiSplitFlap_Deinit(void){ |
|
|
|
|
dictDealoc(flapDict); |
|
|
|
|
amountOfFlaps = 0; |
|
|
|
|
addedFlaps = 0; |
|
|
|
|
numberOfFlaps = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
uint8_t MultiSplitFlap_GetAmountOfSplitFlaps(void){ |
|
|
|
|
return amountOfFlaps; |
|
|
|
|
uint8_t MultiSplitFlap_GetAmountOfAddedSplitFlaps(void){ |
|
|
|
|
return addedFlaps; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void MultiSplitFlap_AddFlap(SF_Handle_t splitflap){ |
|
|
|
|
PRINTF("Adding split flap to multi splitflap combination:\n"); |
|
|
|
|
addItem(flapDict, (char*)&amountOfFlaps, (SF_Handle_t*)splitflap); |
|
|
|
|
//TODO probably starting with 0 does not work since its a pointer to the number 0
|
|
|
|
|
PRINTF("Added flap nr. %i. There are now %i flaps.\n", amountOfFlaps, ++amountOfFlaps); |
|
|
|
|
PRINTF("Adding split flap to multi splitflap combination...\n"); |
|
|
|
|
addItem(flapDict, flapKeys[addedFlaps], (SF_Handle_t*)splitflap); |
|
|
|
|
PRINTF("Added flap nr. %i/%i.\n", addedFlaps+1, numberOfFlaps); |
|
|
|
|
addedFlaps++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void MultiSplitFlap_Display(char* sentence[]){ |
|
|
|
|
SF_Handle_t* sfHandle0 = (SF_Handle_t*)(getItem(*flapDict, (char*)0)); |
|
|
|
|
SF_Handle_t* sfHandle1 = (SF_Handle_t*)(getItem(*flapDict, (char*)1)); |
|
|
|
|
SF_t* sf0 = (SF_t*)sfHandle0; |
|
|
|
|
SF_t* sf1 = (SF_t*)sfHandle1; |
|
|
|
|
SF_t* sf0 = (SF_t*)(SF_Handle_t)(getItem(*flapDict, flapKeys[0])); |
|
|
|
|
SF_t* sf1 = (SF_t*)(SF_Handle_t)(getItem(*flapDict, flapKeys[1])); |
|
|
|
|
int32_t test = McuULN2003_GetPos(sf1->motor); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|