From 145dde360ee31fe7fd127f42cfd019f495780297 Mon Sep 17 00:00:00 2001 From: lijie Date: Thu, 6 Mar 2025 17:37:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=87=AA=E5=8A=A8=E6=9B=9D?= =?UTF-8?q?=E5=85=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- APP/communication.c | 21 +++++++++++---------- APP/communication.h | 2 +- APP/mymain.c | 12 ++++++------ APP/mymain.h | 12 ++++++++++++ 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/APP/communication.c b/APP/communication.c index 5f30f63..512d4a9 100644 --- a/APP/communication.c +++ b/APP/communication.c @@ -21,13 +21,14 @@ void Send_Shutter_Time(uint32_t shutter_time) { HAL_UART_Transmit(&huart2,t_buff,4,100); } - -uint32_t Opt_Snenser(int persent, uint16_t *data,uint32_t Size,uint32_t Shutter_Now) { +//自动曝光 成功返回曝光时间 失败返回0 +uint32_t Opt_Snenser(int persent, uint16_t *data,uint32_t Size) { int maxvalue=maxValue*1.0*persent / 100; int maxvaluenow = 0; - uint32_t shutter_time; - uint32_t max_shutter_time = 100; + uint32_t min_shutter_time = 10; + static uint32_t shutter_time; + shutter_time < min_shutter_time ? shutter_time = min_shutter_time : shutter_time; for (int i = 0; i < Size; i++) { if (data[i] > maxvaluenow) { @@ -35,15 +36,15 @@ uint32_t Opt_Snenser(int persent, uint16_t *data,uint32_t Size,uint32_t Shutter } } - if (Shutter_Now<=min_shutter_time || Shutter_Now>=max_shutter_time) return 0; + if (maxvaluenow= maxvalue*1.05 ) { + shutter_time = shutter_time * maxvalue / maxvaluenow; + + shutter_time < min_shutter_time ? shutter_time = min_shutter_time : shutter_time; - if (maxvaluenowmaxvalue) { - shutter_time = Shutter_Now * maxvaluenow / maxvalue; Send_Shutter_Time(shutter_time); - - HAL_Delay(1000); - return shutter_time; + if (shutter_time <= min_shutter_time ) return shutter_time; } + else return 1; return 0; } diff --git a/APP/communication.h b/APP/communication.h index a280ffc..91d795f 100644 --- a/APP/communication.h +++ b/APP/communication.h @@ -7,5 +7,5 @@ #include "mymain.h" void Send_Shutter_Time(uint32_t shutter_time); -uint32_t Opt_Snenser(int persent, uint16_t *data,uint32_t Size,uint32_t Shutter_Now); +uint32_t Opt_Snenser(int persent, uint16_t *data,uint32_t Size); #endif //COMMUNICATION_H diff --git a/APP/mymain.c b/APP/mymain.c index 2093aa0..678131d 100644 --- a/APP/mymain.c +++ b/APP/mymain.c @@ -84,12 +84,12 @@ void mymain() // uint32_t a=0; while (1) { while (mode == 0) { + shutter_time = 0x0000; commander_run(); if (Receive_Data_Count != Last_Receive_Data_Count) { - - uint32_t a = Opt_Snenser(90, Receive_Data_Buffer ,USART2_RX_BUFFER_SIZE,shutter_time ); - if (a != 0) shutter_time = a; - else { + uint32_t a = Opt_Snenser(90, Receive_Data_Buffer ,USART2_RX_BUFFER_SIZE); + if (a != 0) { + shutter_time = a; mode = 1; } Last_Receive_Data_Count = Receive_Data_Count; @@ -141,11 +141,11 @@ void mymain() break; case 2: sgi(Receive_Data_Buffer,sgi_result); - Send_Data(0x61,(uint8_t *)sgi_result,515*2); + Send_Data(0x61,(uint8_t *)sgi_result,515*2); break; case 3: sgi(Average_Buffer,sgi_result); - Send_Data(0x61,(uint8_t *)sgi_result,515*2); + Send_Data(0x61,(uint8_t *)sgi_result,515*2); break; case 4: Send_Data(0x61,(uint8_t *)Moving_Average_Buffer,515*2); diff --git a/APP/mymain.h b/APP/mymain.h index 6355c3b..ad3997b 100644 --- a/APP/mymain.h +++ b/APP/mymain.h @@ -28,3 +28,15 @@ void mymain(); void commander_run(void); #endif //FOC_N_MYMAIN_H + + +// int _write (int fd, char *pBuffer, int size) +// { +// for (int i = 0; i < size; i++) +// { +// USART1->TDR = (unsigned char) *(pBuffer+i); +// while((USART1->ISR & USART_ISR_TC) == 0) +// {} +// } +// return size; +// } \ No newline at end of file