|
|
|
@ -7,13 +7,19 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#include "splitflap.h" |
|
|
|
#include "splitflap.h" |
|
|
|
|
|
|
|
#include "fsl_debug_console.h" |
|
|
|
#include "McuULN2003.h" |
|
|
|
#include "McuULN2003.h" |
|
|
|
#include <stdbool.h> |
|
|
|
#include <stdbool.h> |
|
|
|
#include "McuWait.h" |
|
|
|
#include "McuWait.h" |
|
|
|
#include "lib/dict.h" |
|
|
|
#include "lib/dict.h" |
|
|
|
#include "splitflap_flaps.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* dynamic dictionary for the letters of the dictionary */ |
|
|
|
static dict_t **splitFlapDict; |
|
|
|
static dict_t **splitFlapDict; |
|
|
|
|
|
|
|
/* all letters of the splitflap in the correct order */ |
|
|
|
|
|
|
|
static char* SF_Letters[] = { " ", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", |
|
|
|
|
|
|
|
"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", |
|
|
|
|
|
|
|
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", |
|
|
|
|
|
|
|
"!", "?", ":"}; |
|
|
|
|
|
|
|
|
|
|
|
void SF_InitConfig(void){ |
|
|
|
void SF_InitConfig(void){ |
|
|
|
splitFlapDict = dictAlloc(); |
|
|
|
splitFlapDict = dictAlloc(); |
|
|
|
@ -21,46 +27,16 @@ void SF_InitConfig(void){ |
|
|
|
((dict_t*)splitFlapDict)->value=NULL; |
|
|
|
((dict_t*)splitFlapDict)->value=NULL; |
|
|
|
((dict_t*)splitFlapDict)->next=NULL; |
|
|
|
((dict_t*)splitFlapDict)->next=NULL; |
|
|
|
float stepsPerSegment = SPLITFLAP_STEPS_PER_SEGMENT; // do division once
|
|
|
|
float stepsPerSegment = SPLITFLAP_STEPS_PER_SEGMENT; // do division once
|
|
|
|
addItem(splitFlapDict, SF_SPACE, (int32_t*)0); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_A, (int32_t*)(int32_t)(stepsPerSegment * 1.0 + 0.5)); // +0.5 so that the rounding is
|
|
|
|
// add all splitflap flaps to the dictionary, calculating the position automatically
|
|
|
|
addItem(splitFlapDict, SF_B, (int32_t*)(int32_t)(stepsPerSegment * 2.0 + 0.5)); // done correctly
|
|
|
|
// print out for debugging
|
|
|
|
addItem(splitFlapDict, SF_C, (int32_t*)(int32_t)(stepsPerSegment * 3.0 + 0.5)); |
|
|
|
PRINTF("Splitflap positioning data is automatically calculated:\n"); |
|
|
|
addItem(splitFlapDict, SF_D, (int32_t*)(int32_t)(stepsPerSegment * 4.0 + 0.5)); |
|
|
|
for(int i = 0; i < SPLITFLAP_AMOUNT_OF_SEGMENTS; i ++){ |
|
|
|
addItem(splitFlapDict, SF_E, (int32_t*)(int32_t)(stepsPerSegment * 5.0 + 0.5)); |
|
|
|
// + 0.5 so the rounding is done correctly
|
|
|
|
addItem(splitFlapDict, SF_F, (int32_t*)(int32_t)(stepsPerSegment * 6.0 + 0.5)); |
|
|
|
int32_t position = (stepsPerSegment * (float)i); |
|
|
|
addItem(splitFlapDict, SF_G, (int32_t*)(int32_t)(stepsPerSegment * 7.0 + 0.5)); |
|
|
|
addItem(splitFlapDict, SF_Letters[i], (int32_t*)position); |
|
|
|
addItem(splitFlapDict, SF_H, (int32_t*)(int32_t)(stepsPerSegment * 8.0 + 0.5)); |
|
|
|
PRINTF("Letter '%s': Position %i\n", SF_Letters[i], (int)position); |
|
|
|
addItem(splitFlapDict, SF_I, (int32_t*)(int32_t)(stepsPerSegment * 9.0 + 0.5)); |
|
|
|
} |
|
|
|
addItem(splitFlapDict, SF_J, (int32_t*)(int32_t)(stepsPerSegment * 10.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_K, (int32_t*)(int32_t)(stepsPerSegment * 11.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_L, (int32_t*)(int32_t)(stepsPerSegment * 12.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_M, (int32_t*)(int32_t)(stepsPerSegment * 13.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_N, (int32_t*)(int32_t)(stepsPerSegment * 14.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_O, (int32_t*)(int32_t)(stepsPerSegment * 15.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_P, (int32_t*)(int32_t)(stepsPerSegment * 16.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_Q, (int32_t*)(int32_t)(stepsPerSegment * 17.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_R, (int32_t*)(int32_t)(stepsPerSegment * 18.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_S, (int32_t*)(int32_t)(stepsPerSegment * 19.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_T, (int32_t*)(int32_t)(stepsPerSegment * 20.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_U, (int32_t*)(int32_t)(stepsPerSegment * 21.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_V, (int32_t*)(int32_t)(stepsPerSegment * 22.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_W, (int32_t*)(int32_t)(stepsPerSegment * 23.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_X, (int32_t*)(int32_t)(stepsPerSegment * 24.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_Y, (int32_t*)(int32_t)(stepsPerSegment * 25.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_Z, (int32_t*)(int32_t)(stepsPerSegment * 26.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_0, (int32_t*)(int32_t)(stepsPerSegment * 27.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_1, (int32_t*)(int32_t)(stepsPerSegment * 28.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_2, (int32_t*)(int32_t)(stepsPerSegment * 29.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_3, (int32_t*)(int32_t)(stepsPerSegment * 30.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_4, (int32_t*)(int32_t)(stepsPerSegment * 31.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_5, (int32_t*)(int32_t)(stepsPerSegment * 32.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_6, (int32_t*)(int32_t)(stepsPerSegment * 33.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_7, (int32_t*)(int32_t)(stepsPerSegment * 34.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_8, (int32_t*)(int32_t)(stepsPerSegment * 35.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_9, (int32_t*)(int32_t)(stepsPerSegment * 36.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_EXCLAMATION, (int32_t*)(int32_t)(stepsPerSegment * 37.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_QUESTION, (int32_t*)(int32_t)(stepsPerSegment * 38.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_COLON, (int32_t*)(int32_t)(stepsPerSegment * 39.0 + 0.5)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SF_DeInitConfig(void){ |
|
|
|
void SF_DeInitConfig(void){ |
|
|
|
@ -102,7 +78,7 @@ bool SF_MoveMotorToZeroPosition(SF_Handle_t instance, int8_t offsetSegments){ |
|
|
|
// one more segment if not already one round
|
|
|
|
// one more segment if not already one round
|
|
|
|
if(numStepsMoved < SPLITFLAP_STEPS_ONE_ROUND){ |
|
|
|
if(numStepsMoved < SPLITFLAP_STEPS_ONE_ROUND){ |
|
|
|
// +0.5 so that the rounding is done correctly
|
|
|
|
// +0.5 so that the rounding is done correctly
|
|
|
|
int8_t offsetSteps = (int8_t)((float)offsetSegments*SPLITFLAP_STEPS_PER_SEGMENT + 0.5); |
|
|
|
int8_t offsetSteps = offsetSegments * SPLITFLAP_STEPS_ONE_ROUND/SPLITFLAP_AMOUNT_OF_SEGMENTS; // (int8_t)((float)offsetSegments*SPLITFLAP_STEPS_PER_SEGMENT + 0.5);
|
|
|
|
for(int i=0; i < offsetSteps; i++){ |
|
|
|
for(int i=0; i < offsetSteps; i++){ |
|
|
|
McuULN2003_IncStep(((SF_t*)instance)->motor); |
|
|
|
McuULN2003_IncStep(((SF_t*)instance)->motor); |
|
|
|
McuWait_Waitms(20); |
|
|
|
McuWait_Waitms(20); |
|
|
|
|