Skip to content

Commit 5ab8b22

Browse files
committed
Added pan feature to camera capture
Updated tests
1 parent 2afcfed commit 5ab8b22

File tree

4 files changed

+61
-769
lines changed

4 files changed

+61
-769
lines changed

source/application/lua_libraries/camera.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ static int lua_camera_capture(lua_State *L)
8787
}
8888
}
8989

90+
int16_t pan = 0;
91+
92+
if (lua_getfield(L, 1, "pan") != LUA_TNIL)
93+
{
94+
pan = luaL_checkinteger(L, -1) * 2;
95+
96+
if (pan < -280 || pan > 280)
97+
{
98+
luaL_error(L, "pan value must be value between -140 and 140");
99+
}
100+
}
101+
90102
uint8_t quality_level = 6;
91103

92104
if (lua_getfield(L, 1, "quality") != LUA_TNIL)
@@ -179,10 +191,18 @@ static int lua_camera_capture(lua_State *L)
179191
data_bytes_sent_out = 0;
180192
footer_bytes_sent_out = 0;
181193

194+
// Apply resolution
182195
capture_settings.resolution = resolution;
183196
uint8_t resolution_bytes[2] = {(uint8_t)(resolution >> 8), (uint8_t)(resolution & 0xFF)};
184197
spi_write(FPGA, 0x23, resolution_bytes, sizeof(resolution_bytes));
185198

199+
// Apply pan
200+
// Normalize pan to center of sensor with correct offset for 720 native resolution
201+
pan += (1280 / 2) - (720 / 2);
202+
check_error(i2c_write(CAMERA, 0x3810, 0xFF, pan >> 8).fail);
203+
check_error(i2c_write(CAMERA, 0x3811, 0xFF, pan).fail);
204+
205+
// Apply quality
186206
// These should match the indexed tables in quant_tables.sv
187207
switch (quality_level)
188208
{
@@ -214,6 +234,7 @@ static int lua_camera_capture(lua_State *L)
214234

215235
spi_write(FPGA, 0x26, &quality_level, sizeof(quality_level));
216236

237+
// Start capture
217238
spi_write(FPGA, 0x20, NULL, 0);
218239

219240
return 0;

tests/test_api.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,40 @@ async def main():
175175
await test.lua_send("frame.sleep(0.05)")
176176
await test.lua_equals("frame.camera.image_ready()", "true")
177177

178-
## Capture in different modes
179-
await test.lua_send("frame.camera.capture{quality_factor=10}")
180-
await test.lua_send("frame.sleep(0.1)")
181-
await test.lua_send("frame.camera.capture{quality_factor=25}")
182-
await test.lua_send("frame.sleep(0.1)")
183-
await test.lua_send("frame.camera.capture{quality_factor=50}")
184-
await test.lua_send("frame.sleep(0.1)")
185-
await test.lua_send("frame.camera.capture{quality_factor=100}")
186-
await test.lua_send("frame.sleep(0.1)")
187-
await test.lua_error("frame.camera.capture{quality_factor=75}")
178+
## Capture in different resolutions
179+
await test.lua_send("frame.camera.capture { resolution = 100 }")
180+
await test.lua_send("frame.camera.capture { resolution = 256 }")
181+
await test.lua_send("frame.camera.capture { resolution = 512 }")
182+
await test.lua_send("frame.camera.capture { resolution = 720 }")
183+
184+
await test.lua_error("frame.camera.capture { resolution = 80 }")
185+
await test.lua_error("frame.camera.capture { resolution = 513 }")
186+
await test.lua_error("frame.camera.capture { resolution = 721 }")
187+
188+
## Capture in different quality
189+
await test.lua_send("frame.camera.capture { quality = 'VERY_HIGH' }")
190+
await test.lua_send("frame.camera.capture { quality = 'HIGH' }")
191+
await test.lua_send("frame.camera.capture { quality = 'MEDIUM' }")
192+
await test.lua_send("frame.camera.capture { quality = 'LOW' }")
193+
await test.lua_send("frame.camera.capture { quality = 'VERY_LOW' }")
194+
195+
await test.lua_error("frame.camera.capture { quality = 50 }")
196+
await test.lua_error("frame.camera.capture { quality = 'BAD' }")
197+
198+
## Capture with different pan amounts
199+
await test.lua_send("frame.camera.capture { pan = -140 }")
200+
await test.lua_send("frame.camera.capture { pan = -75 }")
201+
await test.lua_send("frame.camera.capture { pan = 0 }")
202+
await test.lua_send("frame.camera.capture { pan = 75 }")
203+
await test.lua_send("frame.camera.capture { pan = 140 }")
204+
205+
await test.lua_error("frame.camera.capture { pan = -141 }")
206+
await test.lua_error("frame.camera.capture { pan = 200 }")
188207

189208
## Read
209+
await test.lua_send("frame.sleep(0.1)")
190210
await test.lua_equals("#frame.camera.read(123)", "123")
211+
await test.lua_equals("#frame.camera.read_raw(54)", "54")
191212

192213
## Test sleep prevents captures
193214
await test.lua_send("frame.camera.power_save(true)")
@@ -196,9 +217,6 @@ async def main():
196217
await test.lua_send("frame.sleep(0.1)")
197218
await test.lua_send("frame.camera.capture{}")
198219

199-
## Zoom & pan
200-
# TODO
201-
202220
## Manual exposure & gain
203221
# TODO
204222

tests/test_camera.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async def main():
5555
frame.camera.power_save(false)
5656
5757
frame.camera.set_gain(1)
58-
frame.camera.set_shutter(2500)
58+
frame.camera.set_shutter(1500)
5959
6060
frame.camera.capture { resolution = 100, quality = 'VERY_HIGH' }; transfer()
6161
frame.camera.capture { resolution = 100, quality = 'HIGH' }; transfer()
@@ -81,6 +81,14 @@ async def main():
8181
frame.camera.capture { resolution = 720, quality = 'LOW' }; transfer()
8282
frame.camera.capture { resolution = 720, quality = 'VERY_LOW' }; transfer()
8383
84+
frame.camera.capture { resolution = 720, pan = -140 }; transfer()
85+
frame.camera.capture { resolution = 720, pan = -75 }; transfer()
86+
frame.camera.capture { resolution = 720, pan = 0 }; transfer()
87+
frame.camera.capture { resolution = 720, pan = 75 }; transfer()
88+
frame.camera.capture { resolution = 720, pan = 140 }; transfer()
89+
90+
frame.camera.capture { }; transfer()
91+
8492
print("Done - Press enter to finish")
8593
"""
8694

0 commit comments

Comments
 (0)