changed splitflap positioning,

not calculating position dynamically anymore, is now static
main
Jonas Arnold 4 years ago
parent 5151e8524c
commit f332019866
  1. 4
      ADIS_tinyK22_SplitFlap/source/multi-splitflap.c
  2. 2
      ADIS_tinyK22_SplitFlap/source/platform.c
  3. 45
      ADIS_tinyK22_SplitFlap/source/splitflap.c
  4. 6
      ADIS_tinyK22_SplitFlap/source/splitflap.h
  5. 71
      ADIS_tinyK22_SplitFlap/source/splitflap_positions.c
  6. 15
      ADIS_tinyK22_SplitFlap/source/splitflap_positions.h

@ -89,9 +89,7 @@ bool MultiSplitFlap_Display(char sentence[]){
// 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];
char letter_move[] = " "; SF_MoveToFlapAsync(sfHandle, letter);
letter_move[0] = letter;
SF_MoveToFlapAsync(sfHandle, letter_move);
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);
vTaskDelay(pdMS_TO_TICKS(100)); // delay loop vTaskDelay(pdMS_TO_TICKS(100)); // delay loop
} }

@ -38,14 +38,12 @@ void PL_Init(void){
McuLog_Init(); McuLog_Init();
McuLog_set_console(McuRTT_GetStdio(), 0); McuLog_set_console(McuRTT_GetStdio(), 0);
SHELL_Init(); SHELL_Init();
SF_InitConfig();
McuRTOS_Init(); McuRTOS_Init();
} }
void PL_Deinit(void){ void PL_Deinit(void){
McuRTOS_Deinit(); McuRTOS_Deinit();
SF_DeInitConfig();
SHELL_Deinit(); SHELL_Deinit();
McuLog_Deinit(); McuLog_Deinit();
McuShellUart_Deinit(); McuShellUart_Deinit();

@ -1,4 +1,5 @@
/* /*
#include <splitflap_positions.c>
#include <splitflap_flaps.h> #include <splitflap_flaps.h>
* splitflap.c * splitflap.c
* *
@ -23,9 +24,6 @@
#define FLAP_QUEUE_LENGTH (5) /* number of elements in queue */ #define FLAP_QUEUE_LENGTH (5) /* number of elements in queue */
#define FLAP_QUEUE_SELEM_SIZE (sizeof(Flap_t)) /* size of element */ #define FLAP_QUEUE_SELEM_SIZE (sizeof(Flap_t)) /* size of element */
/* dynamic dictionary for the letters of the dictionary */
static dict_t **splitFlapDict;
/* function declarations */ /* function declarations */
static bool OngoingMoveMutex_Lock(SF_Handle_t instance); static bool OngoingMoveMutex_Lock(SF_Handle_t instance);
static void OngoingMoveMutex_Unlock(SF_Handle_t instance); static void OngoingMoveMutex_Unlock(SF_Handle_t instance);
@ -34,28 +32,6 @@ static void SF_Task(void *pv);
/**********************/ /**********************/
/* INIT / DEINIT */ /* INIT / DEINIT */
/**********************/ /**********************/
void SF_InitConfig(void){
splitFlapDict = dictAlloc();
((dict_t*)splitFlapDict)->key=NULL;
((dict_t*)splitFlapDict)->value=NULL;
((dict_t*)splitFlapDict)->next=NULL;
float stepsPerSegment = SPLITFLAP_STEPS_PER_SEGMENT; // do division once
// add all splitflap flaps to the dictionary, calculating the position automatically
// print out for debugging
McuLog_info("Splitflap positioning data is automatically calculated:\n");
for(int i = 0; i < SPLITFLAP_AMOUNT_OF_SEGMENTS; i ++){
// + 0.5 so the rounding is done correctly
int32_t position = (stepsPerSegment * (float)i + 0.5);
addItem(splitFlapDict, SF_Letters[i], (int32_t*)position);
//McuLog_info("Letter '%s': Position %i", SF_Letters[i], (int)position);
}
}
void SF_DeInitConfig(void){
dictDealoc(splitFlapDict);
}
SF_Handle_t SF_Init(SF_Config_t* config){ SF_Handle_t SF_Init(SF_Config_t* config){
SF_t* splitflap; SF_t* splitflap;
@ -254,7 +230,12 @@ void SF_MoveToFlap(SF_Handle_t instance, Flap_t flap){
if(OngoingMoveMutex_Lock(instance)){ if(OngoingMoveMutex_Lock(instance)){
// get flap pos from dictonary // get flap pos from dictonary
int32_t flapPos = (int32_t)getItem(*splitFlapDict, flap); Position_t flapPos;
if(SF_Position_Get(flap, &flapPos) == ERR_FAILED){
McuLog_error("SF_MoveToFlap did not find the position of Flap %c", flap);
OngoingMoveMutex_Unlock(instance);
return;
}
// get current motor pos // get current motor pos
int32_t currentPos = SF_GetMotorPosition(instance) % SPLITFLAP_STEPS_ONE_ROUND; int32_t currentPos = SF_GetMotorPosition(instance) % SPLITFLAP_STEPS_ONE_ROUND;
// calc steps to move // calc steps to move
@ -299,8 +280,7 @@ static void SF_Task(void *pv){
// parse parameter // parse parameter
SF_Handle_t instance = (SF_Handle_t)pv; SF_Handle_t instance = (SF_Handle_t)pv;
SF_t* splitflap = (SF_t*)instance; SF_t* splitflap = (SF_t*)instance;
char nextFlap = ' '; Flap_t nextFlap = ' ';
Flap_t flapBuffer = "";
bool initSuccess = false; bool initSuccess = false;
McuLog_info("Splitflap: Task for Splitflap <%i> started.", splitflap->id); McuLog_info("Splitflap: Task for Splitflap <%i> started.", splitflap->id);
@ -325,27 +305,26 @@ static void SF_Task(void *pv){
// action: check if any moves need to be made // action: check if any moves need to be made
case SF_STATE_READY: case SF_STATE_READY:
// check if anything is in queue once (poll once, don't get item) // check if anything is in queue once (poll once, don't get item)
if(xQueuePeek(splitflap->flapQueue, &flapBuffer, 0) != pdPASS){ if(xQueuePeek(splitflap->flapQueue, &nextFlap, 0) != pdPASS){
/* failed to receive => queue empty */ /* failed to receive => queue empty */
continue; continue;
} }
McuLog_info("Splitflap <%i> recognized new flap '%c' in queue to move to.", splitflap->id, flapBuffer[0]); McuLog_info("Splitflap <%i> recognized new flap '%c' in queue to move to.", splitflap->id, nextFlap);
// new flap to move to is available // new flap to move to is available
// check if ongoing move // check if ongoing move
if(OngoingMoveMutex_Lock(instance)){ if(OngoingMoveMutex_Lock(instance)){
// now get the queue item // now get the queue item
if(xQueueReceive(splitflap->flapQueue, &flapBuffer, 0) != pdPASS){ if(xQueueReceive(splitflap->flapQueue, &nextFlap, 0) != pdPASS){
/* failed to receive => queue empty but previously an item was there? error */ /* failed to receive => queue empty but previously an item was there? error */
McuLog_error("Failed to receive Queue item of Splitflap <%i>.", splitflap->id); McuLog_error("Failed to receive Queue item of Splitflap <%i>.", splitflap->id);
OngoingMoveMutex_Unlock(instance); OngoingMoveMutex_Unlock(instance);
continue; // ignore & proceed continue; // ignore & proceed
} }
nextFlap = flapBuffer[0];
//=> execute move //=> execute move
McuLog_info("Splitflap <%i> moving to flap '%c'.", splitflap->id, nextFlap); McuLog_info("Splitflap <%i> moving to flap '%c'.", splitflap->id, nextFlap);
SF_MoveToFlap(instance, &nextFlap); SF_MoveToFlap(instance, nextFlap);
McuLog_info("Splitflap <%i> move done to flap '%c'.", splitflap->id, nextFlap); McuLog_info("Splitflap <%i> move done to flap '%c'.", splitflap->id, nextFlap);
vTaskDelay(pdMS_TO_TICKS(100)); // wait for logger to finish vTaskDelay(pdMS_TO_TICKS(100)); // wait for logger to finish

@ -27,7 +27,7 @@
typedef void* SF_Handle_t; typedef void* SF_Handle_t;
/* descriptor to identify the flap */ /* descriptor to identify the flap */
typedef char* Flap_t; typedef char Flap_t;
/* descriptor to identify the hardware */ /* descriptor to identify the hardware */
typedef uint8_t HardwareIdentifier_t; typedef uint8_t HardwareIdentifier_t;
@ -71,10 +71,10 @@ typedef struct {
/****** FUNCTIONS ******/ /****** FUNCTIONS ******/
/* initializes dictonary with splitflap flaps position */ /* initializes dictonary with splitflap flaps position */
void SF_InitConfig(void); //void SF_InitConfig(void);
/* free splitflap flaps dictionary */ /* free splitflap flaps dictionary */
void SF_DeInitConfig(void); //void SF_DeInitConfig(void);
/* instantiate new split flap /* instantiate new split flap
* only pass configured types, they do not need to be initialized. * only pass configured types, they do not need to be initialized.

@ -0,0 +1,71 @@
/*
* splitflap_positions.c
*
* Created on: 16.10.2022
* Author: jonas
*/
#include <stdint.h>
#include "splitflap.h"
#include "splitflap_positions.h"
/* all letters of the splitflap in the correct order */
static const struct {
Flap_t letter;
uint16_t positionSteps;
} flapPositions[] = {
/* all letters of the splitflap in the correct order */
{.letter = ' ', .positionSteps = 0 },
{.letter = 'A', .positionSteps = 13 },
{.letter = 'B', .positionSteps = 26 },
{.letter = 'C', .positionSteps = 38 },
{.letter = 'D', .positionSteps = 51 },
{.letter = 'E', .positionSteps = 64 },
{.letter = 'F', .positionSteps = 77 },
{.letter = 'G', .positionSteps = 90 },
{.letter = 'H', .positionSteps = 102 },
{.letter = 'I', .positionSteps = 115 },
{.letter = 'J', .positionSteps = 128 },
{.letter = 'K', .positionSteps = 141 },
{.letter = 'L', .positionSteps = 154 },
{.letter = 'M', .positionSteps = 166 },
{.letter = 'N', .positionSteps = 179 },
{.letter = 'O', .positionSteps = 192 },
{.letter = 'P', .positionSteps = 205 },
{.letter = 'Q', .positionSteps = 218 },
{.letter = 'R', .positionSteps = 230 },
{.letter = 'S', .positionSteps = 243 },
{.letter = 'T', .positionSteps = 256 },
{.letter = 'U', .positionSteps = 269 },
{.letter = 'V', .positionSteps = 282 },
{.letter = 'W', .positionSteps = 294 },
{.letter = 'X', .positionSteps = 307 },
{.letter = 'Y', .positionSteps = 320 },
{.letter = 'Z', .positionSteps = 333 },
{.letter = '0', .positionSteps = 346 },
{.letter = '1', .positionSteps = 358 },
{.letter = '2', .positionSteps = 371 },
{.letter = '3', .positionSteps = 384 },
{.letter = '4', .positionSteps = 397 },
{.letter = '5', .positionSteps = 410 },
{.letter = '6', .positionSteps = 422 },
{.letter = '7', .positionSteps = 435 },
{.letter = '8', .positionSteps = 448 },
{.letter = '9', .positionSteps = 461 },
{.letter = '!', .positionSteps = 474 },
{.letter = '?', .positionSteps = 486 },
{.letter = ':', .positionSteps = 499 }
};
uint8_t SF_Position_Get(Flap_t letter, Position_t* stepsPosition) {
/* search letter in table */
for(int i=0; i<sizeof(flapPositions)/sizeof(flapPositions[0]); i++) {
if (letter==flapPositions[i].letter) { /* found */
*stepsPosition = flapPositions[i].positionSteps;
return ERR_OK;
}
}
/* not found */
return ERR_FAILED;
}

@ -1,7 +1,7 @@
/* /*
* splitflap_positions.h * splitflap_positions.h
* *
* Created on: 16.10.2022 * Created on: 27.10.2022
* Author: jonas * Author: jonas
*/ */
@ -10,12 +10,13 @@
#include "splitflap.h" #include "splitflap.h"
/* descriptor to identify the type of position */
typedef uint16_t Position_t;
/* all letters of the splitflap in the correct order */ /* return the position of the splitflap
Flap_t SF_Letters[] = { " ", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", * \param [out] stepsPosition Pointer to the amount of steps
"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", * \return Returns ERR_OK if valid, otherwise ERR_FAILED
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", */
"!", "?", ":"}; uint8_t SF_Position_Get(Flap_t letter, Position_t* stepsPosition);
#endif /* SPLITFLAP_POSITIONS_H_ */ #endif /* SPLITFLAP_POSITIONS_H_ */

Loading…
Cancel
Save