Add button to copy camera settings from camera (#26)

Fixes #24.
This commit is contained in:
Peter Johnson 2019-01-02 22:31:55 -08:00 committed by GitHub
parent d0a2bf8deb
commit aaf6f88c9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 82 additions and 9 deletions

View File

@ -41,7 +41,7 @@ function displayStatus(message) {
// Enable and disable buttons based on connection status
var connectedButtonIds = ['systemRestart', 'networkApproach', 'networkAddress', 'networkMask', 'networkGateway', 'networkDNS', 'visionUp', 'visionDown', 'visionTerm', 'visionKill', 'systemReadOnly', 'systemWritable', 'visionClient', 'visionTeam', 'visionDiscard', 'addCamera', 'applicationType'];
var connectedButtonClasses = ['cameraName', 'cameraPath', 'cameraPixelFormat', 'cameraWidth', 'cameraHeight', 'cameraFps', 'cameraBrightness', 'cameraWhiteBalance', 'cameraExposure', 'cameraProperties', 'cameraRemove']
var connectedButtonClasses = ['cameraName', 'cameraPath', 'cameraPixelFormat', 'cameraWidth', 'cameraHeight', 'cameraFps', 'cameraBrightness', 'cameraWhiteBalance', 'cameraExposure', 'cameraProperties', 'cameraRemove', 'cameraCopyConfig']
var writableButtonIds = ['networkSave', 'visionSave', 'applicationSave'];
var systemStatusIds = ['systemMemoryFree1s', 'systemMemoryFree5s',
'systemMemoryAvail1s', 'systemMemoryAvail5s',
@ -352,6 +352,68 @@ function updateVisionCameraView(camera, value) {
camera.find('.cameraProperties').val(JSON.stringify(value.properties));
}
function updateVisionCameraDataFromJson(i, data) {
if (!('name' in data)) {
data.name = visionSettingsDisplay.cameras[i].name;
}
if (!('path' in data)) {
data.path = visionSettingsDisplay.cameras[i].path;
}
if ('properties' in data) {
var newProps = [];
var wbAuto = false;
var exAuto = false;
for (var i = 0; i < data.properties.length; i++) {
var name = data.properties[i].name;
// remove all raw properties
if (name.startsWith('raw_')) {
continue;
}
// brightness
if (name === 'brightness') {
data.brightness = data.properties[i].value;
continue;
}
// white balance
if (name === 'white_balance_temperature_auto') {
if (data.properties[i].value === true) {
data['white balance'] = 'auto';
wbAuto = true;
}
continue;
}
if (name === 'white_balance_temperature') {
if (wbAuto === false) {
data['white balance'] = data.properties.white_balance_temperature;
}
continue;
}
// exposure
if (name === 'exposure_auto') {
if (data.properties[i].value === 3) {
data.exposure = 'auto';
exAuto = true;
}
continue;
}
if (name === 'exposure_absolute') {
if (exAuto === false) {
data.exposure = data.properties.exposure_absolute;
}
continue;
}
newProps.push(data.properties[i]);
}
data.properties = newProps;
}
visionSettingsDisplay.cameras[i] = data;
}
function appendNewVisionCameraView(value, i) {
var camera = $('#cameraNEW').clone();
camera.attr('id', 'camera' + i);
@ -371,17 +433,22 @@ function appendNewVisionCameraView(value, i) {
var fr = new FileReader();
fr.onload = function(e) {
var result = JSON.parse(e.target.result);
if (!('name' in result)) {
result.name = visionSettingsDisplay.cameras[i].name;
}
if (!('path' in result)) {
result.path = visionSettingsDisplay.cameras[i].path;
}
visionSettingsDisplay.cameras[i] = result;
updateVisionCameraDataFromJson(i, result);
updateVisionCameraView(camera, result);
};
fr.readAsText(this.files.item(0));
});
camera.find('.cameraCopyConfig').click(function() {
fetch('http://' + window.location.hostname + ':' + (1181 + i) + '/config.json')
.then(response => response.json())
.then(function(result) {
updateVisionCameraDataFromJson(i, result);
updateVisionCameraView(camera, result);
})
.catch(function(error) {
displayStatus('error reading camera config: ' + error);
});
});
camera.find('[id]').each(function() {
$(this).attr('id', $(this).attr('id').replace('NEW', i));

View File

@ -273,9 +273,15 @@
<div class="form-group">
<div class="custom-file">
<input type="file" class="custom-file-input cameraSettingsFile" accept=".json,text/json,application/json" id="cameraSettingsFileNEW">
<label class="custom-file-label" for="cameraSettingsFileNEW">Load source config from JSON file</label>
<label class="custom-file-label" for="cameraSettingsFileNEW">Load Source Config From JSON File</label>
</div>
</div>
<div class="form-group">
<button class="btn btn-sm cameraCopyConfig" type="button">
<span data-feather="copy"></span>
Copy Source Config From Camera
</button>
</div>
<div class="form-row">
<div class="form-group col-auto">
<label for="cameraPixelFormatNEW">Pixel Format</label>