Adding OXSC v1.0 and images
[openXsensor.git] / OXS_Configurator / OXS_Configurator.pde
blob1f23b8a9284517b854bcb5f4637ee56f3a57a7a3
1 /****************************************************************************
2 **                                                                         **
3 **  OpenXsensor Configurator: GUI for generating oxs_config.h file         **
4 **  Copyright (C) 2014   David LABURTHE                                    **
5 **                                                                         **
6 **  This program is free software: you can redistribute it and/or modify   **
7 **  it under the terms of the GNU General Public License as published by   **
8 **  the Free Software Foundation, either version 3 of the License, or      **
9 **  (at your option) any later version.                                    **
10 **                                                                         **
11 **  This program is distributed in the hope that it will be useful,        **
12 **  but WITHOUT ANY WARRANTY; without even the implied warranty of         **
13 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          **
14 **  GNU General Public License for more details.                           **
15 **                                                                         **
16 **  You should have received a copy of the GNU General Public License      **
17 **  along with this program.  If not, see <http://www.gnu.org/licenses/>.  **
18 **                                                                         **
19 *****************************************************************************
20 **                        Author: David LABURTHE                           **
21 **                      Contact: dlaburthe@free.fr                         **
22 **                           Date: 20.08.2014                              **
23 *****************************************************************************/
25 import controlP5.* ;
27 boolean tempActive = false ;           // Define temperature sensor availability 
29 String oxsVersion = "v1.x" ;
30 String oxsCversion = "v1.0" ;
32 String day = (day() < 10) ? "0" + day() : "" + day() ;
33 String month = (month() < 10) ? "0" + month() : "" + month() ;
35 String oxsDirectory = "" ;
36 PrintWriter output;
37 String outputConfigDir = "" ;
39 int blueAct = color(15, 165, 255) ;
40 int orangeAct = color(255, 128, 0) ;
41 int grayedColor = color(155, 155, 155) ;
43 PShape oxsI ;
44 PShape oxsL ;
46 PFont fontLabel ; //= createFont("arial.ttf", 12, false) ;
47 PFont fontItalic ; //= createFont("arial italic", 12, false) ;
48 PFont fontCells ; //= createFont("arial bold", 12, false) ;
49 PFont font16 ; //= createFont("arial", 16, false) ;
50 PFont font20 ; //= createFont("arial", 20, false) ;
52 ControlP5 cp5 ;
54 ControlGroup messageBox;
56 Tab general ;
58 Textfield oxsDir ;
60 DropdownList prot ;
61 Textlabel protocol ;
63 DropdownList serialPin ;
64 Textlabel serialPinL ;
66 Textlabel aVccL ;
67 Textlabel sensors ;
69 Textlabel sensitivity ;
70 DropdownList ppmPin ;
71 Textlabel ppmPinL ;
72 DropdownList climbPin ;
74 CheckBox checkbox ;
76 DropdownList ddlNbrCells ;
78 int voltNbr = 6 ;
79 int dataSentFieldNbr = 8 ;
81 String[] analogPins = new String[8] ;   // Analogic pins
83 StringList messageList = new StringList() ;
85 boolean numPinsValid ;
86 boolean analogPinsValid ;
87 boolean cellsValid ;
88 boolean oxsMeasureValid ;
89 int versionValid ;
91 boolean allValid ;
93 int tabColor = 200 ;
94 int myColorBackground = 150 ; 
96 int sensMin ;
97 int sensMax ;
98 int vSpeedMin ;
99 int vSpeedMax ;
100 int sensMinMax ;
101 int vSpeedMinMax ;
102 int ppmRngMinMax ;
103 int ppmRngMin ;
104 int ppmRngMax ;
105 int ppmSensMinMax ;
106 int varioHysteresis ;
107 int outClimbRateMinMax ;
109 // *************************************************************************
110 // ********************************  SETUP  ********************************
111 // *************************************************************************
112 void setup() {
114   size(400, 410) ;
115   noStroke() ;
117   cp5 = new ControlP5(this) ;
119   //Alt+mouseDragged to move controllers on the screen
120   //Alt+Shift+h to show/hide controllers
121   //Alt+Shift+s to save properties (what are properties? have a look at the properties examples)
122   //Alt+Shift+l to load properties
123   //cp5.enableShortcuts();  
125   oxsI = loadShape("OXSc_Icon.svg") ;
126   oxsL = loadShape("OXSc_Logo.svg") ; 
128   PGraphics icon = createGraphics(64, 64, JAVA2D) ;
129   icon.beginDraw() ;
130   icon.shape(oxsI, 0, 0, 64, 64) ;
131   icon.endDraw() ;
132   frame.setIconImage(icon.image) ;
134   fontLabel = createFont("arial.ttf", 12, false) ;
135   fontItalic = createFont("ariali.ttf", 12, false) ;
136   fontCells = createFont("arialbd.ttf", 12, false) ;
137   font16 = createFont("arial.ttf", 16, false) ;
138   font20 = createFont("arial.ttf", 20, false) ;
140   for ( int i = 0; i < analogPins.length; i++ ) {
141     analogPins[i] = ("A" + i );
142   }  
143   
144   cp5.setControlFont(fontLabel, 12);
145   
147   // ------------------------ TABS definition ------------------------
148   // By default all controllers are stored inside Tab 'default' 
149   cp5.window().setPositionOfTabs(0, 80); 
150   
151   // About
152   cp5.addButton("about")
153      .setLabel("About")
154      .setPosition(355, 14)  // Other positions (5, 14) (355, 38)      
155      .setSize(40, 15)
156      .setColorLabel(#000000)
157      .setColorBackground(color(150))
158      .setColorForeground(blueAct)
159      .setColorActive(orangeAct)
160      .setTab("global")        
161      ;
162   cp5.getController("about").captionLabel().toUpperCase(false) ;  
164   // ----------------------- First tab: GENERAL SETTINGS ----------------------
165   general = cp5.getTab("default")
166                .setHeight(20)
167                .setColorLabel(color(255))
168                .setColorForeground(color(200))
169                .setColorBackground(color(70))
170                .setColorActive(orangeAct)     
171                .setLabel("GENERAL Settings")              
172                .setId(0)                  
173                ;
174   general.captionLabel().toUpperCase(false) ;
176   // OXS directory
177   oxsDir = cp5.addTextfield("oxsDirectory")
178               .setLabel("OXS directory  ")
179               .setPosition(100, 110)
180               .setColorLabel(color(0))
181               .setSize(260, 20)         
182               .setAutoClear(false)     
183               ;
184   oxsDir.getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER) ;     
185   oxsDir.captionLabel().toUpperCase(false) ;
186   cp5.getTooltip().register("oxsDirectory", "Choose OXS source directory");
188   cp5.addButton("oxsDirButton")    
189      .setColorForeground(blueAct)
190      .setLabel(". . .")
191      .setPosition(365, 111)
192      .setSize(25, 18)           
193      ;
194   cp5.getTooltip().register("oxsDirButton", "Choose OXS source directory");          
196   // Protocol choice
197   protocol = cp5.addTextlabel("protocol")
198                 .setText("FrSky Protocol                                   ")
199                 .setPosition(10, 141)
200                 .setColorValue(#000000)
201                 .setTab("default")        
202                 ;
203   //protocol.captionLabel().toUpperCase(false) ; 
204   cp5.getProperties().remove(cp5.getController("protocol")) ;   
205   cp5.getTooltip().register("protocol", "Choose protocol");  
207   prot = cp5.addDropdownList("protocolChoice") 
208             .setPosition(100, 160)
209             .setSize(105, 300)
210             .setColorForeground(blueAct)
211             .setBackgroundColor(color(190))
212             .setItemHeight(20)
213             .setBarHeight(20)               
214             ; 
215   prot.captionLabel().set("Choose");
216   prot.captionLabel().style().marginTop = 2 ;
217   prot.addItem("HUB - D rx", 1);
218   prot.addItem("Smart Port - X rx", 2);  
219   prot.toUpperCase(false) ;  
220   cp5.getProperties().remove(cp5.getGroup("protocolChoice"), "ListBoxItems") ;
222   // Serial PIN choice
223   serialPinL = cp5.addTextlabel("serialPinlabel")
224                   .setText("Serial output PIN number            ")
225                   .setPosition(215, 141)
226                   .setColorValue(#000000)                
227                   ;
228   cp5.getProperties().remove(cp5.getController("serialPinlabel")) ;         
229   cp5.getTooltip().register("serialPinlabel", "Choose the serial output PIN number - Default: 4 -");
230     
232   serialPin = cp5.addDropdownList("serialPin")
233                  .setPosition(365, 160)
234                  .setSize(25, 300)
235                  .setColorForeground(blueAct)
236                  .setBackgroundColor(color(190))
237                  .setItemHeight(20)
238                  .setBarHeight(20)
239                  ; 
240   serialPin.captionLabel().set(" ") ;
241   serialPin.captionLabel().style().marginTop = 2 ; 
242   serialPin.addItem("2", 2) ;
243   serialPin.addItem("4", 4) ;
244   serialPin.setValue(4) ;
245   cp5.getProperties().remove(cp5.getGroup("serialPin"), "ListBoxItems") ;  
247   // Internal reference 1.1v
248   cp5.addToggle("intRef")
249      .setPosition(190, 173)  
250      .setLabel("Internal voltage reference (1.1v)  ")    
251      ;
252   customizeToggleSensor(cp5.getController("intRef")) ;
253   cp5.getTooltip().register("intRef", "Voltage measurement reference");
256   // Arduino VCC
257   /*
258   aVcc = cp5.addTextfield("arduinoVCC")
259    .setLabel("Arduino VCC               volts") 
260    .setPosition(330, 170)
261    .setColorLabel(color(0))
262    .setColorValueLabel(color(255))
263    .setSize(32, 20)     
264    .setAutoClear(false)
265    .setText("5") 
266    ;
267    aVcc.getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER) ;
268    aVcc.captionLabel().toUpperCase(false) ;
269    //aVcc.getValueLabel().align(ControlP5.RIGHT, ControlP5.CENTER) ;
270    aVcc.setInputFilter(ControlP5.FLOAT);  
271    */
272    
273   cp5.addNumberbox("arduinoVccNb")    
274      .setPosition(325, 170)
275      .setSize(37, 18)
276      .setRange(0, 9.99)
277      .setMultiplier(0.01) // set the sensitifity of the numberbox
278      .setDecimalPrecision(2)
279      .setDirection(Controller.HORIZONTAL) // change the control direction to left/right
280      .setValue(5)
281      .setLabel("Arduino VCC              volts") 
282      .setColorLabel(color(0))
283      ; 
284   cp5.getController("arduinoVccNb").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER).setPaddingX(-65) ;
285   cp5.getController("arduinoVccNb").captionLabel().toUpperCase(false) ;
286   cp5.getTooltip().register("arduinoVccNb", "Arduino alimentation source");
287    
288    // Reset button
289    cp5.addToggle("resetButton")
290       .setPosition(190, 203)  
291       .setLabel("Reset button")    
292       ;
293   customizeToggleSensor(cp5.getController("resetButton")) ;
294   cp5.getController("resetButton").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER).setPaddingX(8) ;  
295   
296   // Reset button pin
297   cp5.addTextlabel("resetButtonPinLabel")
298      .setText("Reset button PIN number           ")
299      .setPosition(215, 202)
300      .setColorValue(#000000)          
301      ;
302   cp5.getProperties().remove(cp5.getController("resetButtonPinLabel")) ;         
303   cp5.getTooltip().register("resetButtonPinLabel", "- Default: 10 -");
304   
305   cp5.addDropdownList("resetButtonPin")
306      .setPosition(360, 220)
307      .setSize(30, 180)
308      .setColorForeground(blueAct)
309      .setBackgroundColor(color(190))
310      .setItemHeight(20)
311      .setBarHeight(20)              
312      ;
313   cp5.get(DropdownList.class, "resetButtonPin").captionLabel().set(" ") ;
314   cp5.get(DropdownList.class, "resetButtonPin").captionLabel().style().marginTop = 2 ;  
315   for ( int i = 2; i <= 12; i++ ) {
316     cp5.get(DropdownList.class, "resetButtonPin").addItem("" + i, i) ;
317   }   
318   cp5.getGroup("resetButtonPin").setValue(10) ;
319   cp5.getProperties().remove(cp5.getGroup("resetButtonPin"), "ListBoxItems") ;
320   
321   // Save to EEPROM
322   cp5.addToggle("saveEprom")
323      .setPosition(190, 233)  
324      .setLabel("Save data to EEPROM")    
325      ;
326   customizeToggleSensor(cp5.getController("saveEprom")) ;
327   cp5.getController("saveEprom").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER).setPaddingX(8) ;
328   //cp5.getTooltip().register("saveEprom", "...");
329   
330   // - Sensors  part
331   sensors = cp5.addTextlabel("sensors")
332                .setText("SENSORS")
333                .setPosition(1, 255)
334                .setColorValue(#FFFFFF)                        
335                ;
336   cp5.getProperties().remove(cp5.getController("sensors")) ;           
337   cp5.getTooltip().register("sensors", "Sensors settings");                
339   // Toggle buttons
340   cp5.addToggle("vario")
341      .setPosition(85, 285)  
342      .setLabel("Vario  ")    
343      ;
344   customizeToggleSensor(cp5.getController("vario")) ;
346   cp5.addToggle("voltage")
347      .setPosition(220, 285)
348      .setLabel("Voltage / Other  ")
349      ; 
350   customizeToggleSensor(cp5.getController("voltage")) ;
352   cp5.addToggle("current")
353      .setPosition(355, 285)
354      .setLabel("Current  ")
355      ; 
356   customizeToggleSensor(cp5.getController("current")) ;
358   
359   cp5.addToggle("temperature")
360      .setPosition(85, 315)
361      .setLabel("Temperature  ")
362      ;
363   customizeToggleSensor(cp5.getController("temperature")) ;
364   if (!tempActive) {
365     cp5.getController("temperature").lock() ;
366   }
368   cp5.addToggle("rpm")
369      .setPosition(220, 315)
370      .setLabel("RPM  ")
371      ; 
372   customizeToggleSensor(cp5.getController("rpm")) ;
374   // ---------------------------- Tab 2 : Vario settings ------------------------------
375   cp5.getTab("vario")     
376      .setHeight(20) 
377      .setColorForeground(color(200))
378      .setColorBackground(color(70))
379      .setColorActive(blueAct)
380      .setLabel("Vario")            
381      .setId(1) 
382      .hide()     
383      ;
384   cp5.getTab("vario").captionLabel().toUpperCase(false) ;
386   // Vario sensitivity range
387   cp5.addTextlabel("sensitivityRange")
388      .setText("Sensitivity            Min.")
389      .setPosition(10, 110)
390      .setColorValue(#000000) 
391      .setTab("vario")        
392      ;
393   cp5.getProperties().remove(cp5.getController("sensitivityRange")) ;           
395   cp5.addRange("sensMinMax") 
396      .setPosition(138, 108)             
397      .setCaptionLabel("Max.")
398      .setSize(195, 20)
399      .setHandleSize(15) 
400      .setRange(20, 150)
401      .setRangeValues(50.9, 50.9)            
402      ;
403   //cp5.getController("sensMinMax").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER) ;     
404   customizeRange(cp5.getController("sensMinMax")) ;
405   cp5.getTooltip().register("sensMinMax", "Sensitivity based on vertical speed - Default: 50:50 -");  
407   // Vario Vertical speed sensitivity range
408   cp5.addTextlabel("vSpeedSensitivityRng")
409      .setText("Vertical speed sensibility (cm/s)                                                ")
410      .setPosition(10, 135)
411      .setColorValue(#000000) 
412      .setTab("vario")        
413      ;
414    cp5.getProperties().remove(cp5.getController("vSpeedSensitivityRng")) ;         
415    cp5.getTooltip().register("vSpeedSensitivityRng", "Vertical speed threshold sensitivity - Default: 20:100 -");         
416             
417    cp5.addNumberbox("vSpeedMin")    
418       .setPosition(230, 134)
419       .setSize(40, 18)
420       .setColorActive(blueAct)
421       .setBroadcast(false) 
422       .setMultiplier(0.5) // set the sensitifity of the numberbox
423       .setDirection(Controller.HORIZONTAL) // change the control direction to left/right
424       .setValue(20)
425       .setLabel("Min.") 
426       .setColorLabel(color(0))
427       .setTab("vario") 
428       ; 
429   cp5.getController("vSpeedMin").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER).setPaddingX(5) ;
430   cp5.getController("vSpeedMin").captionLabel().toUpperCase(false) ; 
432   cp5.addNumberbox("vSpeedMax")    
433      .setPosition(293, 134)
434      .setSize(40, 18)
435      .setColorActive(blueAct)
436      .setBroadcast(false) 
437      .setMultiplier(0.5) // set the sensitifity of the numberbox
438      .setDirection(Controller.HORIZONTAL) // change the control direction to left/right
439      .setValue(100)
440      .setLabel("Max.") 
441      .setColorLabel(color(0))
442      .setTab("vario") 
443      ; 
444   cp5.getController("vSpeedMax").getCaptionLabel().align(ControlP5.RIGHT_OUTSIDE, ControlP5.CENTER).setPaddingX(5) ;
445   cp5.getController("vSpeedMax").captionLabel().toUpperCase(false) ;
447   cp5.getController("vSpeedMin").setBroadcast(true) ;
448   cp5.getController("vSpeedMax").setBroadcast(true) ;
450   // RC Remote PPM pin and settings
451   cp5.addToggle("ppm")
452      .setLabel("RC Remote sensitivity")
453      .setPosition(138, 175)
454      .setTab("vario")
455      ;
456   customizeToggle(cp5.getController("ppm")) ; 
458   ppmPinL = cp5.addTextlabel("ppmPinL")
459                .setText("PPM Pin           ")
460                .setPosition(246, 175)
461                .setColorValue(#000000) 
462                .setTab("vario")           
463                ;
464   cp5.getProperties().remove(cp5.getController("ppmPinL")) ;          
465   cp5.getTooltip().register("ppmPinL", "- Default: 2 -");
467   ppmPin = cp5.addDropdownList("ppmPin") 
468               .setPosition(303, 194)
469               .setSize(30, 75)
470               .setColorForeground(orangeAct)
471               .setColorActive(blueAct)
472               .setBackgroundColor(color(190))
473               .setItemHeight(20)
474               .setBarHeight(20)
475               .setTab("vario")             
476               ; 
477   ppmPin.captionLabel().set(" ");
478   ppmPin.captionLabel().style().marginTop = 2 ;   
479   ppmPin.addItem("2", 2);
480   ppmPin.addItem("3", 3);
481   ppmPin.setValue(2);   
482   ppmPin.toUpperCase(false) ;
483   cp5.getProperties().remove(cp5.getGroup("ppmPin"), "ListBoxItems") ;
485   // PPM range setting
486   cp5.addTextlabel("ppmRngL")
487      .setText("PPM range (us)                                                                          ")
488      .setPosition(5, 200)
489      .setColorValue(#000000) 
490      .setTab("vario")        
491      ;
492   cp5.getProperties().remove(cp5.getController("ppmRngL")) ;         
493   cp5.getTooltip().register("ppmRngL", "RC control range - Default: 988:2012 -");
494    
495   cp5.addNumberbox("ppmRngMin")    
496      .setPosition(230, 199)
497      .setSize(40, 18)
498      .setColorActive(blueAct)
499      .setRange(888, 1088) 
500      .setMultiplier(0.5) // set the sensitifity of the numberbox
501      .setDirection(Controller.HORIZONTAL) // change the control direction to left/right
502      .setValue(988)
503      .setLabel("Min.") 
504      .setColorLabel(color(0))
505      .setTab("vario") 
506      ; 
507   cp5.getController("ppmRngMin").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER).setPaddingX(5) ;
508   cp5.getController("ppmRngMin").captionLabel().toUpperCase(false) ; 
510   cp5.addNumberbox("ppmRngMax")    
511      .setPosition(293, 199)
512      .setSize(40, 18)
513      .setColorActive(blueAct)
514      .setRange(1912, 2112) 
515      .setMultiplier(0.5) // set the sensitifity of the numberbox
516      .setDirection(Controller.HORIZONTAL) // change the control direction to left/right
517      .setValue(2012)
518      .setLabel("Max.") 
519      .setColorLabel(color(0))
520      .setTab("vario") 
521      ; 
522   cp5.getController("ppmRngMax").getCaptionLabel().align(ControlP5.RIGHT_OUTSIDE, ControlP5.CENTER).setPaddingX(5) ;
523   cp5.getController("ppmRngMax").captionLabel().toUpperCase(false) ;
525   // PPM sensitivity range
526   cp5.addTextlabel("ppmSensRngL")
527      .setText("PPM sensitivity      Min.")
528      .setPosition(5, 225)
529      .setColorValue(#000000) 
530      .setTab("vario")        
531      ;
532   cp5.getProperties().remove(cp5.getController("ppmSensRngL")) ;          
534   cp5.addRange("ppmSensMinMax") 
535      .setPosition(138, 223) 
536      .setSize(195, 20)
537      .setCaptionLabel("Max.")
538      .setHandleSize(15)               
539      .setRange(20, 150)
540      .setRangeValues(20, 100.5)      
541      ;     
542   customizeRange(cp5.getController("ppmSensMinMax")) ;
543   cp5.getTooltip().register("ppmSensMinMax", "RC control sensitivity range - Default: 20:100 -");
545   // Vario hysteresis 
546   cp5.addSlider("varioHysteresis")
547      .setPosition(138, 260)
548      .setSize(195, 15)
549      .setLabel("Hysteresis (cm/s)")
550      .setColorForeground(blueAct) 
551      .setColorLabel(#000000) 
552      .setColorValue(#000000)       
553      .setRange(0, 100)
554      .setValue(5) 
555      .setTab("vario")
556      ;
557   // reposition the Labels for controller 'slider'
558   cp5.getController("varioHysteresis").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER).setPaddingX(10) ;   
559   cp5.getController("varioHysteresis").getValueLabel().align(ControlP5.RIGHT_OUTSIDE, ControlP5.CENTER).setPaddingX(10) ;
560   cp5.getController("varioHysteresis").captionLabel().toUpperCase(false) ;
561   cp5.getTooltip().register("varioHysteresis", "Minimum measurement difference - Default: 5 -");  
563   // Analog climb rate  pin and settings
564   cp5.addToggle("analogClimb")
565      .setLabel("Analog climb rate")
566      .setPosition(138, 288)
567      .setTab("vario")
568      ;
569   customizeToggle(cp5.getController("analogClimb")) ; 
571   cp5.addTextlabel("climbPinL")
572      .setText("Climb rate Pin          ")
573      .setPosition(218, 288)
574      .setColorValue(#000000) 
575      .setTab("vario")           
576             ;
577   cp5.getProperties().remove(cp5.getController("climbPinL")) ;          
578   cp5.getTooltip().register("climbPinL", "- Default: 3 -");
580   climbPin = cp5.addDropdownList("climbPin") 
581                 .setPosition(303, 307)
582                 .setSize(30, 75)
583                 .setColorForeground(orangeAct)
584                 .setColorActive(blueAct)
585                 .setBackgroundColor(color(190))
586                 .setItemHeight(20)
587                 .setBarHeight(20)
588                 .setTab("vario")             
589                 ;
590   climbPin.captionLabel().set(" ");
591   climbPin.captionLabel().style().marginTop = 2 ;
592   climbPin.addItem("3", 3);
593   climbPin.addItem("11", 11);
594   climbPin.setValue(3);
595   climbPin.toUpperCase(false) ;
596   cp5.getProperties().remove(cp5.getGroup("climbPin"), "ListBoxItems") ;
598   // Output climb rate range
599   cp5.addTextlabel("outClimbRateRngL")
600      .setText("Climb rate            Min.")
601      .setPosition(10, 315)
602      .setColorValue(#000000) 
603      .setTab("vario")        
604      ;
605   cp5.getProperties().remove(cp5.getController("outClimbRateRngL")) ;           
607   cp5.addRange("outClimbRateMinMax") 
608      .setPosition(138, 312)
609      .setSize(195, 20)    
610      .setCaptionLabel("Max.")
611      .setHandleSize(15)               
612      .setRange(-10, 10)
613      .setRangeValues(-3, 3.3)      
614      ;
615   //cp5.getController("outClimbRateMinMax").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER) ;     
616   customizeRange(cp5.getController("outClimbRateMinMax")) ;
617   cp5.getTooltip().register("outClimbRateMinMax", "Analog climb rate range - Default: -3:3 -"); 
620   // ------------------------------ Tab 3 : Voltage settings ------------------------------
621   cp5.getTab("voltage")     
622      .setHeight(20) 
623      .setColorForeground(color(200))
624      .setColorBackground(color(70))
625      .setColorActive(blueAct)
626      .setLabel("Voltage...")            
627      .setId(2) 
628      .hide()     
629      ;
630   cp5.getTab("voltage").captionLabel().toUpperCase(false) ; 
632   // Voltage 1-6 toggle
633   cp5.addTextlabel("voltages")
634      .setText("Voltage number")
635      .setPosition(10, 138)
636      .setColorValue(#000000) 
637      .setTab("voltage")           
638      ;
639   cp5.getProperties().remove(cp5.getController("voltages")) ;         
641   for ( int i = 1; i <= voltNbr; i++ ) {
642     cp5.addToggle("volt" + i)
643        .setLabel("" + i)
644        .setPosition(127 + 45 * (i-1), 140)
645        .setTab("voltage")          
646        ;
647     customizeToggleVolt(cp5.getController("volt" + i)) ;
648   }
650   // Voltage 1-6 pin
651   cp5.addTextlabel("voltPin")
652      .setText("Pin number")
653      .setPosition(10, 165)
654      .setColorValue(#000000) 
655      .setTab("voltage")       
656      ;
657   cp5.getProperties().remove(cp5.getController("voltPin")) ;          
659   for ( int i = 1; i <= voltNbr; i++ ) {
660     cp5.addDropdownList("ddlVolt" + i)    
661        .setPosition(120 + 45 * (i-1), 185)
662        .setTab("voltage")
663        ;
664     customizeDdlVpin(cp5.get(DropdownList.class, "ddlVolt" + i)) ;
665     cp5.get(DropdownList.class, "ddlVolt" + i).setValue(-1) ;
666     cp5.getProperties().remove(cp5.getGroup("ddlVolt" + i), "ListBoxItems") ;
667   }
669   // Voltage 1-6 divider factor
670   cp5.addTextlabel("voltDivider")
671      .setText("Divider factor                                                                                           ")
672      .setPosition(10, 196)
673      .setColorValue(#000000) 
674      .setTab("voltage")           
675      ;
676   cp5.getProperties().remove(cp5.getController("voltDivider")) ;             
677   cp5.getTooltip().register("voltDivider", "- Default: 1 -");          
679   for ( int i = 1; i <= voltNbr; i++ ) {
680     cp5.addNumberbox("dividerVolt" +i)    
681        .setPosition(115 + 45 * (i-1), 195)
682        .setSize(40, 18)
683        .setColorActive(blueAct)
684        .setDecimalPrecision(2)
685        .setRange(0.01, 10) 
686        .setMultiplier(0.01) // set the sensitifity of the numberbox
687        .setDirection(Controller.HORIZONTAL) // change the control direction to left/right
688        .setValue(1)
689        .setCaptionLabel("")                     
690        .setTab("voltage") 
691        ;   
693     cp5.addTextfield("dividerVolt" + i)
694        .setPosition(120 + 45 * (i-1), 195)
695        .setSize(30, 20)
696        .setCaptionLabel(" ")
697        .setText("1") 
698        .setColorActive(blueAct)      
699        .setAutoClear(false)
700        .setTab("voltage")
701        ;
702 */                   
703   }
705   // Voltage 1-6 Offset
706   cp5.addTextlabel("voltOffset")
707      .setText("Offset (mV)                                                                                              ")
708      .setPosition(10, 225)
709      .setColorValue(#000000) 
710      .setTab("voltage")           
711             ;
712   cp5.getProperties().remove(cp5.getController("voltOffset")) ;          
713   cp5.getTooltip().register("voltOffset", "- Default: 0 -");          
715   for ( int i = 1; i <= voltNbr; i++ ) {
716     cp5.addNumberbox("offsetVolt" +i)    
717        .setPosition(114 + 45 * (i-1), 224)
718        .setSize(42, 18)
719        .setColorActive(blueAct)
720        .setDecimalPrecision(0)
721        .setRange(-5000, 5000) 
722        .setMultiplier(1) // set the sensitifity of the numberbox
723        .setDirection(Controller.HORIZONTAL) // change the control direction to left/right
724        .setValue(0)
725        .setCaptionLabel("")                     
726        .setTab("voltage") 
727        ;               
728   }
730   // Cells monitoring -> Number of Cells
731   cp5.addToggle("cells")
732      .setPosition(148, 280)
733      .setLabel("Battery cells monitoring")        
734      .setColorForeground(orangeAct) 
735      .setColorBackground(color(70)) 
736      .setColorActive(blueAct) 
737      .setColorLabel(#000000) 
738      .setSize(15, 15) 
739      .setTab("voltage")
740      ;  
741   cp5.getController("cells").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER).setPaddingX(10) ;
742   cp5.getController("cells").captionLabel().toUpperCase(false) ;
744   cp5.addTextlabel("NbrCells")
745      .setText("Number of Cells")
746      .setPosition(183, 279)
747      .setColorValue(#000000) 
748      .setTab("voltage")           
749      ;
750   cp5.getProperties().remove(cp5.getController("NbrCells")) ;          
752   ddlNbrCells = cp5.addDropdownList("ddlNbrCells")
753                    .setColorForeground(orangeAct) 
754                    .setColorBackground(color(70)) 
755                    .setColorActive(blueAct) 
756                    .setPosition(283, 299) 
757                    .setSize(25, 80) 
758                    .setItemHeight(20)
759                    .setBarHeight(20)
760                    .setTab("voltage")      
761                    ;                 
762   for ( int i = 1; i <= 6; i++ ) {
763     ddlNbrCells.addItem("" + i, i);
764   }
765   ddlNbrCells.setValue(1) ;  
766   ddlNbrCells.captionLabel().style().marginTop = 2 ;
767   ddlNbrCells.toUpperCase(false) ;
768   cp5.getProperties().remove(cp5.getGroup("ddlNbrCells"), "ListBoxItems") ;
771   // ------------------------------ Tab 4 : Current settings ------------------------------
772   cp5.getTab("current")     
773      .setHeight(20) 
774      .setColorForeground(color(200))
775      .setColorBackground(color(70))
776      .setColorActive(blueAct)
777      .setLabel("Current")            
778      .setId(3) 
779      .hide()     
780      ;
781   cp5.getTab("current").captionLabel().toUpperCase(false) ; 
783   // Current pin 
784   cp5.addTextlabel("currentPinL")
785      .setText("Current sensor pin number")
786      .setPosition(10, 120)
787      .setColorValue(#000000) 
788      .setTab("current")           
789      ;
790   cp5.getProperties().remove(cp5.getController("currentPinL")) ;          
792   cp5.addDropdownList("currentPin")
793      .setColorForeground(orangeAct) 
794      .setColorBackground(color(70)) 
795      .setColorActive(blueAct) 
796      .setPosition(165, 139) 
797      .setSize(30, 200) 
798      .setItemHeight(20)
799      .setBarHeight(20)
800      .setTab("current")
801      ;
802   cp5.get(DropdownList.class, "currentPin").addItem("--", -1) ;                  
803   cp5.get(DropdownList.class, "currentPin").addItems(analogPins) ;  
804   cp5.getGroup("currentPin").captionLabel().style().marginTop = 2 ;
805   cp5.get(DropdownList.class, "currentPin").setValue(-1) ;
806   cp5.get(DropdownList.class, "currentPin").toUpperCase(false) ;
807   cp5.getProperties().remove(cp5.getGroup("currentPin"), "ListBoxItems") ;
809   // Current sensor output sensitivity
810   cp5.addNumberbox("currentOutSensNb")
811      .setColorActive(blueAct) 
812      .setPosition(165, 154)
813      .setSize(33, 18)
814      .setRange(0, 500)
815      .setMultiplier(0.5) // set the sensitifity of the numberbox
816      .setDecimalPrecision(0)
817      .setDirection(Controller.HORIZONTAL) // change the control direction to left/right     
818      .setLabel("Output sensitivity (mV/A)") 
819      .setColorLabel(color(0))
820      .setTab("current")
821      ; 
822   cp5.getController("currentOutSensNb").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER).setPaddingX(8) ;
823   cp5.getController("currentOutSensNb").captionLabel().toUpperCase(false) ;
824   
825   // Current sensor offset
826   cp5.addNumberbox("currentOutOffsetNb")
827      .setColorActive(blueAct) 
828      .setPosition(165, 189)
829      .setSize(45, 18)
830      .setRange(-5000, 5000)
831      .setMultiplier(1) // set the sensitifity of the numberbox
832      .setDecimalPrecision(0)
833      .setDirection(Controller.HORIZONTAL) // change the control direction to left/right
834      .setLabel("Output offset (mV)") 
835      .setColorLabel(color(0))
836      .setTab("current")
837      ; 
838   cp5.getController("currentOutOffsetNb").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER).setPaddingX(8) ;
839   cp5.getController("currentOutOffsetNb").captionLabel().toUpperCase(false) ;
840   //cp5.getTooltip().register("currentOutOffsetNb", "...");
841   
842   // Current sensor divider factor
843   cp5.addNumberbox("currentDivNb")
844      .setColorActive(blueAct) 
845      .setPosition(165, 224)
846      .setSize(35, 18)
847      .setRange(1, 9.99)
848      .setMultiplier(0.01) // set the sensitifity of the numberbox
849      .setDecimalPrecision(2)
850      .setDirection(Controller.HORIZONTAL) // change the control direction to left/right
851      .setValue(1)
852      .setLabel("Divider factor") 
853      .setColorLabel(color(0))
854      .setTab("current")
855      ; 
856   cp5.getController("currentDivNb").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER).setPaddingX(8) ;
857   cp5.getController("currentDivNb").captionLabel().toUpperCase(false) ;
858   cp5.getTooltip().register("currentDivNb", "- Default: 1 -");
859   
860   /*
861   // Current sensor Vcc
862   cp5.addNumberbox("currentVccNb")
863      .setColorActive(blueAct) 
864      .setPosition(330, 118)
865      .setSize(30, 18)
866      .setRange(0, 9.9)
867      .setMultiplier(0.05) // set the sensitifity of the numberbox
868      .setDecimalPrecision(1)
869      .setDirection(Controller.HORIZONTAL) // change the control direction to left/right
870      //.setValue(5)
871      .setLabel("Current sensor Vcc             volts") 
872      .setColorLabel(color(0))
873      .setTab("current")
874      ; 
875   cp5.getController("currentVccNb").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER).setPaddingX(-59) ;
876   cp5.getController("currentVccNb").captionLabel().toUpperCase(false) ;
877   cp5.getTooltip().register("currentVccNb", "Current sensor alimentation source value");         
878   */
879   /*
880   // Current sensor direction
881   cp5.addTextlabel("currentDirL")
882      .setText("Unidirectional")
883      .setPosition(10, 157)
884      .setColorValue(#000000) 
885      .setTab("current")           
886      ;
887   cp5.getProperties().remove(cp5.getController("currentDirL")) ;          
889   cp5.addToggle("currentDir")
890      .setColorForeground(orangeAct)
891      .setColorBackground(color(70))
892      .setColorActive(blueAct)
893      .setColorLabel(#000000)
894      .setPosition(98, 155)
895      .setSize(50, 20)
896      .setLabel("Bidirectional")  
897      .setMode(ControlP5.SWITCH)
898      .setTab("current")
899      ;
900   cp5.getController("currentDir").getCaptionLabel().align(ControlP5.RIGHT_OUTSIDE, ControlP5.CENTER).setPaddingX(10) ;
901   cp5.getController("currentDir").captionLabel().toUpperCase(false) ;
902   */
904   // ------------------------------ Tab 5 : Temperature settings ------------------------------
905   cp5.getTab("temperature")     
906      .setHeight(20) 
907      .setColorForeground(color(200))
908      .setColorBackground(color(70))
909      .setColorActive(blueAct)
910      .setLabel("Temperature")            
911      .setId(4) 
912      .hide()     
913      ; 
914   cp5.getTab("temperature").captionLabel().toUpperCase(false) ; 
916   // Use vario temp
917   cp5.addToggle("vTemp")
918      .setPosition(142, 120)
919      .setLabel("Use vario temperature")        
920      .setColorForeground(orangeAct) 
921      .setColorBackground(color(70)) 
922      .setColorActive(blueAct) 
923      .setColorLabel(#000000) 
924      .setSize(15, 15) 
925      .setTab("temperature")
926      ;  
927   cp5.getController("vTemp").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER).setPaddingX(10) ;
928   cp5.getController("vTemp").captionLabel().toUpperCase(false) ; 
930   // Temperature sensor pin
931   cp5.addTextlabel("tempPinL")
932      .setText("Temperature sensor pin number")
933      .setPosition(10, 157)
934      .setColorValue(#000000) 
935      .setTab("temperature")           
936      ;
937   cp5.getProperties().remove(cp5.getController("tempPinL")) ;          
939   cp5.addDropdownList("tempPin")
940      .setColorForeground(orangeAct) 
941      .setColorBackground(color(70)) 
942      .setColorActive(blueAct) 
943      .setPosition(193, 176) 
944      .setSize(30, 200) 
945      .setItemHeight(20)
946      .setBarHeight(20)
947      .setTab("temperature")                          
948      ;
949   cp5.get(DropdownList.class, "tempPin").addItem("--", -1) ;
950   cp5.get(DropdownList.class, "tempPin").addItems(analogPins) ;
951   cp5.get(DropdownList.class, "tempPin").setValue(-1) ;
952   cp5.getGroup("tempPin").captionLabel().style().marginTop = 2 ;
953   cp5.get(DropdownList.class, "tempPin").toUpperCase(false) ;
954   cp5.getProperties().remove(cp5.getGroup("tempPin"), "ListBoxItems") ;
956   // Temperature sensor offset
957   cp5.addTextfield("tempOffset")
958      .setLabel("Temperature sensor offset") 
959      .setPosition(164, 192)
960      .setColorLabel(color(0))
961      .setColorValueLabel(color(255))
962      .setColorActive(blueAct) 
963      .setSize(28, 20)     
964      .setAutoClear(false)
965      .setText("0") 
966      .setTab("temperature")
967      ;
968   cp5.getController("tempOffset").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER).setPaddingX(10) ;
969   cp5.getController("tempOffset").captionLabel().toUpperCase(false) ;
970   
972   // ------------------------------ Tab 6 : RPM settings ------------------------------   needed ?
973   cp5.getTab("rpm")     
974      .setHeight(20) 
975      .setColorForeground(color(200))
976      .setColorBackground(color(70))
977      .setColorActive(blueAct)
978      .setLabel("RPM")         
979      .setId(5) 
980      .hide()             
981                   ; 
982   cp5.getTab("rpm").captionLabel().toUpperCase(false) ;   
984   // ------------------------------ Tab 7 : DATA to send ------------------------------   
985   cp5.getTab("data")     
986      .setHeight(20) 
987      .setColorForeground(color(200))
988      .setColorBackground(color(40, 90, 40))
989      .setColorActive(color(60, 190, 60))
990      .setLabel("DATA sent")         
991      .setId(6) 
992      .hide()             
993      ; 
994   cp5.getTab("data").captionLabel().toUpperCase(false) ; 
996   // Text Labels   
997   cp5.addTextlabel("sentData")
998      .setText("OXS measurement")
999      .setPosition(12, 105)
1000      .setColorValue(#000000) 
1001      .setTab("data")           
1002      ;
1003   cp5.getProperties().remove(cp5.getController("sentData")) ;          
1005   cp5.addTextlabel("DataFS")
1006      .setText("Telemetry data field")
1007      .setPosition(139, 105)
1008      .setColorValue(#000000) 
1009      .setTab("data")           
1010      ;
1011   cp5.getProperties().remove(cp5.getController("DataFS")) ;          
1013   cp5.addTextlabel("multiplierL")
1014      .setText("Multiplier")
1015      .setPosition(256, 105)
1016      .setColorValue(#000000) 
1017      .setTab("data")           
1018      ;
1019   cp5.getProperties().remove(cp5.getController("multiplierL")) ;          
1021   cp5.addTextlabel("dividerL")
1022      .setText("Divider")
1023      .setPosition(308, 105)
1024      .setColorValue(#000000) 
1025      .setTab("data")           
1026      ;
1027   cp5.getProperties().remove(cp5.getController("dividerL")) ;          
1029   cp5.addTextlabel("offsetL")
1030      .setText("Offset")
1031      .setPosition(356, 105)
1032      .setColorValue(#000000) 
1033      .setTab("data")           
1034      ;
1035   cp5.getProperties().remove(cp5.getController("offsetL")) ;          
1037   for ( int i = 1; i <= dataSentFieldNbr; i++ ) {
1038     // Transmitted DATA field
1039     cp5.addDropdownList("sentDataField" + i)
1040        .setColorForeground(orangeAct) 
1041        .setColorBackground(color(70)) 
1042        .setColorActive(blueAct) 
1043        .setPosition(5, 148 - 25 + i * 25) 
1044        .setSize(127, 180 - 11 * i) 
1045        .setItemHeight(20)
1046        .setBarHeight(20)
1047        .setTab("data")                         
1048        ;
1049     for (int j = 0; j < sentDataList.length; j++ ) {
1050       cp5.get(DropdownList.class, "sentDataField" + i).addItem("" + sentDataList[j][1], j) ;
1051     }    
1052     cp5.get(DropdownList.class, "sentDataField" + i).setValue(0) ;
1053     cp5.getGroup("sentDataField" + i).captionLabel().style().marginTop = 2 ;
1054     cp5.get(DropdownList.class, "sentDataField" + i).toUpperCase(false) ; 
1055     cp5.getProperties().remove(cp5.getGroup("sentDataField" + i), "ListBoxItems") ;
1057     // HUB DATA field
1058     cp5.addDropdownList("hubDataField" + i)
1059        .setColorForeground(orangeAct) 
1060        .setColorBackground(color(70)) 
1061        .setColorActive(blueAct) 
1062        .setPosition(137, 148 - 25 + i * 25) 
1063        .setSize(120, 180 - 11 * i) 
1064        .setItemHeight(20)
1065        .setBarHeight(20)
1066        .setTab("data")                          
1067        ; 
1068     for (int j = 0; j < hubDataList.length; j++ ) {
1069       cp5.get(DropdownList.class, "hubDataField" + i).addItem("" + hubDataList[j][1], j) ;
1070     }      
1071     cp5.getGroup("hubDataField" + i).captionLabel().style().marginTop = 2 ;
1072     cp5.get(DropdownList.class, "hubDataField" + i).toUpperCase(false) ;
1073     cp5.get(DropdownList.class, "hubDataField" + i).setValue(0) ;
1074     cp5.getGroup("hubDataField" + i).hide() ;
1075     cp5.getProperties().remove(cp5.getGroup("hubDataField" + i), "ListBoxItems") ;
1077     // SMART PORT DATA field
1078     cp5.addDropdownList("sPortDataField" + i)
1079        .setColorForeground(orangeAct) 
1080        .setColorBackground(color(70)) 
1081        .setColorActive(blueAct) 
1082        .setPosition(137, 148 - 25 + i * 25) 
1083        .setSize(120, 180 - 11 * i) 
1084        .setItemHeight(20)
1085        .setBarHeight(20)
1086        .setTab("data")                   
1087        ;
1088     for (int j = 0; j < sPortDataList.length; j++ ) {
1089       cp5.get(DropdownList.class, "sPortDataField" + i).addItem("" + sPortDataList[j][1], j) ;
1090     }       
1091     cp5.getGroup("sPortDataField" + i).captionLabel().style().marginTop = 2 ;
1092     cp5.get(DropdownList.class, "sPortDataField" + i).toUpperCase(false) ;
1093     cp5.get(DropdownList.class, "sPortDataField" + i).setValue(0) ;
1094     cp5.getGroup("sPortDataField" + i).hide() ;
1095     cp5.getProperties().remove(cp5.getGroup("sPortDataField" + i), "ListBoxItems") ;
1097     // Data sent multiplier
1098     cp5.addNumberbox("dataMultiplier" + i)
1099        .setColorActive(blueAct) 
1100        .setPosition(265, 128 - 25 + i * 25)
1101        .setSize(40, 18)
1102        .setRange(-1000, 1000)
1103        .setMultiplier(0.5) // set the sensitifity of the numberbox
1104        .setDecimalPrecision(0)
1105        .setDirection(Controller.HORIZONTAL) // change the control direction to left/right
1106        .setValue(1)
1107        .setLabel("")                     
1108        .setTab("data")
1109        ;
1110     cp5.getTooltip().register("dataMultiplier" + i, "- Default: 1 -"); 
1112     // Data sent divider
1113     cp5.addNumberbox("dataDivider" + i)
1114        .setColorActive(blueAct) 
1115        .setPosition(311, 128 - 25 + i * 25)
1116        .setSize(40, 18)
1117        .setRange(1, 1000)
1118        .setMultiplier(0.5) // set the sensitifity of the numberbox
1119        .setDecimalPrecision(0)
1120        .setDirection(Controller.HORIZONTAL) // change the control direction to left/right
1121        .setValue(1)
1122        .setLabel("")                     
1123        .setTab("data")
1124        ; 
1125     cp5.getTooltip().register("dataDivider" + i, "- Default: 1 -");                  
1127     // Data sent offset
1128     cp5.addNumberbox("dataOffset" + i)
1129        .setColorActive(blueAct) 
1130        .setPosition(357, 128 - 25 + i * 25)
1131        .setSize(40, 18)
1132        .setRange(-999, 999)
1133        .setMultiplier(0.5) // set the sensitifity of the numberbox
1134        .setDecimalPrecision(0)
1135        .setDirection(Controller.HORIZONTAL) // change the control direction to left/right
1136        .setValue(0)
1137        .setLabel("")                     
1138        .setTab("data")
1139        ; 
1140     cp5.getTooltip().register("dataOffset" + i, "- Default: 0 -");                     
1141   }
1142   
1143   prot.setValue(1);  // Set the protocol ddl value after telemetry fields creation  
1145   // ------------------------------ File dialog ------------------------------
1146   
1147   // Load preset button
1148   cp5.addButton("loadButton")    
1149      .setColorForeground(blueAct)    
1150      .setLabel("Load Preset")      
1151      .setPosition(10, 369)
1152      .setSize(100, 25)  
1153      .setTab("global")             
1154      ;
1155   cp5.getController("loadButton").captionLabel().setFont(font16) ;
1156   cp5.getController("loadButton").captionLabel().toUpperCase(false) ;
1157   cp5.getController("loadButton").getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER) ;
1158   
1159   // Save preset button
1160   cp5.addButton("saveButton")    
1161      .setColorForeground(orangeAct)
1162      .setColorActive(blueAct)     
1163      .setLabel("Save Preset")      
1164      .setPosition(120, 369)
1165      .setSize(100, 25)  
1166      .setTab("global")   
1167      ;
1168   cp5.getController("saveButton").captionLabel().setFont(font16) ;
1169   cp5.getController("saveButton").captionLabel().toUpperCase(false) ;
1170   cp5.getController("saveButton").getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER) ;
1171   
1172   
1173   // Write button
1174   cp5.addButton("writeConfButton")    
1175      .setColorForeground(orangeAct)
1176      .setColorActive(blueAct)    
1177      .setLabel("Write Config")      
1178      .setPosition(260, 367)
1179      .setSize(120, 30)  
1180      .setTab("data")   
1181      ;
1182   cp5.getController("writeConfButton").captionLabel().setFont(font20) ;            
1183   cp5.getController("writeConfButton").captionLabel().toUpperCase(false) ;
1184   cp5.getController("writeConfButton").getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER) ;
1186   // --------------------------------------------------------------------------
1188   // dropdownlist overlap
1189   prot.bringToFront() ;  
1190   cp5.getGroup("resetButtonPin").bringToFront() ; 
1191   serialPin.bringToFront() ;
1192   climbPin.bringToFront() ;  
1193   ppmPin.bringToFront() ;
1194   ddlNbrCells.bringToFront();
1195   for ( int i = 1; i <= voltNbr; i++ ) {
1196     cp5.getGroup("ddlVolt" + i).bringToFront() ;
1197   }  
1198   cp5.getGroup("currentPin").bringToFront() ;  
1199   cp5.getGroup("tempPin").bringToFront() ;
1200   for ( int i = dataSentFieldNbr; i >= 1; i-- ) {
1201     cp5.getGroup("sentDataField" + i).bringToFront() ;
1202     cp5.getGroup("hubDataField" + i).bringToFront() ;
1203     cp5.getGroup("sPortDataField" + i).bringToFront() ;
1204   } 
1205   
1206   // Tooltips general settings
1207   cp5.getTooltip().setDelay(1000) ;
1208   cp5.getTooltip().getLabel().toUpperCase(false) ;
1209     
1210   createMessageBox() ;          //  Message box creation
1212 // *************************************************************************  
1213 } // ***************************** END SETUP *******************************
1214 // *************************************************************************
1216 // *************************************************************************
1217 // ********************************   DRAW   *******************************
1218 // *************************************************************************
1219 void draw() {
1220   background(myColorBackground); 
1221   // Main screen background
1222   fill(tabColor);
1223   rect(0, 100, width, 300);
1224   fill(70);
1225   rect(0, 97, width, 3);
1226   
1227   // Compatibility subtitle
1228   fill(0) ;
1229   textFont(fontLabel) ;
1230   text("For OXS " + oxsVersion, 50, 65) ;
1231   
1232   // OXS Configurator version display
1233   textFont(fontItalic) ;
1234   text(oxsCversion, 352, 68) ;
1235   
1236   // Logo display
1237   shapeMode(CENTER);                      
1238   shape(oxsL, width/2, 38, 300, 300);    
1239   
1240   // File dialog Zone
1241   fill(myColorBackground);
1242   rect(0, height, width, -60);
1243   fill(70);
1244   rect(0, height-60, width, 3); 
1245   
1246   // Show preset buttons
1247   cp5.getController("loadButton").show() ;    
1248   cp5.getController("saveButton").show() ;  
1250   // ------------ Tabs specific display ------------
1252   int ctid = cp5.window(this).currentTab().id();
1254   switch( ctid ) { 
1255        
1256   case 0 :                                        // TAB GENERAL Settings
1257     // SENSORS part
1258     fill(255, 128, 0);              
1259     rect(0, 255, 68, 18);
1260     rect(0, 270, 180, 3);
1261     rect(0, 271, 290, 2);
1262     rect(0, 272, width, 1);    
1264     if ( cp5.getController("intRef").value() == 1 ) {       
1265       cp5.getController("arduinoVccNb").lock() ;
1266       cp5.getController("arduinoVccNb").setColorBackground(grayedColor) ;
1267       cp5.getController("arduinoVccNb").setColorValueLabel(grayedColor) ;
1268       cp5.getController("arduinoVccNb").setColorLabel(grayedColor) ;      
1269     } else {        
1270       cp5.getController("arduinoVccNb").unlock() ;
1271       cp5.getController("arduinoVccNb").setColorBackground(color(70)) ;
1272       cp5.getController("arduinoVccNb").setColorValueLabel(color(255)) ;
1273       cp5.getController("arduinoVccNb").setColorLabel(color(0)) ;      
1274     }
1275     
1276     if ( cp5.getController("resetButton").value() == 0 ) {       
1277       cp5.getController("resetButtonPinLabel").setColorValue(grayedColor) ;
1278       cp5.getGroup("resetButtonPin").hide() ;
1279       fill(grayedColor) ;
1280       rect(360, 199, 30, 20) ;
1281     } else {        
1282       cp5.getController("resetButtonPinLabel").setColorValue(color(0)) ;
1283       cp5.getGroup("resetButtonPin").show() ;
1284     }
1285     
1286     if ( !tempActive ) {
1287       cp5.getController("temperature").setColorLabel(grayedColor) ;
1288       cp5.getController("temperature").setColorBackground(grayedColor) ;
1289     }    
1290     break ;
1292   case 1 :                                                 // TAB Vario
1293     if ( cp5.getController("ppm").value() == 0 ) {         // RC remote sensitivity
1294       cp5.getGroup("ppmPin").hide() ;
1295       fill(grayedColor) ;
1296       rect(303, 174, 30, 20) ;      
1297       cp5.getController("ppmPinL").setColorValue(grayedColor) ;
1299       cp5.getController("ppmRngL").setColorValue(grayedColor) ;
1300       cp5.getController("ppmRngMin").lock() ;      
1301       cp5.getController("ppmRngMin").setColorBackground(grayedColor) ;      
1302       cp5.getController("ppmRngMin").setColorValueLabel(grayedColor) ;
1303       cp5.getController("ppmRngMin").setColorLabel(grayedColor) ;
1304       
1305       cp5.getController("ppmRngMax").lock() ;      
1306       cp5.getController("ppmRngMax").setColorBackground(grayedColor) ;      
1307       cp5.getController("ppmRngMax").setColorValueLabel(grayedColor) ;
1308       cp5.getController("ppmRngMax").setColorLabel(grayedColor) ;      
1310       cp5.getController("ppmSensRngL").setColorValue(grayedColor) ;
1311       cp5.getController("ppmSensMinMax").lock() ;
1312       cp5.getController("ppmSensMinMax").setColorForeground(grayedColor) ;
1313       cp5.getController("ppmSensMinMax").setColorBackground(grayedColor) ;      
1314       cp5.getController("ppmSensMinMax").setColorValueLabel(grayedColor) ;
1315       cp5.getController("ppmSensMinMax").setColorLabel(grayedColor) ;
1316     } else { 
1317       cp5.getGroup("ppmPin").show() ;
1318       cp5.getController("ppmPinL").setColorValue(color(0)) ;      
1319       
1320       cp5.getController("ppmRngL").setColorValue(color(0)) ;
1321       cp5.getController("ppmRngMin").unlock() ;      
1322       cp5.getController("ppmRngMin").setColorBackground(color(70)) ;
1323       cp5.getController("ppmRngMin").setColorValueLabel(color(255)) ;
1324       cp5.getController("ppmRngMin").setColorLabel(color(0)) ;
1325       
1326       cp5.getController("ppmRngMax").unlock() ;      
1327       cp5.getController("ppmRngMax").setColorBackground(color(70)) ;
1328       cp5.getController("ppmRngMax").setColorValueLabel(color(255)) ;
1329       cp5.getController("ppmRngMax").setColorLabel(color(0)) ;
1330      
1331       cp5.getController("ppmSensRngL").setColorValue(color(0)) ;
1332       cp5.getController("ppmSensMinMax").unlock() ;
1333       cp5.getController("ppmSensMinMax").setColorForeground(blueAct) ;
1334       cp5.getController("ppmSensMinMax").setColorBackground(color(70)) ;
1335       cp5.getController("ppmSensMinMax").setColorValueLabel(color(255)) ;
1336       cp5.getController("ppmSensMinMax").setColorLabel(color(0)) ;
1337     }
1339     if ( cp5.getController("analogClimb").value() == 0 ) {                    // Analog climb rate
1340       cp5.getController("climbPinL").setColorValue(grayedColor) ;
1341       cp5.getGroup("climbPin").hide() ;
1342       fill(grayedColor) ;
1343       rect(303, 287, 30, 20) ;      
1345       cp5.getController("outClimbRateRngL").setColorValue(grayedColor) ;
1346       cp5.getController("outClimbRateMinMax").lock() ;
1347       cp5.getController("outClimbRateMinMax").setColorForeground(grayedColor) ;
1348       cp5.getController("outClimbRateMinMax").setColorBackground(grayedColor) ;      
1349       cp5.getController("outClimbRateMinMax").setColorValueLabel(grayedColor) ;
1350       cp5.getController("outClimbRateMinMax").setColorLabel(grayedColor) ;
1351     } else { 
1352       cp5.getController("climbPinL").setColorValue(color(0)) ;
1353       cp5.getGroup("climbPin").show() ;
1355       cp5.getController("outClimbRateRngL").setColorValue(color(0)) ;
1356       cp5.getController("outClimbRateMinMax").unlock() ;
1357       cp5.getController("outClimbRateMinMax").setColorForeground(blueAct) ;
1358       cp5.getController("outClimbRateMinMax").setColorBackground(color(70)) ;
1359       cp5.getController("outClimbRateMinMax").setColorValueLabel(color(255)) ;
1360       cp5.getController("outClimbRateMinMax").setColorLabel(color(0)) ;
1361     }    
1362     break ;
1364   case 2 :                                                 // TAB Voltage / Other
1365     
1366     for ( int i = 1; i <= voltNbr; i++ ) {                   // Voltage tab grayed items                  
1367       if ( cp5.getController("volt" + i).value() == 0 ) {    
1368         cp5.getGroup("ddlVolt" + i).hide() ;
1369         fill(grayedColor) ;
1370         rect(120 - 45 + i * 45, 165, 30, 20) ;
1371         cp5.getController("dividerVolt" + i).lock() ;
1372         cp5.getController("dividerVolt" + i).setColorBackground(color(165)) ;
1373         cp5.getController("dividerVolt" + i).setColorForeground(color(195)) ;
1374         cp5.getController("dividerVolt" + i).setColorValueLabel(color(165)) ;        
1375         cp5.getController("offsetVolt" + i).lock() ;
1376         cp5.getController("offsetVolt" + i).setColorBackground(color(175)) ;
1377         cp5.getController("offsetVolt" + i).setColorForeground(color(195)) ;
1378         cp5.getController("offsetVolt" + i).setColorValueLabel(color(175)) ;
1379       } else {
1380         cp5.getGroup("ddlVolt" + i).show() ;
1381         cp5.getController("dividerVolt" + i).unlock() ;
1382         cp5.getController("dividerVolt" + i).setColorBackground(color(70)) ;        
1383         cp5.getController("dividerVolt" + i).setColorValueLabel(color(255)) ;
1384         cp5.getController("offsetVolt" + i).unlock() ;
1385         cp5.getController("offsetVolt" + i).setColorBackground(color(70)) ;
1386         cp5.getController("offsetVolt" + i).setColorValueLabel(color(255)) ;
1387       }
1388     }
1390     if ( cp5.getController("volt1").value() == 0 ) {      // Battery cells monitoring grayed
1391       cp5.getController("cells").setBroadcast(false) ;    // deactivate continuous controller event
1392       cp5.getController("cells").setValue(0) ;
1393       cp5.getController("cells").lock() ;
1394       cp5.getController("cells").setColorBackground(grayedColor) ;
1395       cp5.getController("cells").setColorLabel(grayedColor) ;
1396     } else {
1397       cp5.getController("cells").setBroadcast(true) ;
1398       cp5.getController("cells").unlock() ;
1399       cp5.getController("cells").setColorBackground(color(70)) ;
1400       cp5.getController("cells").setColorLabel(color(0)) ;
1401     }
1403     if ( cp5.getController("cells").value() == 0 ) {                   // Cells number grayed
1404       cp5.getController("NbrCells").setColorValue(grayedColor) ;
1405       cp5.getGroup("ddlNbrCells").hide() ;
1406       fill(grayedColor) ;
1407       rect(283, 278, 25, 20) ;
1408     } else {
1409       cp5.getController("NbrCells").setColorValue(color(0)) ;
1410       cp5.getGroup("ddlNbrCells").show() ;
1411     }
1413     // Voltage tab ->  Cells indicator
1414     if ( cp5.getController("cells").value() == 1 && ddlNbrCells.getValue() > 0 ) { 
1415       int nCells = int(ddlNbrCells.getValue()) ;
1416       noSmooth();
1417       stroke(blueAct) ;      
1418       strokeWeight(3) ;
1419       strokeCap(PROJECT);
1420       fill(blueAct) ;      
1421       textFont(fontCells) ;
1422       text("CELLS", 68, 128) ;
1423       line ( 115, 117, 115, 128 ) ;
1424       line ( 115, 117, 110 + 45 * nCells, 117 ) ;
1425       line ( 110 + 45 * nCells, 117, 110 + 45 * nCells, 128 ) ;
1426       noStroke() ;
1427       smooth() ;
1428     }    
1429     break ;
1431   case 3 :                                                            // TAB Current sensor
1432     /*
1433     if ( cp5.getController("currentDir").value() == 0 ) {             // Current grayed switch
1434       cp5.getController("currentDirL").setColorValue(grayedColor) ; 
1435       cp5.getController("currentDir").setColorCaptionLabel(color(0)) ;
1436     } else {
1437       cp5.getController("currentDirL").setColorValue(color(0)) ; 
1438       cp5.getController("currentDir").setColorCaptionLabel(grayedColor) ;
1439     }
1440     */
1441     break ;
1442     
1443   case 6 :                                                            // TAB DATA sent
1444     fill(10);
1445     rect(258, 365, 124, 34);
1446     // Load and Save preset buttons hide  for ( int i = 6 ; i <= dataSentFieldNbr ; i++ ) {
1447       if ( cp5.getGroup("sentDataField" + 6 ).isOpen() || cp5.getGroup("hubDataField" + 6 ).isOpen() || cp5.getGroup("sPortDataField" + 6 ).isOpen() 
1448            || cp5.getGroup("sentDataField" + 7 ).isOpen() || cp5.getGroup("hubDataField" + 7 ).isOpen() || cp5.getGroup("sPortDataField" + 7 ).isOpen() 
1449            || cp5.getGroup("sentDataField" + 8 ).isOpen() || cp5.getGroup("hubDataField" + 8 ).isOpen() || cp5.getGroup("sPortDataField" + 8 ).isOpen() ) {
1450         cp5.getController("loadButton").hide() ;
1451         cp5.getController("saveButton").hide() ;        
1452       } else {
1453          cp5.getController("loadButton").show() ;
1454          cp5.getController("saveButton").show() ;         
1455       }
1456    // }
1457    
1458     // Grayed multiplier + divider + offset if Telemetry data field == DEFAULT
1459     for ( int i = 1 ; i <= dataSentFieldNbr ; i++ ) {
1460       if ( cp5.getGroup("protocolChoice").value() == 1 ) {      
1461         if ( cp5.getGroup("hubDataField" + i).value() == 1 ) {
1462           cp5.getController("dataMultiplier" + i).lock() ;
1463           cp5.getController("dataMultiplier" + i).setColorBackground(grayedColor) ;
1464           cp5.getController("dataMultiplier" + i).setColorValueLabel(grayedColor) ;
1465           cp5.getController("dataDivider" + i).lock() ;
1466           cp5.getController("dataDivider" + i).setColorBackground(grayedColor) ;
1467           cp5.getController("dataDivider" + i).setColorValueLabel(grayedColor) ;
1468           cp5.getController("dataOffset" + i).lock() ;
1469           cp5.getController("dataOffset" + i).setColorBackground(grayedColor) ;
1470           cp5.getController("dataOffset" + i).setColorValueLabel(grayedColor) ;          
1471         } else {        
1472           cp5.getController("dataMultiplier" + i).unlock() ;
1473           cp5.getController("dataMultiplier" + i).setColorBackground(color(70)) ;
1474           cp5.getController("dataMultiplier" + i).setColorValueLabel(color(255)) ;
1475           cp5.getController("dataDivider" + i).unlock() ;
1476           cp5.getController("dataDivider" + i).setColorBackground(color(70)) ;
1477           cp5.getController("dataDivider" + i).setColorValueLabel(color(255)) ;
1478           cp5.getController("dataOffset" + i).unlock() ;
1479           cp5.getController("dataOffset" + i).setColorBackground(color(70)) ;
1480           cp5.getController("dataOffset" + i).setColorValueLabel(color(255)) ;          
1481         }
1482       } else if ( cp5.getGroup("protocolChoice").value() == 2 ) {
1483         if ( cp5.getGroup("sPortDataField" + i).value() == 1 ) {
1484           cp5.getController("dataMultiplier" + i).lock() ;
1485           cp5.getController("dataMultiplier" + i).setColorBackground(grayedColor) ;
1486           cp5.getController("dataMultiplier" + i).setColorValueLabel(grayedColor) ;
1487           cp5.getController("dataDivider" + i).lock() ;
1488           cp5.getController("dataDivider" + i).setColorBackground(grayedColor) ;
1489           cp5.getController("dataDivider" + i).setColorValueLabel(grayedColor) ;
1490           cp5.getController("dataOffset" + i).lock() ;
1491           cp5.getController("dataOffset" + i).setColorBackground(grayedColor) ;
1492           cp5.getController("dataOffset" + i).setColorValueLabel(grayedColor) ;          
1493         } else {        
1494           cp5.getController("dataMultiplier" + i).unlock() ;
1495           cp5.getController("dataMultiplier" + i).setColorBackground(color(70)) ;
1496           cp5.getController("dataMultiplier" + i).setColorValueLabel(color(255)) ;
1497           cp5.getController("dataDivider" + i).unlock() ;
1498           cp5.getController("dataDivider" + i).setColorBackground(color(70)) ;
1499           cp5.getController("dataDivider" + i).setColorValueLabel(color(255)) ;
1500           cp5.getController("dataOffset" + i).unlock() ;
1501           cp5.getController("dataOffset" + i).setColorBackground(color(70)) ;
1502           cp5.getController("dataOffset" + i).setColorValueLabel(color(255)) ;          
1503         }        
1504       }
1505     }
1506     break ;
1507   }
1509   // ---------------- End TAB specific display ---------------
1510   
1511   // Load and Save preset buttons deco
1512   if ( cp5.getController("loadButton").isVisible() ) {    
1513     fill(blueAct);
1514     rect(9, 368, 102, 27);    
1515     fill(orangeAct);
1516     rect(119, 368, 102, 27);
1517   }
1519   // ----------------- Texfield and Numberbox mouse-over -----------------
1520   
1521   if ( cp5.isMouseOver (oxsDir) ) {
1522     oxsDir.setColorForeground(blueAct);
1523   } else {
1524     oxsDir.setColorForeground(color(200));
1525   }
1527   if ( cp5.isMouseOver ( cp5.getController("arduinoVccNb") ) ) {
1528     cp5.getController("arduinoVccNb").setColorForeground(blueAct);
1529   } else {
1530     cp5.getController("arduinoVccNb").setColorForeground(grayedColor);
1531   }
1532   
1533   if ( cp5.isMouseOver ( cp5.getController("vSpeedMin") ) ) {
1534     cp5.getController("vSpeedMin").setColorForeground(orangeAct);
1535   } else {
1536     cp5.getController("vSpeedMin").setColorForeground(grayedColor);
1537   }
1538   
1539   if ( cp5.isMouseOver ( cp5.getController("vSpeedMax") ) ) {
1540     cp5.getController("vSpeedMax").setColorForeground(orangeAct);
1541   } else {
1542     cp5.getController("vSpeedMax").setColorForeground(grayedColor);
1543   }
1544   
1545   if ( cp5.isMouseOver ( cp5.getController("ppmRngMin") ) ) {
1546     cp5.getController("ppmRngMin").setColorForeground(orangeAct);
1547   } else {
1548     cp5.getController("ppmRngMin").setColorForeground(grayedColor);
1549   }
1550   
1551   if ( cp5.isMouseOver ( cp5.getController("ppmRngMax") ) ) {
1552     cp5.getController("ppmRngMax").setColorForeground(orangeAct);
1553   } else {
1554     cp5.getController("ppmRngMax").setColorForeground(grayedColor);
1555   }
1557   for ( int i = 1; i <= voltNbr; i++ ) {
1558     if ( cp5.isMouseOver ( cp5.getController( "dividerVolt" + i ) ) ) {     
1559       cp5.getController( "dividerVolt" + i ).setColorForeground(orangeAct);
1560     } else {
1561       cp5.getController( "dividerVolt" + i ).setColorForeground(color(170));
1562     }
1563   }
1565   for ( int i = 1; i <= voltNbr; i++ ) {
1566     if ( cp5.isMouseOver ( cp5.getController( "offsetVolt" + i ) ) ) {     
1567       cp5.getController( "offsetVolt" + i ).setColorForeground(orangeAct);
1568     } else {
1569       cp5.getController( "offsetVolt" + i ).setColorForeground(color(170));
1570     }
1571   }
1573   if ( cp5.isMouseOver ( cp5.getController( "currentVccNb" ) ) ) {
1574     cp5.getController( "currentVccNb" ).setColorForeground(orangeAct);
1575   } else {
1576     cp5.getController( "currentVccNb" ).setColorForeground(color(170));
1577   }
1578 */ 
1579   if ( cp5.isMouseOver ( cp5.getController( "currentDivNb" ) ) ) {
1580     cp5.getController( "currentDivNb" ).setColorForeground(orangeAct);
1581   } else {
1582     cp5.getController( "currentDivNb" ).setColorForeground(color(170));
1583   }
1585   if ( cp5.isMouseOver ( cp5.getController( "currentOutSensNb" ) ) ) {
1586     cp5.getController( "currentOutSensNb" ).setColorForeground(orangeAct);
1587   } else {
1588     cp5.getController( "currentOutSensNb" ).setColorForeground(color(170));
1589   }
1591   if ( cp5.isMouseOver ( cp5.getController( "currentOutOffsetNb" ) ) ) {
1592     cp5.getController( "currentOutOffsetNb" ).setColorForeground(orangeAct);
1593   } else {
1594     cp5.getController( "currentOutOffsetNb" ).setColorForeground(color(170));
1595   }
1596   
1597   if ( cp5.isMouseOver ( cp5.getController( "tempOffset" ) ) ) {
1598     cp5.getController( "tempOffset" ).setColorForeground(orangeAct);
1599   } else {
1600     cp5.getController( "tempOffset" ).setColorForeground(color(200));
1601   }  
1603   for ( int i = 1; i <= dataSentFieldNbr; i++ ) {
1604     if ( cp5.isMouseOver ( cp5.getController( "dataMultiplier" + i ) ) ) {     
1605       cp5.getController( "dataMultiplier" + i ).setColorForeground(orangeAct);
1606     } else {
1607       cp5.getController( "dataMultiplier" + i ).setColorForeground(grayedColor);
1608     }
1609   }
1611   for ( int i = 1; i <= dataSentFieldNbr; i++ ) {
1612     if ( cp5.isMouseOver ( cp5.getController( "dataDivider" + i ) ) ) {     
1613       cp5.getController( "dataDivider" + i ).setColorForeground(orangeAct);
1614     } else {
1615       cp5.getController( "dataDivider" + i ).setColorForeground(grayedColor);
1616     }
1617   }
1619   for ( int i = 1; i <= dataSentFieldNbr; i++ ) {
1620     if ( cp5.isMouseOver ( cp5.getController( "dataOffset" + i ) ) ) {     
1621       cp5.getController( "dataOffset" + i ).setColorForeground(orangeAct);
1622     } else {
1623       cp5.getController( "dataOffset" + i ).setColorForeground(grayedColor);
1624     }
1625   }
1627   // ----------------- Dropdownlist: mouse pressed elsewhere closes list -----------------
1628   
1629   if ( !cp5.isMouseOver ( prot ) ) {
1630     if (mousePressed == true) {
1631       prot.close() ;
1632     }
1633   }
1634   
1635   if ( !cp5.isMouseOver ( serialPin ) ) {
1636     if (mousePressed == true) {
1637       serialPin.close() ;
1638     }
1639   }
1640   
1641   if ( !cp5.isMouseOver ( cp5.getGroup( "resetButtonPin" ) ) ) {
1642     if (mousePressed == true) {
1643       cp5.getGroup( "resetButtonPin" ).close() ;
1644     }
1645   }
1646   
1648   if ( !cp5.isMouseOver ( ppmPin ) ) {
1649     if (mousePressed == true) {
1650       ppmPin.close() ;
1651     }
1652   }
1654   if ( !cp5.isMouseOver ( climbPin ) ) {
1655     if (mousePressed == true) {
1656       climbPin.close() ;
1657     }
1658   }
1660   for ( int i = 1; i <= voltNbr; i++ ) {
1661     if ( !cp5.isMouseOver ( cp5.getGroup( "ddlVolt" + i ) ) ) {
1662       if (mousePressed == true) {
1663         cp5.getGroup( "ddlVolt" + i ).close() ;
1664       }
1665     }
1666   }
1668   if ( !cp5.isMouseOver ( cp5.getGroup( "ddlNbrCells") ) ) {
1669     if (mousePressed == true) {
1670       cp5.getGroup( "ddlNbrCells" ).close() ;
1671     }
1672   }
1674   if ( !cp5.isMouseOver ( cp5.getGroup( "currentPin") ) ) {
1675     if (mousePressed == true) {
1676       cp5.getGroup( "currentPin" ).close() ;
1677     }
1678   }
1679   
1680   if ( !cp5.isMouseOver ( cp5.getGroup( "tempPin") ) ) {
1681     if (mousePressed == true) {
1682       cp5.getGroup( "tempPin" ).close() ;
1683     }
1684   }  
1686   for ( int i = 1; i <= dataSentFieldNbr; i++ ) {
1687     if ( !cp5.isMouseOver ( cp5.getGroup( "sentDataField" + i ) ) ) {
1688       if (mousePressed == true) {
1689         cp5.getGroup( "sentDataField" + i ).close() ;
1690       }
1691     }
1692   }
1694   for ( int i = 1; i <= dataSentFieldNbr; i++ ) {
1695     if ( !cp5.isMouseOver ( cp5.getGroup( "hubDataField" + i ) ) ) {
1696       if (mousePressed == true) {
1697         cp5.getGroup( "hubDataField" + i ).close() ;
1698       }
1699     }
1700   }
1702   for ( int i = 1; i <= dataSentFieldNbr; i++ ) {
1703     if ( !cp5.isMouseOver ( cp5.getGroup( "sPortDataField" + i ) ) ) {
1704       if (mousePressed == true) {
1705         cp5.getGroup( "sPortDataField" + i ).close() ;
1706       }
1707     }
1708   }
1710   // ----------------- TAB DATA sent display ----------------- 
1711   
1712   if ( cp5.getController("vario").getValue() == 1 || cp5.getController("voltage").getValue() == 1 || 
1713     cp5.getController("current").getValue() == 1 || cp5.getController("temperature").getValue() == 1 ||
1714   cp5.getController("rpm").getValue() == 1 ) {
1715     cp5.getTab("data").show() ;
1716   } else {
1717     cp5.getTab("data").hide() ;
1718   }  
1719 // *************************************************************************
1720 } // ***************************   end DRAW   ******************************
1721 // *************************************************************************
1723 void controlEvent(ControlEvent theEvent) {
1724   // DropdownList is of type ControlGroup.
1725   // A controlEvent will be triggered from inside the ControlGroup class.
1726   // therefore you need to check the originator of the Event with if (theEvent.isGroup()) to avoid an error message thrown by controlP5.  
1728   if ( theEvent.isFrom(cp5.getController("vSpeedMax")) || theEvent.isFrom(cp5.getController("vSpeedMin")) ) {   //  V speed sensitivity range interaction
1729     cp5.getController("vSpeedMax").setBroadcast(false) ;
1730     cp5.getController("vSpeedMin").setBroadcast(false) ;
1731     cp5.get(Numberbox.class, "vSpeedMax").setRange( cp5.getController("vSpeedMin").getValue(), 1000 ) ; 
1732     cp5.get(Numberbox.class, "vSpeedMin").setRange( 0, cp5.getController("vSpeedMax").getValue() ) ; 
1733     cp5.getController("vSpeedMin").setBroadcast(true) ;
1734     cp5.getController("vSpeedMax").setBroadcast(true) ;
1735   }
1737   if ( theEvent.isFrom(cp5.getGroup("protocolChoice")) ) {           // Showing right Telemetry data list in fields
1738     switch( int(theEvent.getGroup().getValue()) ) {      
1739       case 1 :    
1740         for ( int i = 1; i <= dataSentFieldNbr; i++ ) {
1741           cp5.getGroup("hubDataField" + i).show() ;
1742           cp5.getGroup("sPortDataField" + i).hide() ;       
1743         }
1744         break ;
1745       case 2 :    
1746         for ( int i = 1; i <= dataSentFieldNbr; i++ ) {
1747           cp5.getGroup("sPortDataField" + i).show() ;
1748           cp5.getGroup("hubDataField" + i).hide() ;        
1749         }
1750         break ;
1751     }
1752   }
1753   
1754   for ( int i = 1; i <= dataSentFieldNbr; i++ ) { 
1755     if ( theEvent.isFrom(cp5.getGroup("sentDataField" + i )) ) {           // Selecting DEFAULT automaticaly in Telemetry data fields
1756       switch( int(theEvent.getGroup().getValue()) ) {        
1757         case 1 :    // "ALTIMETER"
1758         case 2 :    // "VERTICAL_SPEED"
1759         case 5 :    // "CURRENTMA"
1760         case 7 :    // "CELLS"
1761         case 14 :   // "RPM"
1762           cp5.getGroup("hubDataField" + i).setValue(1) ;
1763           cp5.getGroup("sPortDataField" + i).setValue(1) ;  
1764           break ; 
1765       }
1766     }
1767   }
1768 /*    
1769   if (theEvent.isGroup()) {
1770     // check if the Event was triggered from a ControlGroup
1771     println("event from group : "+theEvent.getGroup().getValue()+" from "+theEvent.getGroup());
1772   } else if (theEvent.isController()) {
1773     println("event from controller : "+theEvent.getController().getValue()+" from "+theEvent.getController());
1774   }
1778 public void mouseWheelMoved(java.awt.event.MouseWheelEvent e) {  // Mouse wheel support for scroll bars !!
1779   super.mouseWheelMoved(e);
1780   cp5.setMouseWheelRotation(e.getWheelRotation());
1783 public void oxsDirButton(int theValue) {
1784   //println("oxsDir button: "+theValue);
1785   selectFolder("Select OXS source folder:", "folderSelected");
1788 void vario(boolean theFlag) {
1789   if (theFlag==true) {
1790     cp5.getTab("vario").show() ;
1791   } else {
1792     cp5.getTab("vario").hide() ;
1793   }
1794   //println("a toggle event.");
1797 void voltage(boolean theFlag) {
1798   if (theFlag==true) {
1799     cp5.getTab("voltage").show() ;
1800   } else {
1801     cp5.getTab("voltage").hide() ;
1802   }
1803   //println("a toggle event.");
1806 void current(boolean theFlag) {
1807   if (theFlag==true) {
1808     cp5.getTab("current").show() ;
1809   } else {
1810     cp5.getTab("current").hide() ;
1811   }
1812   //println("a toggle event.");
1815 void temperature(boolean theFlag) {  
1816   if (theFlag==true) {
1817     cp5.getTab("temperature").show() ;
1818   } else {
1819     cp5.getTab("temperature").hide() ;
1820   }
1821   //println("a toggle event.");  
1824 /* // RPM TAB display
1825  void rpm(boolean theFlag) {
1826  if (theFlag==true) {
1827  cp5.getTab("rpm").show() ;
1828  } else {
1829  cp5.getTab("rpm").hide() ;
1831  println("a toggle event.");
1833  */
1835 void about(boolean theFlag) {
1836   
1837   mbClose() ; 
1838   
1839   messageList.clear() ;
1840   
1841   messageList.append( "                           OXS Configurator for OXS " + oxsVersion ) ;
1842   messageList.append( "                                                   ---" ) ;
1843   messageList.append( "                 -- OpenXsensor configuration file GUI " + oxsCversion + " --" ) ;
1844   messageList.append( "\n" ) ;
1845   messageList.append( "Contributors:" ) ;
1846   messageList.append( "" ) ;
1847   messageList.append( "- Rainer Schloßhan" ) ;
1848   messageList.append( "- Bertrand Songis" ) ;
1849   messageList.append( "- André Bernet" ) ;
1850   messageList.append( "- Michael Blandford" ) ;
1851   messageList.append( "- Michel Strens" ) ;
1852   messageList.append( "- David Laburthe" ) ;
1853   messageList.append( "" ) ;
1854   messageList.append( "" ) ;  
1855   
1856   String[] messageListArray = messageList.array();
1857   
1858   String joinedMessageList = join(messageListArray, "\n") ; 
1859    
1860   cp5.get(Textarea.class, "messageBoxLabel").setText(joinedMessageList) ;    
1861   
1862   cp5.getController("buttonOK").setColorForeground(orangeAct);
1863   cp5.getController("buttonOK").setColorBackground(color(100));
1864   cp5.getController("buttonOK").setColorActive(blueAct);
1865   messageBox.setBackgroundColor(blueAct);
1866   messageBox.show();  
1869 public void loadButton(int theValue) {                                     // Load preset button
1870   File presetDir = new File( sketchPath("Preset/...") ) ;
1871   selectInput("Select a preset file to load:", "presetLoad", presetDir);
1874 public void saveButton(int theValue) {                                     // Save preset button
1875   mbClose() ;
1876   validationProcess("preset") ;
1877   if ( allValid ) {
1878     messageBox.hide();
1879     File presetDir = new File( sketchPath("Preset/type name") ) ;
1880     selectOutput("Type preset name to save:", "presetSave", presetDir);
1881   }
1884 void presetLoad(File selection) {  
1885   if (selection == null) {
1886     //println("Window was closed or the user hit cancel.");
1887   } else {
1888     //println("User selected " + selection.getAbsolutePath());
1889     cp5.loadProperties(selection.getAbsolutePath());
1890   
1891     // Hack to keep slider labels alignement
1892     cp5.getController("varioHysteresis").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER).setPaddingX(10) ;  
1893     cp5.getController("varioHysteresis").getValueLabel().align(ControlP5.RIGHT_OUTSIDE, ControlP5.CENTER).setPaddingX(10) ;
1894   }  
1897 void presetSave(File selection) {
1898   if (selection == null) {
1899     //println("Window was closed or the user hit cancel.");
1900   } else {
1901     //println("User selected " + selection.getAbsolutePath());
1902     cp5.saveProperties(selection.getAbsolutePath());
1903   }    
1906 public void writeConfButton(int theValue) {  
1907   mbOkCancel() ; 
1908   validationProcess("Config") ;  
1909   if ( !allValid ) {   
1910     mbClose() ; 
1911   }
1914 public void validationProcess(String theString) {
1915   
1916   // Config file writing destination
1917   oxsDirectory = trim( cp5.get(Textfield.class, "oxsDirectory").getText() ) ;
1918   if ( oxsDirectory.equals("") ) {       
1919     outputConfigDir = sketchPath("oxs_config.h") ;   
1920   } else {    
1921     outputConfigDir = oxsDirectory + "/oxs_config.h" ;  
1922   }  
1923   
1924   messageList.clear() ;
1925   messageList.set(0, "") ;
1926   messageList.append("") ;
1927   
1928   numPinsValid = true ; 
1929   analogPinsValid = true ; 
1930   cellsValid = true ;
1931   oxsMeasureValid = true ;
1932   versionValid = 2 ;          // 0 -> not valid    1 -> warning   2 -> valid
1933   
1934   validateNumPins() ;  
1935   validateAnalogPins() ;
1936   validateCells() ;
1937   validateSentData() ;
1938   validateVersion() ; 
1939   
1940   if ( numPinsValid && analogPinsValid && cellsValid && oxsMeasureValid && versionValid == 2 ) {    
1941     messageList.set(0, "                                 --- ALL IS GOOD ! ---") ;    
1942     if ( theString.equals("preset") ) {
1943       messageList.append("Preset file can be saved !") ;  
1944     } else {
1945       messageList.append("Configuration file will be written to:") ;
1946       messageList.append(outputConfigDir) ; 
1947       messageList.append("") ;
1948       messageList.append(" ! If the file already exists, it will be replaced !") ;
1949     }
1950     messageList.append("") ;
1951     messageList.append("                                      -------------------") ;    
1952      
1953     allValid = true ;
1954     
1955   } else if ( numPinsValid && analogPinsValid && cellsValid && oxsMeasureValid && versionValid == 1 ) {
1956     messageList.set(0, "                                     --- WARNING---") ;
1957     messageList.append("") ;
1958     messageList.append("                                      --------------------") ;
1959     messageList.append("") ;
1960     messageList.append("Configuration file will be written to:") ;
1961     messageList.append(outputConfigDir) ; 
1962     messageList.append("") ;
1963     messageList.append(" ! If the file already exists, it will be replaced !") ;
1964     
1965     allValid = true ;
1966     
1967   } else {
1968     messageList.set(0, "                                      --- ERROR ---") ;
1969     messageList.append("") ;
1970     messageList.append("                                      -------------------") ;
1971     messageList.append("") ;
1972     if ( theString.equals("preset") ) {
1973       messageList.append("Preset file can't be saved !") ;  
1974     } else {
1975       messageList.append("Config file can't be written !") ;
1976     }     
1977     //cp5.get(Textarea.class, "messageBoxLabel").setColor(color(255,0,0)) ;
1978     allValid = false ;   
1979   }
1980   
1981   String[] messageListArray = messageList.array();
1982   
1983   String joinedMessageList = join(messageListArray, "\n") ; 
1984    
1985   cp5.get(Textarea.class, "messageBoxLabel").setText(joinedMessageList) ; 
1986   //println(messageList) ;
1987   
1988   messageBox.setBackgroundColor(color(240));
1989   cp5.getController("buttonOK").setColorForeground(color(blueAct));  
1990   cp5.getController("buttonOK").setColorActive(color(orangeAct));
1991   messageBox.show();
1992   
1995 void folderSelected(File selection) {
1996   if (selection == null) {
1997     //println("Window was closed or the user hit cancel.");
1998   } else {
1999     //println("User selected " + selection.getAbsolutePath());
2000     cp5.get(Textfield.class, "oxsDirectory").setText(selection.getAbsolutePath());
2001   }
2004 void keyPressed() {
2005   // default properties load/save key combinations are 
2006   // alt+shift+l to load properties
2007   // alt+shift+s to save properties
2008   if (key=='s') {
2009     cp5.saveProperties(("settings.oxs"));
2010   } else if (key=='l') {
2011     cp5.loadProperties(("settings.oxs"));
2013     // Hack to keep slider labels alignement
2014     cp5.getController("varioHysteresis").getCaptionLabel().align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER).setPaddingX(10) ;  
2015     cp5.getController("varioHysteresis").getValueLabel().align(ControlP5.RIGHT_OUTSIDE, ControlP5.CENTER).setPaddingX(10) ;
2017     cp5.getProperties().print();  
2018   } else if ( key == 't' ) {
2019     println( "mAmp / step " + mAmpStep() ) ;
2020     println( "Current offset " + offsetCurrent() ) ;
2021   } else if ( key == 'v' ) {
2022     validationProcess("Config") ;
2023   }
2026 float round(float number, float decimal) {      // Rounding function
2027   return (float)(round((number*pow(10, decimal))))/pow(10, decimal);
2030 float mAmpStep() {    // Current sensor milliAmp per ADC step calculation
2032   float mAmpStep ;
2033   float mAmpPmV ;
2034   float currentDiv = float( cp5.getController("currentDivNb").getValueLabel().getText() ) ;
2035   float arduinoVcc = float( cp5.getController("arduinoVccNb").getValueLabel().getText() ) ;
2037   mAmpPmV = 1000 / float( cp5.getController("currentOutSensNb").getValueLabel().getText() );
2038   if ( cp5.getController("intRef").value() == 0 ) {
2039     mAmpStep = ( arduinoVcc * 1000.0 / 1024.0 ) * mAmpPmV * currentDiv ;
2040   } else {
2041     mAmpStep = ( 1.1 * 1000.0 / 1024.0 ) * mAmpPmV ;
2042   }
2043   return mAmpStep ;
2046 int offsetCurrent() {    // Current sensor offset calculation in ADC step
2047    
2048   int offsetCurrent ;
2049   //float currentVcc = float( cp5.getController("currentVccNb").getValueLabel().getText() ) ;
2050   float currentOutOffset = float( cp5.getController("currentOutOffsetNb").getValueLabel().getText() ) ;
2051   float currentDiv = float( cp5.getController("currentDivNb").getValueLabel().getText() ) ;
2052   float arduinoVcc = float( cp5.getController("arduinoVccNb").getValueLabel().getText() ) ;  
2054   //if ( cp5.getController( "currentDir" ).value() == 0 ) {  
2055   //  offsetCurrent = int( ( currentVcc / 2.0 + currentOutOffset / 1000.0 ) / arduinoVcc  * 1024.0 * currentDiv ) ;
2056   //} else {
2057     offsetCurrent = int( currentOutOffset / 1000.0 / arduinoVcc  * 1024.0 * currentDiv ) ;
2058   //}
2060   return offsetCurrent ;