55 lines
1.4 KiB
C
55 lines
1.4 KiB
C
//
|
|
// Created by IRIS on 25-2-7.
|
|
//
|
|
|
|
#include "communication.h"
|
|
#define maxValue 65535
|
|
//
|
|
void Send_Shutter_Time(uint32_t shutter_time) {
|
|
uint32_t tt = shutter_time*1000;
|
|
// printf("t %d \n",t);
|
|
// printf("tt %d \n",tt);
|
|
uint8_t t_buff[4];
|
|
t_buff[0] = *((uint8_t *)&tt+3);
|
|
t_buff[1] = *((uint8_t *)&tt+2);
|
|
t_buff[2] = *((uint8_t *)&tt+1);
|
|
t_buff[3] = *((uint8_t *)&tt);
|
|
|
|
// HAL_UART_Transmit(&huart1,t_buff,4,100);
|
|
|
|
__HAL_UART_ENABLE(&huart2);
|
|
HAL_UART_Transmit(&huart2,t_buff,4,100);
|
|
}
|
|
|
|
//自动曝光 成功返回曝光时间 失败返回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 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) {
|
|
maxvaluenow = data[i];
|
|
}
|
|
}
|
|
|
|
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;
|
|
|
|
Send_Shutter_Time(shutter_time);
|
|
if (shutter_time <= min_shutter_time ) return shutter_time;
|
|
}
|
|
else return 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|