Selaa lähdekoodia

Config sections, multi-field values, toggles, etc

- Auto-detect “switchable” items where possible
- Handle switchable multi-value fields
- Add standard sections to config form
- Add section markers to configurations
- Add value options to configurations
- Remove and re-add fields for loaded configs
- Preserve sections across configs
- Preserve non-added fields
- Style added fields wider & newline by default
Scott Lahteine 10 vuotta sitten
vanhempi
commit
83cb702e72

+ 48
- 0
Marlin/configurator/config/Configuration.h Näytä tiedosto

@@ -35,6 +35,8 @@ Here are some standard links for getting your machine calibrated:
35 35
 // example_configurations/SCARA directory.
36 36
 //
37 37
 
38
+// @section info
39
+
38 40
 // User-specified version info of this build to display in [Pronterface, etc] terminal window during
39 41
 // startup. Implementation of an idea by Prof Braino to inform user that any changes made to this
40 42
 // build by the user have been successfully uploaded into firmware.
@@ -45,6 +47,8 @@ Here are some standard links for getting your machine calibrated:
45 47
 #define STRING_SPLASH_LINE1 "v" STRING_VERSION // will be shown during bootup in line 1
46 48
 //#define STRING_SPLASH_LINE2 STRING_VERSION_CONFIG_H // will be shown during bootup in line2
47 49
 
50
+// @section machine
51
+
48 52
 // SERIAL_PORT selects which serial port should be used for communication with the host.
49 53
 // This allows the connection of wireless adapters (for instance) to non-default port pins.
50 54
 // Serial port 0 is still used by the Arduino bootloader regardless of this setting.
@@ -84,6 +88,8 @@ Here are some standard links for getting your machine calibrated:
84 88
 // Define this to have the electronics keep the power supply off on startup. If you don't know what this is leave it.
85 89
 // #define PS_DEFAULT_OFF
86 90
 
91
+// @section temperature
92
+
87 93
 //===========================================================================
88 94
 //============================= Thermal Settings ============================
89 95
 //===========================================================================
@@ -237,6 +243,7 @@ Here are some standard links for getting your machine calibrated:
237 243
 // FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles.
238 244
 #endif // PIDTEMPBED
239 245
 
246
+// @section extruder
240 247
 
241 248
 //this prevents dangerous Extruder moves, i.e. if the temperature is under the limit
242 249
 //can be software-disabled for whatever purposes by
@@ -291,9 +298,13 @@ your extruder heater takes 2 minutes to hit the target on heating.
291 298
 //============================= Mechanical Settings =========================
292 299
 //===========================================================================
293 300
 
301
+// @section machine
302
+
294 303
 // Uncomment the following line to enable CoreXY kinematics
295 304
 // #define COREXY
296 305
 
306
+// @section homing
307
+
297 308
 // coarse Endstop Settings
298 309
 #define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
299 310
 
@@ -326,33 +337,51 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
326 337
 //#define DISABLE_MAX_ENDSTOPS
327 338
 //#define DISABLE_MIN_ENDSTOPS
328 339
 
340
+// @section hidden
341
+
329 342
 // Disable max endstops for compatibility with endstop checking routine
330 343
 #if defined(COREXY) && !defined(DISABLE_MAX_ENDSTOPS)
331 344
   #define DISABLE_MAX_ENDSTOPS
332 345
 #endif
333 346
 
347
+// @section homing
348
+
334 349
 // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
350
+// :[0,1]
335 351
 #define X_ENABLE_ON 0
336 352
 #define Y_ENABLE_ON 0
337 353
 #define Z_ENABLE_ON 0
338 354
 #define E_ENABLE_ON 0 // For all extruders
339 355
 
356
+// @section machine
357
+
340 358
 // Disables axis when it's not being used.
341 359
 #define DISABLE_X false
342 360
 #define DISABLE_Y false
343 361
 #define DISABLE_Z false
362
+
363
+// @section extruder
364
+
344 365
 #define DISABLE_E false // For all extruders
345 366
 #define DISABLE_INACTIVE_EXTRUDER true //disable only inactive extruders and keep active extruder enabled
346 367
 
368
+// @section machine
369
+
347 370
 #define INVERT_X_DIR true    // for Mendel set to false, for Orca set to true
348 371
 #define INVERT_Y_DIR false    // for Mendel set to true, for Orca set to false
349 372
 #define INVERT_Z_DIR true     // for Mendel set to false, for Orca set to true
373
+
374
+// @section extruder
375
+
350 376
 #define INVERT_E0_DIR false   // for direct drive extruder v9 set to true, for geared extruder set to false
351 377
 #define INVERT_E1_DIR false    // for direct drive extruder v9 set to true, for geared extruder set to false
352 378
 #define INVERT_E2_DIR false   // for direct drive extruder v9 set to true, for geared extruder set to false
353 379
 
380
+// @section homing
381
+
354 382
 // ENDSTOP SETTINGS:
355 383
 // Sets direction of endstops when homing; 1=MAX, -1=MIN
384
+// :[-1,1]
356 385
 #define X_HOME_DIR -1
357 386
 #define Y_HOME_DIR -1
358 387
 #define Z_HOME_DIR -1
@@ -360,6 +389,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
360 389
 #define min_software_endstops true // If true, axis won't move to coordinates less than HOME_POS.
