-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions.py
More file actions
290 lines (233 loc) · 9.09 KB
/
Copy pathactions.py
File metadata and controls
290 lines (233 loc) · 9.09 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
from functions import Console
from capture.still import Still
from capture.video import Video
from file import File
from PySide6.QtCore import Slot
import globals
import threading
# libcamera control enum values (integers). picamera2 requires int, not str.
_METERING = {'CentreWeighted': 0, 'Spot': 1, 'Matrix': 2}
_EXPOSURE = {'Normal': 0, 'Short': 1, 'Long': 2}
_AWB = {'Auto': 0, 'Incandescent': 1, 'Tungsten': 2,
'Fluorescent': 3, 'Indoor': 4, 'Daylight': 5, 'Cloudy': 6}
console = Console()
class Actions:
# ------------------------------------------------------------------------------
@Slot()
def CaptureImage(self):
capturePrimaryThread = threading.Thread(
target=Still.capture,
args=('primary', File.GetPath(True, False, 1), globals.primary.rotation, globals.primary.raw)
)
capturePrimaryThread.start()
if globals.state.stereoCaptureEnabled and globals.secondary is not None:
captureSecondaryThread = threading.Thread(
target=Still.capture,
args=('secondary', File.GetPath(True, False, 2), globals.secondary.rotation, globals.secondary.raw)
)
captureSecondaryThread.start()
# ------------------------------------------------------------------------------
@Slot()
def CaptureVideo(self):
capturePrimaryThread = threading.Thread(
target=Video.capture,
args=('primary', File.GetPath(True, True, 1), globals.primary.rotation)
)
capturePrimaryThread.start()
if globals.state.stereoCaptureEnabled and globals.secondary is not None:
captureSecondaryThread = threading.Thread(
target=Video.capture,
args=('secondary', File.GetPath(True, True, 2), globals.secondary.rotation)
)
captureSecondaryThread.start()
# ------------------------------------------------------------------------------
@Slot()
def SetStereo(self):
if globals.cameras.count > 1 and globals.secondary is not None:
globals.state.stereoCaptureEnabled = not globals.state.stereoCaptureEnabled
else:
globals.state.stereoCaptureEnabled = False
# ------------------------------------------------------------------------------
@Slot()
def SetShutter(self, direction: str):
shutter = globals.state.shutter
shutterShort: int = globals.state.shutterShort
shutterLong: int = globals.state.shutterLong
shutterLongThreshold: int = globals.state.shutterLongThreshold
defaultFramerate: int = globals.state.defaultFramerate
if direction == 'up':
# Faster shutter = shorter exposure = smaller number
if shutter == 0:
shutter = shutterLong
elif shutter > shutterShort:
shutter = max(shutterShort, int(shutter / 1.5))
else:
# Slower shutter = longer exposure = larger number
if shutter == 0:
shutter = shutterShort
elif shutter < shutterLong:
shutter = min(shutterLong, int(shutter * 1.5))
elif shutter >= shutterLong:
shutter = 0 # wrap back to auto
try:
globals.state.shutter = shutter
# Adjust framerate for long exposure
if shutter == 0 or shutter <= shutterLongThreshold:
# Restore normal framerate
frame_us = int(1_000_000 / defaultFramerate)
globals.primary.module.set_controls({"FrameDurationLimits": (frame_us, frame_us)})
else:
# Slow framerate for long exposure (5fps max)
min_frame_us = int(shutter * 1.1)
globals.primary.module.set_controls({"FrameDurationLimits": (min_frame_us, min_frame_us)})
if shutter == 0:
globals.primary.module.set_controls({"ExposureTime": 0, "AeEnable": True})
else:
globals.primary.module.set_controls({"ExposureTime": shutter, "AeEnable": False})
except Exception as ex:
globals.state.lastMessage = 'Invalid Shutter Speed! ' + str(shutter)
console.warn(globals.state.lastMessage + str(ex))
# ------------------------------------------------------------------------------
@Slot()
def SetISO(self, direction: str):
iso: int = globals.state.iso
isoMin: int = globals.state.isoMin
isoMax: int = globals.state.isoMax
if direction == 'up':
if iso == 0:
iso = isoMin
elif iso < isoMax:
iso = min(isoMax, int(iso * 2))
else:
if iso == 0:
iso = isoMax
elif iso > isoMin:
iso = max(isoMin, int(iso / 2))
elif iso == isoMin:
iso = 0 # back to auto
try:
globals.state.iso = iso
if iso == 0:
globals.primary.module.set_controls({"AeEnable": True, "AnalogueGain": 0.0})
else:
globals.primary.module.set_controls({"AeEnable": False, "AnalogueGain": iso / 100.0})
except Exception as ex:
globals.state.lastMessage = 'Invalid ISO! ' + str(iso)
console.warn(globals.state.lastMessage + str(ex))
# ------------------------------------------------------------------------------
@Slot()
def SetExposureMode(self):
exposureMode: str = globals.state.exposureMode
modes = ['Normal', 'Short', 'Long', 'Disabled']
idx = modes.index(exposureMode) if exposureMode in modes else 0
exposureMode = modes[(idx + 1) % len(modes)]
try:
globals.state.exposureMode = exposureMode
if exposureMode == 'Disabled':
globals.primary.module.set_controls({"AeEnable": False})
else:
globals.primary.module.set_controls({
"AeEnable": True,
"AeExposureMode": _EXPOSURE.get(exposureMode, 0),
})
except Exception as ex:
globals.state.lastMessage = 'Invalid Exposure Mode! ' + str(exposureMode)
console.warn(globals.state.lastMessage + str(ex))
# ------------------------------------------------------------------------------
@Slot()
def SetMeteringMode(self):
meteringMode: str = globals.state.meteringMode
modes = ['CentreWeighted', 'Spot', 'Matrix']
idx = modes.index(meteringMode) if meteringMode in modes else 0
meteringMode = modes[(idx + 1) % len(modes)]
try:
globals.state.meteringMode = meteringMode
globals.primary.module.set_controls({
"AeMeteringMode": _METERING.get(meteringMode, 0),
})
except Exception as ex:
globals.state.lastMessage = 'Invalid Metering Mode! ' + str(meteringMode)
console.warn(globals.state.lastMessage + str(ex))
# ------------------------------------------------------------------------------
@Slot()
def SetExposureValue(self, direction: str):
exposureValue: int = globals.state.exposureValue
exposureValueMin: int = globals.state.exposureValueMin
exposureValueMax: int = globals.state.exposureValueMax
if direction == 'up':
if exposureValue < exposureValueMax:
exposureValue += 1
else:
if exposureValue > exposureValueMin:
exposureValue -= 1
if exposureValue > 0:
globals.state.exposureValuePrefix = '+'
elif exposureValue < 0:
globals.state.exposureValuePrefix = '-'
else:
globals.state.exposureValuePrefix = '+/-'
try:
globals.state.exposureValue = exposureValue
globals.primary.module.set_controls({"ExposureValue": float(exposureValue)})
except Exception as ex:
globals.state.lastMessage = 'Invalid EV! ' + str(exposureValue)
console.warn(globals.state.lastMessage + str(ex))
# ------------------------------------------------------------------------------
@Slot()
def SetBracket(self, direction: str):
bracket: int = globals.state.bracket
exposureValueMin: int = globals.state.exposureValueMin
exposureValueMax: int = globals.state.exposureValueMax
if direction == 'up':
if bracket < exposureValueMax:
bracket += 1
else:
if bracket > 0:
bracket -= 1
try:
globals.state.bracket = bracket
base_ev = globals.state.exposureValue
globals.state.bracketLow = max(exposureValueMin, base_ev - bracket)
globals.state.bracketHigh = min(exposureValueMax, base_ev + bracket)
except Exception as ex:
globals.state.lastMessage = 'Invalid Bracket! ' + str(bracket)
console.warn(globals.state.lastMessage + str(ex))
# ------------------------------------------------------------------------------
@Slot()
def SetAWBMode(self):
awbMode: str = globals.state.awbMode
modes = ['Auto', 'Tungsten', 'Fluorescent', 'Indoor', 'Daylight', 'Cloudy', 'Disabled']
idx = modes.index(awbMode) if awbMode in modes else 0
awbMode = modes[(idx + 1) % len(modes)]
try:
globals.state.awbMode = awbMode
if awbMode == 'Disabled':
globals.primary.module.set_controls({"AwbEnable": False})
else:
globals.primary.module.set_controls({
"AwbEnable": True,
"AwbMode": _AWB.get(awbMode, 0),
})
except Exception as ex:
globals.state.lastMessage = 'Invalid AWB Mode! ' + str(awbMode)
console.warn(globals.state.lastMessage + str(ex))
# ------------------------------------------------------------------------------
@Slot()
def SetTimer(self):
timer: int = globals.state.timer
sequence = [0, 3, 5, 10]
idx = sequence.index(timer) if timer in sequence else 0
globals.state.timer = sequence[(idx + 1) % len(sequence)]
# ------------------------------------------------------------------------------
@Slot()
def ToggleSettings(self):
# Handled directly by the UI layer
pass
# ------------------------------------------------------------------------------
@Slot()
def SetLights(self, red: int = 0, green: int = 0, blue: int = 0, white: int = 0):
globals.state.lights.red = red
globals.state.lights.green = green
globals.state.lights.blue = blue
globals.state.lights.white = white
# ------------------------------------------------------------------------------