Skip to content

Commit

Permalink
Fix filter and threshold values not loading correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
pcprince committed Jun 5, 2020
1 parent 30f1440 commit 3ccdd55
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "AudioMoth-Config",
"version": "1.3.0",
"version": "1.3.1",
"description": "The configuration app for the AudioMoth acoustic monitoring device.",
"main": "main.js",
"author": "openacousticdevices.info",
Expand Down
46 changes: 35 additions & 11 deletions settings/uiFiltering.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ function updateFilterLabel () {

}

function calculateSliderPosition (thresholdValue) {

if (!compressionThresholdValues) calculateCompressionThresholdValues();

for (let i = 0; i < compressionThresholdValues.length; i++) {

if (compressionThresholdValues[i] === thresholdValue) {

return i * 32768 / (compressionThresholdValues.length - 1);

}

}

}

function calculateCompressionThresholdValues () {

var i, j, step;
Expand Down Expand Up @@ -213,11 +229,11 @@ exports.setFilters = function (enabled, lowerSliderValue, higherSliderValue, fil
switch (filterType) {

case FILTER_LOW:
setLowPassSliderValue(lowerSliderValue);
setLowPassSliderValue(higherSliderValue);
break;

case FILTER_HIGH:
setHighPassSliderValue(higherSliderValue);
setHighPassSliderValue(lowerSliderValue);
break;

case FILTER_BAND:
Expand All @@ -226,22 +242,23 @@ exports.setFilters = function (enabled, lowerSliderValue, higherSliderValue, fil

}

updateFilterLabel();

for (i = 0; i < filterRadioButtons.length; i++) {

filterRadioButtons[i].checked = (i === filterType);

}

updateFilterLabel();

}

};

exports.setAmplitudeThreshold = function (enabled, amplitudeThreshold) {

amplitudeThresholdingCheckbox.checked = enabled;
amplitudeThresholdingSlider.setValue(amplitudeThreshold);

amplitudeThresholdingSlider.setValue(calculateSliderPosition(amplitudeThreshold));

};

Expand Down Expand Up @@ -381,8 +398,6 @@ function updateFilterUI () {
highPassMaxLabel.style.color = '';
highPassMinLabel.style.color = '';

updateFilterSliders();
updateFilterLabel();
filterLabel.style.color = '';

} else {
Expand Down Expand Up @@ -410,8 +425,6 @@ function updateFilterUI () {
filterLabel.textContent = 'Recordings will not be filtered.';
filterLabel.style.color = 'grey';

updateFilterSliders();

}

}
Expand Down Expand Up @@ -486,7 +499,13 @@ function addRadioButtonListeners () {

for (i = 0; i < filterRadioButtons.length; i++) {

filterRadioButtons[i].addEventListener('change', updateFilterUI);
filterRadioButtons[i].addEventListener('change', function () {

updateFilterUI();
updateFilterSliders();
updateFilterLabel();

});

}

Expand All @@ -499,7 +518,12 @@ exports.prepareUI = function (changeFunction) {
updateLifeDisplayOnChange = changeFunction;

amplitudeThresholdingCheckbox.addEventListener('change', updateAmplitudeThresholdingUI);
filterCheckbox.addEventListener('change', updateFilterUI);
filterCheckbox.addEventListener('change', function () {

updateFilterUI();
updateFilterLabel();

});

addRadioButtonListeners();

Expand Down
2 changes: 1 addition & 1 deletion settings/uiSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ exports.fillUI = function (settings) {
uiFiltering.setFilters(settings.passFiltersEnabled, settings.lowerFilter, settings.higherFilter, settings.filterType);
uiFiltering.updateFilterUI();

uiFiltering.setAmplitudeThreshold(settings.amplitudeThresholding, settings.amplitudeThreshold);
uiFiltering.setAmplitudeThreshold(settings.amplitudeThresholdingEnabled, settings.amplitudeThreshold);
uiFiltering.updateAmplitudeThresholdingUI();

durationInput.setValue(sleepDurationInput, settings.sleepDuration);
Expand Down

0 comments on commit 3ccdd55

Please sign in to comment.