|
|
|
@ -20,46 +20,47 @@ void SF_InitConfig(void){ |
|
|
|
((dict_t*)splitFlapDict)->key=NULL; |
|
|
|
((dict_t*)splitFlapDict)->key=NULL; |
|
|
|
((dict_t*)splitFlapDict)->value=NULL; |
|
|
|
((dict_t*)splitFlapDict)->value=NULL; |
|
|
|
((dict_t*)splitFlapDict)->next=NULL; |
|
|
|
((dict_t*)splitFlapDict)->next=NULL; |
|
|
|
addItem(splitFlapDict, SF_A, (int32_t*)13); |
|
|
|
float stepsPerSegment = SPLITFLAP_STEPS_PER_SEGMENT; // do division once
|
|
|
|
addItem(splitFlapDict, SF_B, (int32_t*)26); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_C, (int32_t*)39); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_D, (int32_t*)52); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_E, (int32_t*)65); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_F, (int32_t*)78); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_G, (int32_t*)91); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_H, (int32_t*)104); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_I, (int32_t*)117); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_J, (int32_t*)130); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_K, (int32_t*)143); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_L, (int32_t*)156); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_M, (int32_t*)169); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_N, (int32_t*)182); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_O, (int32_t*)195); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_P, (int32_t*)208); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_Q, (int32_t*)221); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_R, (int32_t*)234); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_S, (int32_t*)247); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_T, (int32_t*)260); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_U, (int32_t*)273); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_V, (int32_t*)286); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_W, (int32_t*)299); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_X, (int32_t*)312); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_Y, (int32_t*)325); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_Z, (int32_t*)338); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_0, (int32_t*)351); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_1, (int32_t*)364); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_2, (int32_t*)377); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_3, (int32_t*)390); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_4, (int32_t*)403); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_5, (int32_t*)416); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_6, (int32_t*)429); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_7, (int32_t*)442); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_8, (int32_t*)455); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_9, (int32_t*)468); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_EXCLAMATION, (int32_t*)481); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_QUESTION, (int32_t*)494); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_COLON, (int32_t*)507); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_SPACE, (int32_t*)0); |
|
|
|
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
|
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_B, (int32_t*)(int32_t)(stepsPerSegment * 2.0 + 0.5)); // done correctly
|
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_C, (int32_t*)(int32_t)(stepsPerSegment * 3.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_D, (int32_t*)(int32_t)(stepsPerSegment * 4.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_E, (int32_t*)(int32_t)(stepsPerSegment * 5.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_F, (int32_t*)(int32_t)(stepsPerSegment * 6.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_G, (int32_t*)(int32_t)(stepsPerSegment * 7.0 + 0.5)); |
|
|
|
|
|
|
|
addItem(splitFlapDict, SF_H, (int32_t*)(int32_t)(stepsPerSegment * 8.0 + 0.5)); |
|
|
|
|
|
|
|
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){ |
|
|
|
@ -79,12 +80,10 @@ SF_Handle_t SF_Init(SF_Config_t* instance, int id){ |
|
|
|
splitflap->motor = McuULN2003_InitMotor(&instance->motorConfig); |
|
|
|
splitflap->motor = McuULN2003_InitMotor(&instance->motorConfig); |
|
|
|
splitflap->id = id; |
|
|
|
splitflap->id = id; |
|
|
|
|
|
|
|
|
|
|
|
/* TODO IMPLEMENT ACTUAL INITIALIZATION of Motor */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return splitflap; |
|
|
|
return splitflap; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool SF_MoveMotorToZeroPosition(SF_Handle_t instance){ |
|
|
|
bool SF_MoveMotorToZeroPosition(SF_Handle_t instance, int8_t offsetSegments){ |
|
|
|
int numStepsMoved = 0; |
|
|
|
int numStepsMoved = 0; |
|
|
|
|
|
|
|
|
|
|
|
// move out of sensor
|
|
|
|
// move out of sensor
|
|
|
|
@ -102,7 +101,9 @@ bool SF_MoveMotorToZeroPosition(SF_Handle_t instance){ |
|
|
|
|
|
|
|
|
|
|
|
// 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){ |
|
|
|
for(int i=0; i<SPLITFLAP_STEPS_PER_SEGMENT; i++){ |
|
|
|
// +0.5 so that the rounding is done correctly
|
|
|
|
|
|
|
|
int8_t offsetSteps = (int8_t)((float)offsetSegments*SPLITFLAP_STEPS_PER_SEGMENT + 0.5); |
|
|
|
|
|
|
|
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); |
|
|
|
numStepsMoved++; |
|
|
|
numStepsMoved++; |
|
|
|
@ -115,11 +116,10 @@ bool SF_MoveMotorToZeroPosition(SF_Handle_t instance){ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SF_MoveSteps(SF_Handle_t instance, int32_t steps){ |
|
|
|
void SF_MoveSteps(SF_Handle_t instance, int32_t steps){ |
|
|
|
|
|
|
|
|
|
|
|
// run move with acceleration & deceleration
|
|
|
|
// run move with acceleration & deceleration
|
|
|
|
McuULN2003_AccelerationStart(((SF_t*)instance)->motor); |
|
|
|
McuULN2003_AccelerationStart(((SF_t*)instance)->motor); |
|
|
|
while(steps>0){ |
|
|
|
while(steps>0){ |
|
|
|
if(McuULN2003_StepCallback(((SF_t*)instance)->motor, true) == true){ |
|
|
|
if(McuULN2003_StepCallback(((SF_t*)instance)->motor, true)){ |
|
|
|
steps--; |
|
|
|
steps--; |
|
|
|
} |
|
|
|
} |
|
|
|
McuWait_Waitms(1); |
|
|
|
McuWait_Waitms(1); |
|
|
|
@ -140,7 +140,7 @@ void SF_MoveToFlap(SF_Handle_t instance, char* flap){ |
|
|
|
// get flap pos from dictonary
|
|
|
|
// get flap pos from dictonary
|
|
|
|
int32_t flapPos = (int32_t)getItem(*splitFlapDict, flap); |
|
|
|
int32_t flapPos = (int32_t)getItem(*splitFlapDict, flap); |
|
|
|
// get current motor pos
|
|
|
|
// get current motor pos
|
|
|
|
int32_t currentPos = SF_GetMotorPosition(instance); |
|
|
|
int32_t currentPos = SF_GetMotorPosition(instance) % SPLITFLAP_STEPS_ONE_ROUND; |
|
|
|
// calc steps to move
|
|
|
|
// calc steps to move
|
|
|
|
int32_t stepsToReachFlap = 0; |
|
|
|
int32_t stepsToReachFlap = 0; |
|
|
|
// not already there
|
|
|
|
// not already there
|
|
|
|
@ -150,12 +150,12 @@ void SF_MoveToFlap(SF_Handle_t instance, char* flap){ |
|
|
|
}else if(flapPos > currentPos){ |
|
|
|
}else if(flapPos > currentPos){ |
|
|
|
stepsToReachFlap = flapPos - currentPos; |
|
|
|
stepsToReachFlap = flapPos - currentPos; |
|
|
|
} |
|
|
|
} |
|
|
|
SF_MoveSteps(((SF_t*)instance)->motor, stepsToReachFlap); |
|
|
|
SF_MoveSteps(instance, stepsToReachFlap); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int32_t SF_GetMotorPosition(SF_Handle_t instance){ |
|
|
|
int32_t SF_GetMotorPosition(SF_Handle_t instance){ |
|
|
|
return McuULN2003_GetPos(((SF_t*)instance)->motor) % SPLITFLAP_STEPS_ONE_ROUND; |
|
|
|
return McuULN2003_GetPos(((SF_t*)instance)->motor); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SF_Deinit(SF_Handle_t instance){ |
|
|
|
void SF_Deinit(SF_Handle_t instance){ |
|
|
|
|