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