mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-05-04 07:10:17 +00:00
fix logic
This commit is contained in:
parent
e4cc2cecf5
commit
3424b775aa
@ -37,6 +37,7 @@ typedef struct CurrentShot {
|
||||
uint8_t indexGlobal;
|
||||
uint16_t currentBallCount;
|
||||
Shot shot;
|
||||
uint16_t doneCount;
|
||||
} CurrentShot;
|
||||
|
||||
typedef struct CurrentProgram {
|
||||
@ -45,6 +46,7 @@ typedef struct CurrentProgram {
|
||||
CurrentShot currentShot;
|
||||
uint8_t currentShotIndexLocal;
|
||||
uint16_t currentBallCount;
|
||||
uint16_t doneCount;
|
||||
} CurrentProgram;
|
||||
|
||||
typedef struct CurrentMacro {
|
||||
@ -53,6 +55,7 @@ typedef struct CurrentMacro {
|
||||
CurrentProgram currentProgram;
|
||||
uint8_t currentProgramIndexLocal;
|
||||
uint16_t currentBallCount;
|
||||
uint16_t doneCount;
|
||||
} CurrentMacro;
|
||||
|
||||
//typedef struct CurrentState {
|
||||
@ -82,6 +85,7 @@ uint8_t prepareProgramm(uint8_t number);
|
||||
uint8_t prepareMacro(uint8_t number);
|
||||
|
||||
|
||||
|
||||
void startShooting(uint32_t delayTime);
|
||||
void stopShooting();
|
||||
|
||||
|
@ -28,6 +28,7 @@ void UART3_SetServoMaxAngle(uint8_t *dataPtr, uint8_t len);
|
||||
void UART3_GetServoMaxAngle(uint8_t *dataPtr, uint8_t len);
|
||||
void UART3_SetServoMinAngle(uint8_t *dataPtr, uint8_t len);
|
||||
void UART3_GetServoMinAngle(uint8_t *dataPtr, uint8_t len);
|
||||
void UART3_ResetServoMinAngle(uint8_t *dataPtr, uint8_t len);
|
||||
void UART3_MoveServoToInitialPosition(uint8_t *dataPtr, uint8_t len);
|
||||
void UART3_SetStartupDelay(uint8_t *dataPtr, uint8_t len);
|
||||
void UART3_GetStartupDelay(uint8_t *dataPtr, uint8_t len);
|
||||
|
@ -143,11 +143,12 @@ void RobotTick() {
|
||||
|
||||
uint8_t prepareShot(uint8_t number) {
|
||||
Shot shot;
|
||||
memset(&shot, 0x00, sizeof(shot));
|
||||
getShot(number, &shot);
|
||||
if (shot.isExist) {
|
||||
currentInfo.mode = ShotMode;
|
||||
currentInfo.shot.shot = shot;
|
||||
currentInfo.shot.currentBallCount = 0;
|
||||
currentInfo.shot.indexGlobal = number;
|
||||
return 1;
|
||||
} else {
|
||||
// TODO: sound_ERR(); ledFX_ERR();
|
||||
@ -157,13 +158,12 @@ uint8_t prepareShot(uint8_t number) {
|
||||
}
|
||||
uint8_t prepareProgramm(uint8_t number) {
|
||||
Program program;
|
||||
memset(&program, 0x00, sizeof(program));
|
||||
getProg(number, &program);
|
||||
if (program.header.shotCount) { // isExist
|
||||
currentInfo.mode = ProgramMode;
|
||||
currentInfo.program.program = program;
|
||||
currentInfo.program.indexGlobal = number;
|
||||
currentInfo.program.currentShotIndexLocal = 0;
|
||||
currentInfo.program.currentBallCount = 0;
|
||||
return 1;
|
||||
} else {
|
||||
// TODO: sound_ERR(); ledFX_ERR();
|
||||
@ -174,13 +174,12 @@ uint8_t prepareProgramm(uint8_t number) {
|
||||
|
||||
uint8_t prepareMacro(uint8_t number) {
|
||||
Macro macro;
|
||||
memset(¯o, 0x00, sizeof(macro));
|
||||
getMacro(number, ¯o);
|
||||
if (macro.header.programmCount) {
|
||||
currentInfo.mode = MacroMode;
|
||||
currentInfo.macro.macro = macro;
|
||||
currentInfo.macro.indexGlobal = number;
|
||||
currentInfo.macro.currentProgramIndexLocal = 0;
|
||||
currentInfo.macro.currentBallCount = 0;
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
@ -283,11 +282,13 @@ uint8_t loadNextShotInProgram(CurrentProgram *currentProg) {
|
||||
|
||||
if (random) {
|
||||
*currentProgramShotId = rand() % currentProg->program.header.shotCount;
|
||||
|
||||
} else {
|
||||
if ((*currentProgramShotId) + 1
|
||||
< currentProg->program.header.shotCount) {
|
||||
++(*currentProgramShotId);
|
||||
} else {
|
||||
currentProg->doneCount++;
|
||||
*currentProgramShotId = 0;
|
||||
}
|
||||
}
|
||||
@ -344,6 +345,7 @@ uint8_t loadNextProgramInMacro(CurrentMacro *currentMacro) {
|
||||
currentMacro->currentProgramIndexLocal++;
|
||||
} else {
|
||||
currentMacro->currentProgramIndexLocal = 0;
|
||||
currentMacro->doneCount++;
|
||||
}
|
||||
return loadProgramFromMacro(currentMacro);
|
||||
}
|
||||
@ -365,6 +367,7 @@ uint8_t nextBallInShot(CurrentShot *shot) {
|
||||
return 0;
|
||||
} else {
|
||||
print("Shot DONE\n");
|
||||
shot->doneCount++;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -394,25 +397,24 @@ uint8_t nextShotInProgram(CurrentProgram *prog) {
|
||||
}
|
||||
|
||||
uint8_t nextProgramInMacro(CurrentMacro *currentMacro) {
|
||||
// uint8_t shotApply_f = 0;
|
||||
uint8_t shotApply_f = 0;
|
||||
if (nextShotInProgram(¤tMacro->currentProgram)) {
|
||||
print("\nSwitch program\n");
|
||||
if (!loadNextProgramInMacro(currentMacro)) {
|
||||
print("loadNextProgramInMacro ERR\n");
|
||||
return 0;
|
||||
}
|
||||
shotApply(¤tMacro->currentProgram.currentShot);
|
||||
// shotApply_f = 1;
|
||||
shotApply_f = 1;
|
||||
}
|
||||
|
||||
// Проверка на завершение макро
|
||||
// if (currentMacro->currentProgramIndexLocal < currentMacro->macro.header.programmCount) {
|
||||
// } else {
|
||||
// print("Macro DONE\n");
|
||||
// return 1;
|
||||
// }
|
||||
// if (shotApply_f)
|
||||
// shotApply(¤tMacro->currentProgram.currentShot);
|
||||
if (currentMacro->doneCount) {
|
||||
print("Macro DONE\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (shotApply_f)
|
||||
shotApply(¤tMacro->currentProgram.currentShot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,7 @@ void UART3_SaveShot(uint8_t *dataPtr, uint8_t len) {
|
||||
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||
}
|
||||
|
||||
// 101
|
||||
void UART3_SaveProgram(uint8_t *dataPtr, uint8_t len) {
|
||||
const uint8_t MIN_PARAM_LENGTH = 5;
|
||||
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||
@ -80,6 +81,7 @@ void UART3_SaveProgram(uint8_t *dataPtr, uint8_t len) {
|
||||
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||
}
|
||||
|
||||
// 100
|
||||
void UART3_SaveMacro(uint8_t *dataPtr, uint8_t len) {
|
||||
const uint8_t MIN_PARAM_LENGTH = 5;
|
||||
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||
@ -302,6 +304,21 @@ void UART3_SetServoMinAngle(uint8_t *dataPtr, uint8_t len) {
|
||||
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||
}
|
||||
|
||||
// 204
|
||||
void UART3_ResetServoMinAngle(uint8_t *dataPtr, uint8_t len) {
|
||||
const uint8_t MIN_PARAM_LENGTH = 1;
|
||||
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||
return;
|
||||
|
||||
ServoMap servo = dataPtr[1];
|
||||
infoBlock.hwInfo.servos[servo].min = 0;
|
||||
infoBlock.hwInfo.servos[servo].max = 180;
|
||||
|
||||
saveInfoBlock();
|
||||
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
void UART3_GetServoMaxAngle(uint8_t *dataPtr, uint8_t len) {
|
||||
const uint8_t MIN_PARAM_LENGTH = 1;
|
||||
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||
|
@ -294,9 +294,9 @@ void UART3_CMD_Handler(uint8_t *dataPtr, uint8_t len) {
|
||||
case 203:
|
||||
UART3_MoveServoToInitialPosition(dataPtr, len);
|
||||
break;
|
||||
// case 204:
|
||||
// UART3_GetServoOffset(dataPtr, len);
|
||||
// break;
|
||||
case 204:
|
||||
UART3_ResetServoMinAngle(dataPtr, len) ;
|
||||
break;
|
||||
case 205:
|
||||
UART3_GetServoOffset(dataPtr, len);
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user