CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/cameras_gimbals/xacti-config/main.cpp
Views: 1799
1
#include <stdio.h>
2
#include <iostream>
3
#include <cstring>
4
#include "CX-GBXXXCtrl.h"
5
6
const char* this_app_str = "xacti-config";
7
8
// display help
9
void display_help()
10
{
11
printf("Usage: sudo %s option [value]\n", this_app_str);
12
printf(" --dronecan\tenable (value=1) or disable (value=0) dronecan parsing\n");
13
printf(" --format\tformat SD card\n");
14
printf(" --help\t\tdisplay usage\n");
15
printf(" --irpalette\t\tIR pallete (0:white hot, 1:black hot, 2:rainbow, 3:rainHC, 4:ironbow, 5:lava, 6:arctic, 7:glowbow, 8:graded fire, 9:hottest)\n");
16
printf(" --msc\t\tchange to mass storage class mode (for downloading from SD card)\n");
17
}
18
19
int main(int argc, char **argv)
20
{
21
// display help
22
if ((argc <= 1) || ((argc >= 2) && (strcmp(argv[1], "--help") == 0))) {
23
display_help();
24
return 0;
25
}
26
27
// open camera
28
CX_GBXXXCtrl camera_ctrl;
29
if (!camera_ctrl.Open(NULL)) {
30
printf("%s: failed to open camera\n", this_app_str);
31
return 1;
32
}
33
34
// args_ok set to true when command line processed correctly
35
bool args_ok = false;
36
bool ret_ok = true;
37
38
// enable DroneCAN
39
if ((argc >= 3) && (strcmp(argv[1], "--dronecan") == 0)) {
40
args_ok = true;
41
uint8_t enable = (strcmp(argv[2], "1") == 0);
42
ret_ok = camera_ctrl.SetCameraCtrl(0x07, 0x1e, &enable, sizeof(enable));
43
const char* enable_or_disable_str = enable ? "enable" : "disable";
44
if (ret_ok) {
45
printf("%s: %s DroneCAN\n", this_app_str, enable_or_disable_str);
46
} else {
47
printf("%s: failed to %s DroneCAN\n", this_app_str, enable_or_disable_str);
48
}
49
}
50
51
// format SD card
52
if ((argc >= 2) && (strcmp(argv[1], "--format") == 0)) {
53
args_ok = true;
54
uint8_t format_sd = 0;
55
ret_ok = camera_ctrl.SetCameraCtrl(0x07, 0x15, &format_sd, sizeof(format_sd));
56
if (ret_ok) {
57
printf("%s: formatted SD card\n", this_app_str);
58
} else {
59
printf("%s: failed format SD card\n", this_app_str);
60
}
61
}
62
63
// IR palette
64
if ((argc >= 3) && (strcmp(argv[1], "--irpalette") == 0)) {
65
args_ok = true;
66
int palette_int = 0;
67
sscanf(argv[2], "%d", &palette_int);
68
uint8_t palette_uint8 = (uint8_t)palette_int;
69
ret_ok = camera_ctrl.SetCameraCtrl(0x07, 0x19, &palette_uint8, sizeof(palette_uint8));
70
if (ret_ok) {
71
printf("%s: IR palette set to %d\n", this_app_str, (int)palette_uint8);
72
} else {
73
printf("%s: failed to set IR palette to %d\n", this_app_str, (int)palette_uint8);
74
}
75
}
76
77
// change to Mass Storage Mode to allow downloading of images and videos
78
if ((argc >= 2) && (strcmp(argv[1], "--msc") == 0)) {
79
args_ok = true;
80
uint8_t msc_mode = 1;
81
ret_ok = camera_ctrl.SetCameraCtrl(0x06, 0x07, &msc_mode, sizeof(msc_mode));
82
if (ret_ok) {
83
printf("%s: changed to mass storage mode\n", this_app_str);
84
} else {
85
printf("%s: failed to change to mass storage mode\n", this_app_str);
86
}
87
}
88
89
// close camera
90
camera_ctrl.Close();
91
92
// display help if args could not be processed
93
if (!args_ok) {
94
display_help();
95
}
96
97
// return 0 if OK, 1 if not OK
98
return ret_ok ? 0 : 1;
99
}
100
101