Testing IR input

This commit is contained in:
DashyFox 2024-09-01 22:16:38 +03:00
parent 7eb5d4284d
commit db3528f502

View File

@ -7,6 +7,7 @@
#include "IR_CMD_Handler.h" #include "IR_CMD_Handler.h"
#include "IR.h" #include "IR.h"
#include "ShiftReg.h" #include "ShiftReg.h"
#include "RobotFunctions.h"
#include "Print.h" #include "Print.h"
@ -31,12 +32,21 @@ extern IRData data;
extern void NullFunc(); // null func for paramEnter(NullFunc); extern void NullFunc(); // null func for paramEnter(NullFunc);
extern void paramEnter(void(*onEnter_)()); // setParamFunc for enter extern void paramEnter(void(*onEnter_)()); // setParamFunc for enter
uint8_t testData; void IR_ShotPrepared();
void selectShot(){
testData = inputParam; 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 b1 = 1;
unsigned char b2 = 1; unsigned char b2 = 1;
unsigned char b3 = 1; unsigned char b3 = 1;
@ -45,36 +55,143 @@ void IR_Home_Process() {
SetShiftReg_inline(0xff, 0, 0); SetShiftReg_inline(0xff, 0, 0);
switch (data.command) { switch (data.command) {
case IR_FONT_RIGHT: case IR_FONT_RIGHT:
case IR_SHOT:
paramEnter(selectShot); paramEnter(onSelectShot);
break;
case IR_PROG:
// paramEnter(onSelectShot);
break; break;
// case IR_FONT_RIGHT:
// // if(!(b1>64 || b2> 64|| b3>64)) b1 = 64;
// // else
// // {
// // b1 = b1>>1;
// // b2 = b2<<1;
// // b3 = b3<<1;
// // }
// SetShiftReg_inline(b1, b2, b3);
// break;
case IR_FRONT_MID: case IR_FRONT_MID:
SetShiftReg_inline(0, 0, 0); SetShiftReg_inline(0, 0, 0);
b1 = b2 = b3 = 0; b1 = b2 = b3 = 0;
break; break;
case IR_FRONT_LEFT: case IR_FRONT_LEFT:
// if(!b3)
// b3 = 128;
// b3 = b3>>1;
// if(!b3)
// b2 = 64;
SetShiftReg_inline(++b1, ++b2, ++b3); SetShiftReg_inline(++b1, ++b2, ++b3);
break; 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: default:
break; break;
} }
} }
void IR_ShotPrepared(){
InputHandler = IR_ShotPrepared;
switch (data.command) {
case IR_START:
startShooting();
break;
default:
InputHandler();
break;
}
}