Skip to content

Commit 81cac5f

Browse files
committed
Fixed auto-exposure limit bug
Added variable VTS registers back in Adjusted auto-exp defaults
1 parent 3eba9a0 commit 81cac5f

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

source/application/lua_libraries/camera.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* PERFORMANCE OF THIS SOFTWARE.
2323
*/
2424

25+
#include <math.h>
2526
#include <stdbool.h>
2627
#include <stdint.h>
2728
#include "error_logging.h"
@@ -336,8 +337,8 @@ static int lua_camera_auto(lua_State *L)
336337
camera_metering_mode_t metering = AVERAGE;
337338
double target_exposure = 0.18;
338339
double exposure_speed = 0.50;
339-
double shutter_limit = 800.0;
340-
double analog_gain_limit = 248.0;
340+
double shutter_limit = 1600.0;
341+
double analog_gain_limit = 60.0;
341342

342343
// Default white balance settings
343344
double white_balance_speed = 0.5;
@@ -409,7 +410,7 @@ static int lua_camera_auto(lua_State *L)
409410
if (lua_getfield(L, 1, "analog_gain_limit") != LUA_TNIL)
410411
{
411412
analog_gain_limit = luaL_checknumber(L, -1);
412-
if (analog_gain_limit < 0.0 || analog_gain_limit > 248.0)
413+
if (analog_gain_limit < 1.0 || analog_gain_limit > 248.0)
413414
{
414415
luaL_error(L, "analog_gain_limit must be between 0 and 248");
415416
}
@@ -505,33 +506,28 @@ static int lua_camera_auto(lua_State *L)
505506
{
506507
last.shutter *= error;
507508

508-
if (last.shutter > shutter_limit)
509+
if (last.shutter < 4.0)
509510
{
510-
last.shutter = shutter_limit;
511+
last.shutter = 4.0;
511512
}
512513
}
513514
}
514515

515-
if (last.shutter > shutter_limit)
516-
{
517-
last.shutter = shutter_limit;
518-
}
519-
if (last.shutter < 4.0)
520-
{
521-
last.shutter = 4.0;
522-
}
523-
if (last.analog_gain > analog_gain_limit)
516+
uint16_t shutter = (uint16_t)rint(last.shutter);
517+
uint8_t analog_gain = (uint8_t)rint(last.analog_gain);
518+
519+
// If shutter is longer than frame length (VTS register)
520+
if (shutter > 0x32A)
524521
{
525-
last.analog_gain = analog_gain_limit;
522+
check_error(i2c_write(CAMERA, 0x380E, 0xFF, shutter >> 8).fail);
523+
check_error(i2c_write(CAMERA, 0x380F, 0xFF, shutter).fail);
526524
}
527-
if (last.analog_gain < 0.0)
525+
else
528526
{
529-
last.analog_gain = 0.0;
527+
check_error(i2c_write(CAMERA, 0x380E, 0xFF, 0x03).fail);
528+
check_error(i2c_write(CAMERA, 0x380F, 0xFF, 0x22).fail);
530529
}
531530

532-
uint16_t shutter = (uint16_t)last.shutter;
533-
uint8_t analog_gain = (uint8_t)last.analog_gain;
534-
535531
check_error(i2c_write(CAMERA, 0x3500, 0x03, shutter >> 12).fail);
536532
check_error(i2c_write(CAMERA, 0x3501, 0xFF, shutter >> 4).fail);
537533
check_error(i2c_write(CAMERA, 0x3502, 0xF0, shutter << 4).fail);

tests/test_camera_fps.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,10 @@ async def main():
698698
end
699699
700700
if frame.time.utc() - last_autoexp_time > 0.1 then
701-
frame.camera.auto { }
701+
local stats = frame.camera.auto { analog_gain_limit=30, shutter_limit=3200 }
702+
-- if stats ~= nil then
703+
-- print('gain = '..stats['analog_gain']..', shutter = '..stats['shutter'])
704+
-- end
702705
last_autoexp_time = frame.time.utc()
703706
end
704707
end

0 commit comments

Comments
 (0)