Skip to content

Commit

Permalink
Temporarily disabled pin usage check in robot configurator
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarvandevelde authored and cesarvandevelde committed Sep 15, 2017
1 parent 91608e0 commit b3dba68
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
43 changes: 32 additions & 11 deletions src/opsoro/apps/robot_configurator/static/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var select_dof = function(index) {
self.name_formatted = ko.observable(virtualModel.selected_module.dofs[self.index].name_formatted);

self.pin_value = ko.observable(virtualModel.selected_module.dofs[self.index].servo.pin);
self.pin = ko.pureComputed({
self.pin = ko.computed({
read: function () {
return self.pin_value();
},
Expand All @@ -22,7 +22,7 @@ var select_dof = function(index) {
});

self.mid_value = ko.observable(virtualModel.selected_module.dofs[self.index].servo.mid);
self.mid = ko.pureComputed({
self.mid = ko.computed({
read: function () {
return self.mid_value();
},
Expand All @@ -36,7 +36,7 @@ var select_dof = function(index) {
});

self.min_value = ko.observable(virtualModel.selected_module.dofs[self.index].servo.min);
self.min = ko.pureComputed({
self.min = ko.computed({
read: function () {
return self.min_value();
},
Expand All @@ -50,7 +50,7 @@ var select_dof = function(index) {
});

self.max_value = ko.observable(virtualModel.selected_module.dofs[self.index].servo.max);
self.max = ko.pureComputed({
self.max = ko.computed({
read: function () {
return self.max_value();
},
Expand Down Expand Up @@ -111,6 +111,19 @@ var select_module = function() {

};

var PinModel = function(name, pin) {
var self = this;

self.name = name;
self.pin = pin;

self.disabled = ko.computed(function(){
// Quick fix...
// TODO: Check all modules and update accordingly
return false;
});
};

var AppModel = function() {
var self = this;
// Setup link with virtual model
Expand All @@ -127,19 +140,27 @@ var AppModel = function() {
virtualModel.change_handler = self.change_handler;

self.available_servos = ko.observableArray();
self.available_servos.push({ 'name': 'Not connected', 'pin': -1, 'class': '', 'disabled': false });
// self.available_servos.push({ 'name': 'Not connected', 'pin': -1, 'class': '', 'disabled': false });
// for (var i = 0; i < 16; i++) {
// self.available_servos.push({ 'name': 'Pin ' + i, 'pin': i, 'class': 'pin' + i, 'disabled': false });
// }
self.available_servos.push(new PinModel("Not connected", -1));
for (var i = 0; i < 16; i++) {
self.available_servos.push({ 'name': 'Pin ' + i, 'pin': i, 'class': 'pin' + i, 'disabled': false });
self.available_servos.push(new PinModel("Pin " + i, i));
}

self.servo_option_disable = function(option, item) {
ko.applyBindingsToNode(option, {disable: item ? item.disabled : false}, item);
};

self.update_servo_pins = function(old_value, new_value) {
if (new_value >= 0) {
self.available_servos()[new_value + 1]['disabled'] = true;
$('.' + self.available_servos()[new_value + 1]['class']).attr('disabled', '');
//self.available_servos()[new_value + 1]['disabled'] = true;
//$('.' + self.available_servos()[new_value + 1]['class']).attr('disabled', '');
}
if (old_value >= 0) {
self.available_servos()[old_value + 1]['disabled'] = false;
$('.' + self.available_servos()[old_value + 1]['class']).removeAttr('disabled');
//self.available_servos()[old_value + 1]['disabled'] = false;
//$('.' + self.available_servos()[old_value + 1]['class']).removeAttr('disabled');
}
};

Expand Down Expand Up @@ -177,7 +198,7 @@ var AppModel = function() {
for (var j = 0; j < mod.dofs.length; j++) {
var dof = mod.dofs[j];
if (dof.servo.pin >= 0) {
self.available_servos()[dof.servo.pin + 1].disabled = true;
//self.available_servos()[dof.servo.pin + 1].disabled = true;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@
<span data-bind="text: name"></span>
</div>
<div class="settings-item small-5 large-6 columns">
<select data-bind="value: pin, valueUpdate: 'input', foreach: $root.available_servos">
<!-- <select data-bind="value: pin, valueUpdate: 'input', foreach: $root.available_servos">
<option data-bind="text: $data.name, value: $data.pin, css: $data.class, attr: $data.disabled ? { 'disabled': '' } : { }"></option>
</select> -->
<select data-bind="
value: pin,
valueUpdate: 'input',
options: $root.available_servos,
optionsText: 'name',
optionsValue: 'pin',
optionsAfterRender: $root.servo_option_disable">
</select>
</div>
</div>
Expand Down

0 comments on commit b3dba68

Please sign in to comment.