forked from MicroPythonOS/MicroPythonOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanual_test_camera.py
More file actions
62 lines (53 loc) · 2.78 KB
/
manual_test_camera.py
File metadata and controls
62 lines (53 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import unittest
from mpos import App, AppManager
from camera import Camera, GrabMode, PixelFormat, FrameSize, GainCeiling
class TestCompareVersions(unittest.TestCase):
def init_cam(self):
try:
cam = Camera(data_pins=[12,13,15,11,14,10,7,2],vsync_pin=6,href_pin=4,sda_pin=21,scl_pin=16,pclk_pin=9,xclk_pin=8,xclk_freq=20000000,pixel_format=PixelFormat.RGB565,powerdown_pin=-1,reset_pin=-1,frame_size=FrameSize.R240X240,grab_mode=GrabMode.LATEST)
return cam
except Exception as e:
#self.assertTrue(False, f"camera init received exception: {e}")
print(f"camera init received exception: {e}")
return None
def test_init_capture_deinit(self):
cam = self.init_cam()
self.assertTrue(cam is not None, "camera failed to initialize")
self.assertEqual(cam.get_pixel_height(), 240, "wrong pixel height")
self.assertEqual(cam.get_pixel_width(), 240, "wrong pixel width")
memview = cam.capture()
self.assertEqual(len(memview), 2 * 240 * 240, "capture size does not match expectations")
cam.deinit()
def disabled_test_multiple_runs(self):
for _ in range(10):
self.test_init_capture_deinit()
def disabled_test_init_capture_deinit_poweroff(self):
self.test_init_capture_deinit()
from machine import Pin, I2C
i2c = I2C(1, scl=Pin(16), sda=Pin(21), freq=100000) # Adjust pins and frequency
devices = i2c.scan()
print([hex(addr) for addr in devices]) # finds it on 60 = 0x3C after init
camera_addr = 0x3C # for OV5640
reg_addr = 0x3008
reg_high = (reg_addr >> 8) & 0xFF # 0x30
reg_low = reg_addr & 0xFF # 0x08
power_off_command = 0x40 # Power off command Bit[6]: Software power down
#i2c.writeto(camera_addr, bytes([reg_high, reg_low, power_off_command]))
print("\nSecond capture will fail!")
self.test_init_capture_deinit()
def test_init_twice_capture_deinit_poweroff(self):
self.test_init_capture_deinit()
from machine import Pin, I2C
i2c = I2C(1, scl=Pin(16), sda=Pin(21), freq=100000) # Adjust pins and frequency
devices = i2c.scan()
print([hex(addr) for addr in devices]) # finds it on 60 = 0x3C after init
camera_addr = 0x3C # for OV5640
reg_addr = 0x3008
reg_high = (reg_addr >> 8) & 0xFF # 0x30
reg_low = reg_addr & 0xFF # 0x08
power_off_command = 0x40 # Power off command Bit[6]: Software power down
#i2c.writeto(camera_addr, bytes([reg_high, reg_low, power_off_command]))
cam = self.init_cam()
self.assertTrue(cam is None, "expected camera to fail after i2c")
print("\nSecond capture should now work!")
self.test_init_capture_deinit()