Skip to content

Commit 64b85d7

Browse files
authored
Merge pull request #7 from adafruit/fix-effects-modes
Fix effects modes
2 parents 8cd38a6 + ee855e1 commit 64b85d7

File tree

2 files changed

+105
-4
lines changed

2 files changed

+105
-4
lines changed

adafruit_ov5640.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@
571571
_contrast_settings = [
572572
[0x20, 0x00], # 0
573573
[0x24, 0x10], # +1
574-
[0x1a, 0x13], # +2
574+
[0x28, 0x18], # +2
575575
[0x2c, 0x1c], # +3
576576
[0x14, 0x14], # -3
577577
[0x18, 0x18], # -2
@@ -625,7 +625,7 @@
625625
OV5640_SPECIAL_EFFECT_SEPIA = 6
626626

627627
_sensor_special_effects = [
628-
[0x06, 0x40, 0x2C, 0x08], # Normal
628+
[0x06, 0x40, 0x10, 0x08], # Normal
629629
[0x46, 0x40, 0x28, 0x08], # Negative
630630
[0x1E, 0x80, 0x80, 0x08], # Grayscale
631631
[0x1E, 0x80, 0xC0, 0x08], # Red Tint
@@ -1198,7 +1198,7 @@ def brightness(self, value):
11981198
"Invalid brightness value {value}, use a value from -4..4 inclusive"
11991199
)
12001200
self._write_group_3_settings(
1201-
[0x5587, abs(value) << 4, 0x9 if value < 0 else 0x1]
1201+
[0x5587, abs(value) << 4, 0x5588, 0x9 if value < 0 else 0x1]
12021202
)
12031203

12041204
@property

examples/ov5640_directio_kaluga1_3_ili9341.py

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@
2020

2121
import board
2222
import busio
23+
import digitalio
2324
import displayio
2425
import adafruit_ov5640
26+
from adafruit_ticks import ticks_ms, ticks_add, ticks_less
27+
28+
# Set to True to enable the various effects & exposure modes to be tested
29+
test_effects = False
2530

2631
# Release any resources currently in use for the displays
2732
displayio.release_displays()
2833

34+
state = digitalio.DigitalInOut(board.IO4)
35+
state.switch_to_output(True)
36+
2937
spi = busio.SPI(MOSI=board.LCD_MOSI, clock=board.LCD_CLK)
3038
display_bus = displayio.FourWire(
3139
spi,
@@ -81,16 +89,109 @@
8189
cam.effect = adafruit_ov5640.OV5640_SPECIAL_EFFECT_NONE
8290
cam.saturation = 3
8391
bitmap = displayio.Bitmap(cam.width, cam.height, 65536)
84-
92+
print(len(memoryview(bitmap)))
8593
display.auto_refresh = False
8694

8795

96+
def special_modes(cam):
97+
def effect_modes(cam):
98+
for i in [
99+
"NONE",
100+
"NEGATIVE",
101+
"GRAYSCALE",
102+
"RED_TINT",
103+
"GREEN_TINT",
104+
"BLUE_TINT",
105+
"SEPIA",
106+
]:
107+
print(f"Effect {i}")
108+
cam.effect = getattr(adafruit_ov5640, f"OV5640_SPECIAL_EFFECT_{i}")
109+
yield
110+
cam.effect = adafruit_ov5640.OV5640_SPECIAL_EFFECT_NONE
111+
112+
def saturation_modes(cam):
113+
for i in range(-4, 5):
114+
print(f"Saturation {i}")
115+
cam.saturation = i
116+
yield
117+
cam.saturation = 0
118+
119+
def brightness_modes(cam):
120+
for i in range(-4, 5):
121+
print(f"Brightness {i}")
122+
cam.brightness = i
123+
yield
124+
cam.brightness = 0
125+
126+
def contrast_modes(cam):
127+
for i in range(-3, 4):
128+
print(f"Contrast {i}")
129+
cam.contrast = i
130+
yield
131+
cam.contrast = 0
132+
133+
def white_balance_modes(cam):
134+
for i in ["AUTO", "SUNNY", "FLUORESCENT", "CLOUDY", "INCANDESCENT"]:
135+
print(f"White Balance {i}")
136+
cam.white_balance = getattr(adafruit_ov5640, f"OV5640_WHITE_BALANCE_{i}")
137+
yield
138+
cam.white_balance = adafruit_ov5640.OV5640_WHITE_BALANCE_AUTO
139+
140+
def exposure_value_modes(cam):
141+
for i in range(-3, 4):
142+
print(f"EV {i}")
143+
cam.exposure_value = i
144+
yield
145+
cam.exposure_value = 0
146+
147+
def nite_modes(cam):
148+
print(f"Night Mode On")
149+
cam.night_mode = True
150+
print(cam.night_mode)
151+
yield
152+
print(f"Night Mode Off")
153+
cam.night_mode = False
154+
print(cam.night_mode)
155+
yield
156+
157+
def test_modes(cam):
158+
print("Test pattern On")
159+
cam.test_pattern = True
160+
yield
161+
print("Test pattern Off")
162+
cam.test_pattern = False
163+
yield
164+
165+
while True:
166+
yield from test_modes(cam)
167+
yield from contrast_modes(cam)
168+
yield from effect_modes(cam)
169+
yield from saturation_modes(cam)
170+
yield from brightness_modes(cam)
171+
# These don't work right (yet)
172+
# yield from exposure_value_modes(cam) # Issue #8
173+
# yield from nite_modes(cam) # Issue #6
174+
175+
88176
def main():
89177
display.auto_refresh = False
90178
display_bus.send(42, struct.pack(">hh", 0, bitmap.width - 1))
91179
display_bus.send(43, struct.pack(">hh", 0, bitmap.height - 1))
180+
181+
if test_effects:
182+
time_per_effect = 1500
183+
deadline = ticks_ms() + time_per_effect
184+
effects = special_modes(cam)
185+
92186
while True:
187+
if test_effects:
188+
now = ticks_ms()
189+
if ticks_less(deadline, now):
190+
deadline += time_per_effect
191+
next(effects)
192+
state.value = True
93193
cam.capture(bitmap)
194+
state.value = False
94195
display_bus.send(44, bitmap)
95196

96197

0 commit comments

Comments
 (0)