You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.9 KiB
71 lines
1.9 KiB
/*
|
|
* multi-splitflap.c
|
|
*
|
|
* Created on: 07.10.2022
|
|
* Author: jonas
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdbool.h>
|
|
#include "multi-splitflap.h"
|
|
#include "fsl_debug_console.h"
|
|
|
|
static dict_t **flapDict;
|
|
static uint8_t addedFlaps = 0;
|
|
static const uint8_t BYTES_PER_KEY = 3;
|
|
static char* flapKeys[NUM_FLAPS]; // reserve memory
|
|
|
|
void initFlapKeys(uint8_t numberOfFlaps);
|
|
|
|
void MultiSplitFlap_Init(){
|
|
addedFlaps = 0;
|
|
flapDict = dictAlloc();
|
|
((dict_t*)flapDict)->key=NULL;
|
|
((dict_t*)flapDict)->value=NULL;
|
|
((dict_t*)flapDict)->next=NULL;
|
|
initFlapKeys(NUM_FLAPS);
|
|
}
|
|
|
|
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);
|
|
addedFlaps = 0;
|
|
}
|
|
|
|
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, flapKeys[addedFlaps], (SF_Handle_t*)splitflap);
|
|
PRINTF("Added flap nr. %i/%i.\n", addedFlaps+1, NUM_FLAPS);
|
|
addedFlaps++;
|
|
}
|
|
|
|
void MultiSplitFlap_Display(char sentence[]){
|
|
for (uint8_t num = 0; num < NUM_FLAPS; ++num) {
|
|
SF_Handle_t sfHandle = (SF_Handle_t)(getItem(*flapDict, flapKeys[num]));
|
|
SF_MoveToFlapAsync(sfHandle, (char*)(sentence[num]));
|
|
PRINTF("Moved multisplitflap: Flap nr. %i to letter '%c'.\n", num+1, sentence[num]);
|
|
}
|
|
// for testing purposes only
|
|
//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);
|
|
}
|
|
|
|
|
|
|