This commit is contained in:
2024-09-04 04:01:15 +03:00
parent ff754d60a6
commit b962cbb419
11 changed files with 174 additions and 116 deletions

View File

@ -23,6 +23,7 @@ enum IR_MENU {
// <<
extern void (*InputHandler)(void); // ProcessFunc
extern void (*onHoldRepeat)(void);
extern uint16_t inputParam; // current input parameter
// >>
@ -46,10 +47,14 @@ void onSelectShot(){
unsigned char b1 = 1;
unsigned char b2 = 1;
unsigned char b3 = 1;
uint8_t screwSpeed;
uint8_t speedUP = 100;
uint8_t speedDown = 100;
void IR_Home_Process() {
InputHandler = IR_Home_Process;
SetShiftReg_inline(0xff, 0, 0);
@ -59,115 +64,120 @@ void IR_Home_Process() {
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_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);
onHoldRepeat = IR_Home_Process;
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);
}
}
// {
// 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];
uint8_t buf[32];
uint16_t blockAddr16 = 0;
uint8_t blockAddr[2] = {HIBYTE(blockAddr16), LOBYTE(blockAddr16)};
uint16_t blockAddr16 = 0; // Начальный адрес блока в EEPROM
uint8_t blockAddr[2] = {HIBYTE(blockAddr16), LOBYTE(blockAddr16)}; // Адрес в формате 2 байта
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);
// Отправляем адрес в EEPROM
if (HAL_I2C_Master_Transmit(&hi2c1, (AT24C_ADRESS << 1), blockAddr, 2, 1000) == HAL_OK) {
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(" ");
// Читаем данные из EEPROM
if (HAL_I2C_Master_Receive(&hi2c1, (AT24C_ADRESS << 1), buf, sizeof(buf), 1000) == HAL_OK) {
// Выводим считанные данные
for (int i = 0; i < sizeof(buf); ++i) {
if (!(i % 8)) print(" ");
if (!(i % 32)) print("\n");
char buffer[16];
snprintf(buffer, sizeof(buffer), "%02X ", buf[i]); // Преобразуем байт в шестнадцатеричную строку
CDC_Transmit_FS((uint8_t*)buffer, strlen(buffer));
}
} else {
print("Read Error EEPROM\n");
}
} else {
print("Address TX Error EEPROM\n");
}
}
break;
case IR_DEBUG:
{
uint8_t i2c_address;
HAL_StatusTypeDef result;
print("Scan\n");
// Перебираем все возможные адреса на шине I2C (7 бит, от 0x08 до 0x77)
for (i2c_address = 0x08; i2c_address <= 0x77; i2c_address++) {
// Отправляем запрос на указанный адрес (HAL_I2C_Master_Transmit без данных)
result = HAL_I2C_IsDeviceReady(&hi2c1, (i2c_address << 1), 1, 100);
if (result == HAL_OK) {
// Если устройство отвечает, выводим его адрес
print("Found I2C at: ");
printNumber(i2c_address);
print("\n");
} else {
// Если устройство не отвечает, продолжаем сканирование
print(".");
}
HAL_Delay(10); // Задержка для стабильности сканирования
}
print("\nScanning completed.\n");
}
break;
case IR_NUM_1:
// SetServo(0, 90+25);
setRollersSpeed(200,200);
setRollersSpeed(speedUP+=1, speedDown);
onHoldRepeat = IR_Home_Process;
break;
case IR_NUM_2:
setRollersSpeed(0,0);
// SetServo(1, 90+25);
setScrewkSpeed(screwSpeed+=1);
onHoldRepeat = IR_Home_Process;
break;
case IR_NUM_3:
setScrewkSpeed(100);
// SetServo(3, 90+25);
setRollersSpeed(speedUP, speedDown+=1);
onHoldRepeat = IR_Home_Process;
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);
}
setRollersSpeed(speedUP-=1, speedDown);
onHoldRepeat = IR_Home_Process;
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);
}
setScrewkSpeed(screwSpeed-=1);
onHoldRepeat = IR_Home_Process;
break;
case IR_NUM_9:
// SetServo(3, 90-25);
setRollersSpeed(speedUP, speedDown-=1);
onHoldRepeat = IR_Home_Process;
break;
case IR_NUM_5: