|
16 | 16 | the one which usually uses rotation=90 to get a landscape display.
|
17 | 17 | """
|
18 | 18 |
|
19 |
| -import os |
20 | 19 | import struct
|
21 |
| - |
22 |
| -import analogio |
23 | 20 | import board
|
24 | 21 | import busio
|
| 22 | +import digitalio |
25 | 23 | import displayio
|
26 |
| -import sdcardio |
27 |
| -import storage |
28 | 24 | import adafruit_ov5640
|
| 25 | +from adafruit_ticks import ticks_ms, ticks_add, ticks_less |
| 26 | + |
| 27 | +# Set to True to enable the various effects & exposure modes to be tested |
| 28 | +test_effects = False |
29 | 29 |
|
30 | 30 | # Release any resources currently in use for the displays
|
31 | 31 | displayio.release_displays()
|
32 | 32 |
|
| 33 | +state = digitalio.DigitalInOut(board.IO4) |
| 34 | +state.switch_to_output(True) |
| 35 | + |
33 | 36 | spi = busio.SPI(MOSI=board.LCD_MOSI, clock=board.LCD_CLK)
|
34 | 37 | display_bus = displayio.FourWire(
|
35 | 38 | spi,
|
|
85 | 88 | cam.effect = adafruit_ov5640.OV5640_SPECIAL_EFFECT_NONE
|
86 | 89 | cam.saturation = 3
|
87 | 90 | bitmap = displayio.Bitmap(cam.width, cam.height, 65536)
|
88 |
| - |
| 91 | +print(len(memoryview(bitmap))) |
89 | 92 | display.auto_refresh = False
|
90 | 93 |
|
91 | 94 |
|
| 95 | +def special_modes(cam): |
| 96 | + def effect_modes(cam): |
| 97 | + for i in [ |
| 98 | + "NONE", |
| 99 | + "NEGATIVE", |
| 100 | + "GRAYSCALE", |
| 101 | + "RED_TINT", |
| 102 | + "GREEN_TINT", |
| 103 | + "BLUE_TINT", |
| 104 | + "SEPIA", |
| 105 | + ]: |
| 106 | + print(f"Effect {i}") |
| 107 | + cam.effect = getattr(adafruit_ov5640, f"OV5640_SPECIAL_EFFECT_{i}") |
| 108 | + yield |
| 109 | + cam.effect = adafruit_ov5640.OV5640_SPECIAL_EFFECT_NONE |
| 110 | + |
| 111 | + def saturation_modes(cam): |
| 112 | + for i in range(-4, 5): |
| 113 | + print(f"Saturation {i}") |
| 114 | + cam.saturation = i |
| 115 | + yield |
| 116 | + cam.saturation = 0 |
| 117 | + |
| 118 | + def brightness_modes(cam): |
| 119 | + for i in range(-4, 5): |
| 120 | + print(f"Brightness {i}") |
| 121 | + cam.brightness = i |
| 122 | + yield |
| 123 | + cam.brightness = 0 |
| 124 | + |
| 125 | + def contrast_modes(cam): |
| 126 | + for i in range(-3, 4): |
| 127 | + print(f"Contrast {i}") |
| 128 | + cam.contrast = i |
| 129 | + yield |
| 130 | + cam.contrast = 0 |
| 131 | + |
| 132 | + def white_balance_modes(cam): |
| 133 | + for i in ["AUTO", "SUNNY", "FLUORESCENT", "CLOUDY", "INCANDESCENT"]: |
| 134 | + print(f"White Balance {i}") |
| 135 | + cam.white_balance = getattr(adafruit_ov5640, f"OV5640_WHITE_BALANCE_{i}") |
| 136 | + yield |
| 137 | + cam.white_balance = adafruit_ov5640.OV5640_WHITE_BALANCE_AUTO |
| 138 | + |
| 139 | + def exposure_value_modes(cam): |
| 140 | + for i in range(-3, 4): |
| 141 | + print(f"EV {i}") |
| 142 | + cam.exposure_value = i |
| 143 | + yield |
| 144 | + cam.exposure_value = 0 |
| 145 | + |
| 146 | + def nite_modes(cam): |
| 147 | + print(f"Night Mode On") |
| 148 | + cam.night_mode = True |
| 149 | + print(cam.night_mode) |
| 150 | + yield |
| 151 | + print(f"Night Mode Off") |
| 152 | + cam.night_mode = False |
| 153 | + print(cam.night_mode) |
| 154 | + yield |
| 155 | + |
| 156 | + def test_modes(cam): |
| 157 | + print("Test pattern On") |
| 158 | + cam.test_pattern = True |
| 159 | + yield |
| 160 | + print("Test pattern Off") |
| 161 | + cam.test_pattern = False |
| 162 | + yield |
| 163 | + |
| 164 | + while True: |
| 165 | + yield from test_modes(cam) |
| 166 | + yield from contrast_modes(cam) |
| 167 | + yield from effect_modes(cam) |
| 168 | + yield from saturation_modes(cam) |
| 169 | + yield from brightness_modes(cam) |
| 170 | + # These don't work right (yet) |
| 171 | + # yield from exposure_value_modes(cam) # Issue #8 |
| 172 | + # yield from nite_modes(cam) # Issue #6 |
| 173 | + |
| 174 | + |
92 | 175 | def main():
|
93 | 176 | display.auto_refresh = False
|
94 | 177 | display_bus.send(42, struct.pack(">hh", 0, bitmap.width - 1))
|
95 | 178 | display_bus.send(43, struct.pack(">hh", 0, bitmap.height - 1))
|
| 179 | + |
| 180 | + if test_effects: |
| 181 | + time_per_effect = 1500 |
| 182 | + deadline = ticks_ms() + time_per_effect |
| 183 | + effects = special_modes(cam) |
| 184 | + |
96 | 185 | while True:
|
| 186 | + if test_effects: |
| 187 | + now = ticks_ms() |
| 188 | + if ticks_less(deadline, now): |
| 189 | + deadline += time_per_effect |
| 190 | + next(effects) |
| 191 | + state.value = True |
97 | 192 | cam.capture(bitmap)
|
| 193 | + state.value = False |
98 | 194 | display_bus.send(44, bitmap)
|
99 | 195 |
|
100 | 196 |
|
|
0 commit comments