IR_CMD_Handler

This commit is contained in:
2024-08-25 20:27:17 +03:00
parent 55e8424f78
commit 148d748c20
17 changed files with 853 additions and 469 deletions

View File

@ -23,11 +23,17 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "GlobalDefines.h"
#include "usbd_cdc_if.h"
#include "pca9685.h"
#include "IR.h"
#include "IR_CMD_Handler.h"
#include "EEPROM.h"
#include "Print.h"
#include "SimpleTimer.h"
#include "RobotFunctions.h"
#include "ShiftReg.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@ -62,6 +68,8 @@ uint8_t velosety[600];
uint8_t rxcomlite = 0;
uint8_t initcomlete = 0;
uint8_t uart_rx_buffer[64];
unsigned char Shiftreg[3];
uint8_t rejim[60]; // 0 - chislo rejimov, 1-6 - rejim1, 7-12 - rejim2...
@ -76,14 +84,9 @@ uint16_t vi = 0;
uint16_t timing1 = 0;
uint16_t timing2 = 0;
uint8_t MYIR_command = 0;
volatile uint32_t millisCounter = 0;
uint32_t previousMillis = 0;
struct StructShot BufShots[MAX_NUMBER_SHOTS];
struct StructProgram BufPrograms;
struct StructMacro BufMacro;
struct Shot BufShots[MAX_NUMBER_SHOTS];
struct Program BufPrograms;
struct Macro BufMacro;
extern PCD_HandleTypeDef hpcd_USB_FS;
@ -107,19 +110,12 @@ static void MX_USART3_UART_Init(void);
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
unsigned char b1 = 1;
unsigned char b2 = 1;
unsigned char b3 = 1;
IRMenu menu();
* @brief The application entry point.
* @retval int
*/
int main(void)
{
menu.foo();
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
@ -206,45 +202,8 @@ initcomlete = 1;
/* USER CODE BEGIN WHILE */
while (1)
{
if (IRStatus == STATUS_REPEAT)
{
if (IR_Address == 0x01)
{
MYIR_command = IR_Command;
printNumber(MYIR_command);
// CDC_Transmit_FS(&MYIR_command, 1);
switch (MYIR_command)
{
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;
}
}
ClearIRStatus();
}
IR_CMD_Handler();
if (rxcomlite == 1)
{
@ -388,14 +347,13 @@ initcomlete = 1;
// // HAL_Delay(1000);
}
uint32_t currentMillis = millisCounter;
if (currentMillis - previousMillis >= 500)
{
previousMillis = currentMillis;
GPIOC->ODR ^= GPIO_PIN_13;
// unsigned char text[] = "Hello\n";
// printNumber(SysTick->LOAD);
// CDC_Transmit_FS(text, sizeof(text));
forTimer(blinkTimer, 500)
{
resetForTimer(blinkTimer);
GPIOC->ODR ^= GPIO_PIN_13;
// unsigned char text[] = "Hello\n";
// printNumber(SysTick->LOAD);
// CDC_Transmit_FS(text, sizeof(text));
}
/* USER CODE END WHILE */
@ -406,9 +364,9 @@ initcomlete = 1;
}
/**
* @brief System Clock Configuration
* @retval None
*/
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
@ -416,8 +374,8 @@ void SystemClock_Config(void)
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
@ -431,8 +389,9 @@ void SystemClock_Config(void)
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
@ -451,10 +410,10 @@ void SystemClock_Config(void)
}
/**
* @brief I2C1 Initialization Function
* @param None
* @retval None
*/
* @brief I2C1 Initialization Function
* @param None
* @retval None
*/
static void MX_I2C1_Init(void)
{
@ -481,13 +440,14 @@ static void MX_I2C1_Init(void)
/* USER CODE BEGIN I2C1_Init 2 */
/* USER CODE END I2C1_Init 2 */
}
/**
* @brief TIM1 Initialization Function
* @param None
* @retval None
*/
* @brief TIM1 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM1_Init(void)
{
@ -559,13 +519,14 @@ static void MX_TIM1_Init(void)
/* USER CODE END TIM1_Init 2 */
HAL_TIM_MspPostInit(&htim1);
}
/**
* @brief TIM2 Initialization Function
* @param None
* @retval None
*/
* @brief TIM2 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM2_Init(void)
{
@ -629,13 +590,14 @@ static void MX_TIM2_Init(void)
/* USER CODE END TIM2_Init 2 */
HAL_TIM_MspPostInit(&htim2);
}
/**
* @brief TIM3 Initialization Function
* @param None
* @retval None
*/
* @brief TIM3 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM3_Init(void)
{
@ -690,13 +652,14 @@ static void MX_TIM3_Init(void)
/* USER CODE BEGIN TIM3_Init 2 */
/* USER CODE END TIM3_Init 2 */
}
/**
* @brief USART3 Initialization Function
* @param None
* @retval None
*/
* @brief USART3 Initialization Function
* @param None
* @retval None
*/
static void MX_USART3_UART_Init(void)
{
@ -720,20 +683,24 @@ static void MX_USART3_UART_Init(void)
Error_Handler();
}
/* USER CODE BEGIN USART3_Init 2 */
if (HAL_UART_Receive_IT(&huart3, uart_rx_buffer, UART_BUFFER_SIZE) != HAL_OK)
{
Error_Handler();
}
/* USER CODE END USART3_Init 2 */
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
@ -745,7 +712,7 @@ static void MX_GPIO_Init(void)
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, LED_DATA_Pin | LED_CLK_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, LED_DATA_Pin|LED_CLK_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin : PC13 */
GPIO_InitStruct.Pin = GPIO_PIN_13;
@ -755,7 +722,7 @@ static void MX_GPIO_Init(void)
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pins : LED_DATA_Pin LED_CLK_Pin */
GPIO_InitStruct.Pin = LED_DATA_Pin | LED_CLK_Pin;
GPIO_InitStruct.Pin = LED_DATA_Pin|LED_CLK_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
@ -780,8 +747,8 @@ static void MX_GPIO_Init(void)
HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI1_IRQn);
/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}
/* USER CODE BEGIN 4 */
@ -789,9 +756,9 @@ static void MX_GPIO_Init(void)
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
@ -804,14 +771,14 @@ void Error_Handler(void)
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */