mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-06-28 13:19:41 +00:00
led and rc
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
#include "IR.h"
|
||||
#include "ShiftReg.h"
|
||||
#include "RobotFunctions.h"
|
||||
#include "Indicator.h"
|
||||
|
||||
#include "Print.h"
|
||||
|
||||
@ -30,11 +31,30 @@ extern IRData data;
|
||||
extern void NullFunc(); // null func for paramEnter(NullFunc);
|
||||
extern void paramEnter(void (*onEnter_)()); // setParamFunc for enter
|
||||
|
||||
void IR_ShotPrepared();
|
||||
void IR_ShootingStart();
|
||||
|
||||
void onSelectShot() {
|
||||
if (prepareShot(inputParam)) {
|
||||
InputHandler = IR_ShotPrepared;
|
||||
InputHandler = IR_ShootingStart;
|
||||
} else {
|
||||
paramEnter(onSelectShot);
|
||||
print("Shot not found\n");
|
||||
// Shot not found
|
||||
}
|
||||
}
|
||||
|
||||
void onSelectProgram() {
|
||||
if (prepareProgramm(inputParam)) {
|
||||
InputHandler = IR_ShootingStart;
|
||||
} else {
|
||||
paramEnter(onSelectShot);
|
||||
print("Shot not found\n");
|
||||
// Shot not found
|
||||
}
|
||||
}
|
||||
void onSelectMacro() {
|
||||
if (prepareMacro(inputParam)) {
|
||||
InputHandler = IR_ShootingStart;
|
||||
} else {
|
||||
paramEnter(onSelectShot);
|
||||
print("Shot not found\n");
|
||||
@ -50,37 +70,172 @@ uint8_t screwSpeed;
|
||||
uint8_t speedUP = 100;
|
||||
uint8_t speedDown = 100;
|
||||
|
||||
// onHoldRepeat = IR_Home_Process;
|
||||
|
||||
void IR_Home_Process() {
|
||||
InputHandler = IR_Home_Process;
|
||||
// SetShiftReg_inline(0xff, 0, 0);
|
||||
switch (data.command) {
|
||||
case IR_SHOT:
|
||||
paramEnter(onSelectShot);
|
||||
break;
|
||||
|
||||
case IR_PROG: {
|
||||
SetShiftReg_inline(0, 7, 0);
|
||||
b1 = b2 = b3 = 0;
|
||||
paramEnter(onSelectProgram);
|
||||
break;
|
||||
}
|
||||
|
||||
case IR_FONT_RIGHT:
|
||||
SetShiftReg_inline(b1, b2, ++b3);
|
||||
break;
|
||||
case IR_FRONT_MID:
|
||||
SetShiftReg_inline(b1, ++b2, b3);
|
||||
break;
|
||||
case IR_FRONT_LEFT:
|
||||
SetShiftReg_inline(++b1, b2, b3);
|
||||
// onHoldRepeat = IR_Home_Process;
|
||||
case IR_MACRO: {
|
||||
paramEnter(onSelectMacro);
|
||||
break;
|
||||
}
|
||||
|
||||
case IR_F_BTN: {
|
||||
EEPROM_INIT();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case IR_PAUSE:
|
||||
if (currentInfo.state == RUN) {
|
||||
currentInfo.state = PAUSE;
|
||||
}
|
||||
break;
|
||||
|
||||
case IR_START:
|
||||
if (currentInfo.state == PAUSE) {
|
||||
currentInfo.state = RUN;
|
||||
}
|
||||
break;
|
||||
|
||||
case IR_ESC: {
|
||||
// if (EEPROM_EARSE() != EEPROM_OK) {
|
||||
// char errorMsg[] = "Error EEPROM_EARSE\n\n";
|
||||
// CDC_Transmit_FS((uint8_t*) errorMsg, strlen(errorMsg));
|
||||
// } else {
|
||||
// char doneMsg[] = "EEPROM_EARSE Done\n\n";
|
||||
// CDC_Transmit_FS((uint8_t*) doneMsg, strlen(doneMsg));
|
||||
// }
|
||||
break;
|
||||
}
|
||||
|
||||
case IR_DEBUG: {
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case IR_NUM_1:
|
||||
|
||||
break;
|
||||
case IR_NUM_2:
|
||||
break;
|
||||
case IR_NUM_3:
|
||||
|
||||
break;
|
||||
|
||||
case IR_NUM_7:
|
||||
break;
|
||||
case IR_NUM_8:
|
||||
break;
|
||||
case IR_NUM_9:
|
||||
break;
|
||||
|
||||
case IR_NUM_5:
|
||||
break;
|
||||
|
||||
case IR_STOP: {
|
||||
speedUP = 100;
|
||||
speedDown = 100;
|
||||
screwSpeed = 0;
|
||||
stopShooting();
|
||||
break;
|
||||
}
|
||||
|
||||
case IR_TEMPO_INC:
|
||||
if (currentInfo.shot.shot.speedScrew < 100) {
|
||||
currentInfo.shot.shot.speedScrew++;
|
||||
shotApply(¤tInfo.shot);
|
||||
// led_progressbar(10, 19, currentInfo.shot.shot.speedScrew); //todo: led_progressbarTMP
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
case IR_TEMPO_DEC:
|
||||
if (currentInfo.shot.shot.speedScrew > 0) {
|
||||
currentInfo.shot.shot.speedScrew--;
|
||||
shotApply(¤tInfo.shot);
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
case IR_ENGINE_UP_INC:
|
||||
if (currentInfo.shot.shot.speedRollerTop < 200) {
|
||||
currentInfo.shot.shot.speedRollerTop++;
|
||||
shotApply(¤tInfo.shot);
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
case IR_ENGINE_UP_DEC:
|
||||
if (currentInfo.shot.shot.speedRollerTop > 0) {
|
||||
currentInfo.shot.shot.speedRollerTop--;
|
||||
shotApply(¤tInfo.shot);
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
case IR_ENGINE_DOWM_INC:
|
||||
if (currentInfo.shot.shot.speedRollerBottom < 200) {
|
||||
currentInfo.shot.shot.speedRollerBottom++;
|
||||
shotApply(¤tInfo.shot);
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
case IR_ENGINE_DOWM_DEC:
|
||||
if (currentInfo.shot.shot.speedRollerBottom > 0) {
|
||||
currentInfo.shot.shot.speedRollerBottom--;
|
||||
shotApply(¤tInfo.shot);
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
case IR_FONT_RIGHT:
|
||||
for (int i = 0; i <= 100; ++i) {
|
||||
led_progressbar(0, 19, i);
|
||||
HAL_Delay(10);
|
||||
}
|
||||
led_clear();
|
||||
break;
|
||||
|
||||
case IR_FRONT_MID: {
|
||||
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_PAUSE: {
|
||||
case IR_FRONT_LEFT: {
|
||||
uint8_t buf[1024]; // Буфер для чтения данных размером 128 байт
|
||||
uint16_t blockAddr16 = START_ADR_MACRO; // Начальный адрес EEPROM
|
||||
uint8_t blockAddr[2] = { (uint8_t) (blockAddr16 >> 8),
|
||||
@ -131,121 +286,13 @@ void IR_Home_Process() {
|
||||
}
|
||||
break;
|
||||
|
||||
case IR_ESC: {
|
||||
|
||||
if (EEPROM_EARSE() != EEPROM_OK) {
|
||||
char errorMsg[] = "Error EEPROM_EARSE\n\n";
|
||||
CDC_Transmit_FS((uint8_t*) errorMsg, strlen(errorMsg));
|
||||
} else {
|
||||
char doneMsg[] = "EEPROM_EARSE Done\n\n";
|
||||
CDC_Transmit_FS((uint8_t*) doneMsg, strlen(doneMsg));
|
||||
}
|
||||
}
|
||||
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:
|
||||
|
||||
break;
|
||||
case IR_NUM_2:
|
||||
break;
|
||||
case IR_NUM_3:
|
||||
|
||||
break;
|
||||
|
||||
case IR_NUM_7:
|
||||
break;
|
||||
case IR_NUM_8:
|
||||
break;
|
||||
case IR_NUM_9:
|
||||
break;
|
||||
|
||||
case IR_NUM_5:
|
||||
break;
|
||||
|
||||
case IR_STOP:
|
||||
speedUP = 100;
|
||||
speedDown = 100;
|
||||
screwSpeed = 0;
|
||||
stopShooting();
|
||||
break;
|
||||
|
||||
case IR_TEMPO_INC:
|
||||
if (screwSpeed < 100) {
|
||||
setScrewkSpeed(++screwSpeed);
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
case IR_TEMPO_DEC:
|
||||
if (screwSpeed > 0) {
|
||||
setScrewkSpeed(--screwSpeed);
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
case IR_ENGINE_UP_INC:
|
||||
if (speedUP < 200) {
|
||||
setRollersSpeed(++speedUP, speedDown);
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
case IR_ENGINE_UP_DEC:
|
||||
if (speedUP > 0) {
|
||||
setRollersSpeed(--speedUP, speedDown);
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
case IR_ENGINE_DOWM_INC:
|
||||
if (speedDown < 200) {
|
||||
setRollersSpeed(speedUP, ++speedDown);
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
case IR_ENGINE_DOWM_DEC:
|
||||
if (speedDown > 0) {
|
||||
setRollersSpeed(speedUP, --speedDown);
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void IR_ShotPrepared() {
|
||||
InputHandler = IR_ShotPrepared;
|
||||
void IR_ShootingStart() {
|
||||
InputHandler = IR_ShootingStart;
|
||||
switch (data.command) {
|
||||
case IR_START:
|
||||
startShooting(infoBlock.hwInfo.timings.preRun);
|
||||
@ -255,3 +302,4 @@ void IR_ShotPrepared() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user