mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-05-04 07:10:17 +00:00
upd
This commit is contained in:
parent
2c2ebd7137
commit
55e8424f78
@ -16,4 +16,37 @@ void IR_handler(void);
|
|||||||
void ClearIRStatus(void);
|
void ClearIRStatus(void);
|
||||||
void ClearIRCommand(void);
|
void ClearIRCommand(void);
|
||||||
void ClearIR(void);
|
void ClearIR(void);
|
||||||
|
void SetShiftReg_inline (unsigned char b1, unsigned char b2, unsigned char b3);
|
||||||
void SetShiftReg (unsigned char shiftreg[3]);
|
void SetShiftReg (unsigned char shiftreg[3]);
|
||||||
|
|
||||||
|
enum IR_CMD_LIST {
|
||||||
|
IR_FRONT_LEFT = 20,
|
||||||
|
IR_FRONT_MID = 58,
|
||||||
|
IR_FONT_RIGHT = 21,
|
||||||
|
IR_MACRO = 63,
|
||||||
|
IR_PROG = 37,
|
||||||
|
IR_SHOT = 56,
|
||||||
|
IR_NUM_1 = 0,
|
||||||
|
IR_NUM_2 = 1,
|
||||||
|
IR_NUM_3 = 2,
|
||||||
|
IR_NUM_4 = 3,
|
||||||
|
IR_NUM_5 = 4,
|
||||||
|
IR_NUM_6 = 5,
|
||||||
|
IR_NUM_7 = 6,
|
||||||
|
IR_NUM_8 = 7,
|
||||||
|
IR_NUM_9 = 8,
|
||||||
|
IR_NUM_0 = 9,
|
||||||
|
IR_DEBUG = 29, // -/--
|
||||||
|
IR_PAUSE = 43,
|
||||||
|
IR_STOP = 116,
|
||||||
|
IR_START = 124,
|
||||||
|
IR_F_BTN = 23,
|
||||||
|
IR_ESC = 117,
|
||||||
|
IR_ENTER = 97,
|
||||||
|
IR_TEMPO_INC = 60,
|
||||||
|
IR_TEMPO_DEC = 54,
|
||||||
|
IR_ENGINE_UP_INC = 18, // скорость верхнего мотора
|
||||||
|
IR_ENGINE_UP_DEC = 19,
|
||||||
|
IR_ENGINE_DOWM_INC = 16,
|
||||||
|
IR_ENGINE_DOWM_DEC = 17
|
||||||
|
};
|
||||||
|
@ -50,7 +50,7 @@ void IR_handler() // SONY (SIRC) protocol 12 bit (7+5)
|
|||||||
if ((currentIR_Pulse < 130000) && (currentIR_Pulse > 110000)) // 2,7 ms - 2,3 ms
|
if ((currentIR_Pulse < 130000) && (currentIR_Pulse > 110000)) // 2,7 ms - 2,3 ms
|
||||||
{
|
{
|
||||||
IRStatus = STATUS_COMMAND; // 129600 - 110400
|
IRStatus = STATUS_COMMAND; // 129600 - 110400
|
||||||
print("STATUS_COMMAND\n");
|
// print("STATUS_COMMAND\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -65,19 +65,19 @@ void IR_handler() // SONY (SIRC) protocol 12 bit (7+5)
|
|||||||
if (currentIR_Pulse < 37440) // 0.78 ms 37440
|
if (currentIR_Pulse < 37440) // 0.78 ms 37440
|
||||||
{
|
{
|
||||||
IR_Command &= ~((1 << IR_IndexBitCommand) & 0xFF);
|
IR_Command &= ~((1 << IR_IndexBitCommand) & 0xFF);
|
||||||
print("0");
|
// print("0");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IR_Command |= ((1 << IR_IndexBitCommand) & 0xFF);
|
IR_Command |= ((1 << IR_IndexBitCommand) & 0xFF);
|
||||||
print("1");
|
// print("1");
|
||||||
}
|
}
|
||||||
|
|
||||||
IR_IndexBitCommand++;
|
IR_IndexBitCommand++;
|
||||||
if (IR_IndexBitCommand == 7)
|
if (IR_IndexBitCommand == 7)
|
||||||
{
|
{
|
||||||
IRStatus = STATUS_ADDRESS;
|
IRStatus = STATUS_ADDRESS;
|
||||||
print(" STATUS_ADDRESS ");
|
// print(" STATUS_ADDRESS ");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -93,19 +93,20 @@ void IR_handler() // SONY (SIRC) protocol 12 bit (7+5)
|
|||||||
if (currentIR_Pulse < 37440) // 0.78 <20><>
|
if (currentIR_Pulse < 37440) // 0.78 <20><>
|
||||||
{
|
{
|
||||||
IR_Address &= ~((1 << IR_IndexBitAddress) & 0xFF);
|
IR_Address &= ~((1 << IR_IndexBitAddress) & 0xFF);
|
||||||
print("0");
|
// print("0");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IR_Address |= ((1 << IR_IndexBitAddress) & 0xFF);
|
IR_Address |= ((1 << IR_IndexBitAddress) & 0xFF);
|
||||||
print("1");
|
// print("1");
|
||||||
}
|
}
|
||||||
|
|
||||||
IR_IndexBitAddress++;
|
IR_IndexBitAddress++;
|
||||||
if (IR_IndexBitAddress == 5)
|
if (IR_IndexBitAddress == 5)
|
||||||
{
|
{
|
||||||
|
// printNumber(IR_Command);
|
||||||
IRStatus = STATUS_REPEAT;
|
IRStatus = STATUS_REPEAT;
|
||||||
print("\n\n\n");
|
// print("\n\n\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -118,7 +119,7 @@ void IR_handler() // SONY (SIRC) protocol 12 bit (7+5)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case STATUS_ERROR:
|
case STATUS_ERROR:
|
||||||
print("STATUS_ERROR\n\n");
|
// print("STATUS_ERROR\n\n");
|
||||||
default:
|
default:
|
||||||
ClearIRStatus();
|
ClearIRStatus();
|
||||||
|
|
||||||
@ -158,6 +159,11 @@ void ClearIR()
|
|||||||
ClearIRStatus();
|
ClearIRStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetShiftReg_inline(unsigned char b1, unsigned char b2, unsigned char b3){
|
||||||
|
unsigned char shiftreg[3] = {b1,b2,b3};
|
||||||
|
SetShiftReg(shiftreg);
|
||||||
|
}
|
||||||
|
|
||||||
void SetShiftReg(unsigned char shiftreg[3])
|
void SetShiftReg(unsigned char shiftreg[3])
|
||||||
{
|
{
|
||||||
for (unsigned char i = 0; i < 3; i++)
|
for (unsigned char i = 0; i < 3; i++)
|
||||||
@ -197,3 +203,4 @@ void SetShiftReg(unsigned char shiftreg[3])
|
|||||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
464
Core/Src/main.c
464
Core/Src/main.c
@ -1,20 +1,20 @@
|
|||||||
/* USER CODE BEGIN Header */
|
/* USER CODE BEGIN Header */
|
||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @file : main.c
|
* @file : main.c
|
||||||
* @brief : Main program body
|
* @brief : Main program body
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @attention
|
* @attention
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 STMicroelectronics.
|
* Copyright (c) 2024 STMicroelectronics.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
* in the root directory of this software component.
|
* in the root directory of this software component.
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
/* USER CODE END Header */
|
/* USER CODE END Header */
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
@ -23,10 +23,10 @@
|
|||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
|
|
||||||
#include "usbd_cdc_if.h"
|
#include "usbd_cdc_if.h"
|
||||||
#include "pca9685.h"
|
#include "pca9685.h"
|
||||||
#include "IR.h"
|
#include "IR.h"
|
||||||
#include "EEPROM.h"
|
#include "EEPROM.h"
|
||||||
#include "Print.h"
|
#include "Print.h"
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
@ -64,9 +64,9 @@ uint8_t initcomlete = 0;
|
|||||||
|
|
||||||
unsigned char Shiftreg[3];
|
unsigned char Shiftreg[3];
|
||||||
|
|
||||||
uint8_t rejim[60]; // 0 - chislo rejimov, 1-6 - rejim1, 7-12 - rejim2...
|
uint8_t rejim[60]; // 0 - chislo rejimov, 1-6 - rejim1, 7-12 - rejim2...
|
||||||
uint8_t avto = 0; // vkl/otkl avtomaticheskoi raboti
|
uint8_t avto = 0; // vkl/otkl avtomaticheskoi raboti
|
||||||
uint8_t rejim_number = 1; // nomer tekyshego rejima
|
uint8_t rejim_number = 1; // nomer tekyshego rejima
|
||||||
|
|
||||||
uint8_t Vz1 = 100;
|
uint8_t Vz1 = 100;
|
||||||
uint8_t Vz2 = 100;
|
uint8_t Vz2 = 100;
|
||||||
@ -76,19 +76,16 @@ uint16_t vi = 0;
|
|||||||
uint16_t timing1 = 0;
|
uint16_t timing1 = 0;
|
||||||
uint16_t timing2 = 0;
|
uint16_t timing2 = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t MYIR_command = 0;
|
uint8_t MYIR_command = 0;
|
||||||
|
|
||||||
volatile uint32_t millisCounter = 0;
|
volatile uint32_t millisCounter = 0;
|
||||||
uint32_t previousMillis = 0;
|
uint32_t previousMillis = 0;
|
||||||
|
|
||||||
|
struct StructShot BufShots[MAX_NUMBER_SHOTS];
|
||||||
|
struct StructProgram BufPrograms;
|
||||||
|
struct StructMacro BufMacro;
|
||||||
|
|
||||||
struct StructShot BufShots[MAX_NUMBER_SHOTS];
|
extern PCD_HandleTypeDef hpcd_USB_FS;
|
||||||
struct StructProgram BufPrograms;
|
|
||||||
struct StructMacro BufMacro;
|
|
||||||
|
|
||||||
extern PCD_HandleTypeDef hpcd_USB_FS;
|
|
||||||
|
|
||||||
/* USER CODE END PV */
|
/* USER CODE END PV */
|
||||||
|
|
||||||
@ -110,12 +107,19 @@ static void MX_USART3_UART_Init(void);
|
|||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The application entry point.
|
* @brief The application entry point.
|
||||||
* @retval int
|
* @retval int
|
||||||
*/
|
*/
|
||||||
|
unsigned char b1 = 1;
|
||||||
|
unsigned char b2 = 1;
|
||||||
|
unsigned char b3 = 1;
|
||||||
|
|
||||||
|
IRMenu menu();
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
menu.foo();
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
/* USER CODE END 1 */
|
||||||
@ -134,10 +138,10 @@ int main(void)
|
|||||||
|
|
||||||
/* USER CODE BEGIN SysInit */
|
/* USER CODE BEGIN SysInit */
|
||||||
// Установка приоритета прерывания
|
// Установка приоритета прерывания
|
||||||
// NVIC_SetPriority(SysTick_IRQn, 0);
|
// NVIC_SetPriority(SysTick_IRQn, 0);
|
||||||
// Настройка SysTick таймера на 1 мс
|
// Настройка SysTick таймера на 1 мс
|
||||||
SysTick->LOAD = 479999; // 1ms Sys timer
|
SysTick->LOAD = 479999; // 1ms Sys timer
|
||||||
// SysTick_Config(SystemCoreClock / 1000);
|
// SysTick_Config(SystemCoreClock / 1000);
|
||||||
|
|
||||||
__HAL_RCC_USB_FORCE_RESET();
|
__HAL_RCC_USB_FORCE_RESET();
|
||||||
HAL_Delay(10);
|
HAL_Delay(10);
|
||||||
@ -194,110 +198,205 @@ initcomlete = 1;
|
|||||||
|
|
||||||
HAL_TIM_IC_Start_IT(&htim3, TIM_CHANNEL_1); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 <20>6 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> PA0 PA1
|
HAL_TIM_IC_Start_IT(&htim3, TIM_CHANNEL_1); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 <20>6 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> PA0 PA1
|
||||||
HAL_TIM_Base_Start_IT(&htim3);
|
HAL_TIM_Base_Start_IT(&htim3);
|
||||||
HAL_NVIC_EnableIRQ(TIM3_IRQn);
|
HAL_NVIC_EnableIRQ(TIM3_IRQn);
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
/* USER CODE BEGIN WHILE */
|
/* USER CODE BEGIN WHILE */
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (IRStatus == STATUS_REPEAT) {
|
if (IRStatus == STATUS_REPEAT)
|
||||||
if (IR_Address == 0x01) MYIR_command = IR_Command;
|
{
|
||||||
CDC_Transmit_FS(&MYIR_command, 1);
|
if (IR_Address == 0x01)
|
||||||
ClearIRStatus();
|
{
|
||||||
}
|
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;
|
||||||
|
|
||||||
if (rxcomlite == 1) {
|
SetShiftReg_inline(++b1, ++b2, ++b3);
|
||||||
|
break;
|
||||||
|
|
||||||
txdata[0] = 'O'; txdata[1] = 'K'; txdata[2] = '?';
|
default:
|
||||||
|
break;
|
||||||
switch (rxdata[0]) {
|
}
|
||||||
|
|
||||||
case 1: { SetServo(0, rxdata[1] ); txdata[0] = 'O'; txdata[1] = 'K';
|
|
||||||
txdata[2] = '1'; CDC_Transmit_FS(txdata, 3); break; }
|
|
||||||
|
|
||||||
case 2: { SetServo(1, rxdata[1] ); txdata[0] = 'O'; txdata[1] = 'K';
|
|
||||||
txdata[2] = '2'; CDC_Transmit_FS(txdata, 3); break; }
|
|
||||||
|
|
||||||
case 3: { SetServo(2, rxdata[1] ); txdata[0] = 'O'; txdata[1] = 'K';
|
|
||||||
txdata[2] = '3'; CDC_Transmit_FS(txdata, 3); break; }
|
|
||||||
|
|
||||||
case 4: { SetServo(0, rxdata[1] ); SetServo(1, rxdata[2] ); SetServo(2, rxdata[3] );
|
|
||||||
|
|
||||||
Vz1 = rxdata[4]; //rolic verh 0..200
|
|
||||||
Vz2 = rxdata[5]; //rolic niz 0..200
|
|
||||||
vi = 0;
|
|
||||||
|
|
||||||
//shnek 0..100
|
|
||||||
if (rxdata[6] < 101) { TIM1->CCR1 = 0; TIM1->CCR2 = (uint16_t)(40*rxdata[6]); } else
|
|
||||||
{ TIM1->CCR1 = 0; TIM1->CCR2 = 4000;}
|
|
||||||
|
|
||||||
txdata[0] = 'O'; txdata[1] = 'K'; txdata[2] = '4'; CDC_Transmit_FS(txdata, 3); break; }
|
|
||||||
|
|
||||||
case 5: {txdata[0] = LOBYTE(timing1) ; txdata[1] = HIBYTE(timing1) ;
|
|
||||||
CDC_Transmit_FS(txdata, 3); break; }
|
|
||||||
case 6: { CDC_Transmit_FS(velosety, 600); break; }
|
|
||||||
|
|
||||||
case 7: { rejim[0] = rxdata[1];
|
|
||||||
// copy to buffer
|
|
||||||
for (uint8_t i = 0; i < rejim[0]; i++)
|
|
||||||
{
|
|
||||||
rejim[(i*6)+1] = rxdata[(i*6)+2];
|
|
||||||
rejim[(i*6)+2] = rxdata[(i*6)+3];
|
|
||||||
rejim[(i*6)+3] = rxdata[(i*6)+4];
|
|
||||||
rejim[(i*6)+4] = rxdata[(i*6)+5];
|
|
||||||
rejim[(i*6)+5] = rxdata[(i*6)+6];
|
|
||||||
rejim[(i*6)+6] = rxdata[(i*6)+7];
|
|
||||||
}
|
|
||||||
// set rejim #1
|
|
||||||
SetServo(0, rejim[1] );
|
|
||||||
SetServo(1, rejim[2] );
|
|
||||||
SetServo(2, rejim[3] );
|
|
||||||
Vz1 = rejim[4];
|
|
||||||
Vz2 = rejim[5];
|
|
||||||
TIM1->CCR1 = 0; TIM1->CCR2 = (uint16_t)(40*rejim[6]);
|
|
||||||
// set avto
|
|
||||||
rejim_number = 1;
|
|
||||||
avto = 1;
|
|
||||||
break; }
|
|
||||||
case 8: { // stop avto
|
|
||||||
avto = 0; rejim_number = 1;
|
|
||||||
// stop mecanics
|
|
||||||
SetServo(0, 90);
|
|
||||||
SetServo(1, 90);
|
|
||||||
SetServo(2, 90);
|
|
||||||
Vz1 = 100;
|
|
||||||
Vz2 = 100;
|
|
||||||
TIM1->CCR1 = 0; TIM1->CCR2 = 0;
|
|
||||||
|
|
||||||
break; }
|
|
||||||
|
|
||||||
case 9: { txdata[0] = avto ;
|
|
||||||
txdata[1] = rejim_number;
|
|
||||||
CDC_Transmit_FS(txdata, 3);
|
|
||||||
|
|
||||||
break; }
|
|
||||||
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
rxcomlite = 0;
|
|
||||||
|
|
||||||
// // 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));
|
|
||||||
}
|
}
|
||||||
|
ClearIRStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rxcomlite == 1)
|
||||||
|
{
|
||||||
|
|
||||||
|
txdata[0] = 'O';
|
||||||
|
txdata[1] = 'K';
|
||||||
|
txdata[2] = '?';
|
||||||
|
|
||||||
|
switch (rxdata[0])
|
||||||
|
{
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
SetServo(0, rxdata[1]);
|
||||||
|
txdata[0] = 'O';
|
||||||
|
txdata[1] = 'K';
|
||||||
|
txdata[2] = '1';
|
||||||
|
CDC_Transmit_FS(txdata, 3);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
SetServo(1, rxdata[1]);
|
||||||
|
txdata[0] = 'O';
|
||||||
|
txdata[1] = 'K';
|
||||||
|
txdata[2] = '2';
|
||||||
|
CDC_Transmit_FS(txdata, 3);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
SetServo(2, rxdata[1]);
|
||||||
|
txdata[0] = 'O';
|
||||||
|
txdata[1] = 'K';
|
||||||
|
txdata[2] = '3';
|
||||||
|
CDC_Transmit_FS(txdata, 3);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
{
|
||||||
|
SetServo(0, rxdata[1]);
|
||||||
|
SetServo(1, rxdata[2]);
|
||||||
|
SetServo(2, rxdata[3]);
|
||||||
|
|
||||||
|
Vz1 = rxdata[4]; // rolic verh 0..200
|
||||||
|
Vz2 = rxdata[5]; // rolic niz 0..200
|
||||||
|
vi = 0;
|
||||||
|
|
||||||
|
// shnek 0..100
|
||||||
|
if (rxdata[6] < 101)
|
||||||
|
{
|
||||||
|
TIM1->CCR1 = 0;
|
||||||
|
TIM1->CCR2 = (uint16_t)(40 * rxdata[6]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TIM1->CCR1 = 0;
|
||||||
|
TIM1->CCR2 = 4000;
|
||||||
|
}
|
||||||
|
|
||||||
|
txdata[0] = 'O';
|
||||||
|
txdata[1] = 'K';
|
||||||
|
txdata[2] = '4';
|
||||||
|
CDC_Transmit_FS(txdata, 3);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
{
|
||||||
|
txdata[0] = LOBYTE(timing1);
|
||||||
|
txdata[1] = HIBYTE(timing1);
|
||||||
|
CDC_Transmit_FS(txdata, 3);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 6:
|
||||||
|
{
|
||||||
|
CDC_Transmit_FS(velosety, 600);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 7:
|
||||||
|
{
|
||||||
|
rejim[0] = rxdata[1];
|
||||||
|
// copy to buffer
|
||||||
|
for (uint8_t i = 0; i < rejim[0]; i++)
|
||||||
|
{
|
||||||
|
rejim[(i * 6) + 1] = rxdata[(i * 6) + 2];
|
||||||
|
rejim[(i * 6) + 2] = rxdata[(i * 6) + 3];
|
||||||
|
rejim[(i * 6) + 3] = rxdata[(i * 6) + 4];
|
||||||
|
rejim[(i * 6) + 4] = rxdata[(i * 6) + 5];
|
||||||
|
rejim[(i * 6) + 5] = rxdata[(i * 6) + 6];
|
||||||
|
rejim[(i * 6) + 6] = rxdata[(i * 6) + 7];
|
||||||
|
}
|
||||||
|
// set rejim #1
|
||||||
|
SetServo(0, rejim[1]);
|
||||||
|
SetServo(1, rejim[2]);
|
||||||
|
SetServo(2, rejim[3]);
|
||||||
|
Vz1 = rejim[4];
|
||||||
|
Vz2 = rejim[5];
|
||||||
|
TIM1->CCR1 = 0;
|
||||||
|
TIM1->CCR2 = (uint16_t)(40 * rejim[6]);
|
||||||
|
// set avto
|
||||||
|
rejim_number = 1;
|
||||||
|
avto = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 8:
|
||||||
|
{ // stop avto
|
||||||
|
avto = 0;
|
||||||
|
rejim_number = 1;
|
||||||
|
// stop mecanics
|
||||||
|
SetServo(0, 90);
|
||||||
|
SetServo(1, 90);
|
||||||
|
SetServo(2, 90);
|
||||||
|
Vz1 = 100;
|
||||||
|
Vz2 = 100;
|
||||||
|
TIM1->CCR1 = 0;
|
||||||
|
TIM1->CCR2 = 0;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 9:
|
||||||
|
{
|
||||||
|
txdata[0] = avto;
|
||||||
|
txdata[1] = rejim_number;
|
||||||
|
CDC_Transmit_FS(txdata, 3);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
rxcomlite = 0;
|
||||||
|
|
||||||
|
// // 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));
|
||||||
|
}
|
||||||
|
|
||||||
/* USER CODE END WHILE */
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
@ -307,9 +406,9 @@ initcomlete = 1;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief System Clock Configuration
|
* @brief System Clock Configuration
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void SystemClock_Config(void)
|
void SystemClock_Config(void)
|
||||||
{
|
{
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
@ -317,8 +416,8 @@ void SystemClock_Config(void)
|
|||||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||||
|
|
||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
/** 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.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||||
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
|
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
|
||||||
@ -332,9 +431,8 @@ void SystemClock_Config(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Initializes the CPU, AHB and APB buses clocks
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
*/
|
*/
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
||||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||||
@ -353,10 +451,10 @@ void SystemClock_Config(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief I2C1 Initialization Function
|
* @brief I2C1 Initialization Function
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MX_I2C1_Init(void)
|
static void MX_I2C1_Init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -383,14 +481,13 @@ static void MX_I2C1_Init(void)
|
|||||||
/* USER CODE BEGIN I2C1_Init 2 */
|
/* USER CODE BEGIN I2C1_Init 2 */
|
||||||
|
|
||||||
/* USER CODE END I2C1_Init 2 */
|
/* USER CODE END I2C1_Init 2 */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TIM1 Initialization Function
|
* @brief TIM1 Initialization Function
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MX_TIM1_Init(void)
|
static void MX_TIM1_Init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -462,14 +559,13 @@ static void MX_TIM1_Init(void)
|
|||||||
|
|
||||||
/* USER CODE END TIM1_Init 2 */
|
/* USER CODE END TIM1_Init 2 */
|
||||||
HAL_TIM_MspPostInit(&htim1);
|
HAL_TIM_MspPostInit(&htim1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TIM2 Initialization Function
|
* @brief TIM2 Initialization Function
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MX_TIM2_Init(void)
|
static void MX_TIM2_Init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -533,14 +629,13 @@ static void MX_TIM2_Init(void)
|
|||||||
|
|
||||||
/* USER CODE END TIM2_Init 2 */
|
/* USER CODE END TIM2_Init 2 */
|
||||||
HAL_TIM_MspPostInit(&htim2);
|
HAL_TIM_MspPostInit(&htim2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TIM3 Initialization Function
|
* @brief TIM3 Initialization Function
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MX_TIM3_Init(void)
|
static void MX_TIM3_Init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -595,14 +690,13 @@ static void MX_TIM3_Init(void)
|
|||||||
/* USER CODE BEGIN TIM3_Init 2 */
|
/* USER CODE BEGIN TIM3_Init 2 */
|
||||||
|
|
||||||
/* USER CODE END TIM3_Init 2 */
|
/* USER CODE END TIM3_Init 2 */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USART3 Initialization Function
|
* @brief USART3 Initialization Function
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MX_USART3_UART_Init(void)
|
static void MX_USART3_UART_Init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -628,19 +722,18 @@ static void MX_USART3_UART_Init(void)
|
|||||||
/* USER CODE BEGIN USART3_Init 2 */
|
/* USER CODE BEGIN USART3_Init 2 */
|
||||||
|
|
||||||
/* USER CODE END USART3_Init 2 */
|
/* USER CODE END USART3_Init 2 */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief GPIO Initialization Function
|
* @brief GPIO Initialization Function
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MX_GPIO_Init(void)
|
static void MX_GPIO_Init(void)
|
||||||
{
|
{
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
/* USER CODE END MX_GPIO_Init_1 */
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
/* GPIO Ports Clock Enable */
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||||
@ -652,7 +745,7 @@ static void MX_GPIO_Init(void)
|
|||||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*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 */
|
/*Configure GPIO pin : PC13 */
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_13;
|
GPIO_InitStruct.Pin = GPIO_PIN_13;
|
||||||
@ -662,7 +755,7 @@ static void MX_GPIO_Init(void)
|
|||||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||||
|
|
||||||
/*Configure GPIO pins : LED_DATA_Pin LED_CLK_Pin */
|
/*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.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
@ -687,8 +780,8 @@ static void MX_GPIO_Init(void)
|
|||||||
HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0);
|
HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0);
|
||||||
HAL_NVIC_EnableIRQ(EXTI1_IRQn);
|
HAL_NVIC_EnableIRQ(EXTI1_IRQn);
|
||||||
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
/* USER CODE END MX_GPIO_Init_2 */
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
/* USER CODE BEGIN 4 */
|
||||||
@ -696,30 +789,29 @@ static void MX_GPIO_Init(void)
|
|||||||
/* USER CODE END 4 */
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is executed in case of error occurrence.
|
* @brief This function is executed in case of error occurrence.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void Error_Handler(void)
|
void Error_Handler(void)
|
||||||
{
|
{
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
// GPIOC->ODR &= ~GPIO_PIN_13;
|
// GPIOC->ODR &= ~GPIO_PIN_13;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
/* USER CODE END Error_Handler_Debug */
|
/* 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
|
* @brief Reports the name of the source file and the source line number
|
||||||
* where the assert_param error has occurred.
|
* where the assert_param error has occurred.
|
||||||
* @param file: pointer to the source file name
|
* @param file: pointer to the source file name
|
||||||
* @param line: assert_param error line source number
|
* @param line: assert_param error line source number
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void assert_failed(uint8_t *file, uint32_t line)
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
{
|
{
|
||||||
/* USER CODE BEGIN 6 */
|
/* USER CODE BEGIN 6 */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user