2017-01-08 03:45:19 +00:00
|
|
|
angular.module('appControllers').controller('SettingsCtrl', SettingsCtrl); // get the main module contollers set
|
|
|
|
SettingsCtrl.$inject = ['$rootScope', '$scope', '$state', '$location', '$window', '$http']; // Inject my dependencies
|
|
|
|
|
|
|
|
// create our controller function with all necessary logic
|
|
|
|
function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) {
|
|
|
|
|
|
|
|
$scope.$parent.helppage = 'plates/settings-help.html';
|
|
|
|
|
2017-03-05 22:47:38 +00:00
|
|
|
var toggles = ['UAT_Enabled', 'ES_Enabled', 'Ping_Enabled', 'GPS_Enabled', 'IMU_Sensor_Enabled',
|
2017-03-05 23:34:25 +00:00
|
|
|
'BMP_Sensor_Enabled', 'DisplayTrafficSource', 'DEBUG', 'ReplayLog', 'AHRSLog'];
|
2017-01-08 03:45:19 +00:00
|
|
|
var settings = {};
|
|
|
|
for (i = 0; i < toggles.length; i++) {
|
|
|
|
settings[toggles[i]] = undefined;
|
|
|
|
}
|
|
|
|
$scope.update_files = '';
|
2017-01-09 04:04:16 +00:00
|
|
|
|
2017-01-08 03:45:19 +00:00
|
|
|
function loadSettings(data) {
|
|
|
|
settings = angular.fromJson(data);
|
|
|
|
// consider using angular.extend()
|
|
|
|
$scope.rawSettings = angular.toJson(data, true);
|
|
|
|
$scope.visible_serialout = false;
|
|
|
|
if ((settings.SerialOutputs !== undefined) && (settings.SerialOutputs !== null) && (settings.SerialOutputs['/dev/serialout0'] !== undefined)) {
|
|
|
|
$scope.Baud = settings.SerialOutputs['/dev/serialout0'].Baud;
|
|
|
|
$scope.visible_serialout = true;
|
|
|
|
}
|
|
|
|
$scope.UAT_Enabled = settings.UAT_Enabled;
|
|
|
|
$scope.ES_Enabled = settings.ES_Enabled;
|
|
|
|
$scope.Ping_Enabled = settings.Ping_Enabled;
|
|
|
|
$scope.GPS_Enabled = settings.GPS_Enabled;
|
2017-04-04 17:16:32 +00:00
|
|
|
|
2017-03-05 22:47:38 +00:00
|
|
|
$scope.IMU_Sensor_Enabled = settings.IMU_Sensor_Enabled;
|
|
|
|
$scope.BMP_Sensor_Enabled = settings.BMP_Sensor_Enabled;
|
2017-01-08 03:45:19 +00:00
|
|
|
$scope.DisplayTrafficSource = settings.DisplayTrafficSource;
|
|
|
|
$scope.DEBUG = settings.DEBUG;
|
|
|
|
$scope.ReplayLog = settings.ReplayLog;
|
2017-03-05 23:34:25 +00:00
|
|
|
$scope.AHRSLog = settings.AHRSLog;
|
2017-04-04 17:16:32 +00:00
|
|
|
|
2017-01-08 03:45:19 +00:00
|
|
|
$scope.PPM = settings.PPM;
|
|
|
|
$scope.WatchList = settings.WatchList;
|
2017-05-13 00:40:53 +00:00
|
|
|
$scope.AHRSSmoothingConstant = settings.AHRSSmoothingConstant;
|
|
|
|
$scope.AHRSGPSWeight = settings.AHRSGPSWeight;
|
2017-01-08 03:45:19 +00:00
|
|
|
$scope.OwnshipModeS = settings.OwnshipModeS;
|
|
|
|
$scope.DeveloperMode = settings.DeveloperMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSettings() {
|
2017-01-09 04:04:16 +00:00
|
|
|
// Simple GET request example (note: response is asynchronous)
|
2017-01-08 03:45:19 +00:00
|
|
|
$http.get(URL_SETTINGS_GET).
|
|
|
|
then(function (response) {
|
|
|
|
loadSettings(response.data);
|
|
|
|
// $scope.$apply();
|
|
|
|
}, function (response) {
|
|
|
|
$scope.rawSettings = "error getting settings";
|
|
|
|
for (i = 0; i < toggles.length; i++) {
|
|
|
|
settings[toggles[i]] = false;
|
|
|
|
}
|
|
|
|
});
|
2017-01-09 04:04:16 +00:00
|
|
|
}
|
2017-01-08 03:45:19 +00:00
|
|
|
|
|
|
|
function setSettings(msg) {
|
2017-01-09 04:04:16 +00:00
|
|
|
// Simple POST request example (note: response is asynchronous)
|
2017-01-08 03:45:19 +00:00
|
|
|
$http.post(URL_SETTINGS_SET, msg).
|
|
|
|
then(function (response) {
|
|
|
|
loadSettings(response.data);
|
|
|
|
// $scope.$apply();
|
|
|
|
}, function (response) {
|
|
|
|
$scope.rawSettings = "error setting settings";
|
|
|
|
for (i = 0; i < toggles.length; i++) {
|
|
|
|
settings[toggles[i]] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getSettings();
|
|
|
|
|
|
|
|
$scope.$watchGroup(toggles, function (newValues, oldValues, scope) {
|
2017-01-09 04:04:16 +00:00
|
|
|
var newsettings = {};
|
2017-01-08 03:45:19 +00:00
|
|
|
var dirty = false;
|
|
|
|
for (i = 0; i < newValues.length; i++) {
|
|
|
|
if ((newValues[i] !== undefined) && (settings[toggles[i]] !== undefined)) {
|
|
|
|
if (newValues[i] !== settings[toggles[i]]) {
|
|
|
|
settings[toggles[i]] = newValues[i];
|
|
|
|
newsettings[toggles[i]] = newValues[i];
|
|
|
|
dirty = true;
|
2017-01-09 04:04:16 +00:00
|
|
|
}
|
2017-01-08 03:45:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dirty) {
|
|
|
|
// console.log(angular.toJson(newsettings));
|
|
|
|
setSettings(angular.toJson(newsettings));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.updateppm = function () {
|
2017-01-09 04:04:16 +00:00
|
|
|
settings["PPM"] = 0;
|
2017-01-08 03:45:19 +00:00
|
|
|
if (($scope.PPM !== undefined) && ($scope.PPM !== null) && ($scope.PPM !== settings["PPM"])) {
|
|
|
|
settings["PPM"] = parseInt($scope.PPM);
|
|
|
|
newsettings = {
|
|
|
|
"PPM": settings["PPM"]
|
|
|
|
};
|
|
|
|
// console.log(angular.toJson(newsettings));
|
|
|
|
setSettings(angular.toJson(newsettings));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.updateBaud = function () {
|
2017-01-09 04:04:16 +00:00
|
|
|
settings["Baud"] = 0;
|
2017-01-08 03:45:19 +00:00
|
|
|
if (($scope.Baud !== undefined) && ($scope.Baud !== null) && ($scope.Baud !== settings["Baud"])) {
|
|
|
|
settings["Baud"] = parseInt($scope.Baud);
|
|
|
|
newsettings = {
|
|
|
|
"Baud": settings["Baud"]
|
|
|
|
};
|
|
|
|
// console.log(angular.toJson(newsettings));
|
|
|
|
setSettings(angular.toJson(newsettings));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-13 00:40:53 +00:00
|
|
|
$scope.updatewatchlist = function () {
|
|
|
|
if ($scope.WatchList !== settings["WatchList"]) {
|
|
|
|
settings["WatchList"] = "";
|
|
|
|
if ($scope.WatchList !== undefined) {
|
|
|
|
settings["WatchList"] = $scope.WatchList.toUpperCase();
|
|
|
|
}
|
|
|
|
newsettings = {
|
|
|
|
"WatchList": settings["WatchList"]
|
|
|
|
};
|
|
|
|
// console.log(angular.toJson(newsettings));
|
|
|
|
setSettings(angular.toJson(newsettings));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.updateAHRSSmoothingConst = function () {
|
|
|
|
if ($scope.AHRSSmoothingConstant !== settings["AHRSSmoothingConstant"]) {
|
|
|
|
settings["AHRSSmoothingConstant"] = "0.8";
|
|
|
|
if ($scope.AHRSSmoothingConstant!== undefined) {
|
|
|
|
settings["AHRSSmoothingConstant"] = parseFloat($scope.AHRSSmoothingConstant);
|
|
|
|
}
|
|
|
|
newsettings = {
|
|
|
|
"AHRSSmoothingConstant": settings["AHRSSmoothingConstant"]
|
|
|
|
};
|
|
|
|
// console.log(angular.toJson(newsettings));
|
|
|
|
setSettings(angular.toJson(newsettings));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.updateAHRSGPSWeight = function () {
|
|
|
|
if ($scope.AHRSGPSWeight !== settings["AHRSGPSWeight"]) {
|
|
|
|
settings["AHRSGPSWeight"] = "0.05";
|
|
|
|
if ($scope.AHRSGPSWeight!== undefined) {
|
|
|
|
settings["AHRSGPSWeight"] = parseFloat($scope.AHRSGPSWeight);
|
2017-01-08 03:45:19 +00:00
|
|
|
}
|
|
|
|
newsettings = {
|
2017-05-13 00:40:53 +00:00
|
|
|
"AHRSGPSWeight": settings["AHRSGPSWeight"]
|
2017-01-08 03:45:19 +00:00
|
|
|
};
|
|
|
|
// console.log(angular.toJson(newsettings));
|
|
|
|
setSettings(angular.toJson(newsettings));
|
|
|
|
}
|
|
|
|
};
|
2017-01-09 04:04:16 +00:00
|
|
|
|
2017-01-08 03:45:19 +00:00
|
|
|
$scope.updatemodes = function () {
|
|
|
|
if ($scope.OwnshipModeS !== settings["OwnshipModeS"]) {
|
|
|
|
settings["OwnshipModeS"] = $scope.OwnshipModeS.toUpperCase();
|
|
|
|
newsettings = {
|
|
|
|
"OwnshipModeS": $scope.OwnshipModeS.toUpperCase()
|
|
|
|
};
|
|
|
|
// console.log(angular.toJson(newsettings));
|
|
|
|
setSettings(angular.toJson(newsettings));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-25 07:03:56 +00:00
|
|
|
$scope.updatestaticips = function () {
|
|
|
|
if ($scope.StaticIps !== settings.StaticIps) {
|
|
|
|
newsettings = {
|
|
|
|
"StaticIps": $scope.StaticIps === undefined? "" : $scope.StaticIps.join(' ')
|
|
|
|
};
|
|
|
|
// console.log(angular.toJson(newsettings));
|
|
|
|
setSettings(angular.toJson(newsettings));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-04 17:16:32 +00:00
|
|
|
|
2017-01-08 03:45:19 +00:00
|
|
|
$scope.postShutdown = function () {
|
|
|
|
$window.location.href = "/";
|
|
|
|
$location.path('/home');
|
|
|
|
$http.post(URL_SHUTDOWN).
|
|
|
|
then(function (response) {
|
|
|
|
// do nothing
|
|
|
|
// $scope.$apply();
|
|
|
|
}, function (response) {
|
|
|
|
// do nothing
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.postReboot = function () {
|
|
|
|
$window.location.href = "/";
|
|
|
|
$location.path('/home');
|
|
|
|
$http.post(URL_REBOOT).
|
|
|
|
then(function (response) {
|
|
|
|
// do nothing
|
|
|
|
// $scope.$apply();
|
|
|
|
}, function (response) {
|
|
|
|
// do nothing
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.setUploadFile = function (files) {
|
|
|
|
$scope.update_files = files;
|
|
|
|
$scope.$apply();
|
2017-01-09 04:04:16 +00:00
|
|
|
};
|
2017-01-08 03:45:19 +00:00
|
|
|
$scope.resetUploadFile = function () {
|
|
|
|
$scope.update_files = '';
|
|
|
|
$scope.$apply();
|
2017-01-09 04:04:16 +00:00
|
|
|
};
|
2017-01-08 03:45:19 +00:00
|
|
|
$scope.uploadFile = function () {
|
|
|
|
var fd = new FormData();
|
|
|
|
//Take the first selected file
|
|
|
|
var file = $scope.update_files[0];
|
|
|
|
// check for empty string
|
|
|
|
if (file === undefined || file === null) {
|
2017-01-09 04:04:16 +00:00
|
|
|
alert ("update file not selected");
|
2017-01-08 03:45:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var filename = file.name;
|
|
|
|
// check for expected file naming convention
|
|
|
|
var re = /^update.*\.sh$/;
|
|
|
|
if (!re.exec(filename)) {
|
2017-01-09 04:04:16 +00:00
|
|
|
alert ("file does not appear to be an update");
|
2017-01-08 03:45:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd.append("update_file", file);
|
|
|
|
|
|
|
|
$http.post(URL_UPDATE_UPLOAD, fd, {
|
|
|
|
withCredentials: true,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': undefined
|
|
|
|
},
|
|
|
|
transformRequest: angular.identity
|
|
|
|
}).success(function (data) {
|
|
|
|
alert("success. wait 60 seconds and refresh home page to verify new version.");
|
|
|
|
window.location.replace("/");
|
|
|
|
}).error(function (data) {
|
|
|
|
alert("error");
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
2017-01-09 04:04:16 +00:00
|
|
|
|
|
|
|
$scope.setOrientation = function(action) {
|
2017-04-04 17:16:32 +00:00
|
|
|
console.log("sending " + action + " message.");
|
2017-01-09 04:04:16 +00:00
|
|
|
$http.post(URL_AHRS_ORIENT, action).
|
|
|
|
then(function (response) {
|
|
|
|
console.log("sent " + action + " message.");
|
|
|
|
}, function(response) {
|
|
|
|
// failure: cancel the calibration
|
2017-04-04 17:16:32 +00:00
|
|
|
console.log(response.data);
|
|
|
|
$scope.Orientation_Failure_Message = response.data;
|
2017-01-09 04:04:16 +00:00
|
|
|
switch (action) {
|
|
|
|
case "forward":
|
|
|
|
$scope.Ui.turnOff("modalCalibrateUp");
|
|
|
|
break;
|
|
|
|
case "up":
|
|
|
|
$scope.Ui.turnOff('modalCalibrateDone');
|
|
|
|
}
|
2017-04-04 17:16:32 +00:00
|
|
|
$scope.Ui.turnOn("modalCalibrateFailed");
|
2017-01-09 04:04:16 +00:00
|
|
|
});
|
|
|
|
};
|
2017-04-04 17:16:32 +00:00
|
|
|
}
|