|
22 | 22 | * PERFORMANCE OF THIS SOFTWARE.
|
23 | 23 | */
|
24 | 24 |
|
| 25 | +#include <math.h> |
25 | 26 | #include <stdbool.h>
|
26 | 27 | #include <stdint.h>
|
27 | 28 | #include "error_logging.h"
|
@@ -336,8 +337,8 @@ static int lua_camera_auto(lua_State *L)
|
336 | 337 | camera_metering_mode_t metering = AVERAGE;
|
337 | 338 | double target_exposure = 0.18;
|
338 | 339 | 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; |
341 | 342 |
|
342 | 343 | // Default white balance settings
|
343 | 344 | double white_balance_speed = 0.5;
|
@@ -409,7 +410,7 @@ static int lua_camera_auto(lua_State *L)
|
409 | 410 | if (lua_getfield(L, 1, "analog_gain_limit") != LUA_TNIL)
|
410 | 411 | {
|
411 | 412 | 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) |
413 | 414 | {
|
414 | 415 | luaL_error(L, "analog_gain_limit must be between 0 and 248");
|
415 | 416 | }
|
@@ -505,33 +506,28 @@ static int lua_camera_auto(lua_State *L)
|
505 | 506 | {
|
506 | 507 | last.shutter *= error;
|
507 | 508 |
|
508 |
| - if (last.shutter > shutter_limit) |
| 509 | + if (last.shutter < 4.0) |
509 | 510 | {
|
510 |
| - last.shutter = shutter_limit; |
| 511 | + last.shutter = 4.0; |
511 | 512 | }
|
512 | 513 | }
|
513 | 514 | }
|
514 | 515 |
|
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) |
524 | 521 | {
|
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); |
526 | 524 | }
|
527 |
| - if (last.analog_gain < 0.0) |
| 525 | + else |
528 | 526 | {
|
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); |
530 | 529 | }
|
531 | 530 |
|
532 |
| - uint16_t shutter = (uint16_t)last.shutter; |
533 |
| - uint8_t analog_gain = (uint8_t)last.analog_gain; |
534 |
| - |
535 | 531 | check_error(i2c_write(CAMERA, 0x3500, 0x03, shutter >> 12).fail);
|
536 | 532 | check_error(i2c_write(CAMERA, 0x3501, 0xFF, shutter >> 4).fail);
|
537 | 533 | check_error(i2c_write(CAMERA, 0x3502, 0xF0, shutter << 4).fail);
|
|
0 commit comments