mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Merge pull request #1542 from openmv/lepton_high_temp
Lepton: Add high temperature measurement mode support.
This commit is contained in:
commit
8b3dc01e08
@ -791,15 +791,16 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
|
||||
case IOCTL_LEPTON_SET_MEASUREMENT_MODE:
|
||||
if (n_args >= 2) {
|
||||
error = sensor_ioctl(request, mp_obj_get_int(args[1]));
|
||||
int high_temp = (n_args == 2) ? false : mp_obj_get_int(args[2]);
|
||||
error = sensor_ioctl(request, mp_obj_get_int(args[1]), high_temp);
|
||||
}
|
||||
break;
|
||||
|
||||
case IOCTL_LEPTON_GET_MEASUREMENT_MODE: {
|
||||
int enabled;
|
||||
error = sensor_ioctl(request, &enabled);
|
||||
int enabled, high_temp;
|
||||
error = sensor_ioctl(request, &enabled, &high_temp);
|
||||
if (error == 0) {
|
||||
ret_obj = mp_obj_new_bool(enabled);
|
||||
ret_obj = mp_obj_new_tuple(2, (mp_obj_t []) {mp_obj_new_bool(enabled), mp_obj_new_bool(high_temp)});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -40,8 +40,13 @@
|
||||
#define VOSPI_FIRST_PACKET (0)
|
||||
#define VOSPI_FIRST_SEGMENT (1)
|
||||
#define LEPTON_TIMEOUT (1000)
|
||||
// Temperatures in Celsius
|
||||
#define DEFAULT_MIN_TEMP (-17.7778f)
|
||||
#define DEFAULT_MAX_TEMP (37.7778f)
|
||||
#define LEPTON_MIN_TEMP_NORM (-10.0f)
|
||||
#define LEPTON_MAX_TEMP_NORM (140.0f)
|
||||
#define LEPTON_MIN_TEMP_HIGH (-10.0f)
|
||||
#define LEPTON_MAX_TEMP_HIGH (600.0f)
|
||||
|
||||
static bool radiometry = false;
|
||||
static int h_res = 0;
|
||||
@ -49,6 +54,7 @@ static int v_res = 0;
|
||||
static bool v_flip = false;
|
||||
static bool h_mirror = false;
|
||||
static bool measurement_mode = false;
|
||||
static bool high_temp_mode = false;
|
||||
static float min_temp = DEFAULT_MIN_TEMP;
|
||||
static float max_temp = DEFAULT_MAX_TEMP;
|
||||
|
||||
@ -64,7 +70,7 @@ static uint8_t *vospi_buffer = _vospi_buf;
|
||||
static volatile uint32_t vospi_pid = 0;
|
||||
static volatile uint32_t vospi_seg = 1;
|
||||
static uint32_t vospi_packets = 60;
|
||||
static int lepton_reset(sensor_t *sensor, bool measurement_mode);
|
||||
static int lepton_reset(sensor_t *sensor, bool measurement_mode, bool high_temp_mode);
|
||||
|
||||
static void lepton_sync()
|
||||
{
|
||||
@ -280,23 +286,29 @@ static int ioctl(sensor_t *sensor, int request, va_list ap)
|
||||
break;
|
||||
}
|
||||
case IOCTL_LEPTON_SET_MEASUREMENT_MODE: {
|
||||
int enabled = va_arg(ap, int);
|
||||
if (measurement_mode != enabled) {
|
||||
measurement_mode = enabled;
|
||||
ret = lepton_reset(sensor, measurement_mode);
|
||||
int measurement_mode_in = va_arg(ap, int);
|
||||
int high_temp_mode_in = va_arg(ap, int);
|
||||
if (measurement_mode != measurement_mode_in) {
|
||||
measurement_mode = measurement_mode_in;
|
||||
high_temp_mode = high_temp_mode_in;
|
||||
ret = lepton_reset(sensor, measurement_mode, high_temp_mode);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IOCTL_LEPTON_GET_MEASUREMENT_MODE: {
|
||||
bool *enabled = va_arg(ap, bool *);
|
||||
*enabled = measurement_mode;
|
||||
int *measurement_mode_out = va_arg(ap, int *);
|
||||
int *high_temp_mode_out = va_arg(ap, int *);
|
||||
*measurement_mode_out = measurement_mode;
|
||||
*high_temp_mode_out = high_temp_mode;
|
||||
break;
|
||||
}
|
||||
case IOCTL_LEPTON_SET_MEASUREMENT_RANGE: {
|
||||
float *arg_min_temp = va_arg(ap, float *);
|
||||
float *arg_max_temp = va_arg(ap, float *);
|
||||
min_temp = IM_MAX(IM_MIN(*arg_min_temp, *arg_max_temp), -10.0f);
|
||||
max_temp = IM_MIN(IM_MAX(*arg_max_temp, *arg_min_temp), 140.0f);
|
||||
float min_temp_range = (high_temp_mode) ? LEPTON_MIN_TEMP_HIGH : LEPTON_MIN_TEMP_NORM;
|
||||
float max_temp_range = (high_temp_mode) ? LEPTON_MAX_TEMP_HIGH : LEPTON_MAX_TEMP_NORM;
|
||||
min_temp = IM_MAX(IM_MIN(*arg_min_temp, *arg_max_temp), min_temp_range);
|
||||
max_temp = IM_MIN(IM_MAX(*arg_max_temp, *arg_min_temp), max_temp_range);
|
||||
break;
|
||||
}
|
||||
case IOCTL_LEPTON_GET_MEASUREMENT_RANGE: {
|
||||
@ -316,7 +328,7 @@ static int ioctl(sensor_t *sensor, int request, va_list ap)
|
||||
}
|
||||
|
||||
|
||||
static int lepton_reset(sensor_t *sensor, bool measurement_mode)
|
||||
static int lepton_reset(sensor_t *sensor, bool measurement_mode, bool high_temp_mode)
|
||||
{
|
||||
DCMI_PWDN_LOW();
|
||||
mp_hal_delay_ms(10);
|
||||
@ -374,6 +386,12 @@ static int lepton_reset(sensor_t *sensor, bool measurement_mode)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Use the low gain mode to enable high temperature readings (~450C) on Lepton 3.5
|
||||
LEP_SYS_GAIN_MODE_E gain_mode = high_temp_mode ? LEP_SYS_GAIN_MODE_LOW : LEP_SYS_GAIN_MODE_HIGH;
|
||||
if (LEP_SetSysGainMode(&LEPHandle, gain_mode) != LEP_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!measurement_mode) {
|
||||
if (LEP_SetRadEnableState(&LEPHandle, LEP_RAD_DISABLE) != LEP_OK
|
||||
|| LEP_SetAgcEnableState(&LEPHandle, LEP_AGC_ENABLE) != LEP_OK
|
||||
@ -405,9 +423,10 @@ static int reset(sensor_t *sensor)
|
||||
h_mirror = false;
|
||||
radiometry = false;
|
||||
measurement_mode = false;
|
||||
high_temp_mode = false;
|
||||
min_temp = DEFAULT_MIN_TEMP;
|
||||
max_temp = DEFAULT_MAX_TEMP;
|
||||
return lepton_reset(sensor, false);
|
||||
return lepton_reset(sensor, false, false);
|
||||
}
|
||||
|
||||
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
|
||||
@ -504,7 +523,7 @@ static int snapshot(sensor_t *sensor, image_t *image, uint32_t flags)
|
||||
// The FLIR lepton might have crashed so reset it (it does this).
|
||||
bool temp_h_mirror = h_mirror;
|
||||
bool temp_v_flip = v_flip;
|
||||
int ret = lepton_reset(sensor, measurement_mode);
|
||||
int ret = lepton_reset(sensor, measurement_mode, high_temp_mode);
|
||||
h_mirror = temp_h_mirror;
|
||||
v_flip = temp_v_flip;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user