Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1702 - 1
/* ******************************************************************/
2
/* *********************** GENERAL FUNCTIONS ********************** */
3
 
4
//Extract functions (get bits from the positioning bytes
5
#define ISa(whichBit) getBit(panA_REG, whichBit)
6
#define ISb(whichBit) getBit(panB_REG, whichBit)
7
#define ISc(whichBit) getBit(panC_REG, whichBit)
8
 
9
boolean getBit(byte Reg, byte whichBit) {
10
  boolean State;
11
  State = Reg & (1 << whichBit);
12
  return State;
13
}
14
 
15
byte setBit(byte &Reg, byte whichBit, boolean stat) {
16
  if (stat) {
17
    Reg = Reg | (1 << whichBit);
18
  }
19
  else {
20
    Reg = Reg & ~(1 << whichBit);
21
  }
22
  return Reg;
23
}
24
 
25
// EEPROM reader/writers
26
// Utilities for writing and reading from the EEPROM
27
byte readEEPROM(int address) {
28
 
29
  return EEPROM.read(address);
30
}
31
 
32
void writeEEPROM(byte value, int address) {
33
  EEPROM.write(address, value);
34
}
35
 
36
 
37
void InitializeOSD() {
38
 
39
  loadBar();
40
  delay(500);
41
 
42
  writeEEPROM(42, CHK1);
43
  writeEEPROM(VER-42,CHK2);
44
  writeSettings();
45
 
46
  osd.setPanel(4,9);
47
  osd.openPanel();
48
  osd.printf_P(PSTR("OSD Initialized, reboot"));
49
  osd.closePanel();
50
 
51
  // run for ever so user resets
52
  for(;;) {}
53
 
54
}
55
 
56
// Write our latest FACTORY settings to EEPROM
57
void writeSettings() {
58
 // Writing all default parameters to EEPROM, ON = panel enabled
59
 // All panels have 3 values:
60
 //  - Enable/Disable
61
 //  - X coordinate on screen
62
 //  - Y coordinate on screen
63
 writeEEPROM(off, panCenter_en_ADDR);
64
 writeEEPROM(13, panCenter_x_ADDR);
65
 writeEEPROM(7,  panCenter_y_ADDR);
66
 writeEEPROM(on, panPitch_en_ADDR);
67
 writeEEPROM(22, panPitch_x_ADDR);
68
 writeEEPROM(9,  panPitch_y_ADDR);
69
 writeEEPROM(on, panRoll_en_ADDR);
70
 writeEEPROM(11, panRoll_x_ADDR);
71
 writeEEPROM(1,  panRoll_y_ADDR);
72
 writeEEPROM(on, panBatt_A_en_ADDR);
73
 writeEEPROM(21, panBatt_A_x_ADDR);
74
 writeEEPROM(1,  panBatt_A_y_ADDR);
75
 //writeEEPROM(on, panBatt_B_en_ADDR);
76
 //writeEEPROM(21, panBatt_B_x_ADDR);
77
 //writeEEPROM(3,  panBatt_B_y_ADDR);
78
 writeEEPROM(on, panGPSats_en_ADDR);
79
 writeEEPROM(2,  panGPSats_x_ADDR);
80
 writeEEPROM(13, panGPSats_y_ADDR);
81
 writeEEPROM(on, panGPL_en_ADDR);
82
 writeEEPROM(5,  panGPL_x_ADDR);
83
 writeEEPROM(13, panGPL_y_ADDR);
84
 writeEEPROM(on, panGPS_en_ADDR);
85
 writeEEPROM(2,  panGPS_x_ADDR);
86
 writeEEPROM(14, panGPS_y_ADDR);
87
 writeEEPROM(on, panRose_en_ADDR);
88
 writeEEPROM(16, panRose_x_ADDR);
89
 writeEEPROM(14, panRose_y_ADDR);
90
 writeEEPROM(on, panHeading_en_ADDR);
91
 writeEEPROM(24, panHeading_x_ADDR);
92
 writeEEPROM(13, panHeading_y_ADDR);
93
 writeEEPROM(on, panMavBeat_en_ADDR);
94
 writeEEPROM(2,  panMavBeat_x_ADDR);
95
 writeEEPROM(9, panMavBeat_y_ADDR);
96
 writeEEPROM(on, panHomeDir_en_ADDR);
97
 writeEEPROM(14, panHomeDir_x_ADDR);
98
 writeEEPROM(3,  panHomeDir_y_ADDR);
99
 writeEEPROM(on, panHomeDis_en_ADDR);
100
 writeEEPROM(2,  panHomeDis_x_ADDR);
101
 writeEEPROM(1,  panHomeDis_y_ADDR);
102
 writeEEPROM(off,panWPDir_en_ADDR);
103
 writeEEPROM(0,  panWPDir_x_ADDR);
104
 writeEEPROM(0,  panWPDir_y_ADDR);
105
 writeEEPROM(off,panWPDis_en_ADDR);
106
 writeEEPROM(0,  panWPDis_x_ADDR);
107
 writeEEPROM(0,  panWPDis_y_ADDR);
108
 //writeEEPROM(on, panRSSI_en_ADDR);
109
 //writeEEPROM(21, panRSSI_x_ADDR);
110
 //writeEEPROM(5,  panRSSI_y_ADDR);
111
 
112
 //writeEEPROM(on, panCur_A_en_ADDR);
113
 //writeEEPROM(21, panCur_A_x_ADDR);
114
 //writeEEPROM(2,  panCur_A_y_ADDR);
115
 //writeEEPROM(on, panCur_B_en_ADDR);
116
 //writeEEPROM(21, panCur_B_x_ADDR);
117
 //writeEEPROM(4,  panCur_B_y_ADDR);
118
 writeEEPROM(on, panAlt_en_ADDR);
119
 writeEEPROM(2,  panAlt_x_ADDR);
120
 writeEEPROM(2,  panAlt_y_ADDR);
121
 writeEEPROM(on, panVel_en_ADDR);
122
 writeEEPROM(2,  panVel_x_ADDR);
123
 writeEEPROM(3,  panVel_y_ADDR);
124
 writeEEPROM(on, panThr_en_ADDR);
125
 writeEEPROM(2,  panThr_x_ADDR);
126
 writeEEPROM(4,  panThr_y_ADDR);
127
 writeEEPROM(on, panFMod_en_ADDR);
128
 writeEEPROM(17,  panFMod_x_ADDR);
129
 writeEEPROM(13, panFMod_y_ADDR);
130
 writeEEPROM(on, panHorizon_en_ADDR);
131
 writeEEPROM(8,  panHorizon_x_ADDR);
132
 writeEEPROM(7,  panHorizon_y_ADDR);
133
}
134
 
