PingPong/Core/Src/IR_CMD_HandlerLogic.c
2024-09-01 22:16:38 +03:00

198 lines
3.7 KiB
C

/*
* IR_CMD_HandlerLogic.c
*
* Created on: Aug 26, 2024
* Author: DashyFox
*/
#include "IR_CMD_Handler.h"
#include "IR.h"
#include "ShiftReg.h"
#include "RobotFunctions.h"
#include "Print.h"
enum IR_MENU {
IR_MENU_Home,
IR_MENU_SHOT,
IR_MENU_PROGR,
IR_MENU_MACRO,
IR_MENU_,
};
// <<
extern void (*InputHandler)(void); // ProcessFunc
extern uint16_t inputParam; // current input parameter
// >>
extern IRData data;
// ()
extern void NullFunc(); // null func for paramEnter(NullFunc);
extern void paramEnter(void(*onEnter_)()); // setParamFunc for enter
void IR_ShotPrepared();
void onSelectShot(){
if(prepareShot(inputParam)){
InputHandler = IR_ShotPrepared;
} else {
paramEnter(onSelectShot);
print("Shot not found\n");
// Shot not found
}
}
unsigned char b1 = 1;
unsigned char b2 = 1;
unsigned char b3 = 1;
void IR_Home_Process() {
InputHandler = IR_Home_Process;
SetShiftReg_inline(0xff, 0, 0);
switch (data.command) {
case IR_FONT_RIGHT:
case IR_SHOT:
paramEnter(onSelectShot);
break;
case IR_PROG:
// paramEnter(onSelectShot);
break;
case IR_FRONT_MID:
SetShiftReg_inline(0, 0, 0);
b1 = b2 = b3 = 0;
break;
case IR_FRONT_LEFT:
SetShiftReg_inline(++b1, ++b2, ++b3);
break;
case IR_F_BTN:
{
Shot testShot = GetShot(3);
if(!testShot.isExist){
testShot.countRepeatShot = 1;
testShot.speedRollerTop = 200;
testShot.speedRollerBottom = 200;
testShot.speedScrew = 100;
testShot.rotationAxial = 90;
testShot.rotationHorizontal = 90;
testShot.rotationVertical = 90;
SaveShot(3, &testShot);
doShot(&testShot);
}
}
break;
case IR_PAUSE:
{
uint8_t buf[256];
uint16_t blockAddr16 = 0;
uint8_t blockAddr[2] = {HIBYTE(blockAddr16), LOBYTE(blockAddr16)};
HAL_I2C_Master_Transmit(&hi2c1, (AT24C_ADRESS << 1), blockAddr, 2, 10);
HAL_Delay(1);
HAL_I2C_Master_Receive(&hi2c1, (AT24C_ADRESS << 1), buf, sizeof(buf), 10);
HAL_Delay(1);
for (int i = 0; i < sizeof(buf); ++i) {
if(!(i % 8)) print(" ");
if(!(i % 32)) print("\n");
char buffer[BUFFER_SIZE];
int_to_str(buf[i], buffer, 16);
CDC_Transmit_FS((uint8_t*)buffer, strlen(buffer));
HAL_Delay(1);
print(" ");
}
}
break;
case IR_NUM_1:
// SetServo(0, 90+25);
setRollersSpeed(200,200);
break;
case IR_NUM_2:
setRollersSpeed(0,0);
// SetServo(1, 90+25);
break;
case IR_NUM_3:
setScrewkSpeed(100);
// SetServo(3, 90+25);
break;
case IR_NUM_7:
// SetServo(0, 90-25);
{
uint16_t blockAddr16 = 0;
uint8_t blockAddr[2] = {HIBYTE(blockAddr16), LOBYTE(blockAddr16)};
unsigned char Buf[2+2];
memset(Buf, 0x00, sizeof(Buf));
Buf[0] = blockAddr[0];
Buf[1] = blockAddr[1];
uint8_t data[2] = {0xAB,0xCD};
for( unsigned char i = 0; i < (sizeof(data)); i++ ) Buf[i+2] = (data)[i];
HAL_I2C_Master_Transmit(&hi2c1, (AT24C_ADRESS << 1), Buf, (sizeof(data) + 2), 10);
HAL_Delay(1);
}
break;
case IR_NUM_8:
// SetServo(1, 90-25);
{
uint16_t blockAddr16 = 0;
uint8_t blockAddr[2] = {HIBYTE(blockAddr16), LOBYTE(blockAddr16)};
unsigned char Buf[2+2];
memset(Buf, 0x00, sizeof(Buf));
Buf[0] = blockAddr[0];
Buf[1] = blockAddr[1];
uint16_t data = 0;
for( unsigned char i = 0; i < (sizeof(data)); i++ ) Buf[i+2] = (&data)[i];
HAL_I2C_Master_Transmit(&hi2c1, (AT24C_ADRESS << 1), Buf, (sizeof(data) + 2), 10);
HAL_Delay(1);
}
break;
case IR_NUM_9:
// SetServo(3, 90-25);
break;
case IR_NUM_5:
setRollersSpeed(100,100);
break;
case IR_STOP:
stopShooting();
break;
default:
break;
}
}
void IR_ShotPrepared(){
InputHandler = IR_ShotPrepared;
switch (data.command) {
case IR_START:
startShooting();
break;
default:
InputHandler();
break;
}
}