361 390
 #define max_software_endstops true  // If true, axis won't move to coordinates greater than the defined lengths below.
362 391
 
392
+// @section machine
393
+
363 394
 // Travel limits after homing (units are in mm)
364 395
 #define X_MAX_POS 205
365 396
 #define X_MIN_POS 0
@@ -368,6 +399,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
368 399
 #define Z_MAX_POS 200
369 400
 #define Z_MIN_POS 0
370 401
 
402
+// @section hidden
403
+
371 404
 #define X_MAX_LENGTH (X_MAX_POS - X_MIN_POS)
372 405
 #define Y_MAX_LENGTH (Y_MAX_POS - Y_MIN_POS)
373 406
 #define Z_MAX_LENGTH (Z_MAX_POS - Z_MIN_POS)
@@ -377,6 +410,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
377 410
 //============================= Bed Auto Leveling ===========================
378 411
 //===========================================================================
379 412
 
413
+// @section bedlevel
414
+
380 415
 //#define ENABLE_AUTO_BED_LEVELING // Delete the comment to enable (remove // at the start of the line)
381 416
 #define Z_PROBE_REPEATABILITY_TEST  // If not commented out, Z-Probe Repeatability test will be included if Auto Bed Leveling is Enabled.
382 417
 
@@ -493,6 +528,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
493 528
 #endif // ENABLE_AUTO_BED_LEVELING
494 529
 
495 530
 
531
+// @section homing
532
+
496 533
 // The position of the homing switches
497 534
 //#define MANUAL_HOME_POSITIONS  // If defined, MANUAL_*_HOME_POS below will be used
498 535
 //#define BED_CENTER_AT_0_0  // If defined, the center of the bed is at (X=0, Y=0)
@@ -504,6 +541,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
504 541
 #define MANUAL_Z_HOME_POS 0
505 542
 //#define MANUAL_Z_HOME_POS 402 // For delta: Distance between nozzle and print surface after homing.
506 543
 
544
+// @section movement
545
+
507 546
 //// MOVEMENT SETTINGS
508 547
 #define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E
509 548
 #define HOMING_FEEDRATE {50*60, 50*60, 4*60, 0}  // set the homing speeds (mm/min)
@@ -533,6 +572,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
533 572
 //============================= Additional Features ===========================
534 573
 //=============================================================================
535 574
 
575
+// @section more
576
+
536 577
 // Custom M code points
537 578
 #define CUSTOM_M_CODES
538 579
 #ifdef CUSTOM_M_CODES
@@ -541,6 +582,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
541 582
   #define Z_PROBE_OFFSET_RANGE_MAX -5
542 583
 #endif
543 584
 
585
+// @section extras
544 586
 
545 587
 // EEPROM
546 588
 // The microcontroller can store settings in the EEPROM, e.g. max velocity...
@@ -553,6 +595,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
553 595
 // please keep turned on if you can.
554 596
 //#define EEPROM_CHITCHAT
555 597
 
598
+// @section temperature
599
+
556 600
 // Preheat Constants
557 601
 #define PLA_PREHEAT_HOTEND_TEMP 180
558 602
 #define PLA_PREHEAT_HPB_TEMP 70
@@ -562,6 +606,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
562 606
 #define ABS_PREHEAT_HPB_TEMP 100
563 607
 #define ABS_PREHEAT_FAN_SPEED 255   // Insert Value between 0 and 255
564 608
 
609
+// @section lcd
610
+
565 611
 //LCD and SD support
566 612
 
567 613
 // Character based displays can have different extended charsets.
@@ -738,6 +784,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
738 784
 # endif
739 785
 #endif
740 786
 
787
+// @section extras
788
+
741 789
 // Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino
742 790
 //#define FAST_PWM_FAN
743 791
 

+ 35
- 1
Marlin/configurator/config/Configuration_adv.h Näytä tiedosto

@@ -1,6 +1,8 @@
1 1
 #ifndef CONFIGURATION_ADV_H
2 2
 #define CONFIGURATION_ADV_H
3 3
 
4
+// @section temperature
5
+
4 6
 //===========================================================================
5 7
 //=============================Thermal Settings  ============================
6 8
 //===========================================================================
@@ -44,6 +46,8 @@
44 46
 //The M105 command return, besides traditional information, the ADC value read from temperature sensors.
45 47
 //#define SHOW_TEMP_ADC_VALUES
46 48
 
49
+// @section extruder
50
+
47 51
 //  extruder run-out prevention.
48 52
 //if the machine is idle, and the temperature over MINTEMP, every couple of SECONDS some filament is extruded
49 53
 //#define EXTRUDER_RUNOUT_PREVENT
@@ -53,6 +57,8 @@
53 57
 #define EXTRUDER_RUNOUT_SPEED 1500.  //extrusion speed
54 58
 #define EXTRUDER_RUNOUT_EXTRUDE 100
55 59
 
60
+// @section temperature
61
+
56 62
 //These defines help to calibrate the AD595 sensor in case you get wrong temperature measurements.
57 63
 //The measured temperature is defined as "actualTemp = (measuredTemp * TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET"
58 64
 #define TEMP_SENSOR_AD595_OFFSET 0.0
