1 // config file writing function
5 boolean dataFirst = true ;
7 output = createWriter( outputConfigDir );
9 output.println("// Configuration file generated by OpenXsensor Configurator " + oxsCversion + " the: " + day + "-" + month + "-" + year() );
10 output.println("// !! This file is only compatible with version " + oxsVersion + " of OpenXsensor !!");
12 output.println("#ifndef OXS_CONFIG_h");
13 output.println("#define OXS_CONFIG_h");
14 output.println("// openxvario http://code.google.com/p/openxvario/");
15 output.println("// started by Rainer Schloßhan");
18 // ---------------------------------- Protocol --------------------------------------
20 if ( prot.getValue() == 2 ) {
21 output.println("// *****************************");
22 output.println("// **** Smart Port Protocol ****");
23 output.println("// *****************************");
24 output.println("#define FRSKY_SPORT // put this line as comment if OXS is connected to a D serie receiver ( = Hub protocol); do not comment for X serie receiver.");
25 output.println("#define SENSOR_ID 0x1B // this parameter identifies a device connected on SPORT. It is not allowed having 2 devices with the same ID connected at the same time");
27 output.println("// ****************************");
28 output.println("// ******** HUB Protocol ******");
29 output.println("// ****************************");
32 // ---------------------------------- Serial pin --------------------------------------
35 output.println("#define PIN_SerialTX " + serialPin.captionLabel().getText() + " // The pin to transmit the serial data to the frsky telemetry enabled receiver");
36 //output.println(" // It is a DIGITAL arduino pin that has to be connected to \"Rx\" pin from receiver (for D serie RX) or to Signal pin (for X serie RX)");
37 //output.println(" // mandatory ; default: 4 ; allowed values are 0 up to 7 but take care not using the same pin as PPM (if PPM is used)");
40 // ------------------------------- Voltage reference -----------------------------------
42 if ( cp5.getController("intRef").value() == 1 ) {
43 output.println("#define USE_INTERNAL_REFERENCE // Select the voltage reference, comment the line to activate the VCC voltage reference");
44 output.println("//#define ARDUINOVCC // Specify the VCC voltage of the arduino to correctly read ADC values");
47 output.println("//#define USE_INTERNAL_REFERENCE // Select the voltage reference, uncomment the line to activate the internal 1.1v voltage reference");
48 output.println("#define ARDUINOVCC " + cp5.getController("arduinoVccNb").getValueLabel().getText() + " // Specify the VCC voltage of the arduino to correctly read ADC values");
52 // -------------------------- Reset button ----------------------------
54 if ( cp5.getController("resetButton").value() == 1 && cp5.getGroup("resetButtonPin").getValue() != -1 ) {
55 output.println("// -------- Reset button --------");
56 output.println("#define PIN_PushButton " + cp5.get(DropdownList.class, "resetButtonPin").captionLabel().getText() + " // check if a button has been pushed to reset some values (consumption, max altititude, max current, ...)");
60 // -------------------------- Save to EEPROM ----------------------------
62 if ( cp5.getController("saveEprom").value() == 1 ) {
63 output.println("// -------- EEPROM save + Reset button --------");
64 output.println("#define SAVE_TO_EEPROM // If defined, some telemetry values will be stored in EEProm every 10 seconds.");
65 output.println(" // These values will be restored every powerup. (e.g. mAh counted...)");
69 // ---------------------------------- Vario --------------------------------------
71 if ( cp5.getController("vario").value() == 1 ) {
72 output.println("// -------- VARIO --------");
73 output.println("#define VARIO // set as comment if there is no vario");
75 output.println("#define SENSITIVITY_MIN " + int(cp5.getController("sensMinMax").getArrayValue(0)) );
76 output.println("#define SENSITIVITY_MAX " + int(cp5.getController("sensMinMax").getArrayValue(1)) );
77 output.println("#define VSPEED_MIN " + int(cp5.getController("vSpeedMin").getValue()) );
78 output.println("#define VSPEED_MAX " + int(cp5.getController("vSpeedMax").getValue()) );
81 if ( cp5.getController("ppm").value() == 1 ) {
82 output.println("#define PIN_PPM " + ppmPin.captionLabel().getText() + " // Arduino can read a PPM Signal coming from Tx. This allows to change the vario sensitivity using a pot or a switch on TX.");
84 output.println("#define PPM_RANGE_MIN " + int(cp5.getController("ppmRngMin").getValue()) );
85 output.println("#define PPM_RANGE_MAX " + int(cp5.getController("ppmRngMax").getValue()) );
86 output.println("#define SENSITIVITY_PPM_MIN " + int(cp5.getController("ppmSensMinMax").getArrayValue(0)) );
87 output.println("#define SENSITIVITY_PPM_MAX " + int(cp5.getController("ppmSensMinMax").getArrayValue(1)) );
90 output.println("// do not modify those lines");
91 output.println("#ifdef PIN_PPM");
92 output.println(" #if PIN_PPM == 2");
93 output.println(" #define PPM_INTERRUPT ON // define to use interrupt code in Aserial.cpp");
95 output.println(" #define PPM_INT_MASK 3");
96 output.println(" #define PPM_INT_EDGE 1");
97 output.println(" #define PPM_PIN_HEX 0x02");
98 output.println(" #define PPM_INT_BIT 0x01");
99 output.println(" #endif");
101 output.println(" #if PIN_PPM == 3");
102 output.println(" #define PPM_INTERRUPT ON // define to use interrupt code in Aserial.cpp");
103 output.println(" #define PPM_INT_MASK 0x0C");
104 output.println(" #define PPM_INT_EDGE 0x04");
105 output.println(" #define PPM_PIN_HEX 0x04");
106 output.println(" #define PPM_INT_BIT 0x02");
107 output.println(" #endif");
108 output.println("#endif");
111 output.println("//#define PIN_PPM // Arduino can read a PPM Signal coming from Tx. This allows to change the vario sensitivity using a pot or a switch on TX.");
113 output.println("//#define PPM_RANGE_MIN ");
114 output.println("//#define PPM_RANGE_MAX ");
115 output.println("//#define SENSITIVITY_PPM_MIN ");
116 output.println("//#define SENSITIVITY_PPM_MAX ");
120 output.println("#define VARIOHYSTERESIS " + int(cp5.getController("varioHysteresis").getValue()) );
122 if ( cp5.getController("analogClimb").value() == 1 ) {
123 output.println("#define PIN_AnalogClimbRate " + climbPin.captionLabel().getText() + " // the pin used to write the vertical speed to the Rx A1 or A2 pin (can be 3 or 11 because it has to use timer 2)");
125 output.println("#define OutputClimbRateMin " + int(cp5.getController("outClimbRateMinMax").getArrayValue(0)) );
126 output.println("#define OutputClimbRateMax " + int(cp5.getController("outClimbRateMinMax").getArrayValue(1)) );
128 output.println("//#define PIN_AnalogClimbRate // the pin used to write the vertical speed to the Rx A1 or A2 pin (can be 3 or 11 because it has to use timer 2)");
130 output.println("//#define OutputClimbRateMin ");
131 output.println("//#define OutputClimbRateMax ");
137 // ---------------------------------- Voltage --------------------------------------
139 output.println("// -------- Voltage --------");
141 for ( int i = 1; i <= voltNbr; i++ ) {
142 if ( cp5.getController( "voltage" ).value() == 1 && cp5.getController( "volt" + i ).value() == 1 && int(cp5.getGroup("ddlVolt" + i).getValue()) >= 0 ) {
143 output.println("#define PIN_Voltage" + i + " " + int(cp5.getGroup("ddlVolt" + i).getValue()) + " // Pin for measuring Voltage " + i + " ( Analog Pin! )");
145 output.println("#define PIN_Voltage" + i + " " + 8 + " // Pin for measuring Voltage " + i + " ( Analog Pin! )");
150 for ( int i = 1; i <= voltNbr; i++ ) {
151 if ( cp5.getController( "voltage" ).value() == 1 && cp5.getController( "volt" + i ).value() == 1 ) {
152 output.println("#define offset_" + i + " " + cp5.getController("offsetVolt" + i).getValueLabel().getText() + " // offset in mv");
153 if ( cp5.getController("intRef").value() == 0 ) {
154 output.println("#define mVoltPerStep_" + i + " ( ARDUINOVCC * 1000.0 / 1024.0 * " + cp5.getController("dividerVolt" + i ).getValueLabel().getText() + " ) // => last number is the divider factor");
156 output.println("#define mVoltPerStep_" + i + " ( 1.1 * 1000.0 / 1024.0 * " + cp5.getController("dividerVolt" + i ).getValueLabel().getText() + " ) // => last number is the divider factor");
159 output.println("#define offset_" + i + " " + 0 + " // offset in mv");
160 output.println("#define mVoltPerStep_" + i + " " + 1 + " ");
165 if ( cp5.getController( "voltage" ).value() == 1 && cp5.getController( "cells" ).value() == 1 ) {
166 output.println("#define NUMBEROFCELLS " + ( int(cp5.getGroup("ddlNbrCells").getValue()) ) + " // keep this line but set value to 0 (zero) if you do not want to transmit cell voltage.");
168 output.println("#define NUMBEROFCELLS " + 0 + " // keep this line but set value to 0 (zero) if you do not want to transmit cell voltage.");
172 // ---------------------------------- Current sensor --------------------------------------
174 if ( cp5.getController( "current" ).value() == 1 && int(cp5.getGroup("currentPin").getValue()) >= 0 ) {
175 output.println("// -------- Current sensor --------");
176 output.println("#define PIN_CurrentSensor " + ( int(cp5.getGroup("currentPin").getValue()) ) + " // The Analog pin the optional current Sensor is connected to");
177 output.println("#define mAmpPerStep " + round(mAmpStep(), 2) + " // INA282 with 0.1 ohm shunt gives 5000mv/A ");
178 output.println("#define offsetCurrentSteps " + offsetCurrent() + " // 66mv offset (set to zero for now)");
180 //output.println("//#define PIN_CurrentSensor // The Analog pin the optional current Sensor is connected to");
181 //output.println("//#define mAmpPerStep // INA282 with 0.1 ohm shunt gives 5000mv/A ");
182 //output.println("//#define offsetCurrentSteps // 66mv offset (set to zero for now)");
186 // ---------------------------------- Temperature sensor --------------------------------------
189 if ( cp5.getController( "temperature" ).value() == 1 && int(cp5.getGroup("tempPin").getValue()) >= 0 ) {
190 output.println("// -------- Temperature sensor --------");
191 output.println("#define PIN_TemperatureSensor " + ( int(cp5.getGroup("tempPin").getValue()) ) + " // The Analog pin the optional temperature sensor is connected to");
192 output.println("#define TEMPOFFSET " + cp5.get(Textfield.class, "tempOffset").getText() + " // Calibration offset");
194 //output.println("#define PIN_TemperatureSensor // The Analog pin the optional temperature sensor is connected to");
195 //output.println("#define TEMPOFFSET // Calibration offset");
200 // ---------------------------------- RPM sensor --------------------------------------
202 if ( cp5.getController( "rpm" ).value() == 1 ) {
203 output.println("// ----------- RPM sensor -----------");
204 output.println("#define MEASURE_RPM 1") ;
209 // ---------------------------------- HUB telemetry data list --------------------------------------
211 output.println("// ----------------------------- HUB telemetry data list ---------------------------------");
212 output.println("// This is the list of all (main) telemetry fields supported by Hub protocol");
213 output.println("// You can use code from this list when you define in which telemetry field a measurement has to be transmitted");
214 output.println("// Do not modify this list");
216 output.println("#define FRSKY_USERDATA_GPS_ALT_B 0x01");
217 output.println("#define FRSKY_USERDATA_TEMP1 0x02");
218 output.println("#define FRSKY_USERDATA_RPM 0x03");
219 output.println("#define FRSKY_USERDATA_FUEL 0x04");
220 output.println("#define FRSKY_USERDATA_TEMP2 0x05");
221 output.println("#define FRSKY_USERDATA_CELL_VOLT 0x06");
222 output.println("#define FRSKY_USERDATA_GPS_ALT_A 0x09");
223 output.println("#define FRSKY_USERDATA_BARO_ALT_B 0x10");
224 output.println("#define FRSKY_USERDATA_GPS_SPEED_B 0x11");
225 output.println("#define FRSKY_USERDATA_GPS_LONG_B 0x12");
226 output.println("#define FRSKY_USERDATA_GPS_LAT_B 0x13");
227 output.println("#define FRSKY_USERDATA_GPS_CURSE_B 0x14");
228 output.println("#define FRSKY_USERDATA_GPS_DM 0x15");
229 output.println("#define FRSKY_USERDATA_GPS_YEAR 0x16");
230 output.println("#define FRSKY_USERDATA_GPS_HM 0x17");
231 output.println("#define FRSKY_USERDATA_GPS_SEC 0x18");
232 output.println("#define FRSKY_USERDATA_GPS_SPEED_A 0x19");
233 output.println("#define FRSKY_USERDATA_GPS_LONG_A 0x1A");
234 output.println("#define FRSKY_USERDATA_GPS_LAT_A 0x1B");
235 output.println("#define FRSKY_USERDATA_GPS_CURSE_A 0x1C");
236 output.println("#define FRSKY_USERDATA_BARO_ALT_A 0x21");
237 output.println("#define FRSKY_USERDATA_GPS_LONG_EW 0x22");
238 output.println("#define FRSKY_USERDATA_GPS_LAT_EW 0x23");
239 output.println("#define FRSKY_USERDATA_ACC_X 0x24");
240 output.println("#define FRSKY_USERDATA_ACC_Y 0x25");
241 output.println("#define FRSKY_USERDATA_ACC_Z 0x26");
242 output.println("#define FRSKY_USERDATA_CURRENT 0x28");
243 output.println("#define FRSKY_USERDATA_VERT_SPEED 0x30 // openTX Vario Mode Only");
244 output.println("#define FRSKY_USERDATA_ALT_MIN 0x31 // openTX Vario Mode Only");
245 output.println("#define FRSKY_USERDATA_ALT_MAX 0x32 // openTX Vario Mode Only");
246 output.println("#define FRSKY_USERDATA_RPM_MAX 0x33 // openTX Vario Mode Only");
247 output.println("#define FRSKY_USERDATA_T1_MAX 0x34 // openTX Vario Mode Only");
248 output.println("#define FRSKY_USERDATA_T2_MAX 0x35 // openTX Vario Mode Only");
249 output.println("#define FRSKY_USERDATA_GPS_SPEED_MAX 0x36 // openTX Vario Mode Only");
250 output.println("#define FRSKY_USERDATA_GPS_DIS_MAX 0x37 // openTX Vario Mode Only");
251 output.println("#define FRSKY_USERDATA_VFAS_NEW 0x39 // openTX Vario Mode Only");
252 output.println("#define FRSKY_USERDATA_VOLTAGE_B 0x3A");
253 output.println("#define FRSKY_USERDATA_VOLTAGE_A 0x3B");
254 output.println("#define FRSKY_USERDATA_GPS_DIST 0x3C");
255 output.println("#define FRSKY_USERDATA_FUELPERCENT 0x3D");
256 output.println("// End of list of all telemetry fields supported by Hub protocol (defined by Frsky)");
259 // ---------------------------------- SMART PORT telemetry data list --------------------------------------
261 output.println("// ---------------------------- SMART PORT telemetry data list ------------------------------");
262 output.println("// This is the list of all (main) telemetry fields supported by SPORT");
263 output.println("// Note : some of those values may not (yet) be displayed on Taranis");
264 output.println("// You can use code from this list when you define in which telemetry field a measurement has to be transmitted");
265 output.println("// Do not modify this list");
267 output.println("//#define RSSI_ID 0xf101 // please do not use this code because it is already used by the receiver");
268 output.println("//#define ADC1_ID 0xf102 // please do not use this code because it is already used by the receiver");
269 output.println("#define ADC2_ID 0xf103");
270 output.println("#define BATT_ID 0xf104");
271 output.println("//#define SWR_ID 0xf105 // please do not use this code because it is already used by the receiver");
272 output.println("#define T1_FIRST_ID 0x0400");
273 output.println("#define T1_LAST_ID 0x040f");
274 output.println("#define T2_FIRST_ID 0x0410");
275 output.println("#define T2_LAST_ID 0x041f");
276 output.println("#define RPM_FIRST_ID 0x0500");
277 output.println("#define RPM_LAST_ID 0x050f");
278 output.println("#define FUEL_FIRST_ID 0x0600");
279 output.println("#define FUEL_LAST_ID 0x060f");
280 output.println("#define ALT_FIRST_ID 0x0100");
281 output.println("#define ALT_LAST_ID 0x010f");
282 output.println("#define VARIO_FIRST_ID 0x0110");
283 output.println("#define VARIO_LAST_ID 0x011f");
284 output.println("#define ACCX_FIRST_ID 0x0700");
285 output.println("#define ACCX_LAST_ID 0x070f");
286 output.println("#define ACCY_FIRST_ID 0x0710");
287 output.println("#define ACCY_LAST_ID 0x071f");
288 output.println("#define ACCZ_FIRST_ID 0x0720");
289 output.println("#define ACCZ_LAST_ID 0x072f");
290 output.println("#define CURR_FIRST_ID 0x0200");
291 output.println("#define CURR_LAST_ID 0x020f");
292 output.println("#define VFAS_FIRST_ID 0x0210");
293 output.println("#define VFAS_LAST_ID 0x021f");
294 output.println("#define GPS_SPEED_FIRST_ID 0x0830");
295 output.println("#define GPS_SPEED_LAST_ID 0x083f");
296 output.println("#define CELLS_FIRST_ID 0x0300");
297 output.println("#define CELLS_SECOND_ID 0x0301");
298 output.println("#define CELLS_THIRD_ID 0x0302");
299 output.println("#define CELLS_LAST_ID 0x030f");
300 output.println("// End of list of all telemetry fields supported by SPORT (defined by Frsky)");
303 // ---------------------------------- Default field --------------------------------------
305 output.println("// ---------------------------- Default field ------------------------------");
306 output.println("#define DEFAULTFIELD 0x00");
309 // ---------------------------------- Transmitted data list --------------------------------------
311 output.println("// ---------------------------- Transmitted data list ------------------------------");
312 output.println("// This is the list of codes for each available measurement");
313 output.println("// Use those codes when you define which data has to be transmitted");
314 output.println("// Do not change those values");
316 output.println("enum DataToTransmit {");
317 output.println(" ALTIMETER = 1, // DEFAULTFIELD can be used in SPORT protocol (is then the same as ALT_FIRST_ID); it MUST be used in Hub protocol because meters and centimeters are sent in different fileds");
318 output.println(" VERTICAL_SPEED, // DEFAULTFIELD can be used");
319 output.println(" SENSITIVITY, // DEFAULTFIELD can NOT be used");
320 output.println(" ALT_OVER_10_SEC, // DEFAULTFIELD can NOT be used ; this is the difference of altitude over the last 10 sec (kind of averaging vertical speed)");
321 output.println(" // there is no telemetry field for this; it is possible to use e.g. T1 or T2; then you can use a custom function \"play value\" on Tx side");
322 output.println(" VOLT1, // DEFAULTFIELD can NOT be used");
323 output.println(" VOLT2, // DEFAULTFIELD can NOT be used");
324 output.println(" VOLT3, // DEFAULTFIELD can NOT be used");
325 output.println(" VOLT4, // DEFAULTFIELD can NOT be used");
326 output.println(" VOLT5, // DEFAULTFIELD can NOT be used");
327 output.println(" VOLT6, // DEFAULTFIELD can NOT be used");
328 output.println(" CURRENTMA, // DEFAULTFIELD can be used");
329 output.println(" MILLIAH, // if value must be sent as percentage, then uncomment the line \"#define SEND_mAhPercentageAsFuel 4000\"");
330 output.println(" CELLS_1_2, // Only DEFAULTFIELD can be used");
331 output.println(" CELLS_3_4, // Only DEFAULTFIELD can be used");
332 output.println(" CELLS_5_6, // Only DEFAULTFIELD can be used");
333 output.println(" RPM, // Only DEFAULTFIELD can be used");
334 //output.println(" VARIOTEMP, // DEFAULTFIELD can NOT be used // Temperature from the MS5611 sensor");
335 //output.println(" TEMP1, // DEFAULTFIELD can be used");
336 //output.println(" TEMP2 // Not usable yet // DEFAULTFIELD can be used");
337 output.println("} ; // End of list of type of available measurements");
340 // ---------------------------------- Transmitted data setting --------------------------------------
342 output.println("// ---------------------------- Transmitted data setting ------------------------------");
344 output.println("#define SETUP_DATA_TO_SEND \\");
345 for ( int i = 1; i <= dataSentFieldNbr; i++ ) {
346 if ( cp5.getGroup("sentDataField" + i ).getValue() != 0 ) {
348 output.println(" , \\");
350 if ( cp5.get(DropdownList.class, "sentDataField" + i ).captionLabel().getText().equals("Cells monitoring") ) {
351 if ( cp5.getController("cells").getValue() == 1 ) {
352 for ( int j = 1 ; j <= int( cp5.getGroup("ddlNbrCells").getValue() ) ; j += 2 ) {
353 output.print(" " + "DEFAULTFIELD , CELLS_" + j + "_" + ( j + 1 ) + " , 1 , 1 , 0" );
354 if ( int( cp5.getGroup("ddlNbrCells").getValue() ) > ( j + 1 ) ) {
355 output.println(" , \\");
360 } else if ( cp5.getGroup("protocolChoice").getValue() == 1 ) {
361 output.print(" " + hubDataList[int(cp5.getGroup("hubDataField" + i ).getValue())][0] + " , "
362 + sentDataList[int(cp5.getGroup("sentDataField" + i ).getValue())][0] + " , "
363 + cp5.getController("dataMultiplier" + i).getValueLabel().getText() + " , "
364 + cp5.getController("dataDivider" + i).getValueLabel().getText() + " , "
365 + cp5.getController("dataOffset" + i).getValueLabel().getText() );
368 output.print(" " + sPortDataList[int(cp5.getGroup("sPortDataField" + i ).getValue())][0] + " , "
369 + sentDataList[int(cp5.getGroup("sentDataField" + i ).getValue())][0] + " , "
370 + cp5.getController("dataMultiplier" + i).getValueLabel().getText() + " , "
371 + cp5.getController("dataDivider" + i).getValueLabel().getText() + " , "
372 + cp5.getController("dataOffset" + i).getValueLabel().getText() );
380 // ---------------------------------- Other parameters --------------------------------------
382 output.println("// ---------------------------- Other parameters ------------------------------");
384 output.println("// There is normally no reason to change the 2 next parameters");
385 output.println("#define I2CAdd 0x77 // 0x77 The I2C Address of the MS5611 breakout board");
386 output.println(" // (normally 0x76 or 0x77 configured on the MS5611 module");
388 output.println("#define PIN_LED 13 // The Signal LED (default=13=onboard LED)");
391 // ---------------------------------- The end --------------------------------------
394 output.println("#endif// End define OXS_CONFIG_h");
396 output.flush(); // Writes the remaining data to the file
397 output.close(); // Finishes the file
399 //exit(); // Stops the program