|
@@ -55,6 +55,9 @@ var configuratorApp = (function(){
|
55
|
55
|
// private variables and functions go here
|
56
|
56
|
var self,
|
57
|
57
|
pi2 = Math.PI * 2,
|
|
58
|
+ boards_file = 'boards.h',
|
|
59
|
+ config_file = 'Configuration.h',
|
|
60
|
+ config_adv_file = 'Configuration_adv.h',
|
58
|
61
|
$config = $('#config_text'),
|
59
|
62
|
$config_adv = $('#config_adv_text'),
|
60
|
63
|
boards_list = {},
|
|
@@ -67,37 +70,106 @@ var configuratorApp = (function(){
|
67
|
70
|
init: function() {
|
68
|
71
|
self = this; // a 'this' for use when 'this' is something else
|
69
|
72
|
|
|
73
|
+ // Make a droppable file uploader
|
|
74
|
+ var $uploader = $('#file-upload');
|
|
75
|
+ var fileUploader = new BinaryFileUploader({
|
|
76
|
+ element: $uploader[0],
|
|
77
|
+ onFileLoad: function(file) { console.log(this); self.handleFileLoad(file, $uploader); }
|
|
78
|
+ });
|
|
79
|
+
|
|
80
|
+ if (!fileUploader.hasFileUploaderSupport()) alert('Your browser doesn\'t support the file reading API');
|
|
81
|
+
|
70
|
82
|
// Read boards.h
|
71
|
83
|
boards_list = {};
|
72
|
|
- $.get(marlin_config + "/boards.h", function(txt) {
|
73
|
|
- // Get all the boards and save them into an object
|
74
|
|
- var r, findDef = new RegExp('[ \\t]*#define[ \\t]+(BOARD_[^ \\t]+)[ \\t]+(\\d+)[ \\t]*(//[ \\t]*)?(.+)?', 'gm');
|
75
|
|
- while((r = findDef.exec(txt)) !== null) {
|
76
|
|
- boards_list[r[1]] = r[2].prePad(3, ' ') + " — " + r[4].replace(/\).*/, ')');
|
77
|
|
- }
|
|
84
|
+
|
|
85
|
+ var errFunc = function(jqXHR, textStatus, errorThrown) {
|
|
86
|
+ alert('Failed to load '+this.url+'. Try the file field.');
|
|
87
|
+ };
|
|
88
|
+
|
|
89
|
+ $.ajax({
|
|
90
|
+ url: marlin_config+'/'+boards_file,
|
|
91
|
+ type: 'GET',
|
|
92
|
+ async: false,
|
|
93
|
+ cache: false,
|
|
94
|
+ success: function(txt) {
|
|
95
|
+ // Get all the boards and save them into an object
|
|
96
|
+ self.initBoardsFromText(txt);
|
|
97
|
+ },
|
|
98
|
+ error: errFunc
|
78
|
99
|
});
|
79
|
100
|
|
80
|
101
|
// Read Configuration.h
|
81
|
|
- $.get(marlin_config+"/Configuration.h", function(txt) {
|
82
|
|
- // File contents into the textarea
|
83
|
|
- $config.text(txt);
|
84
|
|
- // Get all the thermistors and save them into an object
|
85
|
|
- var r, s, findDef = new RegExp('(//.*\n)+\\s+(#define[ \\t]+TEMP_SENSOR_0)', 'g');
|
86
|
|
- r = findDef.exec(txt);
|
87
|
|
- findDef = new RegExp('^//[ \\t]*([-\\d]+)[ \\t]+is[ \\t]+(.*)[ \\t]*$', 'gm');
|
88
|
|
- while((s = findDef.exec(r[0])) !== null) {
|
89
|
|
- therms_list[s[1]] = s[1].prePad(4, ' ') + " — " + s[2];
|
90
|
|
- }
|
|
102
|
+ $.ajax({
|
|
103
|
+ url: marlin_config+'/'+config_file,
|
|
104
|
+ type: 'GET',
|
|
105
|
+ async: false,
|
|
106
|
+ cache: false,
|
|
107
|
+ success: function(txt) {
|
|
108
|
+ // File contents into the textarea
|
|
109
|
+ $config.text(txt);
|
|
110
|
+ self.initThermistorsFromText(txt);
|
|
111
|
+ },
|
|
112
|
+ error: errFunc
|
91
|
113
|
});
|
92
|
114
|
|
93
|
115
|
// Read Configuration.h
|
94
|
|
- $.get(marlin_config+"/Configuration_adv.h", function(txt) {
|
95
|
|
- $config_adv.text(txt);
|
96
|
|
- self.setupConfigForm();
|
|
116
|
+ $.ajax({
|
|
117
|
+ url: marlin_config+'/'+config_adv_file,
|
|
118
|
+ type: 'GET',
|
|
119
|
+ async: false,
|
|
120
|
+ cache: false,
|
|
121
|
+ success: function(txt) {
|
|
122
|
+ // File contents into the textarea
|
|
123
|
+ $config_adv.text(txt);
|
|
124
|
+ self.setupConfigForm();
|
|
125
|
+ },
|
|
126
|
+ error: errFunc
|
97
|
127
|
});
|
98
|
128
|
|
99
|
129
|
},
|
100
|
130
|
|
|
131
|
+ initBoardsFromText: function(txt) {
|
|
132
|
+ boards_list = {};
|
|
133
|
+ var r, findDef = new RegExp('[ \\t]*#define[ \\t]+(BOARD_[^ \\t]+)[ \\t]+(\\d+)[ \\t]*(//[ \\t]*)?(.+)?', 'gm');
|
|
134
|
+ while((r = findDef.exec(txt)) !== null) {
|
|
135
|
+ boards_list[r[1]] = r[2].prePad(3, ' ') + " — " + r[4].replace(/\).*/, ')');
|
|
136
|
+ }
|
|
137
|
+ },
|
|
138
|
+
|
|
139
|
+ initThermistorsFromText: function(txt) {
|
|
140
|
+ // Get all the thermistors and save them into an object
|
|
141
|
+ var r, s, findDef = new RegExp('(//.*\n)+\\s+(#define[ \\t]+TEMP_SENSOR_0)', 'g');
|
|
142
|
+ r = findDef.exec(txt);
|
|
143
|
+ findDef = new RegExp('^//[ \\t]*([-\\d]+)[ \\t]+is[ \\t]+(.*)[ \\t]*$', 'gm');
|
|
144
|
+ while((s = findDef.exec(r[0])) !== null) {
|
|
145
|
+ therms_list[s[1]] = s[1].prePad(4, ' ') + " — " + s[2];
|
|
146
|
+ }
|
|
147
|
+ },
|
|
148
|
+
|
|
149
|
+ handleFileLoad: function(file, $uploader) {
|
|
150
|
+ file += '';
|
|
151
|
+ var filename = $uploader.val().replace(/.*[\/\\](.*)$/, '$1');
|
|
152
|
+ switch(filename) {
|
|
153
|
+ case config_file:
|
|
154
|
+ $config.text(file);
|
|
155
|
+ this.initThermistorsFromText(file);
|
|
156
|
+ this.refreshConfigForm();
|
|
157
|
+ break;
|
|
158
|
+ case config_adv_file:
|
|
159
|
+ $config_adv.text(file);
|
|
160
|
+ this.refreshConfigForm();
|
|
161
|
+ break;
|
|
162
|
+ case boards_file:
|
|
163
|
+ this.initBoardsFromText(file);
|
|
164
|
+ $('#MOTHERBOARD').html('').addOptions(boards_list);
|
|
165
|
+ this.initField('MOTHERBOARD');
|
|
166
|
+ break;
|
|
167
|
+ default:
|
|
168
|
+ console.log("Can't parse "+filename);
|
|
169
|
+ break;
|
|
170
|
+ }
|
|
171
|
+ },
|
|
172
|
+
|
101
|
173
|
setupConfigForm: function() {
|
102
|
174
|
// Modify form fields and make the form responsive.
|
103
|
175
|
// As values change on the form, we could update the
|
|
@@ -128,6 +200,17 @@ var configuratorApp = (function(){
|
128
|
200
|
);
|
129
|
201
|
});
|
130
|
202
|
|
|
203
|
+ $('#SERIAL_PORT').addOptions([0,1,2,3,4,5,6,7]);
|
|
204
|
+ $('#BAUDRATE').addOptions([2400,9600,19200,38400,57600,115200,250000]);
|
|
205
|
+ $('#MOTHERBOARD').addOptions(boards_list);
|
|
206
|
+ $('#EXTRUDERS').addOptions([1,2,3,4]);
|
|
207
|
+ $('#POWER_SUPPLY').addOptions({'1':'ATX','2':'Xbox 360'});
|
|
208
|
+
|
|
209
|
+ this.refreshConfigForm();
|
|
210
|
+ },
|
|
211
|
+
|
|
212
|
+ refreshConfigForm: function() {
|
|
213
|
+
|
131
|
214
|
/**
|
132
|
215
|
* For now I'm manually creating these references
|
133
|
216
|
* but I should be able to parse Configuration.h
|
|
@@ -140,30 +223,25 @@ var configuratorApp = (function(){
|
140
|
223
|
* Then we only need to specify exceptions to
|
141
|
224
|
* standard behavior, (which is to add a text field)
|
142
|
225
|
*/
|
143
|
|
- $('#SERIAL_PORT').addOptions([0,1,2,3,4,5,6,7]);
|
144
|
226
|
this.initField('SERIAL_PORT');
|
145
|
227
|
|
146
|
|
- $('#BAUDRATE').addOptions([2400,9600,19200,38400,57600,115200,250000]);
|
147
|
228
|
this.initField('BAUDRATE');
|
148
|
229
|
|
149
|
230
|
this.initField('BTENABLED');
|
150
|
231
|
|
151
|
|
- $('#MOTHERBOARD').addOptions(boards_list);
|
152
|
232
|
this.initField('MOTHERBOARD');
|
153
|
233
|
|
154
|
234
|
this.initField('CUSTOM_MENDEL_NAME');
|
155
|
235
|
|
156
|
236
|
this.initField('MACHINE_UUID');
|
157
|
237
|
|
158
|
|
- $('#EXTRUDERS').addOptions([1,2,3,4]);
|
159
|
238
|
this.initField('EXTRUDERS');
|
160
|
239
|
|
161
|
|
- $('#POWER_SUPPLY').addOptions({'1':'ATX','2':'Xbox 360'});
|
162
|
240
|
this.initField('POWER_SUPPLY');
|
163
|
241
|
|
164
|
242
|
this.initField('PS_DEFAULT_OFF');
|
165
|
243
|
|
166
|
|
- $('#TEMP_SENSOR_0, #TEMP_SENSOR_1, #TEMP_SENSOR_2, #TEMP_SENSOR_BED').addOptions(therms_list);
|
|
244
|
+ $('#TEMP_SENSOR_0, #TEMP_SENSOR_1, #TEMP_SENSOR_2, #TEMP_SENSOR_BED').html('').addOptions(therms_list);
|
167
|
245
|
this.initField('TEMP_SENSOR_0');
|
168
|
246
|
this.initField('TEMP_SENSOR_1');
|
169
|
247
|
this.initField('TEMP_SENSOR_2');
|