@@ -70,6 +76,8 @@
70 76
 // before setting a PWM value. (Does not work with software PWM for fan on Sanguinololu)
71 77
 //#define FAN_KICKSTART_TIME 100
72 78
 
79
+// @section extruder
80
+
73 81
 // Extruder cooling fans
74 82
 // Configure fan pin outputs to automatically turn on/off when the associated
75 83
 // extruder temperature is above/below EXTRUDER_AUTO_FAN_TEMPERATURE.
@@ -87,6 +95,8 @@
87 95
 //=============================Mechanical Settings===========================
88 96
 //===========================================================================
89 97
 
98
+// @section machine
99
+
90 100
 #define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing
91 101
 
92 102
 
@@ -210,12 +220,16 @@
210 220
 
211 221
 #endif //DUAL_X_CARRIAGE
212 222
 
223
+// @section homing
224
+
213 225
 //homing hits the endstop, then retracts by this distance, before it tries to slowly bump again:
214 226
 #define X_HOME_RETRACT_MM 5
215 227
 #define Y_HOME_RETRACT_MM 5
216 228
 #define Z_HOME_RETRACT_MM 2
217 229
 //#define QUICK_HOME  //if this is defined, if both x and y are to be homed, a diagonal move will be performed initially.
218 230
 
231
+// @section machine
232
+
219 233
 #define AXIS_RELATIVE_MODES {false, false, false, false}
220 234
 #ifdef CONFIG_STEPPERS_TOSHIBA
221 235
 #define MAX_STEP_FREQUENCY 10000 // Max step frequency for Toshiba Stepper Controllers
@@ -228,12 +242,14 @@
228 242
 #define INVERT_Z_STEP_PIN false
229 243
 #define INVERT_E_STEP_PIN false
230 244
 
231
-//default stepper release if idle
245
+//default stepper release if idle. Set to 0 to deactivate.
232 246
 #define DEFAULT_STEPPER_DEACTIVE_TIME 60
233 247
 
234 248
 #define DEFAULT_MINIMUMFEEDRATE       0.0     // minimum feedrate
235 249
 #define DEFAULT_MINTRAVELFEEDRATE     0.0
236 250
 
251
+// @section lcd
252
+
237 253
 // Feedrates for manual moves along X, Y, Z, E from panel
238 254
 #ifdef ULTIPANEL
239 255
 #define MANUAL_FEEDRATE {50*60, 50*60, 4*60, 60}  // set the speeds for manual moves (mm/min)
@@ -244,6 +260,8 @@
244 260
     #define ULTIPANEL_FEEDMULTIPLY
245 261
 #endif
246 262
 
263
+// @section extras
264
+
247 265
 // minimum time in microseconds that a movement needs to take if the buffer is emptied.
248 266
 #define DEFAULT_MINSEGMENTTIME        20000
249 267
 
@@ -287,6 +305,8 @@
287 305
 //#define CHDK 4        //Pin for triggering CHDK to take a picture see how to use it here http://captain-slow.dk/2014/03/09/3d-printing-timelapses/
288 306
 #define CHDK_DELAY 50 //How long in ms the pin should stay HIGH before going LOW again
289 307
 
308
+// @section lcd
309
+
290 310
 #define SD_FINISHED_STEPPERRELEASE true  //if sd support and the file is finished: disable steppers?
291 311
 #define SD_FINISHED_RELEASECOMMAND "M84 X Y Z E" // You might want to keep the z enabled so your bed stays in place.
292 312
 
@@ -315,6 +335,8 @@
315 335
   #endif
316 336
 #endif
317 337
 
338
+// @section more
339
+
318 340
 // The hardware watchdog should reset the microcontroller disabling all outputs, in case the firmware gets stuck and doesn't do temperature regulation.
319 341
 //#define USE_WATCHDOG
320 342
 
@@ -373,12 +395,16 @@
373 395
 
374 396
 const unsigned int dropsegments=5; //everything with less than this number of steps will be ignored as move and joined with the next movement
375 397
 
398
+// @section lcd
399
+
376 400
 // If you are using a RAMPS board or cheap E-bay purchased boards that do not detect when an SD card is inserted
377 401
 // You can get round this by connecting a push button or single throw switch to the pin defined as SDCARDCARDDETECT
378 402
 // in the pins.h file.  When using a push button pulling the pin to ground this will need inverted.  This setting should
379 403
 // be commented out otherwise
380 404
 #define SDCARDDETECTINVERTED
381 405
 
406
+// @section hidden
407
+
382 408
 #ifdef ULTIPANEL
383 409
  #undef SDCARDDETECTINVERTED
384 410
 #endif
@@ -399,6 +425,8 @@ const unsigned int dropsegments=5; //everything with less than this number of st
399 425
   #define PS_ON_ASLEEP LOW
400 426
 #endif
401 427
 
428
+// @section temperature
429
+
402 430
 // Control heater 0 and heater 1 in parallel.
403 431
 //#define HEATERS_PARALLEL
404 432
 
@@ -406,6 +434,8 @@ const unsigned int dropsegments=5; //everything with less than this number of st
406 434
 //=============================Buffers           ============================
407 435
 //===========================================================================
408 436
 
437
+// @section hidden
438
+
409 439
 // The number of linear motions that can be in the plan at any give time.
