From df2b8c8a8ce0401cb7cb6fa258e3a34f2732da6d Mon Sep 17 00:00:00 2001 From: DashyFox Date: Mon, 26 Aug 2024 22:24:42 +0300 Subject: [PATCH] IR_CMD_Wrapper --- Core/Inc/IR_CMD_Handler.h | 1 + Core/Src/IR_CMD_HandlerLogic.c | 80 +++++++++++++++++ .../{IR_CMD_Handler.c => IR_CMD_Wrapper.c} | 85 ++++++------------- Core/Src/main.c | 2 +- Core/Src/stm32f1xx_it.c | 2 +- 5 files changed, 107 insertions(+), 63 deletions(-) create mode 100644 Core/Src/IR_CMD_HandlerLogic.c rename Core/Src/{IR_CMD_Handler.c => IR_CMD_Wrapper.c} (60%) diff --git a/Core/Inc/IR_CMD_Handler.h b/Core/Inc/IR_CMD_Handler.h index 0fbd0eb..55a8bb1 100644 --- a/Core/Inc/IR_CMD_Handler.h +++ b/Core/Inc/IR_CMD_Handler.h @@ -9,6 +9,7 @@ #define INC_IR_CMD_HANDLER_H_ #include "stm32f1xx_hal.h" +#include void IR_CMD_Handler(); diff --git a/Core/Src/IR_CMD_HandlerLogic.c b/Core/Src/IR_CMD_HandlerLogic.c new file mode 100644 index 0000000..b9b4443 --- /dev/null +++ b/Core/Src/IR_CMD_HandlerLogic.c @@ -0,0 +1,80 @@ +/* + * IR_CMD_HandlerLogic.c + * + * Created on: Aug 26, 2024 + * Author: DashyFox + */ +#include "IR_CMD_Handler.h" +#include "IR.h" +#include "ShiftReg.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 + +uint8_t testData; +void selectShot(){ + testData = inputParam; +} + + +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: + + paramEnter(selectShot); + 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: + SetShiftReg_inline(0, 0, 0); + b1 = b2 = b3 = 0; + break; + case IR_FRONT_LEFT: + // if(!b3) + // b3 = 128; + // b3 = b3>>1; + // if(!b3) + // b2 = 64; + + SetShiftReg_inline(++b1, ++b2, ++b3); + break; + + default: + break; + } + +} diff --git a/Core/Src/IR_CMD_Handler.c b/Core/Src/IR_CMD_Wrapper.c similarity index 60% rename from Core/Src/IR_CMD_Handler.c rename to Core/Src/IR_CMD_Wrapper.c index 2391698..a1df673 100644 --- a/Core/Src/IR_CMD_Handler.c +++ b/Core/Src/IR_CMD_Wrapper.c @@ -8,8 +8,9 @@ #include "IR_CMD_Handler.h" #include "IR.h" #include "SimpleTimer.h" -#include "Print.h" #include "ShiftReg.h" +#include "Print.h" + #define IR_Timeout 137 #define ResetInputProgerss_Timeout 2500 @@ -22,10 +23,6 @@ extern unsigned char IRStatus; IRData data; IRData old_data; -unsigned char b1 = 1; -unsigned char b2 = 1; -unsigned char b3 = 1; - uint32_t IR_Timeout_timer = 0; uint8_t dataHandled_flag = 0; @@ -35,21 +32,21 @@ uint8_t digitInputInProgerss = 0; uint8_t inputDigit = 0; // left = 0 to right -uint16_t inputNumberParam = NULL_NumberParam; - -enum IR_MENU { - IR_MENU_Home, - - IR_MENU_SHOT, IR_MENU_PROGR, IR_MENU_MACRO, IR_MENU_, - -}; +uint16_t inputParam = NULL_NumberParam; void IR_Home_Process(); -void IR_Shot_Selection(); + +void IR_ParamEnter(); void IR_CMD_Clear(); - void (*InputHandler)(void) = IR_Home_Process; +void NullFunc(){}; +void (*onParamEnter)() = NullFunc; +void paramEnter(void(*onEnter_)()){ + InputHandler = IR_ParamEnter; + onParamEnter = onEnter_; + +} void IR_CMD_Handler() { @@ -90,57 +87,19 @@ void IR_CMD_Clear() { inputDigit = 0; inputInProgerss = 0; digitInputInProgerss = 0; - inputNumberParam = NULL_NumberParam; + inputParam = NULL_NumberParam; SetShiftReg_inline(0, 0xff, 0); } -void IR_Home_Process() { - InputHandler = IR_Home_Process; - SetShiftReg_inline(0xff, 0, 0); - switch (data.command) { - case IR_FONT_RIGHT: - InputHandler = IR_Shot_Selection; - 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: - SetShiftReg_inline(0, 0, 0); - b1 = b2 = b3 = 0; - break; - case IR_FRONT_LEFT: - // if(!b3) - // b3 = 128; - // b3 = b3>>1; - // if(!b3) - // b2 = 64; - - SetShiftReg_inline(++b1, ++b2, ++b3); - break; - - default: - break; - } - -} - -void IR_Shot_Selection() { // Сделать общим +void IR_ParamEnter() { SetShiftReg_inline(0x03, 0, 0); if (0 <= data.command && data.command <= 9) { if (digitInputInProgerss) { - inputNumberParam = inputNumberParam * 10; // dec shift << 1 - inputNumberParam += data.command + 1; + inputParam = inputParam * 10; // dec shift << 1 + inputParam += data.command + 1; SetShiftReg_inline(0xF0, 0, 0); } else { - inputNumberParam = data.command + 1; + inputParam = data.command + 1; } digitInputInProgerss = 1; } else { @@ -148,10 +107,11 @@ void IR_Shot_Selection() { // Сделать общим switch (data.command) { case IR_ENTER: - if(inputNumberParam != NULL_NumberParam){ - SetShiftReg_inline(0, 0, inputNumberParam); + if(inputParam != NULL_NumberParam){ + SetShiftReg_inline(0, 0, inputParam); + onParamEnter(); } - inputNumberParam = NULL_NumberParam; + inputParam = NULL_NumberParam; digitInputInProgerss = 0; break; @@ -161,3 +121,6 @@ void IR_Shot_Selection() { // Сделать общим } } } + + + diff --git a/Core/Src/main.c b/Core/Src/main.c index 44ec0e1..634a62c 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -68,7 +68,7 @@ uint8_t velosety[600]; uint8_t rxcomlite = 0; uint8_t initcomlete = 0; -uint8_t uart_rx_buffer[64]; +uint8_t uart_rx_buffer[UART_BUFFER_SIZE]; unsigned char Shiftreg[3]; diff --git a/Core/Src/stm32f1xx_it.c b/Core/Src/stm32f1xx_it.c index 0c82535..5a4e264 100644 --- a/Core/Src/stm32f1xx_it.c +++ b/Core/Src/stm32f1xx_it.c @@ -184,7 +184,7 @@ extern I2C_HandleTypeDef hi2c1; extern TIM_HandleTypeDef htim3; extern UART_HandleTypeDef huart3; /* USER CODE BEGIN EV */ - +extern uint8_t uart_rx_buffer[UART_BUFFER_SIZE]; /* USER CODE END EV */ /******************************************************************************/