|
20 | 20 |
|
21 | 21 | import board
|
22 | 22 | import busio
|
| 23 | +import digitalio |
23 | 24 | import displayio
|
24 | 25 | 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 |
25 | 30 |
|
26 | 31 | # Release any resources currently in use for the displays
|
27 | 32 | displayio.release_displays()
|
28 | 33 |
|
| 34 | +state = digitalio.DigitalInOut(board.IO4) |
| 35 | +state.switch_to_output(True) |
| 36 | + |
29 | 37 | spi = busio.SPI(MOSI=board.LCD_MOSI, clock=board.LCD_CLK)
|
30 | 38 | display_bus = displayio.FourWire(
|
31 | 39 | spi,
|
|
81 | 89 | cam.effect = adafruit_ov5640.OV5640_SPECIAL_EFFECT_NONE
|
82 | 90 | cam.saturation = 3
|
83 | 91 | bitmap = displayio.Bitmap(cam.width, cam.height, 65536)
|
84 |
| - |
| 92 | +print(len(memoryview(bitmap))) |
85 | 93 | display.auto_refresh = False
|
86 | 94 |
|
87 | 95 |
|
| 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 | + |
88 | 176 | def main():
|
89 | 177 | display.auto_refresh = False
|
90 | 178 | display_bus.send(42, struct.pack(">hh", 0, bitmap.width - 1))
|
91 | 179 | 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 | + |
92 | 186 | 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 |
93 | 193 | cam.capture(bitmap)
|
| 194 | + state.value = False |
94 | 195 | display_bus.send(44, bitmap)
|
95 | 196 |
|
96 | 197 |
|
|
0 commit comments