410 440
 // THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, i.g. 8,16,32 because shifts and ors are used to do the ring-buffering.
411 441
 #if defined SDSUPPORT
@@ -414,11 +444,13 @@ const unsigned int dropsegments=5; //everything with less than this number of st
414 444
   #define BLOCK_BUFFER_SIZE 16 // maximize block buffer
415 445
 #endif
416 446
 
447
+// @section more
417 448
 
418 449
 //The ASCII buffer for receiving from the serial:
419 450
 #define MAX_CMD_SIZE 96
420 451
 #define BUFSIZE 4
421 452
 
453
+// @section extras
422 454
 
423 455
 // Firmware based and LCD controlled retract
424 456
 // M207 and M208 can be used to define parameters for the retraction.
@@ -460,6 +492,8 @@ const unsigned int dropsegments=5; //everything with less than this number of st
460 492
 //=============================  Define Defines  ============================
461 493
 //===========================================================================
462 494
 
495
+// @section hidden
496
+
463 497
 #if defined (ENABLE_AUTO_BED_LEVELING) && defined (DELTA)
464 498
   #error "Bed Auto Leveling is still not compatible with Delta Kinematics."
465 499
 #endif

+ 23
- 9
Marlin/configurator/css/configurator.css Näytä tiedosto

@@ -45,7 +45,9 @@ p.info span { color: #800; }
45 45
 #message p.message { color: #080; background: #CFC; }
46 46
 #message p.error { color: #F00; background: #FF4; }
47 47
 #message p.warning { color: #FF0; background: #BA4; }
48
-#message p.message span {
48
+#message p.message span,
49
+#message p.error span,
50
+#message p.warning span {
49 51
 	color: #A00;
50 52
 	background: rgba(255, 255, 255, 1);
51 53
 	border: 1px solid rgba(0,0,0,0.5);
@@ -89,21 +91,22 @@ label {
89 91
 	}
90 92
 input[type="text"], select { margin: 0.75em 0 0; }
91 93
 input[type="checkbox"], input[type="radio"], input[type="file"] { margin: 1em 0 0; }
92
-input[type="checkbox"], input[type="radio"].enabler { margin-left: 1em; }
94
+input[type="checkbox"].enabler, input[type="radio"].enabler { margin-left: 1em; }
93 95
 
94 96
 input:disabled { color: #BBB; }
95 97
 
96
-#more input[type="text"] { width: 20em; }
98
+#config_form input[type="text"].subitem { width: 4em; }
99
+#config_form input[type="text"].subitem+.subitem { margin-left: 4px; }
97 100
 
98
-#more label {
99
-	width: 240px; /* label area */
101
+input[type="text"].added { width: 20em; }
102
+label.added {
103
+	width: 275px; /* label area */
100 104
 	height: 1em;
101 105
 	padding: 10px 360px 10px 1em;
102 106
 	margin-right: -350px;
103 107
 	text-align: right;
104 108
 	}
105 109
 
106
-
107 110
 ul.tabs { padding: 0; list-style: none; }
108 111
 ul.tabs li { display: inline; }
109 112
 ul.tabs li a,
@@ -192,8 +195,19 @@ fieldset legend { display: none; }
192 195
 
193 196
 /* Tooltips Checkbox */
194 197
 
195
-#tipson { float: right; font-weight: bold; font-size: 100%; font-family: helvetica; }
196
-#tipson input { float: none; display: inline; }
198
+#tipson {
199
+	width: auto;
200
+	height: auto;
201
+	padding: 0;
202
+	margin-right: 0;
203
+	float: right;
204
+	font-weight: bold;
205
+	font-size: 100%;
206
+	font-family: helvetica;
207
+	text-align: left;
208
+	cursor: pointer;
209
+	}
210
+#tipson input { float: none; display: inline; cursor: pointer; }
197 211
 
198 212
 /* Config Text */
199 213
 
@@ -206,7 +220,7 @@ pre.config {
206 220
 	clear: both;
207 221
 	background-color: #FFF;
208 222
 	color: #000;
209
-	font-family: "Fira Mono";
223
+	font-family: "Fira Mono", monospace;
210 224
 	font-size: small;
211 225
 	}
212 226
 

+ 19
- 7
Marlin/configurator/index.html Näytä tiedosto

@@ -25,7 +25,7 @@
25 25
         <div id="tooltip"></div>
26 26
 
27 27
         <label>Drop Files Here:</label><input type="file" id="file-upload" />
28
-        <div id="tipson"><input type="checkbox" checked /> ?</div>
28
+        <label id="tipson"><input type="checkbox" checked /> ?</label>
29 29
         <br class="clear" />
30 30
 
31 31
         <fieldset id="machine">
@@ -40,9 +40,9 @@
40 40
 
41 41
           <label class="newline">Motherboard:</label><select name="MOTHERBOARD"></select>
42 42
 
43
-          <label class="newline">Custom Name:</label><input name="CUSTOM_MENDEL_NAME" class="switchable" type="text" size="14" maxlength="12" value="" />
43
+          <label class="newline">Custom Name:</label><input name="CUSTOM_MENDEL_NAME" type="text" size="14" maxlength="12" value="" />
44 44
 
45
-          <label class="newline">Machine UUID:</label><input name="MACHINE_UUID" class="switchable" type="text" size="38" maxlength="36" value="" />
45
+          <label class="newline">Machine UUID:</label><input name="MACHINE_UUID" type="text" size="38" maxlength="36" value="" />
46 46
 
47 47
           <label class="newline">Extruders:</label><select name="EXTRUDERS"></select>
48 48
 
@@ -52,6 +52,10 @@
52 52
             <input name="PS_DEFAULT_OFF" type="checkbox" value="1" checked />
53 53
         </fieldset>
54 54
 
55
+        <fieldset id="homing">
56
+          <legend>Homing</legend>
57
+        </fieldset>
58
+
55 59
         <fieldset id="temperature">
56 60
           <legend>Temperature</legend>
57 61
           <label class="newline">Temp Sensor 0:</label><select name="TEMP_SENSOR_0"></select>
@@ -69,12 +73,20 @@
69 73
             <input name="TEMP_RESIDENCY_TIME" type="text" size="3" maxlength="2" />
70 74
         </fieldset>
71 75
 
72
-        <fieldset id="hotends">
73
-          <legend>Hot Ends</legend>
76
+        <fieldset id="extruder">
77
+          <legend>Extruder</legend>
78
+        </fieldset>
79
+
80
+        <fieldset id="lcd">
81
+          <legend>LCD / SD</legend>
82
+        </fieldset>
83
+
84
+        <fieldset id="bedlevel">
85
+          <legend>Bed Leveling</legend>
74 86
         </fieldset>
75 87
 
76
-        <fieldset id="heatbed">
77
-          <legend>Heated Bed</legend>
88
+        <fieldset id="extras">
89
+          <legend>Extras</legend>
78 90
         </fieldset>
79 91
 
80 92
         <fieldset id="more">

+ 177
- 76
Marlin/configurator/js/configurator.js Näytä tiedosto

@@ -143,6 +143,7 @@ var configuratorApp = (function(){
143 143
       $config = $('#config_text pre'),
144 144
       $config_adv = $('#config_adv_text pre'),
145 145
       define_list = [[],[]],
146
+      define_section = {},
146 147
       boards_list = {},
147 148
       therms_list = {},
148 149
       total_config_lines,
@@ -308,16 +309,21 @@ var configuratorApp = (function(){
308 309
     /**
309 310
      * Get all the unique define names
310 311
      */
311
-    getDefinesFromText: function(txt) {
312
-      var leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H', 'STRING_VERSION', 'STRING_URL', 'STRING_VERSION_CONFIG_H', 'STRING_CONFIG_H_AUTHOR', 'STRING_SPLASH_LINE1', 'STRING_SPLASH_LINE2'];
313
-      // Get all the unique #define's and save them in an array
314
-      var r, define_obj = {}, findDef = new RegExp('#define[ \\t]+(\\w+)', 'gm');
312
+    updateDefinesFromText: function(index, txt) {
313
+      var section = 'machine',
314
+          leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H', 'STRING_VERSION', 'STRING_URL', 'STRING_VERSION_CONFIG_H', 'STRING_CONFIG_H_AUTHOR', 'STRING_SPLASH_LINE1', 'STRING_SPLASH_LINE2'],
315
+          define_sect = {},
316
+          r, findDef = new RegExp('(@section|#define)[ \\t]+(\\w+)', 'gm');
315 317
       while((r = findDef.exec(txt)) !== null) {
316
-        if ($.inArray(r[1], leave_out_defines) < 0 && !(r[1] in define_obj))
317
-          define_obj[r[1]] = null;
318
+        var name = r[2];
319
+        if (r[1] == '@section')
320
+          section = name;
321
+        else if ($.inArray(name, leave_out_defines) < 0 && !(name in define_sect))
322
+          define_sect[name] = section;
318 323
       }
319
-      this.log(Object.keys(define_obj), 2);
320
-      return Object.keys(define_obj);
324
+      define_list[index] = Object.keys(define_sect);
325
+      $.extend(define_section, define_sect);
326
+      this.log(define_list[index], 2);
321 327
     },
322 328
 
323 329
     /**
@@ -327,24 +333,48 @@ var configuratorApp = (function(){
327 333
       var e = adv ? 1 : 0, n = 0;
328 334
       var fail_list = [];
329 335
       $.each(define_list[e], function(i,name) {
330
-        if (!$('#'+name).length) {
331
-          var $ff = $('#more'),
332
-              inf = self.getDefineInfo(name, adv);
336
+        var section = define_section[name];
337
+        if (section != 'hidden' && !$('#'+name).length) {
338
+          var inf = self.getDefineInfo(name, adv);
339
+
333 340
           if (inf) {
334
-            var $newlabel = $('<label>',{for:name}).text(name.toLabel());
341
+
342
+            var $ff = $('#'+section), $newfield,
343
+                $newlabel = $('<label>',{for:name,class:'added'}).text(name.toLabel());
344
+
335 345
             // if (!(++n % 3))
336 346
               $newlabel.addClass('newline');
337 347
 
338
-            var $newfield;
339
-            if (inf.options !== undefined) {
340
-              $newfield = $('<select>'); //.addOptions(inf.options);
348
+            $ff.append($newlabel);
349
+
350
+            // Multiple fields?
351
+            if (inf.type == 'list') {
352
+              for (var i=0; i<inf.size; i++) {
353
+                var fieldname = i > 0 ? name+'-'+i : name;
354
+                $newfield = $('<input>',{type:'text',size:6,maxlength:10,id:fieldname,name:fieldname,class:'subitem added'}).prop({defineInfo:inf});
355
+                $ff.append($newfield);
356
+              }
341 357
             }
342 358
             else {
343
-              $newfield = inf.type == 'switch' ? $('<input>',{type:'checkbox'}) : $('<input>',{type:'text',size:10,maxlength:40});
359
+              // Items with options, either toggle or select
360
+              // TODO: Radio buttons for other values
361
+              if (inf.options !== undefined) {
362
+                if (inf.type == 'toggle') {
363
+                  $newfield = $('<input>',{type:'checkbox'});
364
+                }
365
+                else {
366
+                  // Otherwise selectable
367
+                  $newfield = $('<select>');
368
+                }
369
+                // ...Options added when field initialized
370
+              }
371
+              else {
372
+                $newfield = inf.type == 'switch' ? $('<input>',{type:'checkbox'}) : $('<input>',{type:'text',size:10,maxlength:40});
373
+              }
374
+              $newfield.attr({id:name,name:name,class:'added'}).prop({defineInfo:inf});
375
+              // Add the new field to the form
376
+              $ff.append($newfield);
344 377
             }
345
-            $newfield.attr({id:name,name:name}).prop({defineInfo:inf});
346
-            // Add the new field to the form
347
-            $ff.append($newlabel, $newfield);
348 378
           }
349 379
           else
350 380
             fail_list.push(name);
@@ -410,10 +440,9 @@ var configuratorApp = (function(){
410 440
       // When a config file loads defines might change
411 441
       if (init_index != null) {
412 442
         var adv = init_index == 1;
413
-        define_list[init_index] = this.getDefinesFromText(txt);
414
-        this.log(define_list[init_index], 2);
415
-        this.purgeDefineInfo(adv);
416
-        this.createFieldsForDefines(init_index);
443
+        this.purgeAddedFields(init_index);
444
+        this.updateDefinesFromText(init_index, txt);
445
+        this.createFieldsForDefines(adv);
417 446
         this.refreshConfigForm(init_index);
418 447
         this.activateDownloadLink(adv);
419 448
       }
@@ -446,13 +475,14 @@ var configuratorApp = (function(){
446 475
       });
447 476
 
448 477
       // Get all 'switchable' class items and add a checkbox
449
-      $form.find('.switchable').each(function(){
450
-        $(this).after(
451
-          $('<input>',{type:'checkbox',value:'1',class:'enabler'}).prop('checked',true)
452
-            .attr('id',this.id + '-switch')
453
-            .change(self.handleSwitch)
454
-        );
455
-      });
478
+      // $form.find('.switchable').each(function(){
479
+      //   $(this).after(
480
+      //     $('<input>',{type:'checkbox',value:'1',class:'enabler added'})
481
+      //       .prop('checked',true)
482
+      //       .attr('id',this.id + '-switch')
483
+      //       .change(self.handleSwitch)
484
+      //   );
485
+      // });
456 486
 
457 487
       // Add options to the popup menus
458 488
       // $('#SERIAL_PORT').addOptions([0,1,2,3,4,5,6,7]);
@@ -516,7 +546,7 @@ var configuratorApp = (function(){
516 546
       /**
517 547
        * Any manually-created form elements will remain
518 548
        * where they are. Unknown defines (currently most)
519
-       * are added to the "More..." tab for now.
549
+       * are added to tabs based on section
520 550
        *
521 551
        * Specific exceptions can be managed by applying
522 552
        * classes to the associated form fields.
@@ -550,11 +580,7 @@ var configuratorApp = (function(){
550 580
       if (inf == null)
551 581
         inf = elm.defineInfo = this.getDefineInfo(name, adv);
552 582
 
553
-      // Set options on the field if there are any
554
-      if (inf.options !== undefined)
555
-        $elm.html('').addOptions(inf.options);
556
-
557
-      // Create a tooltip if there is one
583
+      // Create a tooltip on the label if there is one
558 584
       if (inf.tooltip) {
559 585
         var $tipme = $elm.prev('label');
560 586
         if ($tipme.length) {
@@ -583,8 +609,34 @@ var configuratorApp = (function(){
583 609
         }
584 610
       }
585 611
 
586
-      $elm.unbind('input change');
587
-      $elm.on($elm.attr('type') == 'text' ? 'input' : 'change', this.handleChange);
612
+      // Make the element(s) respond to events
613
+      if (inf.type == 'list') {
614
+        // Multiple fields need to respond
615
+        for (var i=0; i<inf.size; i++) {
616
+          if (i > 0) $elm = $('#'+name+'-'+i);
617
+          $elm.unbind('input');
618
+          $elm.on('input', this.handleChange);
619
+        }
620
+      }
621
+      else {
622
+        var elmtype = $elm.attr('type');
623
+        // Set options on single fields if there are any
624
+        if (inf.options !== undefined && elmtype === undefined)
625
+          $elm.html('').addOptions(inf.options);
626
+        $elm.unbind('input change');
627
+        $elm.on(elmtype == 'text' ? 'input' : 'change', this.handleChange);
628
+      }
629
+
630
+      // Add an enabler checkbox if it needs one
631
+      if (inf.switchable && $('#'+name+'-switch').length == 0) {
632
+        // $elm = the last element added
633
+        $elm.after(
634
+          $('<input>',{type:'checkbox',value:'1',class:'enabler added'})
635
+            .prop('checked',self.defineIsEnabled(name))
636
+            .attr({id: name+'-switch'})
637
+            .change(self.handleSwitch)
638
+        );
639
+      }
588 640
 
589 641
       // Set the field's initial value from the define
590 642
       this.setFieldFromDefine(name);
@@ -592,17 +644,31 @@ var configuratorApp = (function(){
592 644
 
593 645
     /**
594 646
      * Handle any value field being changed
647
+     * this = the field
595 648
      */
596 649
     handleChange: function() { self.updateDefineFromField(this.id); },
597 650
 
598 651
     /**
599 652
      * Handle a switch checkbox being changed
653
+     * this = the switch checkbox
600 654
      */
601 655
     handleSwitch: function() {
602
-      var $elm = $(this), $prev = $elm.prev();
603
-      var on = $elm.prop('checked') || false;
604
-      $prev.attr('disabled', !on);
605
-      self.setDefineEnabled($prev[0].id, on);
656
+      var $elm = $(this),
657
+          name = $elm[0].id.replace(/-.+/,''),
658
+          inf = $('#'+name)[0].defineInfo,
659
+          on = $elm.prop('checked') || false;
660
+
661
+      self.setDefineEnabled(name, on);
662
+
663
+      if (inf.type == 'list') {
664
+        // Multiple fields?
665
+        for (var i=0; i<inf.size; i++) {
666
+          $('#'+name+(i?'-'+i:'')).attr('disabled', !on);
667
+        }
668
+      }
669
+      else {
670
+        $elm.prev().attr('disabled', !on);
671
+      }
606 672
     },
607 673
 
608 674
     /**
@@ -656,11 +722,15 @@ var configuratorApp = (function(){
656 722
      */
657 723
     updateDefineFromField: function(name) {
658 724
       this.log('updateDefineFromField:'+name,4);
725
+
726
+      // Drop the suffix on sub-fields
727
+      name = name.replace(/-\d+$/, '');
728
+
659 729
       var $elm = $('#'+name), inf = $elm[0].defineInfo;
660 730
       if (inf == null) return;
661 731
 
662 732
       var isCheck = $elm.attr('type') == 'checkbox',
663
-          val = isCheck ? $elm.prop('checked') : $elm.val();
733
+          val = isCheck ? $elm.prop('checked') : $elm.val().trim();
664 734
 
665 735
       var newline;
666 736
       switch(inf.type) {
@@ -668,12 +738,19 @@ var configuratorApp = (function(){
668 738
           var slash = val ? '' : '//';
669 739
           newline = inf.line.replace(inf.repl, '$1'+slash+'$3');
670 740
           break;
741
+        case 'list':
671 742
         case 'quoted':
672 743
         case 'plain':
673
-          if (isCheck)
674
-            this.setMessage(name + ' should not be a checkbox!', 'error');
675
-          else
676
-            newline = inf.line.replace(inf.repl, '$1'+val.replace('$','\\$')+'$3');
744
+          if (isCheck) this.setMessage(name + ' should not be a checkbox!', 'error');
745
+        case 'toggle':
746
+          if (isCheck) {
747
+            val = val ? inf.options[1] : inf.options[0];
748
+          }
749
+          else {
750
+            if (inf.type == 'list')
751
+              for (var i=1; i<inf.size; i++) val += ', ' + $('#'+name+'-'+i).val().trim();
752
+          }
753
+          newline = inf.line.replace(inf.repl, '$1'+(''+val).replace('$','\\$')+'$3');
677 754
           break;
678 755
       }
679 756
       this.setDefineLine(name, newline);
@@ -725,31 +802,40 @@ var configuratorApp = (function(){
725 802
      * Set a form field to the current #define value in the config text
726 803
      */
727 804
     setFieldFromDefine: function(name) {
728
-      var $elm = $('#'+name), val = this.defineValue(name);
805
+      var $elm = $('#'+name), inf = $elm[0].defineInfo,
806
+          val = this.defineValue(name);
729 807
 
730 808
       this.log('setFieldFromDefine:' + name + ' to ' + val, 2);
731 809
 
732
-      // Set the field value
733
-      $elm.attr('type') == 'checkbox' ? $elm.prop('checked', val) : $elm.val(''+val);
734
-
735 810
       // If the item has a checkbox then set enabled state too
736
-      var $cb = $('#'+name+'-switch');
811
+      var $cb = $('#'+name+'-switch'), on = true;
737 812
       if ($cb.length) {
738
-        var on = self.defineIsEnabled(name);
813
+        on = self.defineIsEnabled(name);
814
+        $cb.prop('checked', on);
815
+      }
816
+
817
+      if (inf.type == 'list') {
818
+        $.each(val.split(','),function(i,v){
819
+          var $e = i > 0 ? $('#'+name+'-'+i) : $elm;
820
+          $e.val(v.trim());
821
+          $e.attr('disabled', !on);
822
+        });
823
+      }
824
+      else {
825
+        if (inf.type == 'toggle') val = val == inf.options[1];
826
+        $elm.attr('type') == 'checkbox' ? $elm.prop('checked', val) : $elm.val(''+val);
739 827
         $elm.attr('disabled', !on); // enable/disable the form field (could also dim it)
740
-        $cb.prop('checked', on);    // check/uncheck the checkbox
741 828
       }
742 829
     },
743 830
 
744 831
     /**
745
-     * Purge #define information for one of the config files
832
+     * Purge added fields and all their define info
746 833
      */
747
-    purgeDefineInfo: function(adv) {
748
-      if (adv === undefined) adv = false;
749
-      $('[name]').each(function() {
750
-        var inf = this.defineInfo;
751
-        if (inf && adv === inf.adv) $(this).removeProp('defineInfo');
834
+    purgeAddedFields: function(index) {
835
+      $.each(define_list[index], function(){
836
+        $('#'+this + ",[id^='"+this+"-'],label[for='"+this+"']").filter('.added').remove();
752 837
       });
838
+      define_list[index] = [];
753 839
     },
754 840
 
755 841
     /**
@@ -805,6 +891,7 @@ var configuratorApp = (function(){
805 891
             line:   result[0],
806 892
             pre:    result[1] === undefined ? '' : result[1].replace('//',''),
807 893
             define: result[2],
894
+            size:   result[3].split(',').length,
808 895
             post:   result[4] === undefined ? '' : result[4]
809 896
           });
810 897
           info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '\{([^\}]*)\}' + info.post.regEsc(), 'm');
@@ -837,6 +924,10 @@ var configuratorApp = (function(){
837 924
                 define: result[2],
838 925
                 post:   result[4] === undefined ? '' : result[4]
839 926
               });
927
+              if (result[3].match(/false|true/)) {
928
+                info.type = 'toggle';
929
+                info.options = ['false','true'];
930
+              }
840 931
               info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '(\\S*)' + info.post.regEsc(), 'm');
841 932
               info.repl  = new RegExp('(([ \\t]*//)?[ \\t]*' + info.define.regEsc() + ')\\S*(' + info.post.regEsc() + ')', 'm');
842 933
             }
@@ -854,31 +945,41 @@ var configuratorApp = (function(){
854 945
 
855 946
         // Get all the comments immediately before the item
856 947
         var r, s;
857
-        findDef = new RegExp('(([ \\t]*(//|#)[^\n]+\n){1,4})([ \\t]*\n){0,1}' + info.line.regEsc(), 'g');
948
+        findDef = new RegExp('(([ \\t]*(//|#)[^\n]+\n){1,4})([ \\t]*\n)?' + info.line.regEsc(), 'g');
858 949
         if (r = findDef.exec(txt)) {
950
+          // Get the text of the found comments
859 951
           findDef = new RegExp('^[ \\t]*//+[ \\t]*(.*)[ \\t]*$', 'gm');
860 952
           while((s = findDef.exec(r[1])) !== null) {
861
-            if (s[1].match(/^#define[ \\t]/) != null) {
862
-              tooltip = '';
863
-              break;
864
-            }
865
-            // JSON data? Save as select options
866
-            if (s[1].match(/:[\[{]/) != null) {
867
-              // TODO
868
-              // :[1-6] = value limits
869
-              eval('info.options = ' + s[1].substr(1));
870
-            }
871
-            else {
872
-              // Other lines added to the tooltip
873
-              tooltip += ' ' + s[1] + '\n';
953
+            var tip = s[1].replace(/[ \\t]*(={5,}|@section[ \\t]+\w+)[ \\t]*/g, '');
954
+            if (tip.length) {
955
+              if (tip.match(/^#define[ \\t]/) != null) {
956
+                tooltip = '';
957
+                break;
958
+              }
959
+              // JSON data? Save as select options
960
+              if (!info.options && tip.match(/:[\[{]/) != null) {
961
+                // TODO
962
+                // :[1-6] = value limits
963
+                var o; eval('o=' + tip.substr(1));
964
+                info.options = o;
965
+                if (Object.prototype.toString.call(o) == "[object Array]" && o.length == 2 && !eval(''+o[0]))
966
+                  info.type = 'toggle';
967
+              }
968
+              else {
969
+                // Other lines added to the tooltip
970
+                tooltip += ' ' + tip + '\n';
971
+              }
874 972
             }
875 973
           }
876 974
         }
877 975
 
878
-        findDef = new RegExp('^'+name); // To strip the name from the start
976
+
977
+        // Add .tooltip and .lineNum properties to the info
978
+        findDef = new RegExp('^'+name); // Strip the name from the tooltip
879 979
         $.extend(info, {
880 980
           tooltip: '<strong>'+name+'</strong> '+tooltip.trim().replace(findDef,'').toHTML(),
881
-          lineNum: this.getLineNumberOfText(info.line, txt)
981
+          lineNum: this.getLineNumberOfText(info.line, txt),
982
+          switchable: (info.type != 'switch' && info.line.match(/^[ \t]*\/\//)) || false // Disabled? Mark as "switchable"
882 983
         });
883 984
       }
884 985
       else

Loading…
Peruuta
Tallenna