135
void readSettings() {
136
 
137
  //****** First set of 8 Panels ******
138
 
139
  setBit(panA_REG, Cen_BIT, readEEPROM(panCenter_en_ADDR));
140
  panCenter_XY[0] = readEEPROM(panCenter_x_ADDR);
141
  panCenter_XY[1] = checkPAL(readEEPROM(panCenter_y_ADDR));
142
 
143
  setBit(panA_REG, Pit_BIT, readEEPROM(panPitch_en_ADDR));
144
  panPitch_XY[0] = readEEPROM(panPitch_x_ADDR);
145
  panPitch_XY[1] = checkPAL(readEEPROM(panPitch_y_ADDR));
146
 
147
  setBit(panA_REG, Rol_BIT, readEEPROM(panRoll_en_ADDR));
148
  panRoll_XY[0] = readEEPROM(panRoll_x_ADDR);
149
  panRoll_XY[1] = checkPAL(readEEPROM(panRoll_y_ADDR));
150
 
151
  setBit(panA_REG, BatA_BIT, readEEPROM(panBatt_A_en_ADDR));
152
  panBatt_A_XY[0] = readEEPROM(panBatt_A_x_ADDR);
153
  panBatt_A_XY[1] = checkPAL(readEEPROM(panBatt_A_y_ADDR));
154
 
155
  //setBit(panA_REG, BatB_BIT, readEEPROM(panBatt_B_en_ADDR));
156
  //panBatt_B_XY[0] = readEEPROM(panBatt_B_x_ADDR);
157
  //panBatt_B_XY[1] = checkPAL(readEEPROM(panBatt_B_y_ADDR));
158
 
159
  setBit(panA_REG, GPSats_BIT, readEEPROM(panGPSats_en_ADDR));
160
  panGPSats_XY[0] = readEEPROM(panGPSats_x_ADDR);
161
  panGPSats_XY[1] = checkPAL(readEEPROM(panGPSats_y_ADDR));
162
 
163
  setBit(panA_REG, GPL_BIT, readEEPROM(panGPL_en_ADDR));
164
  panGPL_XY[0] = readEEPROM(panGPL_x_ADDR);
165
  panGPL_XY[1] = checkPAL(readEEPROM(panGPL_y_ADDR));
166
 
167
  setBit(panA_REG, GPS_BIT, readEEPROM(panGPS_en_ADDR));
168
  panGPS_XY[0] = readEEPROM(panGPS_x_ADDR);
169
  panGPS_XY[1] = checkPAL(readEEPROM(panGPS_y_ADDR));
170
 
171
  //****** Second set of 8 Panels ******
172
 
173
  setBit(panB_REG, Rose_BIT, readEEPROM(panRose_en_ADDR));
174
  panRose_XY[0] = readEEPROM(panRose_x_ADDR);
175
  panRose_XY[1] = checkPAL(readEEPROM(panRose_y_ADDR));
176
 
177
  setBit(panB_REG, Head_BIT, readEEPROM(panHeading_en_ADDR));
178
  panHeading_XY[0] = readEEPROM(panHeading_x_ADDR);
179
  panHeading_XY[1] = checkPAL(readEEPROM(panHeading_y_ADDR));
180
 
181
  setBit(panB_REG, MavB_BIT, readEEPROM(panMavBeat_en_ADDR));
182
  panMavBeat_XY[0] = readEEPROM(panMavBeat_x_ADDR);
183
  panMavBeat_XY[1] = checkPAL(readEEPROM(panMavBeat_y_ADDR));
184
 
185
  setBit(panB_REG, HDis_BIT, readEEPROM(panHomeDis_en_ADDR));
186
  panHomeDis_XY[0] = readEEPROM(panHomeDis_x_ADDR);
187
  panHomeDis_XY[1] = checkPAL(readEEPROM(panHomeDis_y_ADDR));
188
 
189
  setBit(panB_REG, HDir_BIT, readEEPROM(panHomeDir_en_ADDR));
190
  panHomeDir_XY[0] = readEEPROM(panHomeDir_x_ADDR);
191
  panHomeDir_XY[1] = checkPAL(readEEPROM(panHomeDir_y_ADDR));
192
 
193
  //setBit(panB_REG, RSSI_BIT, readEEPROM(panRSSI_en_ADDR));
194
  //panRSSI_XY[0] = readEEPROM(panRSSI_x_ADDR);
195
  //panRSSI_XY[1] = checkPAL(readEEPROM(panRSSI_y_ADDR));
196
 
197
  //****** Third set of 8 Panels ******
198
 
199
  //setBit(panC_REG, CurA_BIT, readEEPROM(panCur_A_en_ADDR));
200
  //panCur_A_XY[0] = readEEPROM(panCur_A_x_ADDR);
201
  //panCur_A_XY[1] = checkPAL(readEEPROM(panCur_A_y_ADDR));
202
 
203
  //setBit(panC_REG, CurB_BIT, readEEPROM(panCur_B_en_ADDR));
204
  //panCur_B_XY[0] = readEEPROM(panCur_B_x_ADDR);
205
  //panCur_B_XY[1] = checkPAL(readEEPROM(panCur_B_y_ADDR));
206
 
207
  setBit(panC_REG, Alt_BIT, readEEPROM(panAlt_en_ADDR));
208
  panAlt_XY[0] = readEEPROM(panAlt_x_ADDR);
209
  panAlt_XY[1] = checkPAL(readEEPROM(panAlt_y_ADDR));
210
 
211
  setBit(panC_REG, Vel_BIT, readEEPROM(panVel_en_ADDR));
212
  panVel_XY[0] = readEEPROM(panVel_x_ADDR);
213
  panVel_XY[1] = checkPAL(readEEPROM(panVel_y_ADDR));
214
 
215
  setBit(panC_REG, Thr_BIT, readEEPROM(panThr_en_ADDR));
216
  panThr_XY[0] = readEEPROM(panThr_x_ADDR);
217
  panThr_XY[1] = checkPAL(readEEPROM(panThr_y_ADDR));
218
 
219
  setBit(panC_REG, FMod_BIT, readEEPROM(panFMod_en_ADDR));
220
  panFMod_XY[0] = readEEPROM(panFMod_x_ADDR);
221
  panFMod_XY[1] = checkPAL(readEEPROM(panFMod_y_ADDR));
222
 
223
  setBit(panC_REG, Hor_BIT, readEEPROM(panHorizon_en_ADDR));
224
  panHorizon_XY[0] = readEEPROM(panHorizon_x_ADDR);
225
  panHorizon_XY[1] = checkPAL(readEEPROM(panHorizon_y_ADDR));
226
 
227
}
228
 
229
int checkPAL(int line){
230
  if(line >= osd.getCenter() && osd.getMode() == 0){
231
    line -= 3;//Cutting lines offset after center if NTSC
232
  }
233
  return line;
234
}
235
 
236
void updateSettings(byte panel, byte panel_x, byte panel_y, byte panel_s ) {
237
  if(panel >= 1 && panel <= 32) {
238
 
239
    writeEEPROM(panel_s, (6 * panel) - 6 + 0);
240
    if(panel_s != 0) {
241
      writeEEPROM(panel_x, (6 * panel) - 6 + 2);
242
      writeEEPROM(panel_y, (6 * panel) - 6 + 4);
243
    }
244
    osd.clear();
245
    readSettings();
246
  }
247
}
248