修改自动曝光
This commit is contained in:
@ -21,13 +21,14 @@ void Send_Shutter_Time(uint32_t shutter_time) {
|
|||||||
HAL_UART_Transmit(&huart2,t_buff,4,100);
|
HAL_UART_Transmit(&huart2,t_buff,4,100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//自动曝光 成功返回曝光时间 失败返回0
|
||||||
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) {
|
||||||
int maxvalue=maxValue*1.0*persent / 100;
|
int maxvalue=maxValue*1.0*persent / 100;
|
||||||
int maxvaluenow = 0;
|
int maxvaluenow = 0;
|
||||||
uint32_t shutter_time;
|
|
||||||
uint32_t max_shutter_time = 100;
|
|
||||||
uint32_t min_shutter_time = 10;
|
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++) {
|
for (int i = 0; i < Size; i++) {
|
||||||
if (data[i] > maxvaluenow) {
|
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 || maxvaluenow >= maxvalue*1.05 ) {
|
||||||
|
shutter_time = shutter_time * maxvalue / maxvaluenow;
|
||||||
|
|
||||||
|
shutter_time < min_shutter_time ? shutter_time = min_shutter_time : shutter_time;
|
||||||
|
|
||||||
if (maxvaluenow<maxvalue*0.95 || maxvaluenow>maxvalue) {
|
|
||||||
shutter_time = Shutter_Now * maxvaluenow / maxvalue;
|
|
||||||
Send_Shutter_Time(shutter_time);
|
Send_Shutter_Time(shutter_time);
|
||||||
|
if (shutter_time <= min_shutter_time ) return shutter_time;
|
||||||
HAL_Delay(1000);
|
|
||||||
return shutter_time;
|
|
||||||
}
|
}
|
||||||
|
else return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,5 @@
|
|||||||
#include "mymain.h"
|
#include "mymain.h"
|
||||||
|
|
||||||
void Send_Shutter_Time(uint32_t shutter_time);
|
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
|
#endif //COMMUNICATION_H
|
||||||
|
@ -84,12 +84,12 @@ void mymain()
|
|||||||
// uint32_t a=0;
|
// uint32_t a=0;
|
||||||
while (1) {
|
while (1) {
|
||||||
while (mode == 0) {
|
while (mode == 0) {
|
||||||
|
shutter_time = 0x0000;
|
||||||
commander_run();
|
commander_run();
|
||||||
if (Receive_Data_Count != Last_Receive_Data_Count) {
|
if (Receive_Data_Count != Last_Receive_Data_Count) {
|
||||||
|
uint32_t a = Opt_Snenser(90, Receive_Data_Buffer ,USART2_RX_BUFFER_SIZE);
|
||||||
uint32_t a = Opt_Snenser(90, Receive_Data_Buffer ,USART2_RX_BUFFER_SIZE,shutter_time );
|
if (a != 0) {
|
||||||
if (a != 0) shutter_time = a;
|
shutter_time = a;
|
||||||
else {
|
|
||||||
mode = 1;
|
mode = 1;
|
||||||
}
|
}
|
||||||
Last_Receive_Data_Count = Receive_Data_Count;
|
Last_Receive_Data_Count = Receive_Data_Count;
|
||||||
|
12
APP/mymain.h
12
APP/mymain.h
@ -28,3 +28,15 @@
|
|||||||
void mymain();
|
void mymain();
|
||||||
void commander_run(void);
|
void commander_run(void);
|
||||||
#endif //FOC_N_MYMAIN_H
|
#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;
|
||||||
|
// }
|
Reference in New Issue
Block a user