forked from theonemule/gphoto-webui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Camera.php
175 lines (156 loc) · 4.31 KB
/
Camera.php
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
<?php
require_once("gPhoto2.php");
/**
* A class that defines a camera.
*
*/
class Camera {
public string $camera;
public string $cameraModel;
public string $manufacturer;
public string $port;
public string $shutterCounter;
public string $serialNumber;
public string $batteryLevel;
public array $availableCfg;
private gPhoto2 $gphoto2;
function __construct($port='NA') {
$this->gphoto2=new gPhoto2();
$this->port = ($port=='-1' ? 'NA': $port);
$this->camera = 'No Camera Detected';
$this->serialNumber = 'NA';
$this->batteryLevel = 'NA';
}
function __destruct() {
unset($availableCfg);
unset($gphoto2);
}
public function updateInfo(): bool {
$this->availableCfg=$this->gphoto2->getConfigList($this->port);
$this->updateSerialNumber();
$this->updateShutterCount();
$this->updateBatteryLevel();
$this->cameraModel=$this->gphoto2->getCameraModel($this->port);
$this->manufacturer=$this->gphoto2->getManufacturer($this->port);
return true;
}
public function captureImageAndDownload(): bool {
return $this->gphoto2->captureImageAndDownload($this->port);
}
public function updateBatteryLevel(): bool {
if ($this->configAvailable("batterylevel")){
$this->batteryLevel=$this->gphoto2->getBatteryLevel($this->port);
return true;
}
return false;
}
public function updateShutterCount(): bool {
if ($this->configAvailable("shuttercount")){
$this->shutterCounter=$this->gphoto2->getShutterCount($this->port);
return true;
}
return false;
}
public function updateSerialNumber(): bool {
if ($this->configAvailable("serialnumber")){
$this->serialNumber=$this->gphoto2->getSerialNumber($this->port);
return true;
}
return false;
}
public function configAvailable($config): bool {
foreach($this->availableCfg as $key=>$value){
if("$config" == substr($key,-strlen($config))){
// $number = substr($key,strrpos($key,'_'));
return true;
}
}
return false;
}
}
class Cameras {
public array $cameras;
function __construct() {
}
function __destruct() {
unset($cameras);
}
public static function getCameras($gphoto2): Cameras {
$returnObj = new Cameras();
$returnObj->cameras=[];
$output=$gphoto2->getCameras();
foreach ($output as $line) {
$camera = new Camera();
$camera->camera = trim(explode("usb", $line)[0]);
$camera->port = "usb:".trim(explode("usb:", $line)[1]);
$camera->updateInfo();
$returnObj->cameras[] = $camera;
}
unset($output);
return $returnObj;
}
public static function checkTetherStatus($gphoto2, $port='-1') {
if ($port == "-1") {
// check for all cameras
$cameras = Cameras::getCameras($gphoto2)->cameras;
foreach ($cameras as $camera) {
$tetherStatus = new TetherStatus($camera->port);
if($gphoto2->tetherIsRunning($camera->port)) {
$tetherStatus->status = "Running";
}
$returnObj[]=$tetherStatus;
}
} else {
// check for single camera
$tetherStatus = new TetherStatus($port);
if($gphoto2->tetherIsRunning($port)) {
$tetherStatus->status = "Running";
}
$returnObj[]=$tetherStatus;
}
if(!isset($returnObj)){
$returnObj[]= new TetherStatus("NA");
}
return $returnObj;
}
public static function captureImageAndDownload($gphoto2, $port='-1'): bool {
if ($port == "-1") {
// capture from all cameras
$cameras = Cameras::getCameras($gphoto2)->cameras;
foreach ($cameras as $camera) {
$gphoto2->captureImageAndDownload($camera->port);
}
} else {
// capture from single camera
$gphoto2->captureImageAndDownload($port);
}
return true;
}
public static function tetherStart($gphoto2, $port): bool {
if ($port == "-1") {
// capture from all cameras
$cameras = Cameras::getCameras($gphoto2)->cameras;
foreach ($cameras as $camera) {
$gphoto2->tetherStart($camera->port);
}
} else {
// capture from single camera
$gphoto2->tetherStart($port);
}
return true;
}
public static function tetherStop($gphoto2, $port): bool {
if ($port == "-1") {
// capture from all cameras
$cameras = Cameras::getCameras($gphoto2)->cameras;
foreach ($cameras as $camera) {
echo "$camera->port";
$gphoto2->tetherStop($camera->port);
}
} else {
// capture from single camera
$gphoto2->tetherStop($port);
}
return true;
}
}