forked from RigacciOrg/ambarella-api-pytools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sj8-white
executable file
·66 lines (52 loc) · 1.79 KB
/
sj8-white
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Communicate with a SJCAM SJ8PRO through the TCP JSON API.
* Get camera info and settings.
* Set the following settings:
'White Balance': 'Auto|Sunny|Cloudy'
"""
import ambarella_api as A
import datetime
import logging
import sys
__author__ = "Niccolo Rigacci"
__copyright__ = "Copyright 2021 Niccolo Rigacci <[email protected]>"
__license__ = "GPLv3-or-later"
__email__ = "[email protected]"
__version__ = "0.2.1"
# Valid options.
WHITE_BALANCE_OPTIONS = ['Auto', 'Sunny', 'Cloudy', 'Fluorescent', 'Underwater']
# Camera settings to be changed.
SET_ITEMS = {
'White Balance': 'Auto'
}
#--------------------------------------------------------------
# Main program.
#--------------------------------------------------------------
# Get option from command line.
white_balance = None
if len(sys.argv) > 1:
white_balance = sys.argv[1]
if white_balance not in WHITE_BALANCE_OPTIONS:
white_balance = WHITE_BALANCE_OPTIONS[0]
SET_ITEMS['White Balance'] = white_balance
logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s')
# Choose logging level: NOTSET, DEBUG, INFO, WARNING, ERROR
logging.getLogger().setLevel(logging.INFO)
# Open the TCP socket and get the communication token.
A.get_token()
# Set 'camera_clock' to system time.
date_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
reply = A.set_param(msg_type='camera_clock', param=date_time)
if reply is None:
A.api_error('CLOCK', 'Error setting camera clock')
# Change some camera settings.
for key in SET_ITEMS:
val = SET_ITEMS[key]
reply = A.set_param(msg_type=key, param=val)
if reply is None:
A.api_error('SET!', 'Error setting param for "%s"' % (key,))
# Close session.
A.close_session()
A.print_big('WhiteB\n%s' % (white_balance,))