Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2136 | - | 1 | /***************************************************************************** |
2 | * Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
||
3 | * Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
||
4 | * Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
||
5 | * Copyright (C) 2011 Harald Bongartz * |
||
6 | * * |
||
7 | * This program is free software; you can redistribute it and/or modify * |
||
8 | * it under the terms of the GNU General Public License as published by * |
||
9 | * the Free Software Foundation; either version 2 of the License. * |
||
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, write to the * |
||
18 | * Free Software Foundation, Inc., * |
||
19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
20 | * * |
||
21 | * * |
||
22 | * Credits to: * |
||
23 | * Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
||
24 | * http://www.mikrokopter.de * |
||
25 | * Gregor "killagreg" Stobrawa for his version of the MK code * |
||
26 | * Thomas Kaiser "thkais" for the original project. See * |
||
27 | * http://www.ft-fanpage.de/mikrokopter/ * |
||
28 | * http://forum.mikrokopter.de/topic-4061-1.html * |
||
29 | * Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
||
30 | * http://www.mylifesucks.de/oss/c-osd/ * |
||
31 | * Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
||
32 | *****************************************************************************/ |
||
33 | |||
34 | |||
35 | //############################################################################ |
||
36 | //# HISTORY motortest.c |
||
37 | //# |
||
38 | //# 13.05.2014 OG |
||
39 | //# - chg: motor_test() - #ifdef USE_I2CMOTORTEST erweitert um unsigned int SerLoop; |
||
40 | //# wegen Warning: variable set but not used |
||
41 | //# |
||
42 | //# 12.02.2014 OG |
||
43 | //# - chg: motor_test() Verschiebung von var 'buffer' wegen "unused variable 'buffer'" |
||
44 | //# |
||
45 | //# 13.05.2013 Cebra |
||
46 | //# - chg: #define USE_I2CMOTORTEST, I2C Funktionen schaltbar |
||
47 | //# |
||
48 | //############################################################################ |
||
49 | |||
50 | |||
51 | #include "../cpu.h" |
||
52 | #include <avr/io.h> |
||
53 | #include <avr/interrupt.h> |
||
54 | #include <avr/pgmspace.h> |
||
55 | #include <string.h> |
||
56 | #include <stdlib.h> |
||
57 | #include "../main.h" |
||
58 | #include "motortest.h" |
||
59 | #include "../lcd/lcd.h" |
||
60 | #include "../timer/timer.h" |
||
61 | #include "../motortest/twimaster.h" |
||
62 | //#include "menu.h" |
||
63 | #include "../uart/uart1.h" |
||
64 | #include "../uart/usart.h" |
||
65 | #include "../messages.h" |
||
66 | |||
67 | |||
68 | |||
69 | |||
70 | uint8_t m; |
||
71 | uint8_t mmode; // 0=Value 1=Motor |
||
72 | uint8_t v; |
||
73 | |||
74 | volatile uint8_t i2c_state; |
||
75 | volatile uint8_t motor_addr = 0; |
||
76 | |||
77 | #ifdef USE_I2CMOTORTEST |
||
78 | //-------------------------------------------------------------- |
||
79 | // Senden der Motorwerte per I2C-Bus |
||
80 | // |
||
81 | void SendMotorData(uint8_t m,uint8_t v) |
||
82 | { |
||
83 | if (m==0) |
||
84 | |||
85 | for(m=0;m<MAX_MOTORS;m++) // alle Motoren |
||
86 | { |
||
87 | // Motor[m].SetPoint = MotorTest[m]; |
||
88 | Motor[m].SetPoint = v; |
||
89 | Motor[m].SetPointLowerBits = 0; |
||
90 | |||
91 | // Motor[i].SetPoint = MotorTest[i] / 4; // testing the high resolution |
||
92 | // Motor[i].SetPointLowerBits = MotorTest[i] % 4; |
||
93 | |||
94 | } |
||
95 | else |
||
96 | { |
||
97 | Motor[m-1].SetPoint = v; |
||
98 | Motor[m-1].SetPointLowerBits = 0; |
||
99 | } |
||
100 | |||
101 | |||
102 | |||
103 | if(I2C_TransferActive) |
||
104 | I2C_TransferActive = 0; // enable for the next time |
||
105 | else |
||
106 | { |
||
107 | motor_write = 0; |
||
108 | I2C_Start(TWI_STATE_MOTOR_TX); //Start I2C Interrupt Mode |
||
109 | } |
||
110 | } |
||
111 | |||
112 | |||
113 | //-------------------------------------------------------------- |
||
114 | // |
||
115 | void Search_BL (void) |
||
116 | { |
||
117 | uint8_t i = 0; |
||
118 | unsigned int timer; |
||
119 | lcd_cls (); |
||
120 | MotorenEin =0; |
||
121 | MotorTest[i] = 0; |
||
122 | |||
123 | lcd_printp (PSTR("Suche BL-Ctrl"), 0); |
||
124 | |||
125 | // Check connected BL-Ctrls |
||
126 | BLFlags |= BLFLAG_READ_VERSION; |
||
127 | motor_read = 0; // read the first I2C-Data |
||
128 | |||
129 | SendMotorData(0,0); |
||
130 | timer = SetDelay(1); |
||
131 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
||
132 | |||
133 | timer = SetDelay(1); |
||
134 | for(i=0; i < MAX_MOTORS; i++) |
||
135 | { |
||
136 | |||
137 | SendMotorData(i,0); |
||
138 | |||
139 | |||
140 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
||
141 | |||
142 | |||
143 | if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) |
||
144 | { |
||
145 | |||
146 | lcd_printp_at (0, 1, PSTR("Found BL-Ctrl:"), 0); |
||
147 | lcd_print_hex_at (18,1,i,0); |
||
148 | |||
149 | lcd_printp_at (0, 2, PSTR("Version:"), 0); |
||
150 | lcd_print_hex_at (8,2,Motor[i].Version,0); |
||
151 | lcd_printp_at (11, 2, PSTR("SetPoi:"), 0); |
||
152 | lcd_print_hex_at (18,2,Motor[i].SetPoint,0); |
||
153 | |||
154 | lcd_printp_at (0, 3, PSTR("SetPoiL:"), 0); |
||
155 | lcd_print_hex_at (8,3,Motor[i].SetPointLowerBits,0); |
||
156 | lcd_printp_at (11, 3, PSTR("State :"), 0); |
||
157 | lcd_print_hex_at (18,3,Motor[i].State,0); |
||
158 | |||
159 | lcd_printp_at (0, 4, PSTR("ReadMod:"), 0); |
||
160 | lcd_print_hex_at (8,4,Motor[i].ReadMode,0); |
||
161 | lcd_printp_at (11, 4, PSTR("Currnt:"), 0); |
||
162 | lcd_print_hex_at (18,4,Motor[i].Current,0); |
||
163 | |||
164 | lcd_printp_at (0, 5, PSTR("MaxPWM :"), 0); |
||
165 | lcd_print_hex_at (8,5,Motor[i].MaxPWM,0); |
||
166 | lcd_printp_at (11, 5, PSTR("Temp :"), 0); |
||
167 | write_ndigit_number_u (18,5,Motor[i].Temperature,3,1,0); |
||
168 | } |
||
169 | |||
170 | } //End For I |
||
171 | } |
||
172 | #endif |
||
173 | |||
174 | |||
175 | //-------------------------------------------------------------- |
||
176 | // |
||
177 | void motor (uint8_t m,uint8_t v) |
||
178 | { |
||
179 | memset (buffer, 0, 16); |
||
180 | |||
181 | if(m == 0) |
||
182 | { |
||
183 | memset (buffer, v, 16); |
||
184 | } |
||
185 | else |
||
186 | { |
||
187 | buffer[m-1] = v; |
||
188 | } |
||
189 | |||
190 | SendOutData('t', ADDRESS_FC, 1, buffer, 16); |
||
191 | } |
||
192 | |||
193 | |||
194 | |||
195 | //-------------------------------------------------------------- |
||
196 | // |
||
197 | void motor_test (uint8_t MotorMode) |
||
198 | { |
||
199 | |||
200 | lcd_cls (); |
||
201 | mmode = 1; // 1=Motor |
||
202 | m = 1; |
||
203 | v = 0; |
||
204 | |||
205 | #ifdef USE_I2CMOTORTEST |
||
206 | unsigned int SerLoop; |
||
207 | SerLoop = 10; |
||
208 | |||
209 | char buffer[7]; |
||
210 | |||
211 | if (MotorMode == I2C_Mode) |
||
212 | { |
||
213 | Search_BL(); |
||
214 | do |
||
215 | { |
||
216 | lcd_printp_at (11, 7, PSTR("Ende Check"), 0); |
||
217 | if (get_key_press (1 << KEY_ESC)) |
||
218 | { |
||
219 | get_key_press(KEY_ALL); |
||
220 | return; |
||
221 | } |
||
222 | } |
||
223 | while (!get_key_press (1 << KEY_ENTER)); |
||
224 | } |
||
225 | #endif |
||
226 | lcd_cls(); |
||
227 | lcd_printp (PSTR(" BL-Ctrl Test "), 2); |
||
228 | lcd_printp_at (2, 2, PSTR("Motor: 1"), 0); |
||
229 | lcd_printp_at (2, 3, PSTR("Value: 0"), 0); |
||
230 | lcd_frect ((8*1), (8*5), (0 * (14*8)) / 255, 6, 1); |
||
231 | // lcd_printp_at (0, 7, PSTR(KEY_LINE_3), 0); |
||
232 | lcd_printp_at(0, 7, strGet(KEYLINE3), 0); |
||
233 | lcd_printp_at (18, 7, PSTR("\x1a \x1b"), 0); |
||
234 | lcd_printp_at (0, 2, PSTR("\x1d"), 0); |
||
235 | |||
236 | |||
237 | #ifdef USE_I2CMOTORTEST |
||
238 | if (MotorMode == I2C_Mode) |
||
239 | uart1_puts("Motor;Version;Setpoint high;Setpoint low;State;ReadMode;Current;MaxPWM;Temperature\r"); |
||
240 | #endif |
||
241 | |||
242 | if (MotorMode == FC_Mode) |
||
243 | { |
||
244 | if (hardware == NC && current_hardware == NC) |
||
245 | { |
||
246 | SwitchToFC(); |
||
247 | } |
||
248 | } |
||
249 | do |
||
250 | { |
||
251 | // mmode 0=Value 1=Motor |
||
252 | |||
253 | if ((mmode == 0) && (get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 3)) && (v < 254)) |
||
254 | { |
||
255 | v++; |
||
256 | write_ndigit_number_u (9, 3, v, 3, 0,0); |
||
257 | if (MotorMode == FC_Mode) |
||
258 | lcd_frect ((8*1), (8*5), (v * (14*8)) / 255, 6, 1); |
||
259 | } |
||
260 | |||
261 | if ((mmode == 0) && (get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 3)) && (v > 0)) |
||
262 | { |
||
263 | if (MotorMode == FC_Mode) |
||
264 | lcd_frect (((v * (14*8) / 255) + 8), (8*5), ((14*8) / 255), 6, 0); |
||
265 | |||
266 | v--; |
||
267 | write_ndigit_number_u (9, 3, v, 3, 0,0); |
||
268 | if (MotorMode == FC_Mode) |
||
269 | lcd_frect ((8*1), (8*5), (v * (14*8)) / 255, 6, 1); |
||
270 | } |
||
271 | |||
272 | if ((mmode == 1) && (get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 1)) && (m < 16)) |
||
273 | { |
||
274 | m++; |
||
275 | write_ndigit_number_u (9, 2, m, 3, 0,0); |
||
276 | } |
||
277 | |||
278 | if ((mmode == 1) && (get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 1)) && (m > 0)) |
||
279 | { |
||
280 | m--; |
||
281 | if(m > 0) |
||
282 | write_ndigit_number_u (9, 2, m, 3, 0,0); |
||
283 | if(m == 0) |
||
284 | lcd_printp_at (9, 2, PSTR("All"), 0); |
||
285 | } |
||
286 | |||
287 | if (get_key_press (1 << KEY_ENTER)) |
||
288 | { |
||
289 | #ifdef USE_I2CMOTORTEST |
||
290 | if (MotorMode == I2C_Mode) |
||
291 | { |
||
292 | if (v > 0) |
||
293 | { |
||
294 | m = 0; |
||
295 | v=0; |
||
296 | lcd_frect ((8*1), (8*5), (0 * (14*8)) / 255, 6, 1); |
||
297 | lcd_cls_line (0, 5, 21); |
||
298 | if(m > 0) write_ndigit_number_u (9, 2, m, 3, 0,0); |
||
299 | if(m == 0) lcd_printp_at (9, 2, PSTR("All"), 0); |
||
300 | write_ndigit_number_u (9, 3, v, 3, 0,0); |
||
301 | SendMotorData(m,v); |
||
302 | timer = SetDelay(1); |
||
303 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
||
304 | } |
||
305 | } |
||
306 | #endif |
||
307 | |||
308 | if(mmode == 0) // 0=Value |
||
309 | { |
||
310 | lcd_printp_at (0, 2, PSTR("\x1d"), 0); |
||
311 | lcd_printp_at (0, 3, PSTR(" "), 0); |
||
312 | mmode = 1; // 1=Motor |
||
313 | } |
||
314 | else |
||
315 | { |
||
316 | lcd_printp_at (0, 2, PSTR(" "), 0); |
||
317 | lcd_printp_at (0, 3, PSTR("\x1d"), 0); |
||
318 | mmode = 0; // 0=Value |
||
319 | } |
||
320 | } |
||
321 | //if (get_key_press (1 << KEY_ENTER))// |
||
322 | #ifdef USE_I2CMOTORTEST |
||
323 | if (MotorMode == I2C_Mode) |
||
324 | { |
||
325 | SendMotorData(m,v); |
||
326 | timer = SetDelay(1); |
||
327 | lcd_printp_at (0, 3, PSTR("SetPoint :"), 0); |
||
328 | |||
329 | write_ndigit_number_u (13,3,Motor[m-1].SetPoint,3,0,0); |
||
330 | lcd_printp_at (0, 4, PSTR("Current :"), 0); |
||
331 | lcd_print_hex_at (13,4,Motor[m-1].Current,0); |
||
332 | write_ndigit_number_u (13,4,Motor[m-1].Current,3,0,0); |
||
333 | lcd_printp_at (0, 5, PSTR("Temperature:"), 0); |
||
334 | write_ndigit_number_u (13,5,Motor[m-1].Temperature,3,0,0); |
||
335 | lcd_printp_at (0, 6, PSTR("Version:"), 0); |
||
336 | lcd_print_hex_at (8,6,Motor[m-1].Version,0); |
||
337 | lcd_printp_at (11, 6, PSTR("State :"), 0); |
||
338 | lcd_print_hex_at (18,6,Motor[m-1].State,0); |
||
339 | |||
340 | |||
341 | if (Motor[m-1].SetPoint > 0) |
||
342 | { |
||
343 | if (SerLoop == 0) |
||
344 | { |
||
345 | itoa( m-1, buffer, 10); // convert interger into string (decimal format) |
||
346 | uart1_puts(buffer); // and transmit string to UART |
||
347 | uart1_puts(";"); |
||
348 | itoa( Motor[m-1].Version, buffer, 10); // |
||
349 | uart1_puts(buffer); |
||
350 | uart1_puts(";"); |
||
351 | itoa( Motor[m-1].SetPoint, buffer, 10); // |
||
352 | uart1_puts(buffer); |
||
353 | uart1_puts(";"); |
||
354 | itoa( Motor[m-1].SetPointLowerBits, buffer, 10); // |
||
355 | uart1_puts(buffer); |
||
356 | uart1_puts(";"); |
||
357 | itoa( Motor[m-1].State, buffer, 10); // |
||
358 | uart1_puts(buffer); |
||
359 | uart1_puts(";"); |
||
360 | itoa( Motor[m-1].ReadMode, buffer, 10); // |
||
361 | uart1_puts(buffer); |
||
362 | uart1_puts(";"); |
||
363 | itoa( Motor[m-1].Current, buffer, 10); // |
||
364 | uart1_puts(buffer); |
||
365 | uart1_puts(";"); |
||
366 | itoa( Motor[m-1].MaxPWM, buffer, 10); // |
||
367 | uart1_puts(buffer); |
||
368 | uart1_puts(";"); |
||
369 | itoa( Motor[m-1].Temperature, buffer, 10); // |
||
370 | uart1_puts(buffer); |
||
371 | uart1_puts("\r"); |
||
372 | uart1_puts("\n"); |
||
373 | SerLoop =200; |
||
374 | } |
||
375 | else |
||
376 | SerLoop--; |
||
377 | } |
||
378 | |||
379 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
||
380 | } |
||
381 | else |
||
382 | #endif |
||
383 | motor (m,v); //if (MotorMode == I2C_Mode)// |
||
384 | |||
385 | } |
||
386 | while (!get_key_press (1 << KEY_ESC)); |
||
387 | |||
388 | get_key_press(KEY_ALL); |
||
389 | |||
390 | if (MotorMode == FC_Mode) |
||
391 | { |
||
392 | motor(0,0); // switch all engines off at exit |
||
393 | } |
||
394 | |||
395 | } |
||
396 |