-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_usage.py
More file actions
202 lines (158 loc) Β· 5.57 KB
/
example_usage.py
File metadata and controls
202 lines (158 loc) Β· 5.57 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
"""
GoProUSB Class Usage Example
Demonstrates complete control of a GoPro via USB
"""
from gopro_usb import GoProUSB
import time
SN1 = "C3504224696431"
SN2 = "C3504224677229"
SN3 = "C3504224682139"
SN = SN2
def main():
# Replace with your GoPro serial number
# The last 3 digits are used to generate the IP
# Example: if SN = "C1234567890", will use 172.29.190.51
SERIAL_NUMBER = SN
print("="*60)
print("π₯ GoPro USB Control Demo")
print("="*60)
# Initialisation de la camΓ©ra
gopro = GoProUSB(SERIAL_NUMBER)
try:
# 1. POWER ON
print("\nπ Step 1: Powering on the camera")
print("-" * 60)
if not gopro.power_on():
print("β οΈ Make sure the GoPro is connected via USB")
return
time.sleep(2)
# 2. Initial configuration
print("\nπ Step 2: Configuring camera")
print("-" * 60)
# Switch to video mode
gopro.mode_video()
time.sleep(1)
# IMPORTANT: For Hero 12 Black, set resolution BEFORE FPS
# Valid combinations:
# - 5.3K @ 60 FPS max
# - 4K @ 120 FPS max
# - 2.7K @ 240 FPS max
# - 1080p @ 240 FPS max
# Option 1: 4K @ 120 FPS (high quality + smooth)
print("βοΈ Setting 4K @ 120 FPS (high quality + smooth)")
gopro.set_resolution_4k()
time.sleep(0.5)
gopro.set_fps_120()
time.sleep(0.5)
# Option 2: High resolution (uncomment to use 5.3K @ 60 FPS instead)
# print("βοΈ Setting 5.3K @ 60 FPS (high quality)")
# gopro.set_resolution_5_3k()
# time.sleep(0.5)
# gopro.set_fps_60()
# time.sleep(0.5)
# Option 3: Slow motion (uncomment to use 2.7K @ 240 FPS instead)
# print("βοΈ Setting 2.7K @ 240 FPS (slow motion)")
# gopro.set_resolution_2_7k()
# time.sleep(0.5)
# gopro.set_fps_240()
# time.sleep(0.5)
# Set lens to Linear
gopro.set_lens_linear()
time.sleep(1)
print("β
Configuration complete")
# 3. Status verification
print("\nπ Step 3: Status verification")
print("-" * 60)
state = gopro.get_state()
print(f"π Battery: {state['status'].get('70', 'N/A')}%")
print(f"πΎ Free space: {state['status'].get('54', 'N/A')} MB")
print(f"π Resolution: {gopro._get_resolution_name(state['settings'].get('2', 'N/A'))}")
print(f"π¬ FPS: {gopro._get_fps_name(state['settings'].get('3', 'N/A'))}")
print(f"π Lens: {gopro._get_lens_name(state['settings'].get('121', 'N/A'))}")
# 4. Start recording
print("\nπ Step 4: Starting recording")
print("-" * 60)
gopro.record_start()
# 5. Real-time status monitoring during recording
print("\nπ Step 5: Real-time monitoring (10 seconds)")
print("-" * 60)
print("π‘ Status will be displayed every 2 seconds")
gopro.get_status_realtime(interval=2.0, duration=10.0)
# 6. Stop recording
print("\nπ Step 6: Stopping recording")
print("-" * 60)
gopro.record_stop()
time.sleep(2)
# 7. Download last media (optional)
print("\nπ Step 7: Download last media")
print("-" * 60)
download = input("Do you want to download the last media? (y/n): ")
if download.lower() == 'y':
gopro.download_last_media("last_recording")
# 8. POWER OFF
print("\nπ Step 8: Powering off the camera")
print("-" * 60)
gopro.power_off()
print("\n" + "="*60)
print("β
Demo completed successfully!")
print("="*60)
except KeyboardInterrupt:
print("\n\nβ οΈ User interruption")
print("Stopping recording if active...")
gopro.record_stop()
time.sleep(1)
gopro.power_off()
except Exception as e:
print(f"\nβ Error: {e}")
print("Attempting to stop recording...")
try:
gopro.record_stop()
time.sleep(1)
except:
pass
def demo_continuous_monitoring():
"""
Example of continuous status monitoring.
Press Ctrl+C to stop.
"""
SERIAL_NUMBER = SN
gopro = GoProUSB(SERIAL_NUMBER)
print("π₯ Continuous GoPro monitoring")
print("Press Ctrl+C to stop\n")
try:
gopro.power_on()
time.sleep(2)
# Infinite monitoring until Ctrl+C
gopro.get_status_realtime(interval=1.0)
except KeyboardInterrupt:
print("\n\nπ Monitoring stopped")
gopro.power_off()
def demo_quick_recording():
"""
Example of a quick 5-second recording.
"""
SERIAL_NUMBER = SN
gopro = GoProUSB(SERIAL_NUMBER)
print("π₯ Quick 5-second recording\n")
gopro.power_on()
time.sleep(2)
gopro.mode_video()
gopro.set_resolution_5_3k()
gopro.set_fps_240()
gopro.set_lens_linear()
time.sleep(2)
print("π΄ Starting recording...")
gopro.record_start()
print("β±οΈ Recording for 5 seconds...")
time.sleep(5)
print("βΉοΈ Stopping recording...")
gopro.record_stop()
time.sleep(2)
gopro.power_off()
print("β
Recording complete!")
if __name__ == "__main__":
# Complete demonstration
main()
# To use other examples, uncomment:
# demo_continuous_monitoring()
# demo_quick_recording()