Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 1733 → Rev 1734

/Transportables_Koptertool/branch/PKT_V363a_V088n_MartinR/servo.c
0,0 → 1,153
/*****************************************************************************
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de *
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net *
* Copyright (C) 2011 Harald Bongartz *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
* *
* Credits to: *
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN *
* http://www.mikrokopter.de *
* Gregor "killagreg" Stobrawa for his version of the MK code *
* Thomas Kaiser "thkais" for the original project. See *
* http://www.ft-fanpage.de/mikrokopter/ *
* http://forum.mikrokopter.de/topic-4061-1.html *
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code *
* http://www.mylifesucks.de/oss/c-osd/ *
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility*
*****************************************************************************/
 
 
#include "cpu.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
 
#include "lcd.h"
#include "timer.h"
#include "servo.h"
#include "messages.h"
 
#define SERVO_CORRECT 3.125
 
 
//--------------------------------------------------------------
//
void servo_test (void)
{
#ifdef HWVERSION3_9
uint8_t chg = 0;
uint8_t Pos = 150; // 1,5mS
 
OCR1A = 150 * SERVO_CORRECT; // Servomitte
 
lcd_cls ();
 
lcd_printp (PSTR(" Servo Tester "), 2);
lcd_printp_at (7, 5, PSTR("%"), 0);
lcd_printp_at (16, 5, PSTR("mS"), 0);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_3), 0);
lcd_puts_at(0, 7, strGet(KEYLINE3), 0);
lcd_printp_at (18, 7, PSTR("\x19O\x18"), 0);
 
lcd_rect(3, 23, 120, 8, 1); // +-150% Rahmen
lcd_line(23,23,23,31,1); // -100%
lcd_line(43,23,43,31,1); // -50%
lcd_frect(61, 23, 3, 8, 1); // 0%
lcd_line(83,23,83,31,1); // +50%
lcd_line(103,23,103,31,1); // +100%
 
write_ndigit_number_u (4, 5, 0, 3, 0,0); // Pulse width in %
write_ndigit_number_u_100th(12, 5, 150, 3, 0); // Pulse width in ms
 
do
{
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 3)) && (Pos < 225))
{
if (Pos < 150)
lcd_frect ((63 - ((150 - Pos) * 0.8)), 24, 1, 6, 0);
 
Pos++;
if (Pos == 75 || Pos == 100 || Pos == 125 || Pos == 150 || Pos == 175 || Pos == 200 || Pos == 225)
{
set_beep ( 200, 0x0080, BeepNormal);
}
 
if (Pos >= 225)
Pos = 225;
 
chg++;
}
else if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 3)) && (Pos > 75))
{
if (Pos > 150)
lcd_frect ((((Pos - 150) * 0.8) + 63), 24, ((Pos - 150) * 0.8), 6, 0);
 
Pos--;
if (Pos == 75 || Pos == 100 || Pos == 125 || Pos == 150 || Pos == 175 || Pos == 200 || Pos == 225)
{
set_beep ( 200, 0x0080, BeepNormal);
}
 
if (Pos <= 75)
Pos = 75;
 
chg++;
}
else if (get_key_press (1 << KEY_ENTER))
{
lcd_frect (4, 24, 118, 6, 0); // Balken löschen
lcd_frect(61, 23, 3, 8, 1); // 0%
Pos = 150;
set_beep ( 200, 0x0080, BeepNormal);
chg++;
}
 
if (chg)
{
chg = 0;
 
if (Pos >= 150)
{
lcd_frect (63, 24, ((Pos - 150) * 0.8), 6, 1);
write_ndigit_number_u (4, 5, ((Pos - 150) * 2), 3, 0,0); // Pulse width in %
lcd_frect(62, 23, 2, 8, 1); // 0%
}
else
{
lcd_frect (63 - ((150 - Pos) * 0.8), 24, ((150 - Pos) * 0.8), 6, 1);
write_ndigit_number_u (4, 5, ((150 - Pos) * 2), 3, 0,0); // Pulse width in %
lcd_frect(61, 23, 2, 8, 1); // 0%
}
write_ndigit_number_u_100th(12, 5, Pos, 3, 0); // Pulse width in ms
 
lcd_line(3, 23,3, 31,1); // -150%
lcd_line(23, 23,23, 31,1); // -100%
lcd_line(43, 23,43, 31,1); // -50%
lcd_line(83, 23,83, 31,1); // +50%
lcd_line(103,23,103,31,1); // +100%
lcd_line(123,23,123,31,1); // +150%
 
 
OCR1A = Pos * SERVO_CORRECT; // Servostellung
 
}
}
while (!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
#endif
}