Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 1919 → Rev 1920

/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/bluetooth/.directory
0,0 → 1,3
[Dolphin]
Timestamp=2012,12,28,23,42,17
ViewMode=1
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/followme/followme.c
0,0 → 1,338
/*
* FollowMe.c
*
* Created on: 18.05.2012
* Author: cebra
*/
/*****************************************************************************
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net *
* *
* 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 <inttypes.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
 
#include "../main.h"
#include "../followme/followme.h"
#include "../osd/osd.h"
#include "../lcd/lcd.h"
#include "../timer/timer.h"
#include "../uart/usart.h"
#include "../eeprom/eeprom.h"
#include "../messages.h"
#include "../parameter.h"
#include "../mk-data-structs.h"
 
#define COSD_WASFLYING 4
#define TIMEOUT 200 // 2 sec
 
// global definitions and global vars
NaviData_t *naviData;
mk_param_struct_t *mk_param_struct;
//uint16_t old_hh = 0;
uint8_t Flags_ExtraConfig;
uint8_t Flags_GlobalConfig;
uint8_t Flags_GlobalConfig3;
unsigned char Element;
uint16_t heading_home;
 
// Hier Höhenanzeigefehler Korrigieren
#define AltimeterAdjust 1.5
 
 
// Positionen der Anzeigeelemente im Bildschirm
#define OSD_ALTITUDE_CONTROL 1
#define OSD_ALTITUDE 2
#define OSD_BATTERY_LEVEL 3
#define OSD_CAPACITY 4
#define OSD_CARE_FREE 5
#define OSD_COMPASS_DEGREE 6
#define OSD_COMPASS_DIRECTION 7
#define OSD_COMPASS_ROSE 8
#define OSD_CURRENT 9
#define OSD_FLYING_TIME 10
#define OSD_GROUND_SPEED 11
#define OSD_HOME_CIRCLE 12
#define OSD_HOME_DEGREE 13
#define OSD_HOME_DISTANCE 14
#define OSD_LED1_OUTPUT 15
#define OSD_LED2_OUTPUT 16
#define OSD_MANUELL 17
#define OSD_NAVI_MODE 18
#define OSD_RC_INTENSITY 19
#define OSD_SATS_IN_USE 20
#define OSD_STATUS_FLAGS 21
#define OSD_VARIOMETER 22
 
// Flags
//uint8_t COSD_FLAGS2 = 0;
//
//GPS_Pos_t last5pos[7];
uint8_t FM_error = 0;
 
//--------------------------------------------------------------
void FollowMe (void)
{
uint8_t flag;
uint8_t tmp_dat;
// uint8_t OSD_Mode;
// uint8_t info_3D = 0;
uint8_t status;
 
// Clear statistics
// max_Altimeter = 0;
// max_GroundSpeed = 0;
// max_Distance = 0;
// min_UBat = 255;
// max_FlyingTime = 0;
 
// flags from last round to check for changes
uint8_t old_FCFlags = 0;
 
// uint8_t old_AngleNick = 0;
// uint8_t old_AngleRoll = 0;
lcd_cls();
 
 
 
 
 
 
if (hardware == FC)
{
lcd_puts_at(0, 3, strGet(ONLY_NC), 0); // Nur mit NC
timer = 100;
while (timer > 0);
 
return;
}
 
SwitchToFC();
 
status = load_setting(0xff);
if(status == 255)
{
lcd_puts_at(0, 0, strGet(NO_SETTINGS), 0); // Keine Setings
_delay_ms(2000);
}
Flags_ExtraConfig = mk_param_struct->ExtraConfig;
Flags_GlobalConfig = mk_param_struct->GlobalConfig;
Flags_GlobalConfig3 = mk_param_struct->GlobalConfig3;
 
SwitchToNC();
 
mode = 'O';
 
// disable debug...
// RS232_request_mk_data (0, 'd', 0);
tmp_dat = 0;
SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
 
// request OSD Data from NC every 100ms
// RS232_request_mk_data (1, 'o', 100);
tmp_dat = 10;
// OSD_active = true; // benötigt für Navidata Ausgabe an SV2
SendOutData ('o', ADDRESS_NC, 1, &tmp_dat, 1);
 
flag = 0;
timer = TIMEOUT;
abo_timer = ABO_TIMEOUT;
 
do
{
if (rxd_buffer_locked)
{
timer = TIMEOUT;
Decode64 ();
naviData = (NaviData_t *) pRxData;
 
if(FM_error == 1)
lcd_cls();
 
FM_error = 0;
GPS_Pos_t currpos;
currpos.Latitude = naviData->CurrentPosition.Latitude;
currpos.Longitude = naviData->CurrentPosition.Longitude;
 
 
flag = 1;
 
 
{
//-------------------------------------------
// OSD_Screen_Element() is depricated!
// USE NEW OSD_Element_xyz() FUNCTIONS!
//-------------------------------------------
// Altitude Control
//OSD_Screen_Element (0, 3, OSD_ALTITUDE_CONTROL,Config.OSD_ScreenMode);
OSD_Element_AltitudeControl( 0, 0 );
 
//
// // Altitude
// OSD_Screen_Element (11, 3, OSD_ALTITUDE);
 
// Battery level
//OSD_Screen_Element (0, 7, OSD_BATTERY_LEVEL,Config.OSD_ScreenMode);
OSD_Element_BatteryLevel( 0, 7, Config.OSD_ScreenMode );
 
// Capacity
//OSD_Screen_Element (13, 7, OSD_CAPACITY,Config.OSD_ScreenMode);
OSD_Element_Capacity( 13, 7 );
 
// Care Free
//OSD_Screen_Element (12, 2, OSD_CARE_FREE,Config.OSD_ScreenMode);
OSD_Element_CareFree( 12, 2 );
 
 
// // Compass Degree
// OSD_Screen_Element (13, 0, OSD_COMPASS_DEGREE);
//
// // Compass Direction
// OSD_Screen_Element (18, 0, OSD_COMPASS_DIRECTION);
//
// // Compass Rose
// OSD_Screen_Element (12, 1, OSD_COMPASS_ROSE);
 
// Current
//OSD_Screen_Element (7, 7, OSD_CURRENT,Config.OSD_ScreenMode);
OSD_Element_Current( 7, 7 );
 
 
// Flying time
lcd_printp_at (0, 1, PSTR("Flytime:"), 0);
//OSD_Screen_Element (8, 1, OSD_FLYING_TIME,Config.OSD_ScreenMode);
OSD_Element_FlyingTime( 8, 1 );
 
 
// Ground Speed
lcd_printp_at (0, 0, PSTR("Speed:"), 0);
//OSD_Screen_Element (6, 0, OSD_GROUND_SPEED,Config.OSD_ScreenMode);
OSD_Element_GroundSpeed( 6, 0 );
 
// Sats in use
//OSD_Screen_Element (16, 0, OSD_SATS_IN_USE,Config.OSD_ScreenMode);
OSD_Element_SatsInUse( 16, 0, Config.OSD_ScreenMode );
 
// // Home Circle
// OSD_Screen_Element (16, 4, OSD_HOME_CIRCLE);
//
// // Home Degree
// OSD_Screen_Element (12, 4, OSD_HOME_DEGREE);
 
// Home Distance
lcd_printp_at (11, 3, PSTR("Dist:"), 0);
//OSD_Screen_Element (17, 3, OSD_HOME_DISTANCE,Config.OSD_ScreenMode);
OSD_Element_HomeDistance( 17, 3, Config.OSD_ScreenMode );
 
//
// // LED1 Output
// OSD_Screen_Element (0, 6, OSD_LED1_OUTPUT);
//
// // LED2 Output
// OSD_Screen_Element (5, 6, OSD_LED2_OUTPUT);
 
// Manuell
// OSD_Screen_Element (7, 0, OSD_MANUELL);
 
// Navi Mode
//OSD_Screen_Element (0, 2, OSD_NAVI_MODE,Config.OSD_ScreenMode);
OSD_Element_NaviMode( 0, 2 );
 
 
// RC Intensity
// OSD_Screen_Element (11, 6, OSD_RC_INTENSITY);
 
 
// Status Flags
// OSD_Screen_Element (0, 2, OSD_STATUS_FLAGS);
 
// // Variometer
// OSD_Screen_Element (9, 0, OSD_VARIOMETER);
 
lcd_printp_at (0, 4, PSTR("MK:"), 0);
write_ndigit_number_u (3, 4, (uint16_t)(currpos.Latitude/10000000), 2, 0,0);
lcd_printp_at (5, 4, PSTR("."), 0);
write_ndigit_number_u (6, 4, (uint16_t)((currpos.Latitude/1000) % 10000), 4, 1,0);
write_ndigit_number_u (10, 4, (uint16_t)((currpos.Latitude/10) % 100), 2, 1,0);
 
 
write_ndigit_number_u (12, 4, (uint16_t)(currpos.Longitude/10000000), 2, 0,0);
lcd_printp_at (14, 4, PSTR("."), 0);
write_ndigit_number_u (15, 4, (uint16_t)((currpos.Longitude/1000) % 10000), 4, 1,0);
write_ndigit_number_u (19, 4, (uint16_t)((currpos.Longitude/10) % 100), 2, 1,0);
 
lcd_printp_at (0, 5, PSTR("!!!not implemented!!!"), 2);
 
// Akku Warnung
if (naviData->UBat < Config.MK_LowBat)
{ //Beeper ein
set_beep ( 3000, 0x0020, BeepNormal);
}
if (naviData->UBat > Config.MK_LowBat) //bei kurzzeitigen Schwankungen Beeper erst wieder aus wenn UBat 0,2 V höher als Warnschwelle
{ //Beeper aus
set_beep ( 0, 0, BeepOff);
}
// Akku Warnung Ende
 
old_FCFlags = naviData->FCStatusFlags;
 
rxd_buffer_locked = FALSE;
}
 
 
if (!abo_timer)
{ // renew abo every 3 sec
// request OSD Data from NC every 100ms
// RS232_request_mk_data (1, 'o', 100);
tmp_dat = 10;
SendOutData ('o', ADDRESS_NC, 1, &tmp_dat, 1);
 
abo_timer = ABO_TIMEOUT;
}
}
if (!timer)
{
OSD_Timeout(flag);
flag = 0;
FM_error = 1;
}
}
 
while (!get_key_press (1 << KEY_ESC));
OSD_active = false;
 
}
 
 
 
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/followme/followme.h
0,0 → 1,13
/*
* FollowMe.h
*
* Created on: 18.05.2012
* Author: cebra
*/
 
#ifndef FOLLOWME_H_
#define FOLLOWME_H_
 
void FollowMe (void);
 
#endif /* FOLLOWME_H_ */
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/gps/gps.c
0,0 → 1,366
/*****************************************************************************
* 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 <avr/io.h>
#include <inttypes.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
 
#include "../main.h"
#include "../lcd/lcd.h"
#include "../timer/timer.h"
#include "../uart/usart.h"
#if defined HWVERSION1_3W || defined HWVERSION3_9 || defined HWVERSION1_2W
#define TIMEOUT 200 // 2 sec
 
uint8_t ck_a = 0;
uint8_t ck_b = 0;
uint8_t UBX_class = 0;
uint8_t UBX_id = 0;
uint8_t UBX_buffer[250];
uint8_t UBX_payload_counter = 0;
 
void checksum(uint8_t);
void UBX_process(void);
uint32_t join_4_bytes(uint8_t*);
 
uint8_t display_mode = 0;
 
 
//--------------------------------------------------------------
void gps(void)
{
lcd_cls();
display_mode = 2;
 
if (hardware == FC)
{
lcd_printp_at(0, 3, PSTR("Nur mit NC !"), 0);
timer = 100;
while (timer > 0);
return;
}
 
 
if(current_hardware != NC)
SwitchToNC();
 
SwitchToGPS();
 
uint8_t mode = 0;
 
// SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
 
timer = TIMEOUT;
uint8_t data = 0;
uint8_t length = 0;
uint8_t UBX_ck_a = 0;
do
{
// if (rxFlag == 1)
if (uart_getc_nb(&data))
{
//rxFlag = 0;
//data = rx_byte;
timer = TIMEOUT;
 
switch(mode)
{
case 0: // init 1
if(data == 0xB5)
{
UBX_payload_counter = 0;
UBX_id = 0;
UBX_class = 0;
ck_a = 0;
ck_b = 0;
mode++;
}
break;
 
case 1: // init 2
if(data == 0x62)
mode++;
else
mode = 0;
break;
 
case 2: //class
if(data != 1)
mode = 0;
else
{
checksum(data);
UBX_class = data;
mode++;
}
break;
 
case 3: // id
if((data != 48)&&(data != 6)&&(data != 18)&&(data != 2))
mode = 0;
else
{
UBX_id = data;
checksum(data);
mode++;
}
break;
 
case 4: // length lo
if(data > 250)
mode = 0;
else
{
checksum(data);
length = data;
mode++;
}
break;
 
case 5: // length hi
if(data != 0)
mode = 0;
else
{
checksum(data);
mode++;
}
break;
 
case 6: // length hi
length--;
UBX_buffer[UBX_payload_counter] = data;
checksum(data);
UBX_payload_counter++;
if(length==0)
{
mode++;
};
break;
 
case 7: // check lo
mode++;
UBX_ck_a = data;
break;
 
case 8: // check hi
mode=0;
if((UBX_ck_a == ck_a) && (data == ck_b))
UBX_process();
 
}
 
 
// write_ndigit_number_u (14, 0, data, 3, 0);
}
 
}
while (!get_key_press (1 << KEY_ESC) && timer);
get_key_press(KEY_ALL);
 
SwitchToNC();
 
 
}
 
 
//--------------------------------------------------------------
void UBX_process()
{
 
if ((get_key_press (1 << KEY_MINUS))||(display_mode == 2))
{
if (display_mode != 1)
{
lcd_cls();
lcd_printp_at (0,0, PSTR("Fix Type : "), 0);
lcd_printp_at (0,1, PSTR("Sat : "), 0);
lcd_printp_at (0,2, PSTR("Accuracy : "), 0);
lcd_printp_at (0,3, PSTR("PDOP : "), 0);
lcd_printp_at (0,4, PSTR("Speed : "), 0);
lcd_printp_at (0,5, PSTR("Long : "), 0);
lcd_printp_at (0,6, PSTR("Lat : "), 0);
lcd_printp_at (0,7, PSTR("Alt : "), 0);
}
display_mode = 1;
}
 
if((UBX_class == 1) && (UBX_id == 48)&&(display_mode == 0))
{
uint8_t channels = UBX_buffer[4];
 
uint8_t i = 0;
for(i = 0; i < channels; i++)
{
if (i > 15)
break;
 
uint8_t line;
uint8_t col;
 
if (i > 7)
{
line = i-7;
col = 11;
}
else
col = 0; line = i;
 
write_ndigit_number_u (col, line, UBX_buffer[9 + 12*i], 3, 0,0);
write_ndigit_number_u (col+4, line, UBX_buffer[12 + 12*i], 2, 0,0);
 
if((UBX_buffer[10 + 12*i] & 3) == 3)
lcd_printp_at (col+7,line, PSTR("O"), 0);
else if((UBX_buffer[10 + 12*i] & 1) == 1)
lcd_printp_at (col+7,line, PSTR("X"), 0);
else if(UBX_buffer[11 + 12*i] > 4)
lcd_printp_at (col+7,line, PSTR("x"), 0);
else if(UBX_buffer[11 + 12*i] > 1)
lcd_printp_at (col+7,line, PSTR("-"), 0);
else
lcd_printp_at (col+7,line, PSTR(" "), 0);
 
}
}
 
if(display_mode == 1)
{
if((UBX_class == 1) && (UBX_id == 6)) //SVINFO
{
switch (UBX_buffer[10])
{
case 4:
 
case 3:
lcd_printp_at (11,0, PSTR("3D"), 0);
break;
 
case 2:
lcd_printp_at (11,0, PSTR("2D"), 0);
break;
 
default:
lcd_printp_at (11,0, PSTR("no"), 0);
}
 
if((UBX_buffer[11] & 3) == 3)
lcd_printp_at (17,0, PSTR("D"), 0);
else
lcd_printp_at (17,0, PSTR(" "), 0);
 
if((UBX_buffer[11] & 1) == 1)
lcd_printp_at (14,0, PSTR("ok"), 0);
else
lcd_printp_at (14,0, PSTR(" "), 0);
 
// lcd_write_number_u_at (11, 1, UBX_buffer[47]);
write_ndigit_number_u (11, 1, UBX_buffer[47], 2,0,0);
 
uint16_t acc = (uint16_t)join_4_bytes(&UBX_buffer[24]);
write_ndigit_number_u (11, 2, acc, 5, 0,0);
lcd_printp_at (17,2, PSTR("cm"), 0);
 
uint16_t pdop = UBX_buffer[44]+UBX_buffer[45]*255;
write_ndigit_number_u (11, 3, pdop/100, 2, 0,0);
lcd_printp_at (13,3, PSTR("."), 0);
write_ndigit_number_u (14, 3, (pdop % 100),2, 1,0);
}
 
if((UBX_class == 1) && (UBX_id == 18)) //VELNED
{
uint16_t speed = (uint16_t)((join_4_bytes(&UBX_buffer[20])*60*60)/100000);
write_ndigit_number_u (11, 4, speed, 3, 0,0);
lcd_printp_at (15,4, PSTR("km/h"), 0);
 
}
 
if((UBX_class == 1) && (UBX_id == 2)) //POSLLH
{
uint32_t lon = join_4_bytes(&UBX_buffer[4]);
write_ndigit_number_u (10, 5, (uint16_t)(lon/10000000), 2, 0,0);
lcd_printp_at (12,5, PSTR("."), 0);
write_ndigit_number_u (13, 5, (uint16_t)((lon/1000) % 10000), 4, 1,0);
write_ndigit_number_u (17, 5, (uint16_t)((lon/10) % 100), 2, 1,0);
 
uint32_t lat = join_4_bytes(&UBX_buffer[8]);
write_ndigit_number_u (10, 6, (uint16_t)(lat/10000000), 2, 0,0);
lcd_printp_at (12,6, PSTR("."), 0);
write_ndigit_number_u (13, 6, (uint16_t)((lat/1000) % 10000), 4, 1,0);
write_ndigit_number_u (17, 6, (uint16_t)((lat/10) % 100), 2, 1,0);
 
uint16_t height = (uint16_t)(join_4_bytes(&UBX_buffer[16])/1000);
write_ndigit_number_u (11, 7, height, 4, 0,0);
lcd_printp_at (16,7, PSTR("m"), 0);
 
}
}
}
 
 
//--------------------------------------------------------------
union long_union
{
uint32_t dword;
uint8_t byte[4];
} longUnion;
 
 
//--------------------------------------------------------------
union int_union
{
uint16_t dword;
uint8_t byte[2];
} intUnion;
 
 
//--------------------------------------------------------------
uint32_t join_4_bytes(uint8_t Buffer[])
{
longUnion.byte[0] = *Buffer;
longUnion.byte[1] = *(Buffer+1);
longUnion.byte[2] = *(Buffer+2);
longUnion.byte[3] = *(Buffer+3);
return (longUnion.dword);
}
 
 
//--------------------------------------------------------------
void checksum(uint8_t data)
{
ck_a += data;
ck_b += ck_a;
}
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/gps/gps.h
0,0 → 1,40
/*****************************************************************************
* 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*
*****************************************************************************/
 
 
#ifndef _GPS_H
#define _GPS_H
 
void gps (void);
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/lcd/.directory
0,0 → 1,3
[Dolphin]
Timestamp=2013,3,7,9,13,59
ViewMode=1
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/lcd/Font8x8.c
0,0 → 1,273
/*
* font8x8.c
* LCD-OSD
*
* Created by Peter Mack on 26.12.09.
* Copyright 2009 SCS GmbH & Co. KG. All rights reserved.
*
*/
 
#include <avr/pgmspace.h>
 
const uint8_t Font8x8[256][8]PROGMEM=
{
 
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x00
{0x7E,0x81,0x95,0xB1,0xB1,0x95,0x81,0x7E}, // 0x01
{0x7E,0xFF,0xEB,0xCF,0xCF,0xEB,0xFF,0x7E}, // 0x02
{0x0E,0x1F,0x3F,0x7E,0x3F,0x1F,0x0E,0x00}, // 0x03
{0x08,0x1C,0x3E,0x7F,0x3E,0x1C,0x08,0x00}, // 0x04
{0x38,0x3A,0x9F,0xFF,0x9F,0x3A,0x38,0x00}, // 0x05
{0x10,0x38,0xBC,0xFF,0xBC,0x38,0x10,0x00}, // 0x06
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x07
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x08
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x09
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x0A
{0x70,0xF8,0x88,0x88,0xFD,0x7F,0x07,0x0F}, // 0x0B
{0x00,0x4E,0x5F,0xF1,0xF1,0x5F,0x4E,0x00}, // 0x0C
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x0D
{0xC0,0xFF,0x7F,0x05,0x05,0x65,0x7F,0x3F}, // 0x0E
{0x99,0x5A,0x3C,0xE7,0xE7,0x3C,0x5A,0x99}, // 0x0F
{0x7F,0x3E,0x3E,0x1C,0x1C,0x08,0x08,0x00}, // 0x10
{0x08,0x08,0x1C,0x1C,0x3E,0x3E,0x7F,0x00}, // 0x11
{0x00,0x24,0x66,0xFF,0xFF,0x66,0x24,0x00}, // 0x12
{0x00,0x5F,0x5F,0x00,0x00,0x5F,0x5F,0x00}, // 0x13
{0x06,0x0F,0x09,0x7F,0x7F,0x01,0x7F,0x7F}, // 0x14
{0xDA,0xBF,0xA5,0xA5,0xFD,0x59,0x03,0x02}, // 0x15
{0x00,0x70,0x70,0x70,0x70,0x70,0x70,0x00}, // 0x16
{0x80,0x94,0xB6,0xFF,0xFF,0xB6,0x94,0x80}, // 0x17
{0x00,0x04,0x06,0x7F,0x7F,0x06,0x04,0x00}, // 0x18
{0x00,0x10,0x30,0x7F,0x7F,0x30,0x10,0x00}, // 0x19
{0x08,0x08,0x08,0x2A,0x3E,0x1C,0x08,0x00}, // 0x1A
{0x08,0x1C,0x3E,0x2A,0x08,0x08,0x08,0x00}, // 0x1B
{0x3C,0x3C,0x20,0x20,0x20,0x20,0x20,0x00}, // 0x1C
{0x08,0x1C,0x3E,0x08,0x08,0x3E,0x1C,0x08}, // 0x1D
{0x30,0x38,0x3C,0x3E,0x3E,0x3C,0x38,0x30}, // 0x1E
{0x06,0x0E,0x1E,0x3E,0x3E,0x1E,0x0E,0x06}, // 0x1F
 
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x20
{0x00,0x06,0x5F,0x5F,0x06,0x00,0x00,0x00}, // 0x21
{0x00,0x07,0x07,0x00,0x07,0x07,0x00,0x00}, // 0x22
{0x14,0x7F,0x7F,0x14,0x7F,0x7F,0x14,0x00}, // 0x23
{0x24,0x2E,0x6B,0x6B,0x3A,0x12,0x00,0x00}, // 0x24
{0x46,0x66,0x30,0x18,0x0C,0x66,0x62,0x00}, // 0x25
{0x30,0x7A,0x4F,0x5D,0x37,0x7A,0x48,0x00}, // 0x26
{0x04,0x07,0x03,0x00,0x00,0x00,0x00,0x00}, // 0x27
{0x00,0x1C,0x3E,0x63,0x41,0x00,0x00,0x00}, // 0x28
{0x00,0x41,0x63,0x3E,0x1C,0x00,0x00,0x00}, // 0x29
{0x08,0x2A,0x3E,0x1C,0x1C,0x3E,0x2A,0x08}, // 0x2A
{0x08,0x08,0x3E,0x3E,0x08,0x08,0x00,0x00}, // 0x2B
{0x00,0xA0,0xE0,0x60,0x00,0x00,0x00,0x00}, // 0x2C
{0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00}, // 0x2D
{0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00}, // 0x2E
{0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00}, // 0x2F
{0x3E,0x7F,0x59,0x4D,0x7F,0x3E,0x00,0x00}, // 0x30
{0x42,0x42,0x7F,0x7F,0x40,0x40,0x00,0x00}, // 0x31
{0x62,0x73,0x59,0x49,0x6F,0x66,0x00,0x00}, // 0x32
{0x22,0x63,0x49,0x49,0x7F,0x36,0x00,0x00}, // 0x33
{0x18,0x1C,0x16,0x13,0x7F,0x7F,0x10,0x00}, // 0x34
{0x27,0x67,0x45,0x45,0x7D,0x39,0x00,0x00}, // 0x35
{0x3C,0x7E,0x4B,0x49,0x79,0x30,0x00,0x00}, // 0x36
{0x03,0x63,0x71,0x19,0x0F,0x07,0x00,0x00}, // 0x37
{0x36,0x7F,0x49,0x49,0x7F,0x36,0x00,0x00}, // 0x38
{0x06,0x4F,0x49,0x69,0x3F,0x1E,0x00,0x00}, // 0x39
{0x00,0x00,0x6C,0x6C,0x00,0x00,0x00,0x00}, // 0x3A
{0x00,0xA0,0xEC,0x6C,0x00,0x00,0x00,0x00}, // 0x3B
{0x08,0x1C,0x36,0x63,0x41,0x00,0x00,0x00}, // 0x3C
{0x14,0x14,0x14,0x14,0x14,0x14,0x00,0x00}, // 0x3D
{0x00,0x41,0x63,0x36,0x1C,0x08,0x00,0x00}, // 0x3E
{0x02,0x03,0x51,0x59,0x0F,0x06,0x00,0x00}, // 0x3F
{0x3E,0x7F,0x41,0x5D,0x5D,0x1F,0x1E,0x00}, // 0x40
{0x7C,0x7E,0x13,0x13,0x7E,0x7C,0x00,0x00}, // 0x41
{0x41,0x7F,0x7F,0x49,0x49,0x7F,0x36,0x00}, // 0x42
{0x1C,0x3E,0x63,0x41,0x41,0x63,0x22,0x00}, // 0x43
{0x41,0x7F,0x7F,0x41,0x63,0x7F,0x1C,0x00}, // 0x44
{0x41,0x7F,0x7F,0x49,0x5D,0x41,0x63,0x00}, // 0x45
{0x41,0x7F,0x7F,0x49,0x1D,0x01,0x03,0x00}, // 0x46
{0x1C,0x3E,0x63,0x41,0x51,0x73,0x72,0x00}, // 0x47
{0x7F,0x7F,0x08,0x08,0x7F,0x7F,0x00,0x00}, // 0x48
{0x00,0x41,0x7F,0x7F,0x41,0x00,0x00,0x00}, // 0x49
{0x30,0x70,0x40,0x41,0x7F,0x3F,0x01,0x00}, // 0x4A
{0x41,0x7F,0x7F,0x08,0x1C,0x77,0x63,0x00}, // 0x4B
{0x41,0x7F,0x7F,0x41,0x40,0x60,0x70,0x00}, // 0x4C
{0x7F,0x7F,0x06,0x0C,0x06,0x7F,0x7F,0x00}, // 0x4D
{0x7F,0x7F,0x06,0x0C,0x18,0x7F,0x7F,0x00}, // 0x4E
{0x1C,0x3E,0x63,0x41,0x63,0x3E,0x1C,0x00}, // 0x4F
{0x41,0x7F,0x7F,0x49,0x09,0x0F,0x06,0x00}, // 0x50
{0x1E,0x3F,0x21,0x71,0x7F,0x5E,0x00,0x00}, // 0x51
{0x41,0x7F,0x7F,0x19,0x39,0x6F,0x46,0x00}, // 0x52
{0x26,0x67,0x4D,0x59,0x7B,0x32,0x00,0x00}, // 0x53
{0x03,0x41,0x7F,0x7F,0x41,0x03,0x00,0x00}, // 0x54
{0x7F,0x7F,0x40,0x40,0x7F,0x7F,0x00,0x00}, // 0x55
{0x1F,0x3F,0x60,0x60,0x3F,0x1F,0x00,0x00}, // 0x56
{0x7F,0x7F,0x30,0x18,0x30,0x7F,0x7F,0x00}, // 0x57
{0x63,0x77,0x1C,0x08,0x1C,0x77,0x63,0x00}, // 0x58
{0x07,0x4F,0x78,0x78,0x4F,0x07,0x00,0x00}, // 0x59
{0x67,0x73,0x59,0x4D,0x47,0x63,0x71,0x00}, // 0x5A
{0x00,0x7F,0x7F,0x41,0x41,0x00,0x00,0x00}, // 0x5B
{0x01,0x03,0x06,0x0C,0x18,0x30,0x60,0x00}, // 0x5C
{0x00,0x41,0x41,0x7F,0x7F,0x00,0x00,0x00}, // 0x5D
{0x08,0x0C,0x06,0x03,0x06,0x0C,0x08,0x00}, // 0x5E
{0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80}, // 0x5F
{0x00,0x00,0x03,0x07,0x04,0x00,0x00,0x00}, // 0x60
{0x20,0x74,0x54,0x54,0x3C,0x78,0x40,0x00}, // 0x61
{0x41,0x3F,0x7F,0x44,0x44,0x7C,0x38,0x00}, // 0x62
{0x38,0x7C,0x44,0x44,0x6C,0x28,0x00,0x00}, // 0x63
{0x30,0x78,0x48,0x49,0x3F,0x7F,0x40,0x00}, // 0x64
{0x38,0x7C,0x54,0x54,0x5C,0x18,0x00,0x00}, // 0x65
{0x48,0x7E,0x7F,0x49,0x03,0x02,0x00,0x00}, // 0x66
{0x98,0xBC,0xA4,0xA4,0xF8,0x7C,0x04,0x00}, // 0x67
{0x41,0x7F,0x7F,0x08,0x04,0x7C,0x78,0x00}, // 0x68
{0x00,0x44,0x7D,0x7D,0x40,0x00,0x00,0x00}, // 0x69
{0x40,0xC4,0x84,0xFD,0x7D,0x00,0x00,0x00}, // 0x6A
{0x41,0x7F,0x7F,0x10,0x38,0x6C,0x44,0x00}, // 0x6B
{0x00,0x41,0x7F,0x7F,0x40,0x00,0x00,0x00}, // 0x6C
{0x7C,0x7C,0x0C,0x18,0x0C,0x7C,0x78,0x00}, // 0x6D
{0x7C,0x7C,0x04,0x04,0x7C,0x78,0x00,0x00}, // 0x6E
{0x38,0x7C,0x44,0x44,0x7C,0x38,0x00,0x00}, // 0x6F
{0x84,0xFC,0xF8,0xA4,0x24,0x3C,0x18,0x00}, // 0x70
{0x18,0x3C,0x24,0xA4,0xF8,0xFC,0x84,0x00}, // 0x71
{0x44,0x7C,0x78,0x44,0x1C,0x18,0x00,0x00}, // 0x72
{0x48,0x5C,0x54,0x54,0x74,0x24,0x00,0x00}, // 0x73
{0x00,0x04,0x3E,0x7F,0x44,0x24,0x00,0x00}, // 0x74
{0x3C,0x7C,0x40,0x40,0x3C,0x7C,0x40,0x00}, // 0x75
{0x1C,0x3C,0x60,0x60,0x3C,0x1C,0x00,0x00}, // 0x76
{0x3C,0x7C,0x60,0x30,0x60,0x7C,0x3C,0x00}, // 0x77
{0x44,0x6C,0x38,0x10,0x38,0x6C,0x44,0x00}, // 0x78
{0x9C,0xBC,0xA0,0xA0,0xFC,0x7C,0x00,0x00}, // 0x79
{0x4C,0x64,0x74,0x5C,0x4C,0x64,0x00,0x00}, // 0x7A
{0x08,0x08,0x3E,0x77,0x41,0x41,0x00,0x00}, // 0x7B
{0x00,0x00,0x00,0x77,0x77,0x00,0x00,0x00}, // 0x7C
{0x41,0x41,0x77,0x3E,0x08,0x08,0x00,0x00}, // 0x7D
{0x02,0x03,0x01,0x03,0x02,0x03,0x01,0x00}, // 0x7E
{0x78,0x7C,0x46,0x43,0x46,0x7C,0x78,0x00}, // 0x7F
 
{0x1E,0xBF,0xE1,0x61,0x33,0x12,0x00,0x00}, // 0x80
{0x3A,0x7A,0x40,0x40,0x7A,0x7A,0x40,0x00}, // 0x81
{0x38,0x7C,0x56,0x57,0x5D,0x18,0x00,0x00}, // 0x82
{0x02,0x23,0x75,0x55,0x55,0x7D,0x7B,0x42}, // 0x83
{0x21,0x75,0x54,0x54,0x7D,0x79,0x40,0x00}, // 0x84
{0x20,0x75,0x57,0x56,0x7C,0x78,0x40,0x00}, // 0x85
{0x00,0x22,0x77,0x55,0x55,0x7F,0x7A,0x40}, // 0x86
{0x1C,0xBE,0xE2,0x62,0x36,0x14,0x00,0x00}, // 0x87
{0x02,0x3B,0x7D,0x55,0x55,0x5D,0x1B,0x02}, // 0x88
{0x39,0x7D,0x54,0x54,0x5D,0x19,0x00,0x00}, // 0x89
{0x38,0x7D,0x57,0x56,0x5C,0x18,0x00,0x00}, // 0x8A
{0x01,0x45,0x7C,0x7C,0x41,0x01,0x00,0x00}, // 0x8B
{0x02,0x03,0x45,0x7D,0x7D,0x43,0x02,0x00}, // 0x8C
{0x00,0x45,0x7F,0x7E,0x40,0x00,0x00,0x00}, // 0x8D
{0x79,0x7D,0x26,0x26,0x7D,0x79,0x00,0x00}, // 0x8E
{0x70,0x7A,0x2D,0x2D,0x7A,0x70,0x00,0x00}, // 0x8F
{0x44,0x7C,0x7E,0x57,0x55,0x44,0x00,0x00}, // 0x90
{0x20,0x74,0x54,0x54,0x7C,0x7C,0x54,0x54}, // 0x91
{0x7C,0x7E,0x0B,0x09,0x7F,0x7F,0x49,0x00}, // 0x92
{0x32,0x7B,0x49,0x49,0x7B,0x32,0x00,0x00}, // 0x93
{0x32,0x7A,0x48,0x48,0x7A,0x32,0x00,0x00}, // 0x94
{0x30,0x79,0x4B,0x4A,0x78,0x30,0x00,0x00}, // 0x95
{0x3A,0x7B,0x41,0x41,0x7B,0x7A,0x40,0x00}, // 0x96
{0x38,0x79,0x43,0x42,0x78,0x78,0x40,0x00}, // 0x97
{0xBA,0xBA,0xA0,0xA0,0xFA,0x7A,0x00,0x00}, // 0x98
{0x39,0x7D,0x44,0x44,0x44,0x7D,0x39,0x00}, // 0x99
{0x3D,0x7D,0x40,0x40,0x7D,0x3D,0x00,0x00}, // 0x9A
{0x38,0x7C,0x64,0x54,0x4C,0x7C,0x38,0x00}, // 0x9B
{0x68,0x7E,0x7F,0x49,0x43,0x66,0x20,0x00}, // 0x9C
{0x5C,0x3E,0x73,0x49,0x67,0x3E,0x1D,0x00}, // 0x9D
{0x44,0x6C,0x38,0x38,0x6C,0x44,0x00,0x00}, // 0x9E
{0x40,0xC8,0x88,0xFE,0x7F,0x09,0x0B,0x02}, // 0x9F
{0x20,0x74,0x56,0x57,0x7D,0x78,0x40,0x00}, // 0xA0
{0x00,0x44,0x7E,0x7F,0x41,0x00,0x00,0x00}, // 0xA1
{0x30,0x78,0x48,0x4A,0x7B,0x31,0x00,0x00}, // 0xA2
{0x38,0x78,0x40,0x42,0x7B,0x79,0x40,0x00}, // 0xA3
{0x7A,0x7B,0x09,0x0B,0x7A,0x73,0x01,0x00}, // 0xA4
{0x7A,0x7B,0x19,0x33,0x7A,0x7B,0x01,0x00}, // 0xA5
{0x00,0x26,0x2F,0x29,0x2F,0x2F,0x28,0x00}, // 0xA6
{0x00,0x26,0x2F,0x29,0x29,0x2F,0x26,0x00}, // 0xA7
{0x30,0x78,0x4D,0x45,0x60,0x20,0x00,0x00}, // 0xA8
{0x1C,0x22,0x7D,0x4B,0x5B,0x65,0x22,0x1C}, // 0xA9
{0x08,0x08,0x08,0x08,0x38,0x38,0x00,0x00}, // 0xAA
{0x61,0x3F,0x1F,0xCC,0xEE,0xAB,0xB9,0x90}, // 0xAB
{0x61,0x3F,0x1F,0x4C,0x66,0x73,0xD9,0xF8}, // 0xAC
{0x00,0x00,0x60,0xFA,0xFA,0x60,0x00,0x00}, // 0xAD
{0x08,0x1C,0x36,0x22,0x08,0x1C,0x36,0x22}, // 0xAE
{0x22,0x36,0x1C,0x08,0x22,0x36,0x1C,0x08}, // 0xAF
{0xAA,0x00,0x55,0x00,0xAA,0x00,0x55,0x00}, // 0xB0
{0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55}, // 0xB1
{0x55,0xFF,0xAA,0xFF,0x55,0xFF,0xAA,0xFF}, // 0xB2
{0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00}, // 0xB3
{0x10,0x10,0x10,0xFF,0xFF,0x00,0x00,0x00}, // 0xB4
{0x70,0x78,0x2C,0x2E,0x7B,0x71,0x00,0x00}, // 0xB5
{0x72,0x79,0x2D,0x2D,0x79,0x72,0x00,0x00}, // 0xB6
{0x71,0x7B,0x2E,0x2C,0x78,0x70,0x00,0x00}, // 0xB7
{0x1C,0x22,0x5D,0x55,0x55,0x41,0x22,0x1C}, // 0xB8
{0x14,0x14,0xF7,0xF7,0x00,0xFF,0xFF,0x00}, // 0xB9
{0x00,0x00,0xFF,0xFF,0x00,0xFF,0xFF,0x00}, // 0xBA
{0x14,0x14,0xF4,0xF4,0x04,0xFC,0xFC,0x00}, // 0xBB
{0x14,0x14,0x17,0x17,0x10,0x1F,0x1F,0x00}, // 0xBC
{0x18,0x3C,0x24,0xE7,0xE7,0x24,0x24,0x00}, // 0xBD
{0x2B,0x2F,0xFC,0xFC,0x2F,0x2B,0x00,0x00}, // 0xBE
{0x10,0x10,0x10,0xF0,0xF0,0x00,0x00,0x00}, // 0xBF
{0x00,0x00,0x00,0x1F,0x1F,0x10,0x10,0x10}, // 0xC0
{0x10,0x10,0x10,0x1F,0x1F,0x10,0x10,0x10}, // 0xC1
{0x10,0x10,0x10,0xF0,0xF0,0x10,0x10,0x10}, // 0xC2
{0x00,0x00,0x00,0xFF,0xFF,0x10,0x10,0x10}, // 0xC3
{0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10}, // 0xC4
{0x10,0x10,0x10,0xFF,0xFF,0x10,0x10,0x10}, // 0xC5
{0x22,0x77,0x55,0x57,0x7E,0x7B,0x41,0x00}, // 0xC6
{0x72,0x7B,0x2D,0x2F,0x7A,0x73,0x01,0x00}, // 0xC7
{0x00,0x00,0x1F,0x1F,0x10,0x17,0x17,0x14}, // 0xC8
{0x00,0x00,0xFC,0xFC,0x04,0xF4,0xF4,0x14}, // 0xC9
{0x14,0x14,0x17,0x17,0x10,0x17,0x17,0x14}, // 0xCA
{0x14,0x14,0xF4,0xF4,0x04,0xF4,0xF4,0x14}, // 0xCB
{0x00,0x00,0xFF,0xFF,0x00,0xF7,0xF7,0x14}, // 0xCC
{0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14}, // 0xCD
{0x14,0x14,0xF7,0xF7,0x00,0xF7,0xF7,0x14}, // 0xCE
{0x66,0x3C,0x3C,0x24,0x3C,0x3C,0x66,0x00}, // 0xCF
{0x05,0x27,0x72,0x57,0x7D,0x38,0x00,0x00}, // 0xD0
{0x49,0x7F,0x7F,0x49,0x63,0x7F,0x1C,0x00}, // 0xD1
{0x46,0x7D,0x7D,0x55,0x55,0x46,0x00,0x00}, // 0xD2
{0x45,0x7D,0x7C,0x54,0x55,0x45,0x00,0x00}, // 0xD3
{0x44,0x7D,0x7F,0x56,0x54,0x44,0x00,0x00}, // 0xD4
{0x0A,0x0E,0x08,0x00,0x00,0x00,0x00,0x00}, // 0xD5
{0x00,0x44,0x7E,0x7F,0x45,0x00,0x00,0x00}, // 0xD6
{0x02,0x45,0x7D,0x7D,0x45,0x02,0x00,0x00}, // 0xD7
{0x01,0x45,0x7C,0x7C,0x45,0x01,0x00,0x00}, // 0xD8
{0x10,0x10,0x10,0x1F,0x1F,0x00,0x00,0x00}, // 0xD9
{0x00,0x00,0x00,0xF0,0xF0,0x10,0x10,0x10}, // 0xDA
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, // 0xDB
{0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0}, // 0xDC
{0x00,0x00,0x00,0x77,0x77,0x00,0x00,0x00}, // 0xDD
{0x00,0x45,0x7F,0x7E,0x44,0x00,0x00,0x00}, // 0xDE
{0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F}, // 0xDF
{0x38,0x7C,0x46,0x47,0x45,0x7C,0x38,0x00}, // 0xE0
{0xFC,0xFE,0x2A,0x2A,0x3E,0x14,0x00,0x00}, // 0xE1
{0x3A,0x7D,0x45,0x45,0x45,0x7D,0x3A,0x00}, // 0xE2
{0x38,0x7C,0x45,0x47,0x46,0x7C,0x38,0x00}, // 0xE3
{0x32,0x7B,0x49,0x4B,0x7A,0x33,0x01,0x00}, // 0xE4
{0x3A,0x7F,0x45,0x47,0x46,0x7F,0x39,0x00}, // 0xE5
{0x80,0xFE,0x7E,0x20,0x20,0x3E,0x1E,0x00}, // 0xE6
{0x42,0x7E,0x7E,0x54,0x1C,0x08,0x00,0x00}, // 0xE7
{0x41,0x7F,0x7F,0x55,0x14,0x1C,0x08,0x00}, // 0xE8
{0x3C,0x7C,0x42,0x43,0x7D,0x3C,0x00,0x00}, // 0xE9
{0x3A,0x79,0x41,0x41,0x79,0x3A,0x00,0x00}, // 0xEA
{0x3C,0x7D,0x43,0x42,0x7C,0x3C,0x00,0x00}, // 0xEB
{0xB8,0xB8,0xA2,0xA3,0xF9,0x78,0x00,0x00}, // 0xEC
{0x0C,0x5C,0x72,0x73,0x5D,0x0C,0x00,0x00}, // 0xED
{0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00}, // 0xEE
{0x00,0x00,0x02,0x03,0x01,0x00,0x00,0x00}, // 0xEF
{0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00}, // 0xF0
{0x44,0x44,0x5F,0x5F,0x44,0x44,0x00,0x00}, // 0xF1
{0x28,0x28,0x28,0x28,0x28,0x28,0x00,0x00}, // 0xF2
{0x71,0x35,0x1F,0x4C,0x66,0x73,0xD9,0xF8}, // 0xF3
{0x06,0x0F,0x09,0x7F,0x7F,0x01,0x7F,0x7F}, // 0xF4
{0xDA,0xBF,0xA5,0xA5,0xFD,0x59,0x03,0x02}, // 0xF5
{0x08,0x08,0x6B,0x6B,0x08,0x08,0x00,0x00}, // 0xF6
{0x00,0x80,0xC0,0x40,0x00,0x00,0x00,0x00}, // 0xF7
{0x00,0x06,0x0F,0x09,0x0F,0x06,0x00,0x00}, // 0xF8
{0x02,0x02,0x00,0x00,0x02,0x02,0x00,0x00}, // 0xF9
{0x00,0x00,0x00,0x10,0x10,0x00,0x00,0x00}, // 0xFA
{0x00,0x12,0x13,0x1F,0x1F,0x10,0x10,0x00}, // 0xFB
{0x00,0x11,0x15,0x15,0x1F,0x1F,0x0A,0x00}, // 0xFC
{0x00,0x19,0x1D,0x15,0x17,0x12,0x00,0x00}, // 0xFD
{0x00,0x00,0x3C,0x3C,0x3C,0x3C,0x00,0x00}, // 0xFE
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} // 0xFF
};
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/lcd/Font8x8.h
0,0 → 1,31
/*****************************************************************************
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* - font provided by Claas Anders "CaScAdE" Rathje *
* - umlauts and special characters by Peter "woggle" Mack *
* *
* 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. *
* *
*****************************************************************************/
 
#ifndef _FONT8X8_H
#define _FONT8X8_H
 
#include <avr/pgmspace.h>
 
 
extern const uint8_t Font8x8[256][8];
 
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/lcd/font8x6.c
0,0 → 1,172
/*****************************************************************************
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* - font provided by Claas Anders "CaScAdE" Rathje *
* - umlauts and special characters by Peter "woggle" Mack *
* *
* 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. *
* *
*****************************************************************************/
 
#include <avr/pgmspace.h>
 
// one byte is a column
// bit 7 is the bottom
//
// 123456
// L 1 | XXX |
// O 2 |X X |
// W 4 |X X |
// 8 | XXX |
// H 1 |X X |
// I 2 |X X |
// G 4 | XXX |
// H 8 | |
//
// 0x36,0x49,0x49,0x49,0x36,0x00
//
 
//prog_uint8_t font8x6[128][6] = // führt zu Fehler mit AVR-GCC 4.5.1 21.2.2012 Cebra
const uint8_t font8x6[128][6] PROGMEM =
{
{ 0x00,0x00,0x00,0x00,0x00,0x00 }, // ASCII - 0 00 (not useable)
{ 0x78,0x15,0x14,0x15,0x78,0x00 }, // ASCII - 1 01 'Ä'
{ 0x20,0x55,0x54,0x55,0x78,0x00 }, // ASCII - 2 02 'ä'
{ 0x38,0x45,0x44,0x45,0x38,0x00 }, // ASCII - 3 03 'Ö'
{ 0x30,0x49,0x48,0x49,0x30,0x00 }, // ASCII - 4 04 'ö'
{ 0x3c,0x41,0x40,0x41,0x3c,0x00 }, // ASCII - 5 05 'Ü'
{ 0x38,0x41,0x40,0x21,0x78,0x00 }, // ASCII - 6 06 'ü'
{ 0x7e,0x15,0x15,0x15,0x0a,0x00 }, // ASCII - 7 07 'ß'
{ 0x22,0x17,0x0F,0x17,0x22,0x00 }, // ASCII - 8 08 SAT Symbol
{ 0x00,0x84,0x82,0xFF,0x82,0x84 }, // ASCII - 9 09 Altitude Symbol
{ 0x00,0x00,0x00,0x00,0x00,0x00 }, // ASCII - 10 0A (not useable)
{ 0x00,0x00,0x00,0x00,0x00,0x00 }, // ASCII - 11 0B
{ 0x10,0x38,0x54,0x10,0x10,0x1e }, // ASCII - 12 0C Enter Symbol
{ 0x00,0x00,0x00,0x00,0x00,0x00 }, // ASCII - 13 0D (not useable)
{ 0x10,0x10,0x10,0x10,0x10,0x10 }, // ASCII - 14 0E hor. line
{ 0x10,0x10,0x10,0x7c,0x10,0x10 }, // ASCII - 15 0F hor. line with tick mark
{ 0x00,0x00,0x00,0x00,0x00,0x00 }, // ASCII - 16 10
{ 0x08,0x14,0x00,0x00,0x14,0x08 }, // ASCII - 17 11 <> Change
{ 0x10,0x08,0x04,0x04,0x08,0x10 }, // ASCII - 18 12 /\ Up
{ 0x08,0x10,0x20,0x20,0x10,0x08 }, // ASCII - 19 13 \/ Down
{ 0x00,0x08,0x14,0x22,0x41,0x00 }, // ASCII - 20 14 < Left
{ 0x00,0x41,0x22,0x14,0x08,0x00 }, // ASCII - 21 15 > Right
{ 0x04,0x02,0x7f,0x02,0x04,0x00 }, // ASCII - 22 16 /|\ Arrow up
{ 0x10,0x20,0x7f,0x20,0x10,0x00 }, // ASCII - 23 17 \|/ Arrow down
{ 0x10,0x38,0x54,0x10,0x10,0x10 }, // ASCII - 24 18 <- Arrow left
{ 0x10,0x10,0x10,0x54,0x38,0x10 }, // ASCII - 25 19 -> Arrow right
{ 0x10,0x18,0x1c,0x1c,0x18,0x10 }, // ASCII - 26 1A ^ Triangle up
{ 0x08,0x18,0x38,0x38,0x18,0x08 }, // ASCII - 27 1B v Triangle down
{ 0x00,0x08,0x1c,0x3e,0x7f,0x00 }, // ASCII - 28 1C < Triangle left
{ 0x00,0x7f,0x3e,0x1c,0x08,0x00 }, // ASCII - 29 1D > Triangle right
{ 0x06,0x09,0x09,0x09,0x06,0x00 }, // ASCII - 30 1E '°'
{ 0x06,0x49,0x7d,0x49,0x06,0x00 }, // ASCII - 31 1F Antenne
 
{ 0x00,0x00,0x00,0x00,0x00,0x00 }, // ASCII - 32 20 ' '
{ 0x00,0x00,0x2f,0x00,0x00,0x00 }, // ASCII - 33 21 '!'
{ 0x00,0x07,0x00,0x07,0x00,0x00 }, // ASCII - 34 22 '"'
{ 0x14,0x7f,0x14,0x7f,0x14,0x00 }, // ASCII - 35 23 '#'
{ 0x24,0x2a,0x6b,0x2a,0x12,0x00 }, // ASCII - 36 24 '$'
{ 0x23,0x13,0x08,0x64,0x62,0x00 }, // ASCII - 37 25 '%'
{ 0x36,0x49,0x55,0x22,0x50,0x00 }, // ASCII - 38 26 '&'
{ 0x00,0x05,0x03,0x00,0x00,0x00 }, // ASCII - 39 27 '''
{ 0x00,0x1c,0x22,0x41,0x00,0x00 }, // ASCII - 40 28 '('
{ 0x00,0x41,0x22,0x1c,0x00,0x00 }, // ASCII - 41 29 ')'
{ 0x14,0x08,0x3e,0x08,0x14,0x00 }, // ASCII - 42 2a '*'
{ 0x08,0x08,0x3e,0x08,0x08,0x00 }, // ASCII - 43 2b '+'
{ 0x00,0x50,0x30,0x00,0x00,0x00 }, // ASCII - 44 2c ','
{ 0x08,0x08,0x08,0x08,0x08,0x00 }, // ASCII - 45 2d '-'
{ 0x00,0x60,0x60,0x00,0x00,0x00 }, // ASCII - 46 2e '.'
{ 0x20,0x10,0x08,0x04,0x02,0x00 }, // ASCII - 47 2f '/'
{ 0x3e,0x51,0x49,0x45,0x3e,0x00 }, // ASCII - 48 30 '0'
{ 0x00,0x42,0x7f,0x40,0x00,0x00 }, // ASCII - 49 31 '1'
{ 0x42,0x61,0x51,0x49,0x46,0x00 }, // ASCII - 50 32 '2'
{ 0x21,0x41,0x45,0x4b,0x31,0x00 }, // ASCII - 51 33 '3'
{ 0x18,0x14,0x12,0x7f,0x10,0x00 }, // ASCII - 52 34 '4'
{ 0x27,0x45,0x45,0x45,0x39,0x00 }, // ASCII - 53 35 '5'
{ 0x3c,0x4a,0x49,0x49,0x30,0x00 }, // ASCII - 54 36 '6'
{ 0x03,0x01,0x71,0x09,0x07,0x00 }, // ASCII - 55 37 '7'
{ 0x36,0x49,0x49,0x49,0x36,0x00 }, // ASCII - 56 38 '8'
{ 0x06,0x49,0x49,0x29,0x1e,0x00 }, // ASCII - 57 39 '9'
{ 0x00,0x36,0x36,0x00,0x00,0x00 }, // ASCII - 58 3a ':'
{ 0x00,0x56,0x36,0x00,0x00,0x00 }, // ASCII - 59 3b ';'
{ 0x08,0x14,0x22,0x41,0x00,0x00 }, // ASCII - 60 3c '<'
{ 0x14,0x14,0x14,0x14,0x14,0x00 }, // ASCII - 61 3d '='
{ 0x00,0x41,0x22,0x14,0x08,0x00 }, // ASCII - 62 3e '>'
{ 0x02,0x01,0x51,0x09,0x06,0x00 }, // ASCII - 63 3f '?'
{ 0x32,0x49,0x79,0x41,0x3e,0x00 }, // ASCII - 64 40 '@'
{ 0x7e,0x11,0x11,0x11,0x7e,0x00 }, // ASCII - 65 41 'A'
{ 0x7f,0x49,0x49,0x49,0x36,0x00 }, // ASCII - 66 42 'B'
{ 0x3e,0x41,0x41,0x41,0x22,0x00 }, // ASCII - 67 43 'C'
{ 0x7f,0x41,0x41,0x22,0x1c,0x00 }, // ASCII - 68 44 'D'
{ 0x7f,0x49,0x49,0x49,0x41,0x00 }, // ASCII - 69 45 'E'
{ 0x7f,0x09,0x09,0x09,0x01,0x00 }, // ASCII - 70 46 'F'
{ 0x3e,0x41,0x49,0x49,0x7a,0x00 }, // ASCII - 71 47 'G'
{ 0x7f,0x08,0x08,0x08,0x7f,0x00 }, // ASCII - 72 48 'H'
{ 0x00,0x41,0x7f,0x41,0x00,0x00 }, // ASCII - 73 49 'I'
{ 0x20,0x40,0x41,0x3f,0x01,0x00 }, // ASCII - 74 4a 'J'
{ 0x7f,0x08,0x14,0x22,0x41,0x00 }, // ASCII - 75 4b 'K'
{ 0x7f,0x40,0x40,0x40,0x40,0x00 }, // ASCII - 76 4c 'L'
{ 0x7f,0x02,0x0c,0x02,0x7f,0x00 }, // ASCII - 77 4d 'M'
{ 0x7f,0x04,0x08,0x10,0x7f,0x00 }, // ASCII - 78 4e 'N'
{ 0x3e,0x41,0x41,0x41,0x3e,0x00 }, // ASCII - 79 4f 'O'
{ 0x7f,0x09,0x09,0x09,0x06,0x00 }, // ASCII - 80 50 'P'
{ 0x3e,0x41,0x51,0x21,0x5e,0x00 }, // ASCII - 81 51 'Q'
{ 0x7f,0x09,0x19,0x29,0x46,0x00 }, // ASCII - 82 52 'R'
{ 0x46,0x49,0x49,0x49,0x31,0x00 }, // ASCII - 83 53 'S'
{ 0x01,0x01,0x7f,0x01,0x01,0x00 }, // ASCII - 84 54 'T'
{ 0x3f,0x40,0x40,0x40,0x3f,0x00 }, // ASCII - 85 55 'U'
{ 0x1f,0x20,0x40,0x20,0x1f,0x00 }, // ASCII - 86 56 'V'
{ 0x3f,0x40,0x38,0x40,0x3f,0x00 }, // ASCII - 87 57 'W'
{ 0x63,0x14,0x08,0x14,0x63,0x00 }, // ASCII - 88 58 'X'
{ 0x07,0x08,0x70,0x08,0x07,0x00 }, // ASCII - 89 59 'Y'
{ 0x61,0x51,0x49,0x45,0x43,0x00 }, // ASCII - 90 5a 'Z'
{ 0x7f,0x41,0x41,0x00,0x00,0x00 }, // ASCII - 91 5b '['
{ 0x02,0x04,0x08,0x10,0x20,0x00 }, // ASCII - 92 5c '\'
{ 0x00,0x41,0x41,0x7f,0x00,0x00 }, // ASCII - 93 5d ']'
{ 0x04,0x02,0x01,0x02,0x04,0x00 }, // ASCII - 94 5e '^'
{ 0x40,0x40,0x40,0x40,0x40,0x00 }, // ASCII - 95 5f '_'
{ 0x00,0x01,0x02,0x04,0x00,0x00 }, // ASCII - 96 60 '`'
{ 0x20,0x54,0x54,0x54,0x78,0x00 }, // ASCII - 97 61 'a'
{ 0x7f,0x48,0x44,0x44,0x38,0x00 }, // ASCII - 98 62 'b'
{ 0x38,0x44,0x44,0x44,0x20,0x00 }, // ASCII - 99 63 'c'
{ 0x38,0x44,0x44,0x48,0x7f,0x00 }, // ASCII - 100 64 'd'
{ 0x38,0x54,0x54,0x54,0x18,0x00 }, // ASCII - 101 65 'e'
{ 0x08,0x7e,0x09,0x01,0x02,0x00 }, // ASCII - 102 66 'f'
{ 0x0c,0x52,0x52,0x52,0x3e,0x00 }, // ASCII - 103 67 'g'
{ 0x7f,0x08,0x04,0x04,0x78,0x00 }, // ASCII - 104 68 'h'
{ 0x00,0x44,0x7d,0x40,0x00,0x00 }, // ASCII - 105 69 'i'
{ 0x20,0x40,0x44,0x3d,0x00,0x00 }, // ASCII - 106 6a 'j'
{ 0x7f,0x10,0x28,0x44,0x00,0x00 }, // ASCII - 107 6b 'k'
{ 0x00,0x41,0x7f,0x40,0x00,0x00 }, // ASCII - 108 6c 'l'
{ 0x7c,0x04,0x18,0x04,0x78,0x00 }, // ASCII - 109 6d 'm'
{ 0x7c,0x08,0x04,0x04,0x78,0x00 }, // ASCII - 110 6e 'n'
{ 0x38,0x44,0x44,0x44,0x38,0x00 }, // ASCII - 111 6f 'o'
{ 0x7c,0x14,0x14,0x14,0x08,0x00 }, // ASCII - 112 70 'p'
{ 0x08,0x14,0x14,0x18,0x7c,0x00 }, // ASCII - 113 71 'q'
{ 0x7c,0x08,0x04,0x04,0x08,0x00 }, // ASCII - 114 72 'r'
{ 0x48,0x54,0x54,0x54,0x20,0x00 }, // ASCII - 115 73 's'
{ 0x04,0x3f,0x44,0x40,0x20,0x00 }, // ASCII - 116 74 't'
{ 0x3c,0x40,0x40,0x20,0x7c,0x00 }, // ASCII - 117 75 'u'
{ 0x1c,0x20,0x40,0x20,0x1c,0x00 }, // ASCII - 118 76 'v'
{ 0x3c,0x40,0x38,0x40,0x3c,0x00 }, // ASCII - 119 77 'w'
{ 0x44,0x28,0x10,0x28,0x44,0x00 }, // ASCII - 120 78 'x'
{ 0x0c,0x50,0x50,0x50,0x3c,0x00 }, // ASCII - 121 79 'y'
{ 0x44,0x64,0x54,0x4c,0x44,0x00 }, // ASCII - 122 7a 'z'
{ 0x00,0x08,0x36,0x41,0x00,0x00 }, // ASCII - 123 7b '{'
{ 0x00,0x00,0x7f,0x00,0x00,0x00 }, // ASCII - 124 7c '|'
{ 0x00,0x41,0x36,0x08,0x00,0x00 }, // ASCII - 125 7d '}'
{ 0x08,0x08,0x2a,0x1c,0x08,0x00 }, // ASCII - 126 7e ->
{ 0x08,0x1c,0x2a,0x08,0x08,0x00 }, // ASCII - 127 7f <-
};
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/lcd/font8x6.h
0,0 → 1,30
/*****************************************************************************
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* - font provided by Claas Anders "CaScAdE" Rathje *
* - umlauts and special characters by Peter "woggle" Mack *
* *
* 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. *
* *
*****************************************************************************/
 
#ifndef _FONT8X6_H
#define _FONT8X6_H
 
#include <avr/pgmspace.h>
 
//extern prog_uint8_t font8x6[128][6];
extern const uint8_t font8x6[128][6];
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/lcd/lcd/.directory
0,0 → 1,3
[Dolphin]
Timestamp=2013,3,7,9,14,6
ViewMode=1
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/lcd/lcd/lcd.c
0,0 → 1,1402
/*****************************************************************************
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* - original LCD control by Thomas "thkais" Kaiser *
* - special number formating routines taken from C-OSD *
* from Claas Anders "CaScAdE" Rathje *
* - some extension, ellipse and circ_line by Peter "woggle" Mack *
* *
* 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. *
* *
*****************************************************************************/
 
#include "../cpu.h"
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
#include "font8x6.h"
#include "Font8x8.h"
#include "../eeprom/eeprom.h"
#include "lcd.h"
#include "../main.h"
#include "../HAL_HW3_9.h"
 
 
#define DISP_W 128
#define DISP_H 64
 
#define DISP_BUFFER ((DISP_H * DISP_W) / 8)
#define LINE_BUFFER (((DISP_H/8) * DISP_W) / 8)
 
#define Jeti 1 // Jeti Routinen
 
volatile uint8_t display_buffer[DISP_BUFFER]; // Display-Puffer, weil nicht zurückgelesen werden kann
volatile uint8_t line_buffer[LINE_BUFFER]; // Zeilen-Puffer, weil nicht zurückgelesen werden kann
 
volatile uint16_t display_buffer_pointer; // Pointer auf das aktuell übertragene Byte
volatile uint8_t display_buffer_counter; // Hilfszähler zur Selektierung der Page
volatile uint8_t display_page_counter; // aktuelle Page-Nummer
volatile uint8_t display_mode; // Modus für State-Machine
volatile uint8_t LCD_ORIENTATION;
 
// DOG: 128 x 64 with 6x8 Font => 21 x 8
// MAX7456: 30 x 16
 
uint8_t lcd_xpos;
uint8_t lcd_ypos;
 
 
//-----------------------------------------------------------
void send_byte (uint8_t data)
{
clr_cs ();
SPDR = data;
while (!(SPSR & (1<<SPIF)));
//SPSR = SPSR;
set_cs ();
}
 
 
//-----------------------------------------------------------
// * Writes one command byte
// * cmd - the command byte
//
void lcd_command(uint8_t cmd)
{
// LCD_SELECT();
// LCD_CMD();
// spi_write(cmd);
// LCD_UNSELECT();
clr_cs ();
SPDR = cmd;
while (!(SPSR & (1<<SPIF)));
//SPSR = SPSR;
set_cs ();
}
 
 
//-----------------------------------------------------------
void lcd_cls (void)
{
uint16_t i, j;
 
// memset (display_buffer, 0, 1024);
for (i = 0; i < DISP_BUFFER; i++)
display_buffer[i] = 0x00;
for (i = 0; i < 8; i++)
{
clr_A0 ();
send_byte (0xB0 + i); //1011xxxx
send_byte (0x10); //00010000
// send_byte(0x04); //00000100 gedreht plus 4 Byte
// send_byte(0x00); //00000000
send_byte (LCD_ORIENTATION); //00000000
 
set_A0 ();
for (j = 0; j < 128; j++)
send_byte (0x00);
}
 
lcd_xpos = 0;
lcd_ypos = 0;
}
 
 
//-----------------------------------------------------------
void lcd_cls_line (uint8_t x, uint8_t y, uint8_t w)
{
uint8_t lcd_width;
uint8_t lcd_zpos;
uint8_t i;
uint8_t max = 21;
lcd_width = w;
lcd_xpos = x;
lcd_ypos = y;
 
if ((lcd_xpos + lcd_width) > max)
lcd_width = max - lcd_xpos;
 
lcd_zpos = lcd_xpos + lcd_width;
 
for (i = lcd_xpos; i < lcd_zpos; i++)
lcd_putc (i, lcd_ypos, 0x20, 0);
}
 
 
//-----------------------------------------------------------
void wait_1ms (void)
{
_delay_ms (1);
}
 
 
//-----------------------------------------------------------
void wait_ms (uint16_t time)
{
uint16_t i;
 
for (i = 0; i < time; i++)
wait_1ms ();
}
 
 
//-----------------------------------------------------------
void LCD_Init (uint8_t LCD_Mode) // LCD_Mode 0= Default Mode 1= EEPROM-Parameter)
{
lcd_xpos = 0;
lcd_ypos = 0;
 
// DDRB = 0xFF;
 
// SPI max. speed
// the DOGM128 lcd controller can work at 20 MHz
SPCR = (1 << SPE) | (1 << MSTR) | (1 << CPHA) | (1 << CPOL);
SPSR = (1 << SPI2X);
 
set_cs ();
clr_reset ();
wait_ms (10);
set_reset ();
 
clr_cs ();
clr_A0 ();
 
send_byte (0x40); //Display start line = 0
if (LCD_Mode == 1)
{
if (LCD_ORIENTATION == 0)
{
send_byte (0xA1); // A1 normal A0 reverse(original)
send_byte (0xC0); // C0 normal C8 reverse(original)
}
else
{
send_byte (0xA0); // A1 normal A0 reverse(original)
send_byte (0xC8); // C0 normal C8 reverse(original)
}
}
else
{
send_byte (0xA1); // A1 normal A0 reverse(original)
send_byte (0xC0); // C0 normal C8 reverse(original)
}
if (LCD_Mode == 1)
{
if (Config.LCD_DisplayMode == 0)
send_byte (0xA6); //Display normal, not mirrored
else
send_byte (0xA7); //Display reverse, not mirrored
}
else
send_byte (0xA6);
 
 
send_byte (0xA2); //Set bias 1/9 (Duty 1/65)
send_byte (0x2F); //Booster, regulator and follower on
send_byte (0xF8); //Set internal booster to 4x
send_byte (0x00); //Set internal booster to 4x
send_byte (0x27); //resistor ratio set
 
if (LCD_Mode == 1)
{
send_byte (0x81); //Electronic volume register set
send_byte (Config.LCD_Kontrast); //Electronic volume register set
}
else
{
send_byte (0x81);
send_byte (0x16);
}
 
send_byte (0xAC); //Cursor
send_byte (0x00); //No Cursor
send_byte (0xAF); //No indicator
if (Config.HWSound==0)
{
if (LCD_Mode == 1)
{
// Helligkeit setzen
OCR2A = Config.LCD_Helligkeit * 2.55;
}
else
{
OCR2A = 255;
}
}
lcd_cls ();
}
 
 
//-----------------------------------------------------------
void set_adress (uint16_t adress, uint8_t data)
{
uint8_t page;
uint8_t column;
 
page = adress >> 7;
 
clr_A0 ();
send_byte (0xB0 + page);
 
column = (adress & 0x7F) + LCD_ORIENTATION;
 
send_byte (0x10 + (column >> 4));
send_byte (column & 0x0F);
 
set_A0 ();
send_byte (data);
}
 
 
//-----------------------------------------------------------
void scroll (void)
{
uint16_t adress;
 
for (adress = 0; adress < 896; adress++)
{
display_buffer[adress] = display_buffer[adress + 128];
set_adress (adress, display_buffer[adress]);
}
 
for (adress = 896; adress < 1024; adress++)
{
display_buffer[adress] = 0;
set_adress (adress, 0);
}
}
 
 
//-----------------------------------------------------------
// sicher eine Zeile für die Statusanzeige
void copy_line (uint8_t y)
{
uint8_t i;
uint16_t adress;
 
adress = y * 128 + 0 * 6;
adress &= 0x3FF;
 
for (i = 0; i < 6*21; i++)
{
line_buffer[i] = display_buffer[adress+i];
set_adress (adress + i, display_buffer[adress + i]);
}
}
 
 
//-----------------------------------------------------------
// holt gesicherte Zeile wieder zurück
void paste_line (uint8_t y)
{
uint8_t i;
uint16_t adress;
 
adress = y * 128 + 0 * 6;
adress &= 0x3FF;
 
for (i = 0; i < 6*21; i++)
{
display_buffer[adress+i] =line_buffer[i];
set_adress (adress + i, display_buffer[adress + i]);
}
}
 
 
//-----------------------------------------------------------
void lcd_puts_at(uint8_t x, uint8_t y,const char *s, uint8_t mode )
{
while (*s)
{
lcd_putc(x, y, *s++, mode);
x++;
}
 
}/* lcd_puts */
 
 
//-----------------------------------------------------------
void lcd_putc (uint8_t x, uint8_t y, uint8_t c, uint8_t mode)
{
uint8_t ch;
uint8_t i;
uint16_t adress;
 
if (mode == 2)
lcd_frect ((x*6),(y*8),5,7,1); // invertierte Darstellung
 
if (mode == 3) lcd_putc_jeti (x, y, c,0);
else
if (mode == 4) lcd_putc_jeti (x, y, c,2);
else
{
 
switch (c)
{ // ISO 8859-1
 
case 0xc4: // Ä
c = 0x01;
break;
 
case 0xe4: // ä
c = 0x02;
break;
 
case 0xd6: // Ö
c = 0x03;
break;
 
case 0xf6: // ö
c = 0x04;
break;
 
case 0xdc: // Ü
c = 0x05;
break;
 
case 0xfc: // ü
c = 0x06;
break;
 
case 0xdf: // ß
//c = 0x07;
c = 0x1e; // ° (used by Jeti)
break;
}
 
c &= 0x7f;
 
adress = y * 128 + x * 6;
adress &= 0x3FF;
 
for (i = 0; i < 6; i++)
{
ch = pgm_read_byte (&font8x6[0][0] + i + c * 6);
 
switch (mode)
{
 
case 0:
display_buffer[adress+i] = ch;
break;
 
case 1:
display_buffer[adress+i] |= ch;
break;
 
case 2:
display_buffer[adress+i] ^= ch;
break;
 
case 3:
display_buffer[adress+i] &= ch;
break;
 
case 4:
display_buffer[adress+i] &= ~ch;
break;
}
 
set_adress (adress + i, display_buffer[adress + i]);
}
}
}
 
 
#if Jeti
//-----------------------------------------------------------
void lcd_putc_jeti (uint8_t x, uint8_t y, uint8_t c, uint8_t mode)
{
uint8_t ch;
uint8_t i;
uint16_t adress;
if (mode == 2)
lcd_frect ((x*8),(y*8),8,8,1); // invertierte Darstellung
switch (c)
{
 
case 0x7e:
c = 0x1a; // ->
break;
 
case 0x7f:
c = 0x1b; // <-
break;
 
case 0xdf:
c = 0xf8; // °
break;
}
 
adress = y * 128 + x * 8;
adress &= 0x3FF;
 
for (i = 0; i < 8; i++)
{
ch = pgm_read_byte (&Font8x8[0][0] + i + c * 8);
 
switch (mode)
{
 
case 0:
display_buffer[adress+i] = ch;
break;
 
case 1:
display_buffer[adress+i] |= ch;
break;
 
case 2:
display_buffer[adress+i] ^= ch;
break;
 
case 3:
display_buffer[adress+i] &= ch;
break;
 
case 4:
display_buffer[adress+i] &= ~ch;
break;
}
 
set_adress (adress + i, display_buffer[adress + i]);
}
}
 
 
//-----------------------------------------------------------
void lcd_printpj (const char *text, uint8_t mode)
{
while (pgm_read_byte(text))
{
switch (pgm_read_byte(text))
{
 
case 0x0D:
lcd_xpos = 0;
break;
 
case 0x0A:
new_line();
break;
 
default:
lcd_putc_jeti (lcd_xpos, lcd_ypos, pgm_read_byte(text), mode);
lcd_xpos++;
if (lcd_xpos > 20)
{
lcd_xpos = 0;
new_line ();
}
break;
}
text++;
}
}
 
 
//-----------------------------------------------------------
void lcd_printpj_at (uint8_t x, uint8_t y, const char *text, uint8_t mode)
{
lcd_xpos = x;
lcd_ypos = y;
lcd_printpj (text, mode);
}
#endif
 
 
//-----------------------------------------------------------
void new_line (void)
{
lcd_ypos++;
 
if (lcd_ypos > 7)
{
scroll ();
lcd_ypos = 7;
}
}
 
 
//-----------------------------------------------------------
void lcd_printpns (const char *text, uint8_t mode)
{
while (pgm_read_byte(text))
{
switch (pgm_read_byte(text))
{
 
case 0x0D:
lcd_xpos = 0;
break;
 
case 0x0A:
new_line();
break;
 
default:
lcd_putc (lcd_xpos, lcd_ypos, pgm_read_byte(text), mode);
lcd_xpos++;
if (lcd_xpos > 21)
{
lcd_xpos = 0;
// new_line ();
}
break;
}
text++;
}
}
 
 
//-----------------------------------------------------------
void lcd_printpns_at (uint8_t x, uint8_t y, const char *text, uint8_t mode)
{
lcd_xpos = x;
lcd_ypos = y;
lcd_printpns (text, mode);
}
 
 
//-----------------------------------------------------------
void lcd_printp (const char *text, uint8_t mode)
{
while (pgm_read_byte(text))
{
switch (pgm_read_byte(text))
{
 
case 0x0D:
lcd_xpos = 0;
break;
 
case 0x0A:
new_line();
break;
 
default:
lcd_putc (lcd_xpos, lcd_ypos, pgm_read_byte(text), mode);
lcd_xpos++;
if (lcd_xpos > 21)
{
lcd_xpos = 0;
new_line ();
}
break;
}
text++;
}
}
 
 
//-----------------------------------------------------------
void lcd_printp_at (uint8_t x, uint8_t y, const char *text, uint8_t mode)
{
lcd_xpos = x;
lcd_ypos = y;
lcd_printp (text, mode);
}
 
 
//-----------------------------------------------------------
void lcd_print (uint8_t *text, uint8_t mode)
{
while (*text)
{
switch (*text)
{
 
case 0x0D:
lcd_xpos = 0;
break;
 
case 0x0A:
new_line();
break;
 
default:
lcd_putc (lcd_xpos, lcd_ypos, *text, mode);
lcd_xpos++;
if (lcd_xpos > 21)
{
lcd_xpos = 0;
new_line ();
}
break;
}
text++;
}
}
 
 
//-----------------------------------------------------------
void lcd_print_at (uint8_t x, uint8_t y, uint8_t *text, uint8_t mode)
{
lcd_xpos = x;
lcd_ypos = y;
lcd_print (text, mode);
}
 
 
//-----------------------------------------------------------
void print_display (uint8_t *text)
{
while (*text)
{
lcd_putc (lcd_xpos, lcd_ypos, *text, 0);
lcd_xpos++;
if (lcd_xpos >= 20)
{
lcd_xpos = 0;
new_line ();
}
text++;
}
}
 
 
//-----------------------------------------------------------
void print_display_at (uint8_t x, uint8_t y, uint8_t *text)
{
lcd_xpos = x;
lcd_ypos = y;
print_display (text);
}
 
 
//-----------------------------------------------------------
// + Plot (set one Pixel)
//-----------------------------------------------------------
// mode:
// 0=Clear, 1=Set, 2=XOR
void lcd_plot (uint8_t xpos, uint8_t ypos, uint8_t mode)
{
uint16_t adress;
uint8_t mask;
 
if ((xpos < DISP_W) && (ypos < DISP_H))
{
adress = (ypos / 8) * DISP_W + xpos; // adress = 0/8 * 128 + 0 = 0
mask = 1 << (ypos & 0x07); // mask = 1<<0 = 1
adress &= DISP_BUFFER - 1;
switch (mode)
{
 
case 0:
display_buffer[adress] &= ~mask;
break;
 
case 1:
display_buffer[adress] |= mask;
break;
 
case 2:
display_buffer[adress] ^= mask;
break;
}
set_adress (adress, display_buffer[adress]);
}
}
 
 
//-----------------------------------------------------------
// + Line (draws a line from x1,y1 to x2,y2
// + Based on Bresenham line-Algorithm
// + found in the internet, modified by thkais 2007
//-----------------------------------------------------------
 
void lcd_line (unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, uint8_t mode)
{
int x, y, count, xs, ys, xm, ym;
 
x = (int) x1;
y = (int) y1;
xs = (int) x2 - (int) x1;
ys = (int) y2 - (int) y1;
if (xs < 0)
xm = -1;
else
if (xs > 0)
xm = 1;
else
xm = 0;
if (ys < 0)
ym = -1;
else
if (ys > 0)
ym = 1;
else
ym = 0;
if (xs < 0)
xs = -xs;
 
if (ys < 0)
ys = -ys;
 
lcd_plot ((unsigned char) x, (unsigned char) y, mode);
 
if (xs > ys) // Flat Line <45 degrees
{
count = -(xs / 2);
while (x != x2)
{
count = count + ys;
x = x + xm;
if (count > 0)
{
y = y + ym;
count = count - xs;
}
lcd_plot ((unsigned char) x, (unsigned char) y, mode);
}
}
else // Line >=45 degrees
{
count =- (ys / 2);
while (y != y2)
{
count = count + xs;
y = y + ym;
if (count > 0)
{
x = x + xm;
count = count - ys;
}
lcd_plot ((unsigned char) x, (unsigned char) y, mode);
}
}
}
 
 
//-----------------------------------------------------------
// + Filled rectangle
// + x1, y1 = upper left corner
//-----------------------------------------------------------
 
void lcd_frect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode)
{
uint16_t x2, y2;
uint16_t i;
 
if (x1 >= DISP_W)
x1 = DISP_W - 1;
 
if (y1 >= DISP_H)
y1 = DISP_H - 1;
 
x2 = x1 + widthx;
y2 = y1 + widthy;
 
if (x2 > DISP_W)
x2 = DISP_W;
 
if (y2 > DISP_H)
y2 = DISP_H;
 
for (i = y1; i <= y2; i++)
{
lcd_line (x1, i, x2, i, mode);
}
}
 
 
//-----------------------------------------------------------
// + outline of rectangle
// + x1, y1 = upper left corner
//-----------------------------------------------------------
 
void lcd_rect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode)
{
uint16_t x2, y2;
 
if (x1 >= DISP_W)
x1 = DISP_W - 1;
if (y1 >= DISP_H)
y1 = DISP_H - 1;
x2 = x1 + widthx;
y2 = y1 + widthy;
 
if (x2 > DISP_W)
x2 = DISP_W;
 
if (y2 > DISP_H)
y2 = DISP_H;
 
lcd_line (x1, y1, x2, y1, mode);
lcd_line (x2, y1, x2, y2, mode);
lcd_line (x2, y2, x1, y2, mode);
lcd_line (x1, y2, x1, y1, mode);
}
 
 
//-----------------------------------------------------------
// + outline of a circle
// + Based on Bresenham-algorithm found in wikipedia
// + modified by thkais (2007)
//-----------------------------------------------------------
 
void lcd_circle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode)
{
int16_t f = 1 - radius;
int16_t ddF_x = 0;
int16_t ddF_y = -2 * radius;
int16_t x = 0;
int16_t y = radius;
 
lcd_plot (x0, y0 + radius, mode);
lcd_plot (x0, y0 - radius, mode);
lcd_plot (x0 + radius, y0, mode);
lcd_plot (x0 - radius, y0, mode);
 
while (x < y)
{
if (f >= 0)
{
y --;
ddF_y += 2;
f += ddF_y;
}
x ++;
ddF_x += 2;
f += ddF_x + 1;
 
lcd_plot (x0 + x, y0 + y, mode);
lcd_plot (x0 - x, y0 + y, mode);
 
lcd_plot (x0 + x, y0 - y, mode);
lcd_plot (x0 - x, y0 - y, mode);
 
lcd_plot (x0 + y, y0 + x, mode);
lcd_plot (x0 - y, y0 + x, mode);
 
lcd_plot (x0 + y, y0 - x, mode);
lcd_plot (x0 - y, y0 - x, mode);
}
}
 
 
//-----------------------------------------------------------
// + filled Circle
// + modified circle-algorithm thkais (2007)
//-----------------------------------------------------------
 
void lcd_fcircle (int16_t x0, int16_t y0, int16_t radius,uint8_t mode)
{
int16_t f = 1 - radius;
int16_t ddF_x = 0;
int16_t ddF_y = -2 * radius;
int16_t x = 0;
int16_t y = radius;
 
lcd_line (x0, y0 + radius, x0, y0 - radius, mode);
 
lcd_line (x0 + radius, y0, x0 - radius, y0, mode);
 
while (x < y)
{
if (f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x + 1;
 
lcd_line (x0 + x, y0 + y, x0 - x, y0 + y, mode);
lcd_line (x0 + x, y0 - y, x0 - x, y0 - y, mode);
lcd_line (x0 + y, y0 + x, x0 - y, y0 + x, mode);
lcd_line (x0 + y, y0 - x, x0 - y, y0 - x, mode);
}
}
 
 
//-----------------------------------------------------------
//
void lcd_circ_line (uint8_t x, uint8_t y, uint8_t r, uint16_t deg, uint8_t mode)
{
uint8_t xc, yc;
double deg_rad;
 
deg_rad = (deg * M_PI) / 180.0;
 
yc = y - (uint8_t) round (cos (deg_rad) * (double) r);
xc = x + (uint8_t) round (sin (deg_rad) * (double) r);
lcd_line (x, y, xc, yc, mode);
}
 
 
//-----------------------------------------------------------
//
void lcd_ellipse_line (uint8_t x, uint8_t y, uint8_t rx, uint8_t ry, uint16_t deg, uint8_t mode)
{
uint8_t xc, yc;
double deg_rad;
 
deg_rad = (deg * M_PI) / 180.0;
 
yc = y - (uint8_t) round (cos (deg_rad) * (double) ry);
xc = x + (uint8_t) round (sin (deg_rad) * (double) rx);
lcd_line (x, y, xc, yc, mode);
}
 
 
//-----------------------------------------------------------
//
void lcd_ellipse (int16_t x0, int16_t y0, int16_t rx, int16_t ry, uint8_t mode)
{
const int16_t rx2 = rx * rx;
const int16_t ry2 = ry * ry;
int16_t F = round (ry2 - rx2 * ry + 0.25 * rx2);
int16_t ddF_x = 0;
int16_t ddF_y = 2 * rx2 * ry;
int16_t x = 0;
int16_t y = ry;
 
lcd_plot (x0, y0 + ry, mode);
lcd_plot (x0, y0 - ry, mode);
lcd_plot (x0 + rx, y0, mode);
lcd_plot (x0 - rx, y0, mode);
// while ( 2*ry2*x < 2*rx2*y ) { we can use ddF_x and ddF_y
while (ddF_x < ddF_y)
{
if(F >= 0)
{
y -= 1; // south
ddF_y -= 2 * rx2;
F -= ddF_y;
}
x += 1; // east
ddF_x += 2 * ry2;
F += ddF_x + ry2;
lcd_plot (x0 + x, y0 + y, mode);
lcd_plot (x0 + x, y0 - y, mode);
lcd_plot (x0 - x, y0 + y, mode);
lcd_plot (x0 - x, y0 - y, mode);
}
F = round (ry2 * (x + 0.5) * (x + 0.5) + rx2 * (y - 1) * (y - 1) - rx2 * ry2);
while(y > 0)
{
if(F <= 0)
{
x += 1; // east
ddF_x += 2 * ry2;
F += ddF_x;
}
y -= 1; // south
ddF_y -= 2 * rx2;
F += rx2 - ddF_y;
lcd_plot (x0 + x, y0 + y, mode);
lcd_plot (x0 + x, y0 - y, mode);
lcd_plot (x0 - x, y0 + y, mode);
lcd_plot (x0 - x, y0 - y, mode);
}
}
 
 
//-----------------------------------------------------------
//
void lcd_ecircle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode)
{
lcd_ellipse (x0, y0, radius + 3, radius, mode);
}
 
 
//-----------------------------------------------------------
//
void lcd_ecirc_line (uint8_t x, uint8_t y, uint8_t r, uint16_t deg, uint8_t mode)
{
lcd_ellipse_line(x, y, r + 3, r, deg, mode);
}
 
 
//-----------------------------------------------------------
//
void lcd_view_font (uint8_t page)
{
int x;
int y;
 
lcd_cls ();
lcd_printp (PSTR(" 0123456789ABCDEF\r\n"), 0);
lcd_printpns_at (0, 7, PSTR(" \x1a \x1b Exit"), 0);
 
lcd_ypos = 2;
for (y = page * 4 ; y < (page * 4 + 4); y++)
{
if (y < 10)
{
lcd_putc (0, lcd_ypos, '0' + y, 0);
}
else
{
lcd_putc (0, lcd_ypos, 'A' + y - 10, 0);
}
lcd_xpos = 2;
for (x = 0; x < 16; x++)
{
lcd_putc (lcd_xpos, lcd_ypos, y * 16 + x, 0);
lcd_xpos++;
}
lcd_ypos++;
}
}
 
 
//-----------------------------------------------------------
uint8_t hdigit (uint8_t d)
{
if (d < 10)
{
return '0' + d;
}
else
{
return 'A' + d - 10;
}
}
 
 
//-----------------------------------------------------------
void lcd_print_hex_at (uint8_t x, uint8_t y, uint8_t h, uint8_t mode)
{
lcd_xpos = x;
lcd_ypos = y;
 
lcd_putc (lcd_xpos++, lcd_ypos, hdigit (h >> 4), mode);
lcd_putc (lcd_xpos, lcd_ypos, hdigit (h & 0x0f), mode);
}
 
 
//-----------------------------------------------------------
void lcd_print_hex (uint8_t h, uint8_t mode)
{
// lcd_xpos = x;
// lcd_ypos = y;
 
lcd_putc (lcd_xpos++, lcd_ypos, hdigit (h >> 4), mode);
lcd_putc (lcd_xpos++, lcd_ypos, hdigit (h & 0x0f), mode);
lcd_putc (lcd_xpos++, lcd_ypos, ' ', mode);
}
 
 
//-----------------------------------------------------------
void lcd_write_number_u (uint8_t number)
{
uint8_t num = 100;
uint8_t started = 0;
 
while (num > 0)
{
uint8_t b = number / num;
if (b > 0 || started || num == 1)
{
lcd_putc (lcd_xpos++, lcd_ypos, '0' + b, 0);
started = 1;
}
number -= b * num;
 
num /= 10;
}
}
 
 
//-----------------------------------------------------------
void lcd_write_number_u_at (uint8_t x, uint8_t y, uint8_t number)
{
lcd_xpos = x;
lcd_ypos = y;
lcd_write_number_u (number);
}
 
 
//-----------------------------------------------------------
// Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory
// <num> represents the largest multiple of 10 that will still be displayable as
// the first digit, so num = 10 will be 0-99 and so on
// <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
//
void write_ndigit_number_u (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, uint8_t mode)
{
char s[7];
 
utoa(number, s, 10 );
 
uint8_t len = strlen(s);
 
if (length < len)
{
for (uint8_t i = 0; i < length; i++)
{
lcd_putc (x++, y, '*', mode);
}
return;
}
 
for (uint8_t i = 0; i < length - len; i++)
{
if (pad==1)
{
lcd_putc (x++, y, '0', mode);
}
else
{
lcd_putc (x++, y, ' ', mode);
}
}
lcd_print_at(x, y, (uint8_t*)s, mode);
}
 
//-----------------------------------------------------------
// Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory
// <num> represents the largest multiple of 10 that will still be displayable as
// the first digit, so num = 10 will be 0-99 and so on
// <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
//
void write_ndigit_number_s (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode)
{
char s[7];
 
itoa(number, s, 10 );
 
uint8_t len = strlen(s);
 
if (length < len)
{
for (uint8_t i = 0; i < length; i++)
{
lcd_putc (x++, y, '*', mode);
}
return;
}
 
for (uint8_t i = 0; i < length - len; i++)
{
if (pad)
{
lcd_putc (x++, y, '0', mode);
}
else
{
lcd_putc (x++, y, ' ', mode);
}
}
lcd_print_at(x, y, (uint8_t*)s, mode);
}
 
 
//-----------------------------------------------------------
// Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory
// as /10th of the value
// <num> represents the largest multiple of 10 that will still be displayable as
// the first digit, so num = 10 will be 0-99 and so on
// <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
//
void write_ndigit_number_u_10th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, uint8_t mode)
{
char s[7];
 
itoa(number, s, 10 );
 
uint8_t len = strlen(s);
 
if (length < len)
{
for (uint8_t i = 0; i < length; i++)
{
lcd_putc (x++, y, '*', mode);
}
return;
}
 
for (uint8_t i = 0; i < length - len; i++)
{
if (pad)
{
lcd_putc (x++, y, '0', mode);
}
else
{
lcd_putc (x++, y, ' ', mode);
}
}
 
char rest = s[len - 1];
 
s[len - 1] = 0;
 
if (len == 1)
{
lcd_putc (x-1, y, '0', mode);
}
else if (len == 2 && s[0] == '-')
{
lcd_putc (x-1, y, '-', mode);
lcd_putc (x, y, '0', mode);
}
else
{
lcd_print_at(x, y, (uint8_t*)s, mode);
}
x += len - 1;
lcd_putc (x++, y, '.', mode);
lcd_putc (x++, y, rest, mode);
}
 
 
//-----------------------------------------------------------
void write_ndigit_number_u_100th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad)
{
uint8_t num = 100;
 
while (num > 0)
{
uint8_t b = number / num;
 
if ((num / 10) == 1)
{
lcd_putc (x++, y, '.', 0);
}
lcd_putc (x++, y, '0' + b, 0);
number -= b * num;
 
num /= 10;
}
}
 
 
//-----------------------------------------------------------
// Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory
// as /10th of the value
// <num> represents the largest multiple of 10 that will still be displayable as
// the first digit, so num = 10 will be 0-99 and so on
// <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
//
void write_ndigit_number_s_10th (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode)
{
char s[7];
 
itoa (number, s, 10 );
 
uint8_t len = strlen(s);
 
if (length < len)
{
for (uint8_t i = 0; i < length; i++)
{
lcd_putc (x++, y, '*', mode);
}
return;
}
 
for (uint8_t i = 0; i < length - len; i++)
{
if (pad)
{
lcd_putc (x++, y, '0', mode);
}
else
{
lcd_putc (x++, y, ' ', mode);
}
}
 
char rest = s[len - 1];
 
s[len - 1] = 0;
 
if (len == 1)
{
lcd_putc (x-1, y, '0', mode);
}
else if (len == 2 && s[0] == '-')
{
lcd_putc (x-1, y, '-', mode);
lcd_putc (x, y, '0', mode);
}
else
{
lcd_print_at(x, y, (uint8_t*)s, mode);
}
x += len - 1;
lcd_putc (x++, y, '.', mode);
lcd_putc (x++, y, rest, mode);
}
 
 
//-----------------------------------------------------------
// write <seconds> as human readable time at <x>/<y> to MAX7456 display mem
//
void write_time (uint8_t x, uint8_t y, uint16_t seconds)
{
uint16_t min = seconds / 60;
seconds -= min * 60;
write_ndigit_number_u (x, y, min, 2, 0,0);
lcd_putc (x + 2, y, ':', 0);
write_ndigit_number_u (x + 3, y, seconds, 2, 1,0);
}
 
 
//-----------------------------------------------------------
// wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude
//
void write_gps_pos (uint8_t x, uint8_t y, int32_t position)
{
if (position < 0)
{
position ^= ~0;
position++;
lcd_putc (x++, y, '-', 0);
}
else
{
lcd_putc (x++, y, ' ', 0);
}
write_ndigit_number_u (x, y, (uint16_t) (position / (int32_t) 10000000), 3, 1,0);
lcd_putc (x + 3, y, '.', 0);
position = position - ((position / (int32_t) 10000000) * (int32_t) 10000000);
write_ndigit_number_u (x + 4, y, (uint16_t) (position / (int32_t) 1000), 4, 1,0);
position = position - ((uint16_t) (position / (int32_t) 1000) * (int32_t) 1000);
write_ndigit_number_u (x + 8, y, (uint16_t) position, 3, 1,0);
lcd_putc (x + 11, y, 0x1e, 0); // degree symbol
}
 
 
//------------------------------------------------------------------------------------
// Show PKT Baudrate at given position
//
 
void show_baudrate (uint8_t x, uint8_t y, uint8_t Baudrate, uint8_t mode)
 
{
switch (Baudrate)
{
case Baud_2400: lcd_printp_at (x, y, PSTR("2400"), mode);break;
case Baud_4800: lcd_printp_at (x, y, PSTR("4800"), mode);break;
case Baud_9600: lcd_printp_at (x, y, PSTR("9600"), mode);break;
case Baud_19200: lcd_printp_at (x, y, PSTR("19200"), mode);break;
case Baud_38400: lcd_printp_at (x, y, PSTR("38400"), mode);break;
case Baud_57600: lcd_printp_at (x, y, PSTR("57600"), mode);break;
case Baud_115200: lcd_printp_at (x, y, PSTR("115200"), mode);break;
break;
}
 
 
}
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/lcd/lcd/lcd.h
0,0 → 1,282
/*****************************************************************************
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* - original LCD control by Thomas "thkais" Kaiser *
* - special number formating routines taken from C-OSD *
* from Claas Anders "CaScAdE" Rathje *
* - some extension, ellipse and circ_line by Peter "woggle" Mack *
* Thanks to Oliver Schwaneberg for adding several functions to this library!*
* *
* Author: Jan Michel (jan at mueschelsoft dot de) *
* License: GNU General Public License, version 3 *
* Version: v0.93 September 2010 *
* *
* 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. *
* *
*****************************************************************************/
 
#ifndef _LCD_H
#define _LCD_H
 
/*
 
//-----------------------------------------------------------------------------
// Command Codes
//-----------------------------------------------------------------------------
//1: Display on/off
#define LCD_DISPLAY_ON 0xAF //switch display on
#define LCD_DISPLAY_OFF 0xAE //switch display off
 
//2: display start line set (lower 6 bits select first line on lcd from 64 lines in memory)
#define LCD_START_LINE 0x40
 
//3: Page address set (lower 4 bits select one of 8 pages)
#define LCD_PAGE_ADDRESS 0xB0
 
//4: column address (lower 4 bits are upper / lower nibble of column address)
#define LCD_COL_ADDRESS_MSB 0x10
#define LCD_COL_ADDRESS_LSB 0x00 //second part of column address
 
//8: select orientation (black side of the display should be further away from viewer)
#define LCD_BOTTOMVIEW 0xA1 //6 o'clock view
#define LCD_TOPVIEW 0xA0 //12 o'clock view
 
//9: select normal (white background, black pixels) or reverse (black background, white pixels) mode
#define LCD_DISPLAY_POSITIVE 0xA6 //not inverted mode
#define LCD_DISPLAY_INVERTED 0xA7 //inverted display
 
//10: show memory content or switch all pixels on
#define LCD_SHOW_NORMAL 0xA4 //show dram content
#define LCD_SHOW_ALL_POINTS 0xA5 //show all points
 
//11: lcd bias set
#define LCD_BIAS_1_9 0xA2
#define LCD_BIAS_1_7 0xA3
 
//14: Reset Controller
#define LCD_RESET_CMD 0xE2
 
//15: output mode select (turns display upside-down)
#define LCD_SCAN_DIR_NORMAL 0xC0 //normal scan direction
#define LCD_SCAN_DIR_REVERSE 0xC8 //reversed scan direction
 
//16: power control set (lower 3 bits select operating mode)
//Bit 0: Voltage follower on/off - Bit 1: Voltage regulator on/off - Bit 2: Booster circuit on/off
#define LCD_POWER_CONTROL 0x28 //base command
#define LCD_POWER_LOW_POWER 0x2F
#define LCD_POWER_WIDE_RANGE 0x2F
#define LCD_POWER_LOW_VOLTAGE 0x2B
 
//17: voltage regulator resistor ratio set (lower 3 bits select ratio)
//selects lcd voltage - 000 is low (~ -2V), 111 is high (~ - 10V), also depending on volume mode. Datasheet suggests 011
#define LCD_VOLTAGE 0x20
 
//18: Volume mode set (2-byte command, lower 6 bits in second word select value, datasheet suggests 0x1F)
#define LCD_VOLUME_MODE_1 0x81
#define LCD_VOLUME_MODE_2 0x00
 
//#if DISPLAY_TYPE == 128 || DISPLAY_TYPE == 132
//19: static indicator (2-byte command), first on/off, then blinking mode
#define LCD_INDICATOR_ON 0xAD //static indicator on
#define LCD_INDICATOR_OFF 0xAC //static indicator off
#define LCD_INDICATOR_MODE_OFF 0x00
#define LCD_INDICATOR_MODE_1HZ 0x01
#define LCD_INDICATOR_MODE_2HZ 0x10
#define LCD_INDICATOR_MODE_ON 0x11
 
//20: booster ratio set (2-byte command)
#define LCD_BOOSTER_SET 0xF8 //set booster ratio
#define LCD_BOOSTER_234 0x00 //2x-4x
#define LCD_BOOSTER_5 0x01 //5x
#define LCD_BOOSTER_6 0x03 //6x
//#endif
 
//22: NOP command
#define LCD_NOP 0xE3
 
//#if DISPLAY_TYPE == 102
////25: advanced program control
//#define LCD_ADV_PROG_CTRL 0xFA
//#define LCD_ADV_PROG_CTRL2 0x10
//#endif
 
//-----------------------------------------------------------------------------
// Makros to execute commands
//-----------------------------------------------------------------------------
 
#define LCD_SWITCH_ON() lcd_command(LCD_DISPLAY_ON)
#define LCD_SWITCH_OFF() lcd_command(LCD_DISPLAY_OFF)
#define LCD_SET_FIRST_LINE(i) lcd_command(LCD_START_LINE | ((i) & 0x3F))
#define LCD_SET_PAGE_ADDR(i) lcd_command(LCD_PAGE_ADDRESS | ((i) & 0x0F))
#define LCD_SET_COLUMN_ADDR(i) lcd_command(LCD_COL_ADDRESS_MSB | ((i>>4) & 0x0F)); \
lcd_command(LCD_COL_ADDRESS_LSB | ((i) & 0x0F))
#define LCD_GOTO_ADDRESS(page,col); lcd_command(LCD_PAGE_ADDRESS | ((page) & 0x0F)); \
lcd_command(LCD_COL_ADDRESS_MSB | ((col>>4) & 0x0F)); \
lcd_command(LCD_COL_ADDRESS_LSB | ((col) & 0x0F));
 
#define LCD_SET_BOTTOM_VIEW() lcd_command(LCD_BOTTOMVIEW)
#define LCD_SET_TOP_VIEW() lcd_command(LCD_TOPVIEW)
#define LCD_SET_MODE_POSITIVE() lcd_command(LCD_DISPLAY_POSITIVE)
#define LCD_SET_MODE_INVERTED() lcd_command(LCD_DISPLAY_INVERTED)
#define LCD_SHOW_ALL_PIXELS_ON() lcd_command(LCD_SHOW_ALL_POINTS)
#define LCD_SHOW_ALL_PIXELS_OFF() lcd_command(LCD_SHOW_NORMAL)
#define LCD_SET_BIAS_RATIO_1_7() lcd_command(LCD_BIAS_1_7)
#define LCD_SET_BIAS_RATIO_1_9() lcd_command(LCD_BIAS_1_9)
#define LCD_SEND_RESET() lcd_command(LCD_RESET_CMD)
#define LCD_ORIENTATION_NORMAL() lcd_command(LCD_SCAN_DIR_NORMAL)
#define LCD_ORIENTATION_UPSIDEDOWN() lcd_command(LCD_SCAN_DIR_REVERSE)
#define LCD_SET_POWER_CONTROL(i) lcd_command(LCD_POWER_CONTROL | ((i) & 0x07))
#define LCD_SET_LOW_POWER() lcd_command(LCD_POWER_LOW_POWER)
#define LCD_SET_WIDE_RANGE() lcd_command(LCD_POWER_WIDE_RANGE)
#define LCD_SET_LOW_VOLTAGE() lcd_command(LCD_POWER_LOW_VOLTAGE)
#define LCD_SET_BIAS_VOLTAGE(i) lcd_command(LCD_VOLTAGE | ((i) & 0x07))
#define LCD_SET_VOLUME_MODE(i) lcd_command(LCD_VOLUME_MODE_1); \
lcd_command(LCD_VOLUME_MODE_2 | ((i) & 0x3F))
 
//#if DISPLAY_TYPE == 128 || DISPLAY_TYPE == 132
#define LCD_SET_INDICATOR_OFF() lcd_command(LCD_INDICATOR_OFF); \
lcd_command(LCD_INDICATOR_MODE_OFF)
#define LCD_SET_INDICATOR_STATIC() lcd_command(LCD_INDICATOR_ON); \
lcd_command(LCD_INDICATOR_MODE_ON)
#define LCD_SET_INDICATOR_1HZ() lcd_command(LCD_INDICATOR_ON); \
lcd_command(LCD_INDICATOR_MODE_1HZ)
#define LCD_SET_INDICATOR_2HZ() lcd_command(LCD_INDICATOR_ON); \
lcd_command(LCD_INDICATOR_MODE_2HZ)
#define LCD_SET_INDICATOR(i,j) lcd_command(LCD_INDICATOR_OFF | ((i) & 1)); \
lcd_command(((j) & 2))
#define LCD_SLEEP_MODE lcd_command(LCD_INDICATOR_OFF); \
lcd_command(LCD_DISPLAY_OFF); \
lcd_command(LCD_SHOW_ALL_POINTS)
//#endif
 
//#if DISPLAY_TYPE == 102
//#define LCD_TEMPCOMP_HIGH 0x80
//#define LCD_COLWRAP 0x02
//#define LCD_PAGEWRAP 0x01
//#define LCD_SET_ADV_PROG_CTRL(i) lcd_command(LCD_ADV_PROG_CTRL);
// lcd_command(LCD_ADV_PROG_CTRL2 & i)
//#endif
 
*/
 
 
 
extern volatile uint8_t LCD_ORIENTATION;
 
//#define LCD_LINES 8
//#define LCD_COLS 21
 
extern uint8_t lcd_xpos;
extern uint8_t lcd_ypos;
 
void lcd_command(uint8_t cmd);
void send_byte (uint8_t data);
void LCD_Init (uint8_t LCD_Mode);
void new_line (void);
void lcd_puts_at(uint8_t x, uint8_t y,const char *s, uint8_t mode );
void lcd_putc (uint8_t x, uint8_t y, uint8_t c, uint8_t mode);
void send_byte (uint8_t data);
void lcd_print (uint8_t *text, uint8_t mode);
void lcd_print_at (uint8_t x, uint8_t y, uint8_t *text, uint8_t mode);
void lcd_printp (const char *text, uint8_t mode);
void lcd_printp_at (uint8_t x, uint8_t y, const char *text, uint8_t mode);
void lcd_printpns (const char *text, uint8_t mode);
void lcd_printpns_at (uint8_t x, uint8_t y, const char *text, uint8_t mode);
void lcd_cls (void);
void lcd_cls_line (uint8_t x, uint8_t y, uint8_t w);
 
void print_display (uint8_t *text);
void print_display_at (uint8_t x, uint8_t y, uint8_t *text);
void copy_line (uint8_t y);
void paste_line (uint8_t y);
 
// Jeti
void lcd_putc_jeti (uint8_t x, uint8_t y, uint8_t c, uint8_t mode);
void lcd_printpj (const char *text, uint8_t mode);
void lcd_printpj_at (uint8_t x, uint8_t y, const char *text, uint8_t mode);
 
void lcd_plot (uint8_t x, uint8_t y, uint8_t mode);
void lcd_line (unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, uint8_t mode);
void lcd_rect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode);
void lcd_frect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode);
void lcd_circle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode);
void lcd_fcircle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode);
void lcd_circ_line (uint8_t x, uint8_t y, uint8_t r, uint16_t deg, uint8_t mode);
 
void lcd_ellipse (int16_t x0, int16_t y0, int16_t rx, int16_t ry, uint8_t mode);
void lcd_ellipse_line (uint8_t x, uint8_t y, uint8_t rx, uint8_t ry, uint16_t deg, uint8_t mode);
 
void lcd_ecircle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode);
void lcd_ecirc_line (uint8_t x, uint8_t y, uint8_t r, uint16_t deg, uint8_t mode);
 
void lcd_view_font (uint8_t page);
void lcd_print_hex_at (uint8_t x, uint8_t y, uint8_t h, uint8_t mode);
 
void lcd_write_number_u (uint8_t number);
void lcd_write_number_u_at (uint8_t x, uint8_t y, uint8_t number);
void lcd_print_hex (uint8_t h, uint8_t mode);
/**
* Write only some digits of a unsigned <number> at <x>/<y>
* <length> represents the length to rightbound the number
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
*/
void write_ndigit_number_u (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad,uint8_t mode);
 
/**
* Write only some digits of a signed <number> at <x>/<y>
* <length> represents the length to rightbound the number
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
*/
 
void write_ndigit_number_s (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode);
 
/**
* Write only some digits of a unsigned <number> at <x>/<y> as /10th of the value
* <length> represents the length to rightbound the number
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 00.7 instead of .7
*/
void write_ndigit_number_u_10th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, uint8_t mode);
 
/**
* Write only some digits of a unsigned <number> at <x>/<y> as /100th of the value
* <length> represents the length to rightbound the number
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 00.7 instead of .7
*/
void write_ndigit_number_u_100th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad);
 
/**
* Write only some digits of a signed <number> at <x>/<y> as /10th of the value
* <length> represents the length to rightbound the number
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 00.7 instead of .7
*/
void write_ndigit_number_s_10th (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode);
 
/**
* write <seconds> as human readable time at <x>/<y>
*/
void write_time (uint8_t x, uint8_t y, uint16_t seconds);
 
/**
* wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude
*/
void write_gps_pos (uint8_t x, uint8_t y, int32_t position);
 
//------------------------------------------------------------------------------------
// Show PKT Baudrate at given position
//
 
void show_baudrate (uint8_t x, uint8_t y, uint8_t Baudrate, uint8_t mode);
 
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/lcd/lcd.c
0,0 → 1,1453
/*****************************************************************************
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* - original LCD control by Thomas "thkais" Kaiser *
* - special number formating routines taken from C-OSD *
* from Claas Anders "CaScAdE" Rathje *
* - some extension, ellipse and circ_line by Peter "woggle" Mack *
* *
* 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. *
* *
*****************************************************************************/
 
//############################################################################
//# HISTORY lcd.c
//#
//# 07.03.2013 OG
//# - del: Kompatibilitaetsfunktion lcd_printpj_at() entfernt
//#
//# 06.03.2013 OG
//# - lcdx_putc() wurde erweitert mit Unterstuetzung des 8x8 Font (alte Jeti
//# Funktionen) und Pixel-Verschiebung (xoffs,yoffs)
//# - etliche Char basierte Funktionen wurden erweitert um Parameter xoffs,yoffs
//# um die Ausgabe um +/- Pixel zu verschieben. Fuer Pixelgenaue Positionierung
//# von OSD-Screen Elementen.
//# Die neuen Funktionen mit Pixel-Verschiebung beginnen mit lcdx_, writex_ ...
//# - add: Kompatibilitaet gewaehrleistet durch Mapper-Funktionen
//# - add: defines fuer Char-Drawmode's (MNORMAL, MINVERS, MBIG, MBIGINVERS)
//# - del: Jeti-Funktionen (teilweise ersetzt durch Kompatibilitaetsfunktionen)
//############################################################################
 
 
#include "../cpu.h"
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
#include "font8x6.h"
#include "Font8x8.h"
#include "../eeprom/eeprom.h"
#include "lcd.h"
#include "../main.h"
#include "../HAL_HW3_9.h"
 
 
#define DISP_W 128
#define DISP_H 64
 
#define DISP_BUFFER ((DISP_H * DISP_W) / 8)
#define LINE_BUFFER (((DISP_H/8) * DISP_W) / 8)
 
#define Jeti 1 // Jeti Routinen
 
volatile uint8_t display_buffer[DISP_BUFFER]; // Display-Puffer, weil nicht zurückgelesen werden kann
volatile uint8_t line_buffer[LINE_BUFFER]; // Zeilen-Puffer, weil nicht zurückgelesen werden kann
 
volatile uint16_t display_buffer_pointer; // Pointer auf das aktuell übertragene Byte
volatile uint8_t display_buffer_counter; // Hilfszähler zur Selektierung der Page
volatile uint8_t display_page_counter; // aktuelle Page-Nummer
volatile uint8_t display_mode; // Modus für State-Machine
volatile uint8_t LCD_ORIENTATION;
 
// DOG: 128 x 64 with 6x8 Font => 21 x 8
// MAX7456: 30 x 16
 
uint8_t lcd_xpos;
uint8_t lcd_ypos;
 
char s[7];
 
//-----------------------------------------------------------
void send_byte (uint8_t data)
{
clr_cs ();
SPDR = data;
while (!(SPSR & (1<<SPIF)));
//SPSR = SPSR;
set_cs ();
}
 
 
//-----------------------------------------------------------
// * Writes one command byte
// * cmd - the command byte
//
void lcd_command(uint8_t cmd)
{
// LCD_SELECT();
// LCD_CMD();
// spi_write(cmd);
// LCD_UNSELECT();
clr_cs ();
SPDR = cmd;
while (!(SPSR & (1<<SPIF)));
//SPSR = SPSR;
set_cs ();
}
 
 
//-----------------------------------------------------------
void lcd_cls (void)
{
uint16_t i, j;
 
// memset (display_buffer, 0, 1024);
for (i = 0; i < DISP_BUFFER; i++)
display_buffer[i] = 0x00;
for (i = 0; i < 8; i++)
{
clr_A0 ();
send_byte (0xB0 + i); //1011xxxx
send_byte (0x10); //00010000
// send_byte(0x04); //00000100 gedreht plus 4 Byte
// send_byte(0x00); //00000000
send_byte (LCD_ORIENTATION); //00000000
 
set_A0 ();
for (j = 0; j < 128; j++)
send_byte (0x00);
}
 
lcd_xpos = 0;
lcd_ypos = 0;
}
 
 
//-----------------------------------------------------------
void set_adress (uint16_t adress, uint8_t data)
{
uint8_t page;
uint8_t column;
 
page = adress >> 7;
 
clr_A0 ();
send_byte (0xB0 + page);
 
column = (adress & 0x7F) + LCD_ORIENTATION;
 
send_byte (0x10 + (column >> 4));
send_byte (column & 0x0F);
 
set_A0 ();
send_byte (data);
}
 
 
//-----------------------------------------------------------
void scroll (void)
{
uint16_t adress;
 
for (adress = 0; adress < 896; adress++)
{
display_buffer[adress] = display_buffer[adress + 128];
set_adress (adress, display_buffer[adress]);
}
 
for (adress = 896; adress < 1024; adress++)
{
display_buffer[adress] = 0;
set_adress (adress, 0);
}
}
 
//####################################################################################
//####################################################################################
 
//-----------------------------------------------------------
// + Plot (set one Pixel)
//-----------------------------------------------------------
// mode:
// 0=Clear, 1=Set, 2=XOR
void lcd_plot (uint8_t xpos, uint8_t ypos, uint8_t mode)
{
uint16_t adress;
uint8_t mask;
 
if ((xpos < DISP_W) && (ypos < DISP_H))
{
adress = (ypos / 8) * DISP_W + xpos; // adress = 0/8 * 128 + 0 = 0
mask = 1 << (ypos & 0x07); // mask = 1<<0 = 1
adress &= DISP_BUFFER - 1;
switch (mode)
{
 
case 0:
display_buffer[adress] &= ~mask;
break;
 
case 1:
display_buffer[adress] |= mask;
break;
 
case 2:
display_buffer[adress] ^= mask;
break;
}
set_adress (adress, display_buffer[adress]);
}
}
 
 
 
//-----------------------------------------------------------
//-----------------------------------------------------------
void lcdx_putc( uint8_t x, uint8_t y, uint8_t c, uint8_t mode, int8_t xoffs, int8_t yoffs )
{
uint8_t ch;
uint16_t adress;
 
uint8_t x1,y1;
uint8_t x0,y0;
uint8_t xw;
uint8_t mask;
uint8_t bit;
uint8_t *font;
 
//------------------------
// char translate
//------------------------
switch (c)
{ // ISO 8859-1
 
case 0xc4: c = 0x01; break; // Ä
case 0xe4: c = 0x02; break; // ä
case 0xd6: c = 0x03; break; // Ö
case 0xf6: c = 0x04; break; // ö
case 0xdc: c = 0x05; break; // Ü
case 0xfc: c = 0x06; break; // ü
case 0xdf: c = 0x1e; break; // ß c = 0x07; ° (used by Jeti)
}
 
c &= 0x7f;
 
//------------------------
// Font Parameter setzen
//------------------------
if( mode <=2 ) // normaler font (8x6)
{
font = (uint8_t *) &font8x6[0][0];
xw = 6;
}
else // grosser font (8x8)
{
font = (uint8_t *) &Font8x8[0][0];
xw = 8;
}
//------------------------
//------------------------
x0 = (x*xw) + xoffs;
y0 = (y*8) + yoffs;
 
 
if( yoffs == 0)
{
//----------------------------------------------------------
// orginaler Character Algo
//
// funktioniert auch mit x Verschiebung aber nicht
// mit y Verschiebung.
//
// Da 8 Bit aufeinmal gesetzt werden ist dieser Algo
// bzgl. Geschwindigkeit effektiver als der Y-Algo.
//----------------------------------------------------------
 
if( mode==MINVERS || mode==MBIGINVERS )
lcd_frect( (x*xw)+xoffs, (y*8), xw-1, 7, 1); // invertierte Darstellung
 
adress = y * 128 + x * xw + xoffs;
adress &= 0x3FF;
for( x1 = 0; x1 < xw; x1++)
{
ch = pgm_read_byte (font + x1 + c * xw);
 
if( mode==MINVERS || mode==MBIGINVERS )
display_buffer[adress + x1] ^= ch;
else
display_buffer[adress + x1] = ch;
set_adress (adress + x1, display_buffer[adress + x1]);
}
}
else
{
//----------------------------------------------------------
// Y-Algo
// neuer Character Algo (nur wenn Pixel y-Verschiebung)
//----------------------------------------------------------
for( x1 = 0; x1 < xw; x1++ )
{
ch = pgm_read_byte (font + x1 + c * xw);
 
mask = 1;
for( y1 = 0; y1 < 8; y1++ )
{
bit = (ch & mask);
if( bit )
lcd_plot( x0+x1, y0+y1, ( (mode==MINVERS || mode==MBIGINVERS) ? 0 : 1) );
else
lcd_plot( x0+x1, y0+y1, ( (mode==MINVERS || mode==MBIGINVERS) ? 1 : 0) );
 
mask = (mask << 1);
}
}
}
}
 
 
//-----------------------------------------------------------
//--- Kompatibilitaet
//-----------------------------------------------------------
void lcd_putc( uint8_t x, uint8_t y, uint8_t c, uint8_t mode )
{
lcdx_putc( x, y, c, mode, 0,0 );
}
 
 
//####################################################################################
//####################################################################################
 
 
//-----------------------------------------------------------
void lcd_cls_line (uint8_t x, uint8_t y, uint8_t w)
{
uint8_t lcd_width;
uint8_t lcd_zpos;
uint8_t i;
uint8_t max = 21;
lcd_width = w;
lcd_xpos = x;
lcd_ypos = y;
 
if ((lcd_xpos + lcd_width) > max)
lcd_width = max - lcd_xpos;
 
lcd_zpos = lcd_xpos + lcd_width;
 
for (i = lcd_xpos; i < lcd_zpos; i++)
lcd_putc (i, lcd_ypos, 0x20, 0);
}
 
 
//-----------------------------------------------------------
void wait_1ms (void)
{
_delay_ms (1);
}
 
 
//-----------------------------------------------------------
void wait_ms (uint16_t time)
{
uint16_t i;
 
for (i = 0; i < time; i++)
wait_1ms ();
}
 
 
//-----------------------------------------------------------
void LCD_Init (uint8_t LCD_Mode) // LCD_Mode 0= Default Mode 1= EEPROM-Parameter)
{
lcd_xpos = 0;
lcd_ypos = 0;
 
// DDRB = 0xFF;
 
// SPI max. speed
// the DOGM128 lcd controller can work at 20 MHz
SPCR = (1 << SPE) | (1 << MSTR) | (1 << CPHA) | (1 << CPOL);
SPSR = (1 << SPI2X);
 
set_cs ();
clr_reset ();
wait_ms (10);
set_reset ();
 
clr_cs ();
clr_A0 ();
 
send_byte (0x40); //Display start line = 0
if (LCD_Mode == 1)
{
if (LCD_ORIENTATION == 0)
{
send_byte (0xA1); // A1 normal A0 reverse(original)
send_byte (0xC0); // C0 normal C8 reverse(original)
}
else
{
send_byte (0xA0); // A1 normal A0 reverse(original)
send_byte (0xC8); // C0 normal C8 reverse(original)
}
}
else
{
send_byte (0xA1); // A1 normal A0 reverse(original)
send_byte (0xC0); // C0 normal C8 reverse(original)
}
if (LCD_Mode == 1)
{
if (Config.LCD_DisplayMode == 0)
send_byte (0xA6); //Display normal, not mirrored
else
send_byte (0xA7); //Display reverse, not mirrored
}
else
send_byte (0xA6);
 
 
send_byte (0xA2); //Set bias 1/9 (Duty 1/65)
send_byte (0x2F); //Booster, regulator and follower on
send_byte (0xF8); //Set internal booster to 4x
send_byte (0x00); //Set internal booster to 4x
send_byte (0x27); //resistor ratio set
 
if (LCD_Mode == 1)
{
send_byte (0x81); //Electronic volume register set
send_byte (Config.LCD_Kontrast); //Electronic volume register set
}
else
{
send_byte (0x81);
send_byte (0x16);
}
 
send_byte (0xAC); //Cursor
send_byte (0x00); //No Cursor
send_byte (0xAF); //No indicator
if (Config.HWSound==0)
{
if (LCD_Mode == 1)
{
// Helligkeit setzen
OCR2A = Config.LCD_Helligkeit * 2.55;
}
else
{
OCR2A = 255;
}
}
lcd_cls ();
}
 
 
 
 
//-----------------------------------------------------------
// sicher eine Zeile für die Statusanzeige
void copy_line (uint8_t y)
{
uint8_t i;
uint16_t adress;
 
adress = y * 128 + 0 * 6;
adress &= 0x3FF;
 
for (i = 0; i < 6*21; i++)
{
line_buffer[i] = display_buffer[adress+i];
set_adress (adress + i, display_buffer[adress + i]);
}
}
 
 
//-----------------------------------------------------------
// holt gesicherte Zeile wieder zurück
void paste_line (uint8_t y)
{
uint8_t i;
uint16_t adress;
 
adress = y * 128 + 0 * 6;
adress &= 0x3FF;
 
for (i = 0; i < 6*21; i++)
{
display_buffer[adress+i] =line_buffer[i];
set_adress (adress + i, display_buffer[adress + i]);
}
}
 
 
//-----------------------------------------------------------
//-----------------------------------------------------------
void lcdx_puts_at( uint8_t x, uint8_t y, const char *s, uint8_t mode, int8_t xoffs, int8_t yoffs)
{
while (*s)
{
lcdx_putc(x, y, *s++, mode, xoffs,yoffs);
x++;
}
}/* lcd_puts */
 
 
//-----------------------------------------------------------
//-----------------------------------------------------------
void lcd_puts_at( uint8_t x, uint8_t y, const char *s, uint8_t mode )
{
lcdx_puts_at( x, y, s, mode, 0,0 );
}
 
 
//-----------------------------------------------------------
void new_line (void)
{
lcd_ypos++;
 
if (lcd_ypos > 7)
{
scroll ();
lcd_ypos = 7;
}
}
 
 
//-----------------------------------------------------------
void lcd_printpns (const char *text, uint8_t mode)
{
while (pgm_read_byte(text))
{
switch (pgm_read_byte(text))
{
 
case 0x0D:
lcd_xpos = 0;
break;
 
case 0x0A:
new_line();
break;
 
default:
lcd_putc (lcd_xpos, lcd_ypos, pgm_read_byte(text), mode);
lcd_xpos++;
if (lcd_xpos > 21)
{
lcd_xpos = 0;
// new_line ();
}
break;
}
text++;
}
}
 
 
//-----------------------------------------------------------
void lcd_printpns_at (uint8_t x, uint8_t y, const char *text, uint8_t mode)
{
lcd_xpos = x;
lcd_ypos = y;
lcd_printpns (text, mode);
}
 
 
//-----------------------------------------------------------
//-----------------------------------------------------------
void lcdx_printp (const char *text, uint8_t mode, int8_t xoffs, int8_t yoffs)
{
while( pgm_read_byte(text) )
{
switch (pgm_read_byte(text))
{
 
case 0x0D:
lcd_xpos = 0;
break;
 
case 0x0A:
new_line();
break;
 
default:
lcdx_putc (lcd_xpos, lcd_ypos, pgm_read_byte(text), mode, xoffs,yoffs);
lcd_xpos++;
if (lcd_xpos > 21)
{
lcd_xpos = 0;
new_line ();
}
break;
}
text++;
}
}
 
 
//-----------------------------------------------------------
//-----------------------------------------------------------
void lcd_printp (const char *text, uint8_t mode)
{
lcdx_printp ( text, mode, 0,0);
}
 
 
//-----------------------------------------------------------
//-----------------------------------------------------------
void lcdx_printp_at (uint8_t x, uint8_t y, const char *text, uint8_t mode, int8_t xoffs, int8_t yoffs)
{
lcd_xpos = x;
lcd_ypos = y;
lcdx_printp (text, mode, xoffs,yoffs);
}
 
 
//-----------------------------------------------------------
//-----------------------------------------------------------
void lcd_printp_at (uint8_t x, uint8_t y, const char *text, uint8_t mode)
{
lcdx_printp_at ( x, y, text, mode, 0,0);
}
 
 
//-----------------------------------------------------------
void lcdx_print (uint8_t *text, uint8_t mode, int8_t xoffs, int8_t yoffs)
{
while (*text)
{
switch (*text)
{
 
case 0x0D:
lcd_xpos = 0;
break;
 
case 0x0A:
new_line();
break;
 
default:
lcdx_putc (lcd_xpos, lcd_ypos, *text, mode, xoffs,yoffs);
lcd_xpos++;
if (lcd_xpos > 21)
{
lcd_xpos = 0;
new_line ();
}
break;
}
text++;
}
}
 
 
//-----------------------------------------------------------
//--- lcd_print: Kompatibilitaet
//-----------------------------------------------------------
void lcd_print (uint8_t *text, uint8_t mode )
{
lcdx_print (text, mode, 0,0 );
}
 
 
//-----------------------------------------------------------
void lcdx_print_at (uint8_t x, uint8_t y, uint8_t *text, uint8_t mode, int8_t xoffs, int8_t yoffs)
{
lcd_xpos = x;
lcd_ypos = y;
lcdx_print (text, mode, xoffs, yoffs);
}
 
//-----------------------------------------------------------
//--- lcd_print_at: Kompatibilitaet
//-----------------------------------------------------------
void lcd_print_at (uint8_t x, uint8_t y, uint8_t *text, uint8_t mode )
{
lcdx_print_at ( x, y, text, mode, 0,0);
}
 
 
//-----------------------------------------------------------
void print_display (uint8_t *text)
{
while (*text)
{
lcd_putc (lcd_xpos, lcd_ypos, *text, 0);
lcd_xpos++;
if (lcd_xpos >= 20)
{
lcd_xpos = 0;
new_line ();
}
text++;
}
}
 
 
//-----------------------------------------------------------
void print_display_at (uint8_t x, uint8_t y, uint8_t *text)
{
lcd_xpos = x;
lcd_ypos = y;
print_display (text);
}
 
 
//-----------------------------------------------------------
// + Line (draws a line from x1,y1 to x2,y2
// + Based on Bresenham line-Algorithm
// + found in the internet, modified by thkais 2007
//-----------------------------------------------------------
 
void lcd_line (unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, uint8_t mode)
{
int x, y, count, xs, ys, xm, ym;
 
x = (int) x1;
y = (int) y1;
xs = (int) x2 - (int) x1;
ys = (int) y2 - (int) y1;
if (xs < 0)
xm = -1;
else
if (xs > 0)
xm = 1;
else
xm = 0;
if (ys < 0)
ym = -1;
else
if (ys > 0)
ym = 1;
else
ym = 0;
if (xs < 0)
xs = -xs;
 
if (ys < 0)
ys = -ys;
 
lcd_plot ((unsigned char) x, (unsigned char) y, mode);
 
if (xs > ys) // Flat Line <45 degrees
{
count = -(xs / 2);
while (x != x2)
{
count = count + ys;
x = x + xm;
if (count > 0)
{
y = y + ym;
count = count - xs;
}
lcd_plot ((unsigned char) x, (unsigned char) y, mode);
}
}
else // Line >=45 degrees
{
count =- (ys / 2);
while (y != y2)
{
count = count + xs;
y = y + ym;
if (count > 0)
{
x = x + xm;
count = count - ys;
}
lcd_plot ((unsigned char) x, (unsigned char) y, mode);
}
}
}
 
 
//-----------------------------------------------------------
// + Filled rectangle
// + x1, y1 = upper left corner
//-----------------------------------------------------------
void lcd_frect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode)
{
uint16_t x2, y2;
uint16_t i;
 
if (x1 >= DISP_W)
x1 = DISP_W - 1;
 
if (y1 >= DISP_H)
y1 = DISP_H - 1;
 
x2 = x1 + widthx;
y2 = y1 + widthy;
 
if (x2 > DISP_W)
x2 = DISP_W;
 
if (y2 > DISP_H)
y2 = DISP_H;
 
for (i = y1; i <= y2; i++)
{
lcd_line (x1, i, x2, i, mode);
}
}
 
 
//-----------------------------------------------------------
// + outline of rectangle
// + x1, y1 = upper left corner
//-----------------------------------------------------------
 
void lcd_rect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode)
{
uint16_t x2, y2;
 
if (x1 >= DISP_W)
x1 = DISP_W - 1;
if (y1 >= DISP_H)
y1 = DISP_H - 1;
x2 = x1 + widthx;
y2 = y1 + widthy;
 
if (x2 > DISP_W)
x2 = DISP_W;
 
if (y2 > DISP_H)
y2 = DISP_H;
 
lcd_line (x1, y1, x2, y1, mode);
lcd_line (x2, y1, x2, y2, mode);
lcd_line (x2, y2, x1, y2, mode);
lcd_line (x1, y2, x1, y1, mode);
}
 
 
//-----------------------------------------------------------
// + outline of a circle
// + Based on Bresenham-algorithm found in wikipedia
// + modified by thkais (2007)
//-----------------------------------------------------------
 
void lcd_circle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode)
{
int16_t f = 1 - radius;
int16_t ddF_x = 0;
int16_t ddF_y = -2 * radius;
int16_t x = 0;
int16_t y = radius;
 
lcd_plot (x0, y0 + radius, mode);
lcd_plot (x0, y0 - radius, mode);
lcd_plot (x0 + radius, y0, mode);
lcd_plot (x0 - radius, y0, mode);
 
while (x < y)
{
if (f >= 0)
{
y --;
ddF_y += 2;
f += ddF_y;
}
x ++;
ddF_x += 2;
f += ddF_x + 1;
 
lcd_plot (x0 + x, y0 + y, mode);
lcd_plot (x0 - x, y0 + y, mode);
 
lcd_plot (x0 + x, y0 - y, mode);
lcd_plot (x0 - x, y0 - y, mode);
 
lcd_plot (x0 + y, y0 + x, mode);
lcd_plot (x0 - y, y0 + x, mode);
 
lcd_plot (x0 + y, y0 - x, mode);
lcd_plot (x0 - y, y0 - x, mode);
}
}
 
 
//-----------------------------------------------------------
// + filled Circle
// + modified circle-algorithm thkais (2007)
//-----------------------------------------------------------
 
void lcd_fcircle (int16_t x0, int16_t y0, int16_t radius,uint8_t mode)
{
int16_t f = 1 - radius;
int16_t ddF_x = 0;
int16_t ddF_y = -2 * radius;
int16_t x = 0;
int16_t y = radius;
 
lcd_line (x0, y0 + radius, x0, y0 - radius, mode);
 
lcd_line (x0 + radius, y0, x0 - radius, y0, mode);
 
while (x < y)
{
if (f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x + 1;
 
lcd_line (x0 + x, y0 + y, x0 - x, y0 + y, mode);
lcd_line (x0 + x, y0 - y, x0 - x, y0 - y, mode);
lcd_line (x0 + y, y0 + x, x0 - y, y0 + x, mode);
lcd_line (x0 + y, y0 - x, x0 - y, y0 - x, mode);
}
}
 
 
//-----------------------------------------------------------
//
void lcd_circ_line (uint8_t x, uint8_t y, uint8_t r, uint16_t deg, uint8_t mode)
{
uint8_t xc, yc;
double deg_rad;
 
deg_rad = (deg * M_PI) / 180.0;
 
yc = y - (uint8_t) round (cos (deg_rad) * (double) r);
xc = x + (uint8_t) round (sin (deg_rad) * (double) r);
lcd_line (x, y, xc, yc, mode);
}
 
 
//-----------------------------------------------------------
//
void lcd_ellipse_line (uint8_t x, uint8_t y, uint8_t rx, uint8_t ry, uint16_t deg, uint8_t mode)
{
uint8_t xc, yc;
double deg_rad;
 
deg_rad = (deg * M_PI) / 180.0;
 
yc = y - (uint8_t) round (cos (deg_rad) * (double) ry);
xc = x + (uint8_t) round (sin (deg_rad) * (double) rx);
lcd_line (x, y, xc, yc, mode);
}
 
 
//-----------------------------------------------------------
//
void lcd_ellipse (int16_t x0, int16_t y0, int16_t rx, int16_t ry, uint8_t mode)
{
const int16_t rx2 = rx * rx;
const int16_t ry2 = ry * ry;
int16_t F = round (ry2 - rx2 * ry + 0.25 * rx2);
int16_t ddF_x = 0;
int16_t ddF_y = 2 * rx2 * ry;
int16_t x = 0;
int16_t y = ry;
 
lcd_plot (x0, y0 + ry, mode);
lcd_plot (x0, y0 - ry, mode);
lcd_plot (x0 + rx, y0, mode);
lcd_plot (x0 - rx, y0, mode);
// while ( 2*ry2*x < 2*rx2*y ) { we can use ddF_x and ddF_y
while (ddF_x < ddF_y)
{
if(F >= 0)
{
y -= 1; // south
ddF_y -= 2 * rx2;
F -= ddF_y;
}
x += 1; // east
ddF_x += 2 * ry2;
F += ddF_x + ry2;
lcd_plot (x0 + x, y0 + y, mode);
lcd_plot (x0 + x, y0 - y, mode);
lcd_plot (x0 - x, y0 + y, mode);
lcd_plot (x0 - x, y0 - y, mode);
}
F = round (ry2 * (x + 0.5) * (x + 0.5) + rx2 * (y - 1) * (y - 1) - rx2 * ry2);
while(y > 0)
{
if(F <= 0)
{
x += 1; // east
ddF_x += 2 * ry2;
F += ddF_x;
}
y -= 1; // south
ddF_y -= 2 * rx2;
F += rx2 - ddF_y;
lcd_plot (x0 + x, y0 + y, mode);
lcd_plot (x0 + x, y0 - y, mode);
lcd_plot (x0 - x, y0 + y, mode);
lcd_plot (x0 - x, y0 - y, mode);
}
}
 
 
//-----------------------------------------------------------
//
void lcd_ecircle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode)
{
lcd_ellipse (x0, y0, radius + 3, radius, mode);
}
 
 
//-----------------------------------------------------------
//
void lcd_ecirc_line (uint8_t x, uint8_t y, uint8_t r, uint16_t deg, uint8_t mode)
{
lcd_ellipse_line(x, y, r + 3, r, deg, mode);
}
 
 
//-----------------------------------------------------------
//
void lcd_view_font (uint8_t page)
{
int x;
int y;
 
lcd_cls ();
lcd_printp (PSTR(" 0123456789ABCDEF\r\n"), 0);
lcd_printpns_at (0, 7, PSTR(" \x1a \x1b Exit"), 0);
 
lcd_ypos = 2;
for (y = page * 4 ; y < (page * 4 + 4); y++)
{
if (y < 10)
{
lcd_putc (0, lcd_ypos, '0' + y, 0);
}
else
{
lcd_putc (0, lcd_ypos, 'A' + y - 10, 0);
}
lcd_xpos = 2;
for (x = 0; x < 16; x++)
{
lcd_putc (lcd_xpos, lcd_ypos, y * 16 + x, 0);
lcd_xpos++;
}
lcd_ypos++;
}
}
 
 
//-----------------------------------------------------------
uint8_t hdigit (uint8_t d)
{
if (d < 10)
{
return '0' + d;
}
else
{
return 'A' + d - 10;
}
}
 
 
//-----------------------------------------------------------
void lcd_print_hex_at (uint8_t x, uint8_t y, uint8_t h, uint8_t mode)
{
lcd_xpos = x;
lcd_ypos = y;
 
lcd_putc (lcd_xpos++, lcd_ypos, hdigit (h >> 4), mode);
lcd_putc (lcd_xpos, lcd_ypos, hdigit (h & 0x0f), mode);
}
 
 
//-----------------------------------------------------------
void lcd_print_hex (uint8_t h, uint8_t mode)
{
// lcd_xpos = x;
// lcd_ypos = y;
 
lcd_putc (lcd_xpos++, lcd_ypos, hdigit (h >> 4), mode);
lcd_putc (lcd_xpos++, lcd_ypos, hdigit (h & 0x0f), mode);
lcd_putc (lcd_xpos++, lcd_ypos, ' ', mode);
}
 
 
//-----------------------------------------------------------
void lcd_write_number_u (uint8_t number)
{
uint8_t num = 100;
uint8_t started = 0;
 
while (num > 0)
{
uint8_t b = number / num;
if (b > 0 || started || num == 1)
{
lcd_putc (lcd_xpos++, lcd_ypos, '0' + b, 0);
started = 1;
}
number -= b * num;
 
num /= 10;
}
}
 
 
//-----------------------------------------------------------
void lcd_write_number_u_at (uint8_t x, uint8_t y, uint8_t number)
{
lcd_xpos = x;
lcd_ypos = y;
lcd_write_number_u (number);
}
 
 
//-----------------------------------------------------------
// Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory
// <num> represents the largest multiple of 10 that will still be displayable as
// the first digit, so num = 10 will be 0-99 and so on
// <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
//
void writex_ndigit_number_u (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, uint8_t mode, int8_t xoffs, int8_t yoffs)
{
//char s[7];
 
utoa(number, s, 10 );
 
uint8_t len = strlen(s);
 
 
if (length < len)
{
for (uint8_t i = 0; i < length; i++)
{
lcdx_putc (x++, y, '*', mode, xoffs,yoffs);
}
return;
}
 
for (uint8_t i = 0; i < length - len; i++)
{
if (pad==1)
{
lcdx_putc (x++, y, '0', mode, xoffs,yoffs);
}
else
{
lcdx_putc (x++, y, ' ', mode, xoffs,yoffs);
}
}
lcdx_print_at(x, y, (uint8_t*)s, mode, xoffs,yoffs);
}
 
 
//-----------------------------------------------------------
//-----------------------------------------------------------
void write_ndigit_number_u (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, uint8_t mode)
{
writex_ndigit_number_u( x, y, number, length, pad, mode, 0,0);
}
 
 
//-----------------------------------------------------------
// Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory
// <num> represents the largest multiple of 10 that will still be displayable as
// the first digit, so num = 10 will be 0-99 and so on
// <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
//
void writex_ndigit_number_s (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode, int8_t xoffs, int8_t yoffs)
{
//char s[7];
 
itoa(number, s, 10 );
 
uint8_t len = strlen(s);
 
if (length < len)
{
for (uint8_t i = 0; i < length; i++)
{
lcdx_putc (x++, y, '*', mode, xoffs,yoffs);
}
return;
}
 
for (uint8_t i = 0; i < length - len; i++)
{
if (pad)
{
lcdx_putc (x++, y, '0', mode, xoffs,yoffs);
}
else
{
lcdx_putc (x++, y, ' ', mode, xoffs,yoffs);
}
}
lcdx_print_at(x, y, (uint8_t*)s, mode, xoffs,yoffs);
}
 
 
//-----------------------------------------------------------
//-----------------------------------------------------------
void write_ndigit_number_s (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode)
{
writex_ndigit_number_s (x, y, number, length, pad, mode, 0,0);
}
 
 
//-----------------------------------------------------------
// Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory
// as /10th of the value
// <num> represents the largest multiple of 10 that will still be displayable as
// the first digit, so num = 10 will be 0-99 and so on
// <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
//
void writex_ndigit_number_u_10th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, uint8_t mode, int8_t xoffs, int8_t yoffs)
{
//char s[7];
 
itoa(number, s, 10 );
 
uint8_t len = strlen(s);
 
if (length < len)
{
for (uint8_t i = 0; i < length; i++)
{
lcdx_putc (x++, y, '*', mode, xoffs,yoffs);
}
return;
}
 
for (uint8_t i = 0; i < length - len; i++)
{
if (pad)
{
lcdx_putc (x++, y, '0', mode, xoffs,yoffs);
}
else
{
lcdx_putc (x++, y, ' ', mode, xoffs,yoffs);
}
}
 
char rest = s[len - 1];
 
s[len - 1] = 0;
 
if (len == 1)
{
lcdx_putc (x-1, y, '0', mode, xoffs,yoffs);
}
else if (len == 2 && s[0] == '-')
{
lcdx_putc (x-1, y, '-', mode, xoffs,yoffs);
lcdx_putc (x, y, '0', mode, xoffs,yoffs);
}
else
{
lcdx_print_at(x, y, (uint8_t*)s, mode, xoffs,yoffs);
}
x += len - 1;
lcdx_putc (x++, y, '.', mode, xoffs,yoffs);
lcdx_putc (x++, y, rest, mode, xoffs,yoffs);
}
 
 
//-----------------------------------------------------------
//-----------------------------------------------------------
void write_ndigit_number_u_10th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, uint8_t mode)
{
writex_ndigit_number_u_10th ( x, y, number, length, pad, mode, 0,0);
}
 
 
//-----------------------------------------------------------
//-----------------------------------------------------------
void writex_ndigit_number_u_100th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, int8_t xoffs, int8_t yoffs)
{
uint8_t num = 100;
 
while (num > 0)
{
uint8_t b = number / num;
 
if ((num / 10) == 1)
{
lcdx_putc (x++, y, '.', 0, xoffs,yoffs);
}
lcdx_putc (x++, y, '0' + b, 0, xoffs,yoffs);
number -= b * num;
 
num /= 10;
}
}
 
 
//-----------------------------------------------------------
//-----------------------------------------------------------
void write_ndigit_number_u_100th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad)
{
writex_ndigit_number_u_100th ( x, y, number, length, pad, 0,0);
}
 
 
//-----------------------------------------------------------
// Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory
// as /10th of the value
// <num> represents the largest multiple of 10 that will still be displayable as
// the first digit, so num = 10 will be 0-99 and so on
// <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
//
void writex_ndigit_number_s_10th (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode, int8_t xoffs, int8_t yoffs)
{
//char s[7];
 
itoa (number, s, 10 );
 
uint8_t len = strlen(s);
 
if (length < len)
{
for (uint8_t i = 0; i < length; i++)
{
lcdx_putc (x++, y, '*', mode, xoffs, yoffs);
}
return;
}
 
for (uint8_t i = 0; i < length - len; i++)
{
if (pad)
{
lcdx_putc (x++, y, '0', mode, xoffs, yoffs);
}
else
{
lcdx_putc (x++, y, ' ', mode, xoffs, yoffs);
}
}
 
char rest = s[len - 1];
 
s[len - 1] = 0;
 
if (len == 1)
{
lcdx_putc (x-1, y, '0', mode, xoffs, yoffs);
}
else if (len == 2 && s[0] == '-')
{
lcdx_putc (x-1, y, '-', mode, xoffs,yoffs);
lcdx_putc (x, y, '0', mode, xoffs,yoffs);
}
else
{
lcdx_print_at(x, y, (uint8_t*)s, mode, xoffs, yoffs);
}
x += len - 1;
lcdx_putc (x++, y, '.', mode, xoffs, yoffs);
lcdx_putc (x++, y, rest, mode, xoffs, yoffs);
}
 
 
//-----------------------------------------------------------
//-----------------------------------------------------------
void write_ndigit_number_s_10th (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode)
{
writex_ndigit_number_s_10th ( x, y, number, length, pad, mode, 0,0);
 
}
 
 
//-----------------------------------------------------------
// write <seconds> as human readable time at <x>/<y> to MAX7456 display mem
//
void writex_time (uint8_t x, uint8_t y, uint16_t seconds, uint8_t mode, int8_t xoffs, int8_t yoffs)
{
uint16_t min = seconds / 60;
seconds -= min * 60;
writex_ndigit_number_u (x, y, min, 2, 0,mode, xoffs,yoffs);
lcd_putc (x + 2, y, ':', 0);
writex_ndigit_number_u (x + 3, y, seconds, 2, 1,mode, xoffs,yoffs);
}
 
 
//-----------------------------------------------------------
//-----------------------------------------------------------
void write_time (uint8_t x, uint8_t y, uint16_t seconds)
{
writex_time ( x, y, seconds, 0, 0,0);
}
 
 
//-----------------------------------------------------------
// wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude
//
void write_gps_pos (uint8_t x, uint8_t y, int32_t position)
{
if (position < 0)
{
position ^= ~0;
position++;
lcd_putc (x++, y, '-', 0);
}
else
{
lcd_putc (x++, y, ' ', 0);
}
write_ndigit_number_u (x, y, (uint16_t) (position / (int32_t) 10000000), 3, 1,0);
lcd_putc (x + 3, y, '.', 0);
position = position - ((position / (int32_t) 10000000) * (int32_t) 10000000);
write_ndigit_number_u (x + 4, y, (uint16_t) (position / (int32_t) 1000), 4, 1,0);
position = position - ((uint16_t) (position / (int32_t) 1000) * (int32_t) 1000);
write_ndigit_number_u (x + 8, y, (uint16_t) position, 3, 1,0);
lcd_putc (x + 11, y, 0x1e, 0); // degree symbol
}
 
 
//------------------------------------------------------------------------------------
// Show PKT Baudrate at given position
//
void show_baudrate (uint8_t x, uint8_t y, uint8_t Baudrate, uint8_t mode)
{
switch (Baudrate)
{
case Baud_2400: lcd_printp_at (x, y, PSTR("2400"), mode);break;
case Baud_4800: lcd_printp_at (x, y, PSTR("4800"), mode);break;
case Baud_9600: lcd_printp_at (x, y, PSTR("9600"), mode);break;
case Baud_19200: lcd_printp_at (x, y, PSTR("19200"), mode);break;
case Baud_38400: lcd_printp_at (x, y, PSTR("38400"), mode);break;
case Baud_57600: lcd_printp_at (x, y, PSTR("57600"), mode);break;
case Baud_115200: lcd_printp_at (x, y, PSTR("115200"), mode);break;
break;
}
}
 
 
 
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/lcd/lcd.cold
0,0 → 1,1402
/*****************************************************************************
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* - original LCD control by Thomas "thkais" Kaiser *
* - special number formating routines taken from C-OSD *
* from Claas Anders "CaScAdE" Rathje *
* - some extension, ellipse and circ_line by Peter "woggle" Mack *
* *
* 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. *
* *
*****************************************************************************/
 
#include "../cpu.h"
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
#include "font8x6.h"
#include "Font8x8.h"
#include "../eeprom/eeprom.h"
#include "lcd.h"
#include "../main.h"
#include "../HAL_HW3_9.h"
 
 
#define DISP_W 128
#define DISP_H 64
 
#define DISP_BUFFER ((DISP_H * DISP_W) / 8)
#define LINE_BUFFER (((DISP_H/8) * DISP_W) / 8)
 
#define Jeti 1 // Jeti Routinen
 
volatile uint8_t display_buffer[DISP_BUFFER]; // Display-Puffer, weil nicht zurückgelesen werden kann
volatile uint8_t line_buffer[LINE_BUFFER]; // Zeilen-Puffer, weil nicht zurückgelesen werden kann
 
volatile uint16_t display_buffer_pointer; // Pointer auf das aktuell übertragene Byte
volatile uint8_t display_buffer_counter; // Hilfszähler zur Selektierung der Page
volatile uint8_t display_page_counter; // aktuelle Page-Nummer
volatile uint8_t display_mode; // Modus für State-Machine
volatile uint8_t LCD_ORIENTATION;
 
// DOG: 128 x 64 with 6x8 Font => 21 x 8
// MAX7456: 30 x 16
 
uint8_t lcd_xpos;
uint8_t lcd_ypos;
 
 
//-----------------------------------------------------------
void send_byte (uint8_t data)
{
clr_cs ();
SPDR = data;
while (!(SPSR & (1<<SPIF)));
//SPSR = SPSR;
set_cs ();
}
 
 
//-----------------------------------------------------------
// * Writes one command byte
// * cmd - the command byte
//
void lcd_command(uint8_t cmd)
{
// LCD_SELECT();
// LCD_CMD();
// spi_write(cmd);
// LCD_UNSELECT();
clr_cs ();
SPDR = cmd;
while (!(SPSR & (1<<SPIF)));
//SPSR = SPSR;
set_cs ();
}
 
 
//-----------------------------------------------------------
void lcd_cls (void)
{
uint16_t i, j;
 
// memset (display_buffer, 0, 1024);
for (i = 0; i < DISP_BUFFER; i++)
display_buffer[i] = 0x00;
for (i = 0; i < 8; i++)
{
clr_A0 ();
send_byte (0xB0 + i); //1011xxxx
send_byte (0x10); //00010000
// send_byte(0x04); //00000100 gedreht plus 4 Byte
// send_byte(0x00); //00000000
send_byte (LCD_ORIENTATION); //00000000
 
set_A0 ();
for (j = 0; j < 128; j++)
send_byte (0x00);
}
 
lcd_xpos = 0;
lcd_ypos = 0;
}
 
 
//-----------------------------------------------------------
void lcd_cls_line (uint8_t x, uint8_t y, uint8_t w)
{
uint8_t lcd_width;
uint8_t lcd_zpos;
uint8_t i;
uint8_t max = 21;
lcd_width = w;
lcd_xpos = x;
lcd_ypos = y;
 
if ((lcd_xpos + lcd_width) > max)
lcd_width = max - lcd_xpos;
 
lcd_zpos = lcd_xpos + lcd_width;
 
for (i = lcd_xpos; i < lcd_zpos; i++)
lcd_putc (i, lcd_ypos, 0x20, 0);
}
 
 
//-----------------------------------------------------------
void wait_1ms (void)
{
_delay_ms (1);
}
 
 
//-----------------------------------------------------------
void wait_ms (uint16_t time)
{
uint16_t i;
 
for (i = 0; i < time; i++)
wait_1ms ();
}
 
 
//-----------------------------------------------------------
void LCD_Init (uint8_t LCD_Mode) // LCD_Mode 0= Default Mode 1= EEPROM-Parameter)
{
lcd_xpos = 0;
lcd_ypos = 0;
 
// DDRB = 0xFF;
 
// SPI max. speed
// the DOGM128 lcd controller can work at 20 MHz
SPCR = (1 << SPE) | (1 << MSTR) | (1 << CPHA) | (1 << CPOL);
SPSR = (1 << SPI2X);
 
set_cs ();
clr_reset ();
wait_ms (10);
set_reset ();
 
clr_cs ();
clr_A0 ();
 
send_byte (0x40); //Display start line = 0
if (LCD_Mode == 1)
{
if (LCD_ORIENTATION == 0)
{
send_byte (0xA1); // A1 normal A0 reverse(original)
send_byte (0xC0); // C0 normal C8 reverse(original)
}
else
{
send_byte (0xA0); // A1 normal A0 reverse(original)
send_byte (0xC8); // C0 normal C8 reverse(original)
}
}
else
{
send_byte (0xA1); // A1 normal A0 reverse(original)
send_byte (0xC0); // C0 normal C8 reverse(original)
}
if (LCD_Mode == 1)
{
if (Config.LCD_DisplayMode == 0)
send_byte (0xA6); //Display normal, not mirrored
else
send_byte (0xA7); //Display reverse, not mirrored
}
else
send_byte (0xA6);
 
 
send_byte (0xA2); //Set bias 1/9 (Duty 1/65)
send_byte (0x2F); //Booster, regulator and follower on
send_byte (0xF8); //Set internal booster to 4x
send_byte (0x00); //Set internal booster to 4x
send_byte (0x27); //resistor ratio set
 
if (LCD_Mode == 1)
{
send_byte (0x81); //Electronic volume register set
send_byte (Config.LCD_Kontrast); //Electronic volume register set
}
else
{
send_byte (0x81);
send_byte (0x16);
}
 
send_byte (0xAC); //Cursor
send_byte (0x00); //No Cursor
send_byte (0xAF); //No indicator
if (Config.HWSound==0)
{
if (LCD_Mode == 1)
{
// Helligkeit setzen
OCR2A = Config.LCD_Helligkeit * 2.55;
}
else
{
OCR2A = 255;
}
}
lcd_cls ();
}
 
 
//-----------------------------------------------------------
void set_adress (uint16_t adress, uint8_t data)
{
uint8_t page;
uint8_t column;
 
page = adress >> 7;
 
clr_A0 ();
send_byte (0xB0 + page);
 
column = (adress & 0x7F) + LCD_ORIENTATION;
 
send_byte (0x10 + (column >> 4));
send_byte (column & 0x0F);
 
set_A0 ();
send_byte (data);
}
 
 
//-----------------------------------------------------------
void scroll (void)
{
uint16_t adress;
 
for (adress = 0; adress < 896; adress++)
{
display_buffer[adress] = display_buffer[adress + 128];
set_adress (adress, display_buffer[adress]);
}
 
for (adress = 896; adress < 1024; adress++)
{
display_buffer[adress] = 0;
set_adress (adress, 0);
}
}
 
 
//-----------------------------------------------------------
// sicher eine Zeile für die Statusanzeige
void copy_line (uint8_t y)
{
uint8_t i;
uint16_t adress;
 
adress = y * 128 + 0 * 6;
adress &= 0x3FF;
 
for (i = 0; i < 6*21; i++)
{
line_buffer[i] = display_buffer[adress+i];
set_adress (adress + i, display_buffer[adress + i]);
}
}
 
 
//-----------------------------------------------------------
// holt gesicherte Zeile wieder zurück
void paste_line (uint8_t y)
{
uint8_t i;
uint16_t adress;
 
adress = y * 128 + 0 * 6;
adress &= 0x3FF;
 
for (i = 0; i < 6*21; i++)
{
display_buffer[adress+i] =line_buffer[i];
set_adress (adress + i, display_buffer[adress + i]);
}
}
 
 
//-----------------------------------------------------------
void lcd_puts_at(uint8_t x, uint8_t y,const char *s, uint8_t mode )
{
while (*s)
{
lcd_putc(x, y, *s++, mode);
x++;
}
 
}/* lcd_puts */
 
 
//-----------------------------------------------------------
void lcd_putc (uint8_t x, uint8_t y, uint8_t c, uint8_t mode)
{
uint8_t ch;
uint8_t i;
uint16_t adress;
 
if (mode == 2)
lcd_frect ((x*6),(y*8),5,7,1); // invertierte Darstellung
 
if (mode == 3) lcd_putc_jeti (x, y, c,0);
else
if (mode == 4) lcd_putc_jeti (x, y, c,2);
else
{
 
switch (c)
{ // ISO 8859-1
 
case 0xc4: // Ä
c = 0x01;
break;
 
case 0xe4: // ä
c = 0x02;
break;
 
case 0xd6: // Ö
c = 0x03;
break;
 
case 0xf6: // ö
c = 0x04;
break;
 
case 0xdc: // Ü
c = 0x05;
break;
 
case 0xfc: // ü
c = 0x06;
break;
 
case 0xdf: // ß
//c = 0x07;
c = 0x1e; // ° (used by Jeti)
break;
}
 
c &= 0x7f;
 
adress = y * 128 + x * 6;
adress &= 0x3FF;
 
for (i = 0; i < 6; i++)
{
ch = pgm_read_byte (&font8x6[0][0] + i + c * 6);
 
switch (mode)
{
 
case 0:
display_buffer[adress+i] = ch;
break;
 
case 1:
display_buffer[adress+i] |= ch;
break;
 
case 2:
display_buffer[adress+i] ^= ch;
break;
 
case 3:
display_buffer[adress+i] &= ch;
break;
 
case 4:
display_buffer[adress+i] &= ~ch;
break;
}
 
set_adress (adress + i, display_buffer[adress + i]);
}
}
}
 
 
#if Jeti
//-----------------------------------------------------------
void lcd_putc_jeti (uint8_t x, uint8_t y, uint8_t c, uint8_t mode)
{
uint8_t ch;
uint8_t i;
uint16_t adress;
if (mode == 2)
lcd_frect ((x*8),(y*8),8,8,1); // invertierte Darstellung
switch (c)
{
 
case 0x7e:
c = 0x1a; // ->
break;
 
case 0x7f:
c = 0x1b; // <-
break;
 
case 0xdf:
c = 0xf8; // °
break;
}
 
adress = y * 128 + x * 8;
adress &= 0x3FF;
 
for (i = 0; i < 8; i++)
{
ch = pgm_read_byte (&Font8x8[0][0] + i + c * 8);
 
switch (mode)
{
 
case 0:
display_buffer[adress+i] = ch;
break;
 
case 1:
display_buffer[adress+i] |= ch;
break;
 
case 2:
display_buffer[adress+i] ^= ch;
break;
 
case 3:
display_buffer[adress+i] &= ch;
break;
 
case 4:
display_buffer[adress+i] &= ~ch;
break;
}
 
set_adress (adress + i, display_buffer[adress + i]);
}
}
 
 
//-----------------------------------------------------------
void lcd_printpj (const char *text, uint8_t mode)
{
while (pgm_read_byte(text))
{
switch (pgm_read_byte(text))
{
 
case 0x0D:
lcd_xpos = 0;
break;
 
case 0x0A:
new_line();
break;
 
default:
lcd_putc_jeti (lcd_xpos, lcd_ypos, pgm_read_byte(text), mode);
lcd_xpos++;
if (lcd_xpos > 20)
{
lcd_xpos = 0;
new_line ();
}
break;
}
text++;
}
}
 
 
//-----------------------------------------------------------
void lcd_printpj_at (uint8_t x, uint8_t y, const char *text, uint8_t mode)
{
lcd_xpos = x;
lcd_ypos = y;
lcd_printpj (text, mode);
}
#endif
 
 
//-----------------------------------------------------------
void new_line (void)
{
lcd_ypos++;
 
if (lcd_ypos > 7)
{
scroll ();
lcd_ypos = 7;
}
}
 
 
//-----------------------------------------------------------
void lcd_printpns (const char *text, uint8_t mode)
{
while (pgm_read_byte(text))
{
switch (pgm_read_byte(text))
{
 
case 0x0D:
lcd_xpos = 0;
break;
 
case 0x0A:
new_line();
break;
 
default:
lcd_putc (lcd_xpos, lcd_ypos, pgm_read_byte(text), mode);
lcd_xpos++;
if (lcd_xpos > 21)
{
lcd_xpos = 0;
// new_line ();
}
break;
}
text++;
}
}
 
 
//-----------------------------------------------------------
void lcd_printpns_at (uint8_t x, uint8_t y, const char *text, uint8_t mode)
{
lcd_xpos = x;
lcd_ypos = y;
lcd_printpns (text, mode);
}
 
 
//-----------------------------------------------------------
void lcd_printp (const char *text, uint8_t mode)
{
while (pgm_read_byte(text))
{
switch (pgm_read_byte(text))
{
 
case 0x0D:
lcd_xpos = 0;
break;
 
case 0x0A:
new_line();
break;
 
default:
lcd_putc (lcd_xpos, lcd_ypos, pgm_read_byte(text), mode);
lcd_xpos++;
if (lcd_xpos > 21)
{
lcd_xpos = 0;
new_line ();
}
break;
}
text++;
}
}
 
 
//-----------------------------------------------------------
void lcd_printp_at (uint8_t x, uint8_t y, const char *text, uint8_t mode)
{
lcd_xpos = x;
lcd_ypos = y;
lcd_printp (text, mode);
}
 
 
//-----------------------------------------------------------
void lcd_print (uint8_t *text, uint8_t mode)
{
while (*text)
{
switch (*text)
{
 
case 0x0D:
lcd_xpos = 0;
break;
 
case 0x0A:
new_line();
break;
 
default:
lcd_putc (lcd_xpos, lcd_ypos, *text, mode);
lcd_xpos++;
if (lcd_xpos > 21)
{
lcd_xpos = 0;
new_line ();
}
break;
}
text++;
}
}
 
 
//-----------------------------------------------------------
void lcd_print_at (uint8_t x, uint8_t y, uint8_t *text, uint8_t mode)
{
lcd_xpos = x;
lcd_ypos = y;
lcd_print (text, mode);
}
 
 
//-----------------------------------------------------------
void print_display (uint8_t *text)
{
while (*text)
{
lcd_putc (lcd_xpos, lcd_ypos, *text, 0);
lcd_xpos++;
if (lcd_xpos >= 20)
{
lcd_xpos = 0;
new_line ();
}
text++;
}
}
 
 
//-----------------------------------------------------------
void print_display_at (uint8_t x, uint8_t y, uint8_t *text)
{
lcd_xpos = x;
lcd_ypos = y;
print_display (text);
}
 
 
//-----------------------------------------------------------
// + Plot (set one Pixel)
//-----------------------------------------------------------
// mode:
// 0=Clear, 1=Set, 2=XOR
void lcd_plot (uint8_t xpos, uint8_t ypos, uint8_t mode)
{
uint16_t adress;
uint8_t mask;
 
if ((xpos < DISP_W) && (ypos < DISP_H))
{
adress = (ypos / 8) * DISP_W + xpos; // adress = 0/8 * 128 + 0 = 0
mask = 1 << (ypos & 0x07); // mask = 1<<0 = 1
adress &= DISP_BUFFER - 1;
switch (mode)
{
 
case 0:
display_buffer[adress] &= ~mask;
break;
 
case 1:
display_buffer[adress] |= mask;
break;
 
case 2:
display_buffer[adress] ^= mask;
break;
}
set_adress (adress, display_buffer[adress]);
}
}
 
 
//-----------------------------------------------------------
// + Line (draws a line from x1,y1 to x2,y2
// + Based on Bresenham line-Algorithm
// + found in the internet, modified by thkais 2007
//-----------------------------------------------------------
 
void lcd_line (unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, uint8_t mode)
{
int x, y, count, xs, ys, xm, ym;
 
x = (int) x1;
y = (int) y1;
xs = (int) x2 - (int) x1;
ys = (int) y2 - (int) y1;
if (xs < 0)
xm = -1;
else
if (xs > 0)
xm = 1;
else
xm = 0;
if (ys < 0)
ym = -1;
else
if (ys > 0)
ym = 1;
else
ym = 0;
if (xs < 0)
xs = -xs;
 
if (ys < 0)
ys = -ys;
 
lcd_plot ((unsigned char) x, (unsigned char) y, mode);
 
if (xs > ys) // Flat Line <45 degrees
{
count = -(xs / 2);
while (x != x2)
{
count = count + ys;
x = x + xm;
if (count > 0)
{
y = y + ym;
count = count - xs;
}
lcd_plot ((unsigned char) x, (unsigned char) y, mode);
}
}
else // Line >=45 degrees
{
count =- (ys / 2);
while (y != y2)
{
count = count + xs;
y = y + ym;
if (count > 0)
{
x = x + xm;
count = count - ys;
}
lcd_plot ((unsigned char) x, (unsigned char) y, mode);
}
}
}
 
 
//-----------------------------------------------------------
// + Filled rectangle
// + x1, y1 = upper left corner
//-----------------------------------------------------------
 
void lcd_frect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode)
{
uint16_t x2, y2;
uint16_t i;
 
if (x1 >= DISP_W)
x1 = DISP_W - 1;
 
if (y1 >= DISP_H)
y1 = DISP_H - 1;
 
x2 = x1 + widthx;
y2 = y1 + widthy;
 
if (x2 > DISP_W)
x2 = DISP_W;
 
if (y2 > DISP_H)
y2 = DISP_H;
 
for (i = y1; i <= y2; i++)
{
lcd_line (x1, i, x2, i, mode);
}
}
 
 
//-----------------------------------------------------------
// + outline of rectangle
// + x1, y1 = upper left corner
//-----------------------------------------------------------
 
void lcd_rect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode)
{
uint16_t x2, y2;
 
if (x1 >= DISP_W)
x1 = DISP_W - 1;
if (y1 >= DISP_H)
y1 = DISP_H - 1;
x2 = x1 + widthx;
y2 = y1 + widthy;
 
if (x2 > DISP_W)
x2 = DISP_W;
 
if (y2 > DISP_H)
y2 = DISP_H;
 
lcd_line (x1, y1, x2, y1, mode);
lcd_line (x2, y1, x2, y2, mode);
lcd_line (x2, y2, x1, y2, mode);
lcd_line (x1, y2, x1, y1, mode);
}
 
 
//-----------------------------------------------------------
// + outline of a circle
// + Based on Bresenham-algorithm found in wikipedia
// + modified by thkais (2007)
//-----------------------------------------------------------
 
void lcd_circle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode)
{
int16_t f = 1 - radius;
int16_t ddF_x = 0;
int16_t ddF_y = -2 * radius;
int16_t x = 0;
int16_t y = radius;
 
lcd_plot (x0, y0 + radius, mode);
lcd_plot (x0, y0 - radius, mode);
lcd_plot (x0 + radius, y0, mode);
lcd_plot (x0 - radius, y0, mode);
 
while (x < y)
{
if (f >= 0)
{
y --;
ddF_y += 2;
f += ddF_y;
}
x ++;
ddF_x += 2;
f += ddF_x + 1;
 
lcd_plot (x0 + x, y0 + y, mode);
lcd_plot (x0 - x, y0 + y, mode);
 
lcd_plot (x0 + x, y0 - y, mode);
lcd_plot (x0 - x, y0 - y, mode);
 
lcd_plot (x0 + y, y0 + x, mode);
lcd_plot (x0 - y, y0 + x, mode);
 
lcd_plot (x0 + y, y0 - x, mode);
lcd_plot (x0 - y, y0 - x, mode);
}
}
 
 
//-----------------------------------------------------------
// + filled Circle
// + modified circle-algorithm thkais (2007)
//-----------------------------------------------------------
 
void lcd_fcircle (int16_t x0, int16_t y0, int16_t radius,uint8_t mode)
{
int16_t f = 1 - radius;
int16_t ddF_x = 0;
int16_t ddF_y = -2 * radius;
int16_t x = 0;
int16_t y = radius;
 
lcd_line (x0, y0 + radius, x0, y0 - radius, mode);
 
lcd_line (x0 + radius, y0, x0 - radius, y0, mode);
 
while (x < y)
{
if (f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x + 1;
 
lcd_line (x0 + x, y0 + y, x0 - x, y0 + y, mode);
lcd_line (x0 + x, y0 - y, x0 - x, y0 - y, mode);
lcd_line (x0 + y, y0 + x, x0 - y, y0 + x, mode);
lcd_line (x0 + y, y0 - x, x0 - y, y0 - x, mode);
}
}
 
 
//-----------------------------------------------------------
//
void lcd_circ_line (uint8_t x, uint8_t y, uint8_t r, uint16_t deg, uint8_t mode)
{
uint8_t xc, yc;
double deg_rad;
 
deg_rad = (deg * M_PI) / 180.0;
 
yc = y - (uint8_t) round (cos (deg_rad) * (double) r);
xc = x + (uint8_t) round (sin (deg_rad) * (double) r);
lcd_line (x, y, xc, yc, mode);
}
 
 
//-----------------------------------------------------------
//
void lcd_ellipse_line (uint8_t x, uint8_t y, uint8_t rx, uint8_t ry, uint16_t deg, uint8_t mode)
{
uint8_t xc, yc;
double deg_rad;
 
deg_rad = (deg * M_PI) / 180.0;
 
yc = y - (uint8_t) round (cos (deg_rad) * (double) ry);
xc = x + (uint8_t) round (sin (deg_rad) * (double) rx);
lcd_line (x, y, xc, yc, mode);
}
 
 
//-----------------------------------------------------------
//
void lcd_ellipse (int16_t x0, int16_t y0, int16_t rx, int16_t ry, uint8_t mode)
{
const int16_t rx2 = rx * rx;
const int16_t ry2 = ry * ry;
int16_t F = round (ry2 - rx2 * ry + 0.25 * rx2);
int16_t ddF_x = 0;
int16_t ddF_y = 2 * rx2 * ry;
int16_t x = 0;
int16_t y = ry;
 
lcd_plot (x0, y0 + ry, mode);
lcd_plot (x0, y0 - ry, mode);
lcd_plot (x0 + rx, y0, mode);
lcd_plot (x0 - rx, y0, mode);
// while ( 2*ry2*x < 2*rx2*y ) { we can use ddF_x and ddF_y
while (ddF_x < ddF_y)
{
if(F >= 0)
{
y -= 1; // south
ddF_y -= 2 * rx2;
F -= ddF_y;
}
x += 1; // east
ddF_x += 2 * ry2;
F += ddF_x + ry2;
lcd_plot (x0 + x, y0 + y, mode);
lcd_plot (x0 + x, y0 - y, mode);
lcd_plot (x0 - x, y0 + y, mode);
lcd_plot (x0 - x, y0 - y, mode);
}
F = round (ry2 * (x + 0.5) * (x + 0.5) + rx2 * (y - 1) * (y - 1) - rx2 * ry2);
while(y > 0)
{
if(F <= 0)
{
x += 1; // east
ddF_x += 2 * ry2;
F += ddF_x;
}
y -= 1; // south
ddF_y -= 2 * rx2;
F += rx2 - ddF_y;
lcd_plot (x0 + x, y0 + y, mode);
lcd_plot (x0 + x, y0 - y, mode);
lcd_plot (x0 - x, y0 + y, mode);
lcd_plot (x0 - x, y0 - y, mode);
}
}
 
 
//-----------------------------------------------------------
//
void lcd_ecircle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode)
{
lcd_ellipse (x0, y0, radius + 3, radius, mode);
}
 
 
//-----------------------------------------------------------
//
void lcd_ecirc_line (uint8_t x, uint8_t y, uint8_t r, uint16_t deg, uint8_t mode)
{
lcd_ellipse_line(x, y, r + 3, r, deg, mode);
}
 
 
//-----------------------------------------------------------
//
void lcd_view_font (uint8_t page)
{
int x;
int y;
 
lcd_cls ();
lcd_printp (PSTR(" 0123456789ABCDEF\r\n"), 0);
lcd_printpns_at (0, 7, PSTR(" \x1a \x1b Exit"), 0);
 
lcd_ypos = 2;
for (y = page * 4 ; y < (page * 4 + 4); y++)
{
if (y < 10)
{
lcd_putc (0, lcd_ypos, '0' + y, 0);
}
else
{
lcd_putc (0, lcd_ypos, 'A' + y - 10, 0);
}
lcd_xpos = 2;
for (x = 0; x < 16; x++)
{
lcd_putc (lcd_xpos, lcd_ypos, y * 16 + x, 0);
lcd_xpos++;
}
lcd_ypos++;
}
}
 
 
//-----------------------------------------------------------
uint8_t hdigit (uint8_t d)
{
if (d < 10)
{
return '0' + d;
}
else
{
return 'A' + d - 10;
}
}
 
 
//-----------------------------------------------------------
void lcd_print_hex_at (uint8_t x, uint8_t y, uint8_t h, uint8_t mode)
{
lcd_xpos = x;
lcd_ypos = y;
 
lcd_putc (lcd_xpos++, lcd_ypos, hdigit (h >> 4), mode);
lcd_putc (lcd_xpos, lcd_ypos, hdigit (h & 0x0f), mode);
}
 
 
//-----------------------------------------------------------
void lcd_print_hex (uint8_t h, uint8_t mode)
{
// lcd_xpos = x;
// lcd_ypos = y;
 
lcd_putc (lcd_xpos++, lcd_ypos, hdigit (h >> 4), mode);
lcd_putc (lcd_xpos++, lcd_ypos, hdigit (h & 0x0f), mode);
lcd_putc (lcd_xpos++, lcd_ypos, ' ', mode);
}
 
 
//-----------------------------------------------------------
void lcd_write_number_u (uint8_t number)
{
uint8_t num = 100;
uint8_t started = 0;
 
while (num > 0)
{
uint8_t b = number / num;
if (b > 0 || started || num == 1)
{
lcd_putc (lcd_xpos++, lcd_ypos, '0' + b, 0);
started = 1;
}
number -= b * num;
 
num /= 10;
}
}
 
 
//-----------------------------------------------------------
void lcd_write_number_u_at (uint8_t x, uint8_t y, uint8_t number)
{
lcd_xpos = x;
lcd_ypos = y;
lcd_write_number_u (number);
}
 
 
//-----------------------------------------------------------
// Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory
// <num> represents the largest multiple of 10 that will still be displayable as
// the first digit, so num = 10 will be 0-99 and so on
// <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
//
void write_ndigit_number_u (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, uint8_t mode)
{
char s[7];
 
utoa(number, s, 10 );
 
uint8_t len = strlen(s);
 
if (length < len)
{
for (uint8_t i = 0; i < length; i++)
{
lcd_putc (x++, y, '*', mode);
}
return;
}
 
for (uint8_t i = 0; i < length - len; i++)
{
if (pad==1)
{
lcd_putc (x++, y, '0', mode);
}
else
{
lcd_putc (x++, y, ' ', mode);
}
}
lcd_print_at(x, y, (uint8_t*)s, mode);
}
 
//-----------------------------------------------------------
// Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory
// <num> represents the largest multiple of 10 that will still be displayable as
// the first digit, so num = 10 will be 0-99 and so on
// <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
//
void write_ndigit_number_s (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode)
{
char s[7];
 
itoa(number, s, 10 );
 
uint8_t len = strlen(s);
 
if (length < len)
{
for (uint8_t i = 0; i < length; i++)
{
lcd_putc (x++, y, '*', mode);
}
return;
}
 
for (uint8_t i = 0; i < length - len; i++)
{
if (pad)
{
lcd_putc (x++, y, '0', mode);
}
else
{
lcd_putc (x++, y, ' ', mode);
}
}
lcd_print_at(x, y, (uint8_t*)s, mode);
}
 
 
//-----------------------------------------------------------
// Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory
// as /10th of the value
// <num> represents the largest multiple of 10 that will still be displayable as
// the first digit, so num = 10 will be 0-99 and so on
// <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
//
void write_ndigit_number_u_10th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, uint8_t mode)
{
char s[7];
 
itoa(number, s, 10 );
 
uint8_t len = strlen(s);
 
if (length < len)
{
for (uint8_t i = 0; i < length; i++)
{
lcd_putc (x++, y, '*', mode);
}
return;
}
 
for (uint8_t i = 0; i < length - len; i++)
{
if (pad)
{
lcd_putc (x++, y, '0', mode);
}
else
{
lcd_putc (x++, y, ' ', mode);
}
}
 
char rest = s[len - 1];
 
s[len - 1] = 0;
 
if (len == 1)
{
lcd_putc (x-1, y, '0', mode);
}
else if (len == 2 && s[0] == '-')
{
lcd_putc (x-1, y, '-', mode);
lcd_putc (x, y, '0', mode);
}
else
{
lcd_print_at(x, y, (uint8_t*)s, mode);
}
x += len - 1;
lcd_putc (x++, y, '.', mode);
lcd_putc (x++, y, rest, mode);
}
 
 
//-----------------------------------------------------------
void write_ndigit_number_u_100th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad)
{
uint8_t num = 100;
 
while (num > 0)
{
uint8_t b = number / num;
 
if ((num / 10) == 1)
{
lcd_putc (x++, y, '.', 0);
}
lcd_putc (x++, y, '0' + b, 0);
number -= b * num;
 
num /= 10;
}
}
 
 
//-----------------------------------------------------------
// Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory
// as /10th of the value
// <num> represents the largest multiple of 10 that will still be displayable as
// the first digit, so num = 10 will be 0-99 and so on
// <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
//
void write_ndigit_number_s_10th (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode)
{
char s[7];
 
itoa (number, s, 10 );
 
uint8_t len = strlen(s);
 
if (length < len)
{
for (uint8_t i = 0; i < length; i++)
{
lcd_putc (x++, y, '*', mode);
}
return;
}
 
for (uint8_t i = 0; i < length - len; i++)
{
if (pad)
{
lcd_putc (x++, y, '0', mode);
}
else
{
lcd_putc (x++, y, ' ', mode);
}
}
 
char rest = s[len - 1];
 
s[len - 1] = 0;
 
if (len == 1)
{
lcd_putc (x-1, y, '0', mode);
}
else if (len == 2 && s[0] == '-')
{
lcd_putc (x-1, y, '-', mode);
lcd_putc (x, y, '0', mode);
}
else
{
lcd_print_at(x, y, (uint8_t*)s, mode);
}
x += len - 1;
lcd_putc (x++, y, '.', mode);
lcd_putc (x++, y, rest, mode);
}
 
 
//-----------------------------------------------------------
// write <seconds> as human readable time at <x>/<y> to MAX7456 display mem
//
void write_time (uint8_t x, uint8_t y, uint16_t seconds)
{
uint16_t min = seconds / 60;
seconds -= min * 60;
write_ndigit_number_u (x, y, min, 2, 0,0);
lcd_putc (x + 2, y, ':', 0);
write_ndigit_number_u (x + 3, y, seconds, 2, 1,0);
}
 
 
//-----------------------------------------------------------
// wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude
//
void write_gps_pos (uint8_t x, uint8_t y, int32_t position)
{
if (position < 0)
{
position ^= ~0;
position++;
lcd_putc (x++, y, '-', 0);
}
else
{
lcd_putc (x++, y, ' ', 0);
}
write_ndigit_number_u (x, y, (uint16_t) (position / (int32_t) 10000000), 3, 1,0);
lcd_putc (x + 3, y, '.', 0);
position = position - ((position / (int32_t) 10000000) * (int32_t) 10000000);
write_ndigit_number_u (x + 4, y, (uint16_t) (position / (int32_t) 1000), 4, 1,0);
position = position - ((uint16_t) (position / (int32_t) 1000) * (int32_t) 1000);
write_ndigit_number_u (x + 8, y, (uint16_t) position, 3, 1,0);
lcd_putc (x + 11, y, 0x1e, 0); // degree symbol
}
 
 
//------------------------------------------------------------------------------------
// Show PKT Baudrate at given position
//
 
void show_baudrate (uint8_t x, uint8_t y, uint8_t Baudrate, uint8_t mode)
 
{
switch (Baudrate)
{
case Baud_2400: lcd_printp_at (x, y, PSTR("2400"), mode);break;
case Baud_4800: lcd_printp_at (x, y, PSTR("4800"), mode);break;
case Baud_9600: lcd_printp_at (x, y, PSTR("9600"), mode);break;
case Baud_19200: lcd_printp_at (x, y, PSTR("19200"), mode);break;
case Baud_38400: lcd_printp_at (x, y, PSTR("38400"), mode);break;
case Baud_57600: lcd_printp_at (x, y, PSTR("57600"), mode);break;
case Baud_115200: lcd_printp_at (x, y, PSTR("115200"), mode);break;
break;
}
 
 
}
 
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/lcd/lcd.h
0,0 → 1,303
/*****************************************************************************
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* - original LCD control by Thomas "thkais" Kaiser *
* - special number formating routines taken from C-OSD *
* from Claas Anders "CaScAdE" Rathje *
* - some extension, ellipse and circ_line by Peter "woggle" Mack *
* Thanks to Oliver Schwaneberg for adding several functions to this library!*
* *
* Author: Jan Michel (jan at mueschelsoft dot de) *
* License: GNU General Public License, version 3 *
* Version: v0.93 September 2010 *
* *
* 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. *
* *
*****************************************************************************/
 
#ifndef _LCD_H
#define _LCD_H
 
#define MNORMAL 0 //
#define MINVERS 2
#define MBIG 3
#define MBIGINVERS 4
 
 
//------------------------------------------------------------------------------------
// X-tended
void lcdx_putc( uint8_t x, uint8_t y, uint8_t c, uint8_t mode, int8_t xoffs, int8_t yoffs );
void lcdx_print (uint8_t *text, uint8_t mode, int8_t xoffs, int8_t yoffs);
void lcdx_print_at (uint8_t x, uint8_t y, uint8_t *text, uint8_t mode, int8_t xoffs, int8_t yoffs);
void lcdx_printp (const char *text, uint8_t mode, int8_t xoffs, int8_t yoffs);
void lcdx_printp_at (uint8_t x, uint8_t y, const char *text, uint8_t mode, int8_t xoffs, int8_t yoffs);
 
void writex_ndigit_number_s (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode, int8_t xoffs, int8_t yoffs);
void writex_ndigit_number_s_10th (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode, int8_t xoffs, int8_t yoffs);
 
void writex_ndigit_number_u (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, uint8_t mode, int8_t xoffs, int8_t yoffs);
void writex_ndigit_number_u_10th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, uint8_t mode, int8_t xoffs, int8_t yoffs);
void writex_ndigit_number_u_100th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, int8_t xoffs, int8_t yoffs);
 
void lcdx_puts_at(uint8_t x, uint8_t y, const char *s, uint8_t mode, int8_t xoffs, int8_t yoffs);
void writex_time (uint8_t x, uint8_t y, uint16_t seconds, uint8_t mode, int8_t xoffs, int8_t yoffs);
 
 
/*
 
//-----------------------------------------------------------------------------
// Command Codes
//-----------------------------------------------------------------------------
//1: Display on/off
#define LCD_DISPLAY_ON 0xAF //switch display on
#define LCD_DISPLAY_OFF 0xAE //switch display off
 
//2: display start line set (lower 6 bits select first line on lcd from 64 lines in memory)
#define LCD_START_LINE 0x40
 
//3: Page address set (lower 4 bits select one of 8 pages)
#define LCD_PAGE_ADDRESS 0xB0
 
//4: column address (lower 4 bits are upper / lower nibble of column address)
#define LCD_COL_ADDRESS_MSB 0x10
#define LCD_COL_ADDRESS_LSB 0x00 //second part of column address
 
//8: select orientation (black side of the display should be further away from viewer)
#define LCD_BOTTOMVIEW 0xA1 //6 o'clock view
#define LCD_TOPVIEW 0xA0 //12 o'clock view
 
//9: select normal (white background, black pixels) or reverse (black background, white pixels) mode
#define LCD_DISPLAY_POSITIVE 0xA6 //not inverted mode
#define LCD_DISPLAY_INVERTED 0xA7 //inverted display
 
//10: show memory content or switch all pixels on
#define LCD_SHOW_NORMAL 0xA4 //show dram content
#define LCD_SHOW_ALL_POINTS 0xA5 //show all points
 
//11: lcd bias set
#define LCD_BIAS_1_9 0xA2
#define LCD_BIAS_1_7 0xA3
 
//14: Reset Controller
#define LCD_RESET_CMD 0xE2
 
//15: output mode select (turns display upside-down)
#define LCD_SCAN_DIR_NORMAL 0xC0 //normal scan direction
#define LCD_SCAN_DIR_REVERSE 0xC8 //reversed scan direction
 
//16: power control set (lower 3 bits select operating mode)
//Bit 0: Voltage follower on/off - Bit 1: Voltage regulator on/off - Bit 2: Booster circuit on/off
#define LCD_POWER_CONTROL 0x28 //base command
#define LCD_POWER_LOW_POWER 0x2F
#define LCD_POWER_WIDE_RANGE 0x2F
#define LCD_POWER_LOW_VOLTAGE 0x2B
 
//17: voltage regulator resistor ratio set (lower 3 bits select ratio)
//selects lcd voltage - 000 is low (~ -2V), 111 is high (~ - 10V), also depending on volume mode. Datasheet suggests 011
#define LCD_VOLTAGE 0x20
 
//18: Volume mode set (2-byte command, lower 6 bits in second word select value, datasheet suggests 0x1F)
#define LCD_VOLUME_MODE_1 0x81
#define LCD_VOLUME_MODE_2 0x00
 
//#if DISPLAY_TYPE == 128 || DISPLAY_TYPE == 132
//19: static indicator (2-byte command), first on/off, then blinking mode
#define LCD_INDICATOR_ON 0xAD //static indicator on
#define LCD_INDICATOR_OFF 0xAC //static indicator off
#define LCD_INDICATOR_MODE_OFF 0x00
#define LCD_INDICATOR_MODE_1HZ 0x01
#define LCD_INDICATOR_MODE_2HZ 0x10
#define LCD_INDICATOR_MODE_ON 0x11
 
//20: booster ratio set (2-byte command)
#define LCD_BOOSTER_SET 0xF8 //set booster ratio
#define LCD_BOOSTER_234 0x00 //2x-4x
#define LCD_BOOSTER_5 0x01 //5x
#define LCD_BOOSTER_6 0x03 //6x
//#endif
 
//22: NOP command
#define LCD_NOP 0xE3
 
//#if DISPLAY_TYPE == 102
////25: advanced program control
//#define LCD_ADV_PROG_CTRL 0xFA
//#define LCD_ADV_PROG_CTRL2 0x10
//#endif
 
//-----------------------------------------------------------------------------
// Makros to execute commands
//-----------------------------------------------------------------------------
 
#define LCD_SWITCH_ON() lcd_command(LCD_DISPLAY_ON)
#define LCD_SWITCH_OFF() lcd_command(LCD_DISPLAY_OFF)
#define LCD_SET_FIRST_LINE(i) lcd_command(LCD_START_LINE | ((i) & 0x3F))
#define LCD_SET_PAGE_ADDR(i) lcd_command(LCD_PAGE_ADDRESS | ((i) & 0x0F))
#define LCD_SET_COLUMN_ADDR(i) lcd_command(LCD_COL_ADDRESS_MSB | ((i>>4) & 0x0F)); \
lcd_command(LCD_COL_ADDRESS_LSB | ((i) & 0x0F))
#define LCD_GOTO_ADDRESS(page,col); lcd_command(LCD_PAGE_ADDRESS | ((page) & 0x0F)); \
lcd_command(LCD_COL_ADDRESS_MSB | ((col>>4) & 0x0F)); \
lcd_command(LCD_COL_ADDRESS_LSB | ((col) & 0x0F));
 
#define LCD_SET_BOTTOM_VIEW() lcd_command(LCD_BOTTOMVIEW)
#define LCD_SET_TOP_VIEW() lcd_command(LCD_TOPVIEW)
#define LCD_SET_MODE_POSITIVE() lcd_command(LCD_DISPLAY_POSITIVE)
#define LCD_SET_MODE_INVERTED() lcd_command(LCD_DISPLAY_INVERTED)
#define LCD_SHOW_ALL_PIXELS_ON() lcd_command(LCD_SHOW_ALL_POINTS)
#define LCD_SHOW_ALL_PIXELS_OFF() lcd_command(LCD_SHOW_NORMAL)
#define LCD_SET_BIAS_RATIO_1_7() lcd_command(LCD_BIAS_1_7)
#define LCD_SET_BIAS_RATIO_1_9() lcd_command(LCD_BIAS_1_9)
#define LCD_SEND_RESET() lcd_command(LCD_RESET_CMD)
#define LCD_ORIENTATION_NORMAL() lcd_command(LCD_SCAN_DIR_NORMAL)
#define LCD_ORIENTATION_UPSIDEDOWN() lcd_command(LCD_SCAN_DIR_REVERSE)
#define LCD_SET_POWER_CONTROL(i) lcd_command(LCD_POWER_CONTROL | ((i) & 0x07))
#define LCD_SET_LOW_POWER() lcd_command(LCD_POWER_LOW_POWER)
#define LCD_SET_WIDE_RANGE() lcd_command(LCD_POWER_WIDE_RANGE)
#define LCD_SET_LOW_VOLTAGE() lcd_command(LCD_POWER_LOW_VOLTAGE)
#define LCD_SET_BIAS_VOLTAGE(i) lcd_command(LCD_VOLTAGE | ((i) & 0x07))
#define LCD_SET_VOLUME_MODE(i) lcd_command(LCD_VOLUME_MODE_1); \
lcd_command(LCD_VOLUME_MODE_2 | ((i) & 0x3F))
 
//#if DISPLAY_TYPE == 128 || DISPLAY_TYPE == 132
#define LCD_SET_INDICATOR_OFF() lcd_command(LCD_INDICATOR_OFF); \
lcd_command(LCD_INDICATOR_MODE_OFF)
#define LCD_SET_INDICATOR_STATIC() lcd_command(LCD_INDICATOR_ON); \
lcd_command(LCD_INDICATOR_MODE_ON)
#define LCD_SET_INDICATOR_1HZ() lcd_command(LCD_INDICATOR_ON); \
lcd_command(LCD_INDICATOR_MODE_1HZ)
#define LCD_SET_INDICATOR_2HZ() lcd_command(LCD_INDICATOR_ON); \
lcd_command(LCD_INDICATOR_MODE_2HZ)
#define LCD_SET_INDICATOR(i,j) lcd_command(LCD_INDICATOR_OFF | ((i) & 1)); \
lcd_command(((j) & 2))
#define LCD_SLEEP_MODE lcd_command(LCD_INDICATOR_OFF); \
lcd_command(LCD_DISPLAY_OFF); \
lcd_command(LCD_SHOW_ALL_POINTS)
//#endif
 
//#if DISPLAY_TYPE == 102
//#define LCD_TEMPCOMP_HIGH 0x80
//#define LCD_COLWRAP 0x02
//#define LCD_PAGEWRAP 0x01
//#define LCD_SET_ADV_PROG_CTRL(i) lcd_command(LCD_ADV_PROG_CTRL);
// lcd_command(LCD_ADV_PROG_CTRL2 & i)
//#endif
 
*/
 
 
 
extern volatile uint8_t LCD_ORIENTATION;
 
//#define LCD_LINES 8
//#define LCD_COLS 21
 
extern uint8_t lcd_xpos;
extern uint8_t lcd_ypos;
 
void lcd_command(uint8_t cmd);
void send_byte (uint8_t data);
void LCD_Init (uint8_t LCD_Mode);
void new_line (void);
void lcd_puts_at(uint8_t x, uint8_t y,const char *s, uint8_t mode );
void lcd_putc (uint8_t x, uint8_t y, uint8_t c, uint8_t mode);
void send_byte (uint8_t data);
void lcd_print (uint8_t *text, uint8_t mode);
void lcd_print_at (uint8_t x, uint8_t y, uint8_t *text, uint8_t mode);
 
void lcd_printp (const char *text, uint8_t mode);
void lcd_printp_at (uint8_t x, uint8_t y, const char *text, uint8_t mode);
void lcd_printpns (const char *text, uint8_t mode);
void lcd_printpns_at (uint8_t x, uint8_t y, const char *text, uint8_t mode);
void lcd_cls (void);
void lcd_cls_line (uint8_t x, uint8_t y, uint8_t w);
 
void print_display (uint8_t *text);
void print_display_at (uint8_t x, uint8_t y, uint8_t *text);
void copy_line (uint8_t y);
void paste_line (uint8_t y);
 
void lcd_plot (uint8_t x, uint8_t y, uint8_t mode);
void lcd_line (unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, uint8_t mode);
void lcd_rect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode);
void lcd_frect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode);
void lcd_circle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode);
void lcd_fcircle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode);
void lcd_circ_line (uint8_t x, uint8_t y, uint8_t r, uint16_t deg, uint8_t mode);
 
void lcd_ellipse (int16_t x0, int16_t y0, int16_t rx, int16_t ry, uint8_t mode);
void lcd_ellipse_line (uint8_t x, uint8_t y, uint8_t rx, uint8_t ry, uint16_t deg, uint8_t mode);
 
void lcd_ecircle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode);
void lcd_ecirc_line (uint8_t x, uint8_t y, uint8_t r, uint16_t deg, uint8_t mode);
 
void lcd_view_font (uint8_t page);
void lcd_print_hex_at (uint8_t x, uint8_t y, uint8_t h, uint8_t mode);
 
void lcd_write_number_u (uint8_t number);
void lcd_write_number_u_at (uint8_t x, uint8_t y, uint8_t number);
void lcd_print_hex (uint8_t h, uint8_t mode);
/**
* Write only some digits of a unsigned <number> at <x>/<y>
* <length> represents the length to rightbound the number
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
*/
void write_ndigit_number_u (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad,uint8_t mode);
 
/**
* Write only some digits of a signed <number> at <x>/<y>
* <length> represents the length to rightbound the number
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
*/
 
void write_ndigit_number_s (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode);
 
/**
* Write only some digits of a unsigned <number> at <x>/<y> as /10th of the value
* <length> represents the length to rightbound the number
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 00.7 instead of .7
*/
void write_ndigit_number_u_10th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, uint8_t mode);
 
/**
* Write only some digits of a unsigned <number> at <x>/<y> as /100th of the value
* <length> represents the length to rightbound the number
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 00.7 instead of .7
*/
void write_ndigit_number_u_100th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad);
 
/**
* Write only some digits of a signed <number> at <x>/<y> as /10th of the value
* <length> represents the length to rightbound the number
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 00.7 instead of .7
*/
void write_ndigit_number_s_10th (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode);
 
/**
* write <seconds> as human readable time at <x>/<y>
*/
void write_time (uint8_t x, uint8_t y, uint16_t seconds);
 
/**
* wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude
*/
void write_gps_pos (uint8_t x, uint8_t y, int32_t position);
 
//------------------------------------------------------------------------------------
// Show PKT Baudrate at given position
//
 
void show_baudrate (uint8_t x, uint8_t y, uint8_t Baudrate, uint8_t mode);
 
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/lcd/lcd.hold
0,0 → 1,282
/*****************************************************************************
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* - original LCD control by Thomas "thkais" Kaiser *
* - special number formating routines taken from C-OSD *
* from Claas Anders "CaScAdE" Rathje *
* - some extension, ellipse and circ_line by Peter "woggle" Mack *
* Thanks to Oliver Schwaneberg for adding several functions to this library!*
* *
* Author: Jan Michel (jan at mueschelsoft dot de) *
* License: GNU General Public License, version 3 *
* Version: v0.93 September 2010 *
* *
* 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. *
* *
*****************************************************************************/
 
#ifndef _LCD_H
#define _LCD_H
 
/*
 
//-----------------------------------------------------------------------------
// Command Codes
//-----------------------------------------------------------------------------
//1: Display on/off
#define LCD_DISPLAY_ON 0xAF //switch display on
#define LCD_DISPLAY_OFF 0xAE //switch display off
 
//2: display start line set (lower 6 bits select first line on lcd from 64 lines in memory)
#define LCD_START_LINE 0x40
 
//3: Page address set (lower 4 bits select one of 8 pages)
#define LCD_PAGE_ADDRESS 0xB0
 
//4: column address (lower 4 bits are upper / lower nibble of column address)
#define LCD_COL_ADDRESS_MSB 0x10
#define LCD_COL_ADDRESS_LSB 0x00 //second part of column address
 
//8: select orientation (black side of the display should be further away from viewer)
#define LCD_BOTTOMVIEW 0xA1 //6 o'clock view
#define LCD_TOPVIEW 0xA0 //12 o'clock view
 
//9: select normal (white background, black pixels) or reverse (black background, white pixels) mode
#define LCD_DISPLAY_POSITIVE 0xA6 //not inverted mode
#define LCD_DISPLAY_INVERTED 0xA7 //inverted display
 
//10: show memory content or switch all pixels on
#define LCD_SHOW_NORMAL 0xA4 //show dram content
#define LCD_SHOW_ALL_POINTS 0xA5 //show all points
 
//11: lcd bias set
#define LCD_BIAS_1_9 0xA2
#define LCD_BIAS_1_7 0xA3
 
//14: Reset Controller
#define LCD_RESET_CMD 0xE2
 
//15: output mode select (turns display upside-down)
#define LCD_SCAN_DIR_NORMAL 0xC0 //normal scan direction
#define LCD_SCAN_DIR_REVERSE 0xC8 //reversed scan direction
 
//16: power control set (lower 3 bits select operating mode)
//Bit 0: Voltage follower on/off - Bit 1: Voltage regulator on/off - Bit 2: Booster circuit on/off
#define LCD_POWER_CONTROL 0x28 //base command
#define LCD_POWER_LOW_POWER 0x2F
#define LCD_POWER_WIDE_RANGE 0x2F
#define LCD_POWER_LOW_VOLTAGE 0x2B
 
//17: voltage regulator resistor ratio set (lower 3 bits select ratio)
//selects lcd voltage - 000 is low (~ -2V), 111 is high (~ - 10V), also depending on volume mode. Datasheet suggests 011
#define LCD_VOLTAGE 0x20
 
//18: Volume mode set (2-byte command, lower 6 bits in second word select value, datasheet suggests 0x1F)
#define LCD_VOLUME_MODE_1 0x81
#define LCD_VOLUME_MODE_2 0x00
 
//#if DISPLAY_TYPE == 128 || DISPLAY_TYPE == 132
//19: static indicator (2-byte command), first on/off, then blinking mode
#define LCD_INDICATOR_ON 0xAD //static indicator on
#define LCD_INDICATOR_OFF 0xAC //static indicator off
#define LCD_INDICATOR_MODE_OFF 0x00
#define LCD_INDICATOR_MODE_1HZ 0x01
#define LCD_INDICATOR_MODE_2HZ 0x10
#define LCD_INDICATOR_MODE_ON 0x11
 
//20: booster ratio set (2-byte command)
#define LCD_BOOSTER_SET 0xF8 //set booster ratio
#define LCD_BOOSTER_234 0x00 //2x-4x
#define LCD_BOOSTER_5 0x01 //5x
#define LCD_BOOSTER_6 0x03 //6x
//#endif
 
//22: NOP command
#define LCD_NOP 0xE3
 
//#if DISPLAY_TYPE == 102
////25: advanced program control
//#define LCD_ADV_PROG_CTRL 0xFA
//#define LCD_ADV_PROG_CTRL2 0x10
//#endif
 
//-----------------------------------------------------------------------------
// Makros to execute commands
//-----------------------------------------------------------------------------
 
#define LCD_SWITCH_ON() lcd_command(LCD_DISPLAY_ON)
#define LCD_SWITCH_OFF() lcd_command(LCD_DISPLAY_OFF)
#define LCD_SET_FIRST_LINE(i) lcd_command(LCD_START_LINE | ((i) & 0x3F))
#define LCD_SET_PAGE_ADDR(i) lcd_command(LCD_PAGE_ADDRESS | ((i) & 0x0F))
#define LCD_SET_COLUMN_ADDR(i) lcd_command(LCD_COL_ADDRESS_MSB | ((i>>4) & 0x0F)); \
lcd_command(LCD_COL_ADDRESS_LSB | ((i) & 0x0F))
#define LCD_GOTO_ADDRESS(page,col); lcd_command(LCD_PAGE_ADDRESS | ((page) & 0x0F)); \
lcd_command(LCD_COL_ADDRESS_MSB | ((col>>4) & 0x0F)); \
lcd_command(LCD_COL_ADDRESS_LSB | ((col) & 0x0F));
 
#define LCD_SET_BOTTOM_VIEW() lcd_command(LCD_BOTTOMVIEW)
#define LCD_SET_TOP_VIEW() lcd_command(LCD_TOPVIEW)
#define LCD_SET_MODE_POSITIVE() lcd_command(LCD_DISPLAY_POSITIVE)
#define LCD_SET_MODE_INVERTED() lcd_command(LCD_DISPLAY_INVERTED)
#define LCD_SHOW_ALL_PIXELS_ON() lcd_command(LCD_SHOW_ALL_POINTS)
#define LCD_SHOW_ALL_PIXELS_OFF() lcd_command(LCD_SHOW_NORMAL)
#define LCD_SET_BIAS_RATIO_1_7() lcd_command(LCD_BIAS_1_7)
#define LCD_SET_BIAS_RATIO_1_9() lcd_command(LCD_BIAS_1_9)
#define LCD_SEND_RESET() lcd_command(LCD_RESET_CMD)
#define LCD_ORIENTATION_NORMAL() lcd_command(LCD_SCAN_DIR_NORMAL)
#define LCD_ORIENTATION_UPSIDEDOWN() lcd_command(LCD_SCAN_DIR_REVERSE)
#define LCD_SET_POWER_CONTROL(i) lcd_command(LCD_POWER_CONTROL | ((i) & 0x07))
#define LCD_SET_LOW_POWER() lcd_command(LCD_POWER_LOW_POWER)
#define LCD_SET_WIDE_RANGE() lcd_command(LCD_POWER_WIDE_RANGE)
#define LCD_SET_LOW_VOLTAGE() lcd_command(LCD_POWER_LOW_VOLTAGE)
#define LCD_SET_BIAS_VOLTAGE(i) lcd_command(LCD_VOLTAGE | ((i) & 0x07))
#define LCD_SET_VOLUME_MODE(i) lcd_command(LCD_VOLUME_MODE_1); \
lcd_command(LCD_VOLUME_MODE_2 | ((i) & 0x3F))
 
//#if DISPLAY_TYPE == 128 || DISPLAY_TYPE == 132
#define LCD_SET_INDICATOR_OFF() lcd_command(LCD_INDICATOR_OFF); \
lcd_command(LCD_INDICATOR_MODE_OFF)
#define LCD_SET_INDICATOR_STATIC() lcd_command(LCD_INDICATOR_ON); \
lcd_command(LCD_INDICATOR_MODE_ON)
#define LCD_SET_INDICATOR_1HZ() lcd_command(LCD_INDICATOR_ON); \
lcd_command(LCD_INDICATOR_MODE_1HZ)
#define LCD_SET_INDICATOR_2HZ() lcd_command(LCD_INDICATOR_ON); \
lcd_command(LCD_INDICATOR_MODE_2HZ)
#define LCD_SET_INDICATOR(i,j) lcd_command(LCD_INDICATOR_OFF | ((i) & 1)); \
lcd_command(((j) & 2))
#define LCD_SLEEP_MODE lcd_command(LCD_INDICATOR_OFF); \
lcd_command(LCD_DISPLAY_OFF); \
lcd_command(LCD_SHOW_ALL_POINTS)
//#endif
 
//#if DISPLAY_TYPE == 102
//#define LCD_TEMPCOMP_HIGH 0x80
//#define LCD_COLWRAP 0x02
//#define LCD_PAGEWRAP 0x01
//#define LCD_SET_ADV_PROG_CTRL(i) lcd_command(LCD_ADV_PROG_CTRL);
// lcd_command(LCD_ADV_PROG_CTRL2 & i)
//#endif
 
*/
 
 
 
extern volatile uint8_t LCD_ORIENTATION;
 
//#define LCD_LINES 8
//#define LCD_COLS 21
 
extern uint8_t lcd_xpos;
extern uint8_t lcd_ypos;
 
void lcd_command(uint8_t cmd);
void send_byte (uint8_t data);
void LCD_Init (uint8_t LCD_Mode);
void new_line (void);
void lcd_puts_at(uint8_t x, uint8_t y,const char *s, uint8_t mode );
void lcd_putc (uint8_t x, uint8_t y, uint8_t c, uint8_t mode);
void send_byte (uint8_t data);
void lcd_print (uint8_t *text, uint8_t mode);
void lcd_print_at (uint8_t x, uint8_t y, uint8_t *text, uint8_t mode);
void lcd_printp (const char *text, uint8_t mode);
void lcd_printp_at (uint8_t x, uint8_t y, const char *text, uint8_t mode);
void lcd_printpns (const char *text, uint8_t mode);
void lcd_printpns_at (uint8_t x, uint8_t y, const char *text, uint8_t mode);
void lcd_cls (void);
void lcd_cls_line (uint8_t x, uint8_t y, uint8_t w);
 
void print_display (uint8_t *text);
void print_display_at (uint8_t x, uint8_t y, uint8_t *text);
void copy_line (uint8_t y);
void paste_line (uint8_t y);
 
// Jeti
void lcd_putc_jeti (uint8_t x, uint8_t y, uint8_t c, uint8_t mode);
void lcd_printpj (const char *text, uint8_t mode);
void lcd_printpj_at (uint8_t x, uint8_t y, const char *text, uint8_t mode);
 
void lcd_plot (uint8_t x, uint8_t y, uint8_t mode);
void lcd_line (unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, uint8_t mode);
void lcd_rect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode);
void lcd_frect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode);
void lcd_circle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode);
void lcd_fcircle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode);
void lcd_circ_line (uint8_t x, uint8_t y, uint8_t r, uint16_t deg, uint8_t mode);
 
void lcd_ellipse (int16_t x0, int16_t y0, int16_t rx, int16_t ry, uint8_t mode);
void lcd_ellipse_line (uint8_t x, uint8_t y, uint8_t rx, uint8_t ry, uint16_t deg, uint8_t mode);
 
void lcd_ecircle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode);
void lcd_ecirc_line (uint8_t x, uint8_t y, uint8_t r, uint16_t deg, uint8_t mode);
 
void lcd_view_font (uint8_t page);
void lcd_print_hex_at (uint8_t x, uint8_t y, uint8_t h, uint8_t mode);
 
void lcd_write_number_u (uint8_t number);
void lcd_write_number_u_at (uint8_t x, uint8_t y, uint8_t number);
void lcd_print_hex (uint8_t h, uint8_t mode);
/**
* Write only some digits of a unsigned <number> at <x>/<y>
* <length> represents the length to rightbound the number
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
*/
void write_ndigit_number_u (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad,uint8_t mode);
 
/**
* Write only some digits of a signed <number> at <x>/<y>
* <length> represents the length to rightbound the number
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
*/
 
void write_ndigit_number_s (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode);
 
/**
* Write only some digits of a unsigned <number> at <x>/<y> as /10th of the value
* <length> represents the length to rightbound the number
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 00.7 instead of .7
*/
void write_ndigit_number_u_10th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, uint8_t mode);
 
/**
* Write only some digits of a unsigned <number> at <x>/<y> as /100th of the value
* <length> represents the length to rightbound the number
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 00.7 instead of .7
*/
void write_ndigit_number_u_100th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad);
 
/**
* Write only some digits of a signed <number> at <x>/<y> as /10th of the value
* <length> represents the length to rightbound the number
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 00.7 instead of .7
*/
void write_ndigit_number_s_10th (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode);
 
/**
* write <seconds> as human readable time at <x>/<y>
*/
void write_time (uint8_t x, uint8_t y, uint16_t seconds);
 
/**
* wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude
*/
void write_gps_pos (uint8_t x, uint8_t y, int32_t position);
 
//------------------------------------------------------------------------------------
// Show PKT Baudrate at given position
//
 
void show_baudrate (uint8_t x, uint8_t y, uint8_t Baudrate, uint8_t mode);
 
 
#endif
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/lcd/lcd.zip
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/lipo/lipo.c
0,0 → 1,152
/*****************************************************************************
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de *
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* based on the key handling by Peter Dannegger *
* see www.mikrocontroller.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 <util/delay.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#include "../main.h"
#include "../lcd/lcd.h"
#include "lipo.h"
#include "../eeprom/eeprom.h"
#if defined HWVERSION1_3W || defined HWVERSION3_9 || defined HWVERSION1_2W
// Global variables
double accumulator = 0; //!< Accumulated 10-bit samples
double Vin = 0; //!< 16-bit float number result
short temp = 0; //!< Temporary variable
short samples = 0; //!< Number of conversions
uint16_t volt_avg = 0;
 
 
//! ADC interrupt routine
 
ISR (ADC_vect)
{
accumulator += ADCW;
samples++;
if(samples>4095)
{
oversampled();
}
}
 
 
 
//--------------------------------------------------------------
//
void ADC_Init (void)
{
DDRA &= ~(1<<DDA1); // MartinR
PORTA &= ~(1<<PORTA1); // MartinR
ADMUX = (0<<REFS1) | (1<<REFS0); // externe 5V Referenzspannung nutzen
ADMUX = (ADMUX & ~(0x1F)) | (1 & 0x1F); // ADC1 verwenden
ADCSRA = (1<<ADEN)|(1<<ADIE)|(1<<ADSC)|(1<<ADATE)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); // Prescaler 128, Freilaufend, Interrupte frei
}
 
 
/*! Error compensation, Scaling 16-bit result, Rounding up
, Calculate 16-bit result, Resets variables
 
Quelle AVR121: Enhancing ADC resolution by versampling
 
*/
void oversampled(void)
{
cli();
accumulator += Config.Lipo_UOffset; //5150 Offset error compensation
 
// accumulator *= 0.9993; // Gain error compensation
accumulator *= 0.9600; //0.9800 Gain error compensation
temp=(int)accumulator%64;
accumulator/=64; // Scaling the answer
if(temp>=32)
{
accumulator += 1; // Round up
}
 
// Vin = (accumulator/65536)*4.910; // Calculating 16-bit result
 
Vin =accumulator/7.5;
volt_avg = Vin;
// write_ndigit_number_u(0, 3, Vin, 5, 0,0);
// write_ndigit_number_u(0, 4, volt_avg, 5, 0,0);
samples = 0;
accumulator = 0;
 
sei();
}
 
 
void show_Lipo(void)
{
 
uint16_t Balken = 0;
 
 
lcd_rect(103,2,1,3,1);
if (volt_avg < 320)
{
Balken = 0;
lcd_frect(106 + Balken-1, 2, 19-Balken, 3, 0); // löschen
}
 
 
if (Config.PKT_Accutyp == true) //LiPO Akku
{
lcd_rect(104, 0, 23, 7, 1); // Rahmen
if (volt_avg >= 420) Balken = 19;
if ((volt_avg > 320) && (volt_avg < 420)) Balken = (volt_avg-320)/5;
lcd_frect(106 + Balken+1, 2, 19-Balken, 3, 0); // löschen
}
 
if (Config.PKT_Accutyp == false) // LiON Akku
{
lcd_rect(104, 0, 22, 7, 1); // Rahmen
if (volt_avg >= 410) Balken = 18;
if ((volt_avg > 320) && (volt_avg < 410)) Balken = ((volt_avg-320)/5);
lcd_frect(106 + Balken+1, 2, 18-Balken, 3, 0); // löschen
}
 
 
if (Balken > 0) lcd_frect(106, 2, Balken, 3, 1); // Füllung
 
}
 
#endif
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/lipo/lipo.h
0,0 → 1,50
/*****************************************************************************
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de *
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* based on the key handling by Peter Dannegger *
* see www.mikrocontroller.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*
*****************************************************************************/
 
#ifndef _LIPO_H
#define _LIPO_H
 
 
short samples; //!< Number of conversions
double Vin;
double accumulator;
 
uint16_t volt_avg;
 
void ADC_Init (void);
void oversampled(void);
void show_Lipo(void);
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/motortest/motortest.c
0,0 → 1,419
/*****************************************************************************
* 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 <string.h>
#include <stdlib.h>
#include "../main.h"
#include "motortest.h"
#include "../lcd/lcd.h"
#include "../timer/timer.h"
#include "../motortest/twimaster.h"
//#include "menu.h"
#include "../uart/uart1.h"
#include "../uart/usart.h"
#include "../messages.h"
 
 
 
 
uint8_t m;
uint8_t mmode; // 0=Value 1=Motor
uint8_t v;
 
volatile uint8_t i2c_state;
volatile uint8_t motor_addr = 0;
 
 
//--------------------------------------------------------------
// Senden der Motorwerte per I2C-Bus
//
void SendMotorData(uint8_t m,uint8_t v)
{
if (m==0)
 
for(m=0;m<MAX_MOTORS;m++) // alle Motoren
{
// Motor[m].SetPoint = MotorTest[m];
Motor[m].SetPoint = v;
Motor[m].SetPointLowerBits = 0;
 
// Motor[i].SetPoint = MotorTest[i] / 4; // testing the high resolution
// Motor[i].SetPointLowerBits = MotorTest[i] % 4;
 
}
else
{
Motor[m-1].SetPoint = v;
Motor[m-1].SetPointLowerBits = 0;
}
 
 
 
if(I2C_TransferActive)
I2C_TransferActive = 0; // enable for the next time
else
{
motor_write = 0;
I2C_Start(TWI_STATE_MOTOR_TX); //Start I2C Interrupt Mode
}
}
 
 
//--------------------------------------------------------------
//
void Search_BL (void)
{
uint8_t i = 0;
unsigned int timer;
lcd_cls ();
MotorenEin =0;
MotorTest[i] = 0;
 
lcd_printp (PSTR("Suche BL-Ctrl"), 0);
 
// Check connected BL-Ctrls
BLFlags |= BLFLAG_READ_VERSION;
motor_read = 0; // read the first I2C-Data
 
SendMotorData(0,0);
timer = SetDelay(1);
while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
 
timer = SetDelay(1);
for(i=0; i < MAX_MOTORS; i++)
{
 
SendMotorData(i,0);
 
 
while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
 
 
if(Motor[i].State & MOTOR_STATE_PRESENT_MASK)
{
 
lcd_printp_at (0, 1, PSTR("Found BL-Ctrl:"), 0);
lcd_print_hex_at (18,1,i,0);
 
lcd_printp_at (0, 2, PSTR("Version:"), 0);
lcd_print_hex_at (8,2,Motor[i].Version,0);
lcd_printp_at (11, 2, PSTR("SetPoi:"), 0);
lcd_print_hex_at (18,2,Motor[i].SetPoint,0);
 
lcd_printp_at (0, 3, PSTR("SetPoiL:"), 0);
lcd_print_hex_at (8,3,Motor[i].SetPointLowerBits,0);
lcd_printp_at (11, 3, PSTR("State :"), 0);
lcd_print_hex_at (18,3,Motor[i].State,0);
 
lcd_printp_at (0, 4, PSTR("ReadMod:"), 0);
lcd_print_hex_at (8,4,Motor[i].ReadMode,0);
lcd_printp_at (11, 4, PSTR("Currnt:"), 0);
lcd_print_hex_at (18,4,Motor[i].Current,0);
 
lcd_printp_at (0, 5, PSTR("MaxPWM :"), 0);
lcd_print_hex_at (8,5,Motor[i].MaxPWM,0);
lcd_printp_at (11, 5, PSTR("Temp :"), 0);
write_ndigit_number_u (18,5,Motor[i].Temperature,3,1,0);
}
 
} //End For I
}
 
 
//--------------------------------------------------------------
//
void motor (uint8_t m,uint8_t v)
{
memset (buffer, 0, 16);
 
if(m == 0)
{
memset (buffer, v, 16);
}
else
{
buffer[m-1] = v;
}
 
SendOutData('t', ADDRESS_FC, 1, buffer, 16);
}
 
//--------------------------------------------------------------
//
void motor_test (uint8_t MotorMode)
{
 
lcd_cls ();
mmode = 1; // 1=Motor
m = 1;
v = 0;
char buffer[7];
unsigned int SerLoop;
SerLoop = 10;
 
if (MotorMode == I2C_Mode)
{
Search_BL();
do
{
lcd_printp_at (11, 7, PSTR("Ende Check"), 0);
if (get_key_press (1 << KEY_ESC))
{
get_key_press(KEY_ALL);
return;
}
}
while (!get_key_press (1 << KEY_ENTER));
}
 
lcd_cls();
lcd_printp (PSTR(" BL-Ctrl Test "), 2);
lcd_printp_at (2, 2, PSTR("Motor: 1"), 0);
lcd_printp_at (2, 3, PSTR("Value: 0"), 0);
lcd_frect ((8*1), (8*5), (0 * (14*8)) / 255, 6, 1);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_3), 0);
lcd_puts_at(0, 7, strGet(KEYLINE3), 0);
lcd_printp_at (18, 7, PSTR("\x1a \x1b"), 0);
lcd_printp_at (0, 2, PSTR("\x1d"), 0);
 
#if defined HWVERSION1_3W || defined HWVERSION1_3 || defined HWVERSION3_9
if (MotorMode == I2C_Mode)
uart1_puts("Motor;Version;Setpoint high;Setpoint low;State;ReadMode;Current;MaxPWM;Temperature\r");
#endif
#if defined HWVERSION1_2W || defined HWVERSION1_2
if (MotorMode == I2C_Mode)
USART_puts("Motor;Version;Setpoint high;Setpoint low;State;ReadMode;Current;MaxPWM;Temperature\r");
#endif
 
if (MotorMode == FC_Mode)
{
if (hardware == NC && current_hardware == NC)
{
SwitchToFC();
}
}
do
{
// mmode 0=Value 1=Motor
 
if ((mmode == 0) && (get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 3)) && (v < 254))
{
v++;
write_ndigit_number_u (9, 3, v, 3, 0,0);
if (MotorMode == FC_Mode)
lcd_frect ((8*1), (8*5), (v * (14*8)) / 255, 6, 1);
}
 
if ((mmode == 0) && (get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 3)) && (v > 0))
{
if (MotorMode == FC_Mode)
lcd_frect (((v * (14*8) / 255) + 8), (8*5), ((14*8) / 255), 6, 0);
 
v--;
write_ndigit_number_u (9, 3, v, 3, 0,0);
if (MotorMode == FC_Mode)
lcd_frect ((8*1), (8*5), (v * (14*8)) / 255, 6, 1);
}
 
if ((mmode == 1) && (get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 1)) && (m < 16))
{
m++;
write_ndigit_number_u (9, 2, m, 3, 0,0);
}
 
if ((mmode == 1) && (get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 1)) && (m > 0))
{
m--;
if(m > 0)
write_ndigit_number_u (9, 2, m, 3, 0,0);
if(m == 0)
lcd_printp_at (9, 2, PSTR("All"), 0);
}
 
if (get_key_press (1 << KEY_ENTER))
{
if (MotorMode == I2C_Mode)
{
if (v > 0)
{
m = 0;
v=0;
lcd_frect ((8*1), (8*5), (0 * (14*8)) / 255, 6, 1);
lcd_cls_line (0, 5, 21);
if(m > 0) write_ndigit_number_u (9, 2, m, 3, 0,0);
if(m == 0) lcd_printp_at (9, 2, PSTR("All"), 0);
write_ndigit_number_u (9, 3, v, 3, 0,0);
SendMotorData(m,v);
timer = SetDelay(1);
while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
}
}
 
if(mmode == 0) // 0=Value
{
lcd_printp_at (0, 2, PSTR("\x1d"), 0);
lcd_printp_at (0, 3, PSTR(" "), 0);
mmode = 1; // 1=Motor
}
else
{
lcd_printp_at (0, 2, PSTR(" "), 0);
lcd_printp_at (0, 3, PSTR("\x1d"), 0);
mmode = 0; // 0=Value
}
}
//if (get_key_press (1 << KEY_ENTER))//
 
if (MotorMode == I2C_Mode)
{
SendMotorData(m,v);
timer = SetDelay(1);
lcd_printp_at (0, 3, PSTR("SetPoint :"), 0);
 
write_ndigit_number_u (13,3,Motor[m-1].SetPoint,3,0,0);
lcd_printp_at (0, 4, PSTR("Current :"), 0);
lcd_print_hex_at (13,4,Motor[m-1].Current,0);
write_ndigit_number_u (13,4,Motor[m-1].Current,3,0,0);
lcd_printp_at (0, 5, PSTR("Temperature:"), 0);
write_ndigit_number_u (13,5,Motor[m-1].Temperature,3,0,0);
lcd_printp_at (0, 6, PSTR("Version:"), 0);
lcd_print_hex_at (8,6,Motor[m-1].Version,0);
lcd_printp_at (11, 6, PSTR("State :"), 0);
lcd_print_hex_at (18,6,Motor[m-1].State,0);
 
#if defined HWVERSION1_3W || defined HWVERSION1_3 || defined HWVERSION3_9
 
if (Motor[m-1].SetPoint > 0)
{
if (SerLoop == 0)
{
itoa( m-1, buffer, 10); // convert interger into string (decimal format)
uart1_puts(buffer); // and transmit string to UART
uart1_puts(";");
itoa( Motor[m-1].Version, buffer, 10); //
uart1_puts(buffer);
uart1_puts(";");
itoa( Motor[m-1].SetPoint, buffer, 10); //
uart1_puts(buffer);
uart1_puts(";");
itoa( Motor[m-1].SetPointLowerBits, buffer, 10); //
uart1_puts(buffer);
uart1_puts(";");
itoa( Motor[m-1].State, buffer, 10); //
uart1_puts(buffer);
uart1_puts(";");
itoa( Motor[m-1].ReadMode, buffer, 10); //
uart1_puts(buffer);
uart1_puts(";");
itoa( Motor[m-1].Current, buffer, 10); //
uart1_puts(buffer);
uart1_puts(";");
itoa( Motor[m-1].MaxPWM, buffer, 10); //
uart1_puts(buffer);
uart1_puts(";");
itoa( Motor[m-1].Temperature, buffer, 10); //
uart1_puts(buffer);
uart1_puts("\r");
uart1_puts("\n");
SerLoop =200;
}
else
SerLoop--;
}
 
#endif
 
#if defined HWVERSION1_2W || defined HWVERSION1_2
 
if (Motor[m-1].SetPoint > 0)
{
if (SerLoop == 0)
{
itoa( m-1, buffer, 10); // convert interger into string (decimal format)
USART_puts(buffer); // and transmit string to UART
USART_puts(";");
itoa( Motor[m-1].Version, buffer, 10); //
USART_puts(buffer);
USART_puts(";");
itoa( Motor[m-1].SetPoint, buffer, 10); //
USART_puts(buffer);
USART_puts(";");
itoa( Motor[m-1].SetPointLowerBits, buffer, 10); //
USART_puts(buffer);
USART_puts(";");
itoa( Motor[m-1].State, buffer, 10); //
USART_puts(buffer);
USART_puts(";");
itoa( Motor[m-1].ReadMode, buffer, 10); //
USART_puts(buffer);
USART_puts(";");
itoa( Motor[m-1].Current, buffer, 10); //
USART_puts(buffer);
USART_puts(";");
itoa( Motor[m-1].MaxPWM, buffer, 10); //
USART_puts(buffer);
USART_puts(";");
itoa( Motor[m-1].Temperature, buffer, 10); //
USART_puts(buffer);
USART_puts("\r");
USART_puts("\n");
SerLoop =200;
}
else
SerLoop--;
}
 
#endif
 
while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
}
else
motor (m,v); //if (MotorMode == I2C_Mode)//
 
}
while (!get_key_press (1 << KEY_ESC));
 
get_key_press(KEY_ALL);
 
if (MotorMode == FC_Mode)
{
motor(0,0); // switch all engines off at exit
}
 
}
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/motortest/motortest.h
0,0 → 1,46
/*****************************************************************************
* 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*
*****************************************************************************/
 
 
#ifndef _MOTORTEST_H
#define _MOTORTEST_H
 
#define I2C_Mode 1 // Motortest Lokal
#define FC_Mode 2 // Motortest ueber FC
 
 
 
void motor_test (uint8_t MotorMode);
void SendMotorData(uint8_t m,uint8_t v);
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/motortest/twimaster.c
0,0 → 1,511
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Copyright (c) Holger Buss, Ingo Busker
// + Nur f?r den privaten Gebrauch
// + www.MikroKopter.com
// + porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Es gilt f?r das gesamte Projekt (Hardware, Software, Bin?rfiles, Sourcecode und Dokumentation),
// + dass eine Nutzung (auch auszugsweise) nur f?r den privaten (nicht-kommerziellen) Gebrauch zul?ssig ist.
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
// + bzgl. der Nutzungsbedingungen aufzunehmen.
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Best?ckung und Verkauf von Platinen oder Baus?tzen,
// + Verkauf von Luftbildaufnahmen, usw.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder ver?ffentlicht,
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright m?ssen dann beiliegen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
// + auf anderen Webseiten oder sonstigen Medien ver?ffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
// + eindeutig als Ursprung verlinkt werden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Keine Gew?hr auf Fehlerfreiheit, Vollst?ndigkeit oder Funktion
// + Benutzung auf eigene Gefahr
// + Wir ?bernehmen keinerlei Haftung f?r direkte oder indirekte Personen- oder Sachsch?den
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zul?ssig
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
// + this list of conditions and the following disclaimer.
// + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
// + from this software without specific prior written permission.
// + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
// + for non-commercial use (directly or indirectly)
// + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
// + with our written permission
// + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
// + clearly linked as origin
// + * porting to systems other than hardware from www.mikrokopter.de is not allowed
// + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// + POSSIBILITY OF SUCH DAMAGE.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
#include "../cpu.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/twi.h>
#include <util/delay.h>
#include "../eeprom/eeprom.h"
#include "../motortest/twimaster.h"
#include "../timer/timer.h"
 
volatile uint8_t twi_state = TWI_STATE_MOTOR_TX;
volatile uint8_t dac_channel = 0;
volatile uint8_t motor_write = 0;
volatile uint8_t motor_read = 0;
volatile uint8_t I2C_TransferActive = 0;
 
volatile uint16_t I2CTimeout = 100;
 
uint8_t MissingMotor = 0;
uint8_t RequiredMotors = 1;
char MotorenEin = 0;
 
volatile uint8_t BLFlags = 0;
 
MotorData_t Motor[MAX_MOTORS];
 
// bit mask for witch BL the configuration should be sent
volatile uint16_t BLConfig_WriteMask = 0;
// bit mask for witch BL the configuration should be read
volatile uint16_t BLConfig_ReadMask = 0;
// buffer for BL Configuration
BLConfig_t BLConfig;
 
#define I2C_WriteByte(byte) {TWDR = byte; TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE);}
#define I2C_ReceiveByte() {TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE) | (1<<TWEA);}
#define I2C_ReceiveLastByte() {TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE);}
 
#define SCL_CLOCK 200000L
#define I2C_TIMEOUT 30000
#define TWI_BASE_ADDRESS 0x52
 
 
 
 
uint8_t RAM_Checksum(uint8_t* pBuffer, uint16_t len)
{
uint8_t crc = 0xAA;
uint16_t i;
 
for(i=0; i<len; i++)
{
crc += pBuffer[i];
}
return crc;
}
 
 
 
 
//--------------------------------------------------------------
// Initialize I2C (TWI)
//
void I2C_Init(char clear)
{
uint8_t i;
uint8_t sreg = SREG;
cli();
 
// SDA is INPUT
DDRC &= ~(1<<DDC1);
// SCL is output
DDRC |= (1<<DDC0);
// pull up SDA
//PORTC |= (1<<PORTC0)|(1<<PORTC1);
 
// TWI Status Register
// prescaler 1 (TWPS1 = 0, TWPS0 = 0)
TWSR &= ~((1<<TWPS1)|(1<<TWPS0));
 
// set TWI Bit Rate Register
TWBR = ((F_CPU/SCL_CLOCK)-16)/2;
 
twi_state = TWI_STATE_MOTOR_TX;
motor_write = 0;
motor_read = 0;
 
if(clear) for(i=0; i < MAX_MOTORS; i++)
{
Motor[i].Version = 0;
Motor[i].SetPoint = 0;
Motor[i].SetPointLowerBits = 0;
Motor[i].State = 0;
Motor[i].ReadMode = BL_READMODE_STATUS;
Motor[i].Current = 0;
Motor[i].MaxPWM = 0;
Motor[i].Temperature = 0;
}
sei();
SREG = sreg;
}
 
 
//--------------------------------------------------------------
void I2C_Reset(void)
{
// stop i2c bus
I2C_Stop(TWI_STATE_MOTOR_TX);
TWCR = (1<<TWINT); // reset to original state incl. interrupt flag reset
TWAMR = 0;
TWAR = 0;
TWDR = 0;
TWSR = 0;
TWBR = 0;
I2C_TransferActive = 0;
I2C_Init(0);
I2C_WriteByte(0);
BLFlags |= BLFLAG_READ_VERSION;
}
 
 
//--------------------------------------------------------------
// I2C ISR
//
ISR (TWI_vect)
{
static uint8_t missing_motor = 0, motor_read_temperature = 0;
static uint8_t *pBuff = 0;
static uint8_t BuffLen = 0;
 
switch (twi_state++)
{
// Master Transmit
 
case 0: // TWI_STATE_MOTOR_TX
I2C_TransferActive = 1;
// skip motor if not used in mixer
// while((Mixer.Motor[motor_write][MIX_GAS] <= 0) && (motor_write < MAX_MOTORS)) motor_write++;
if(motor_write >= MAX_MOTORS) // writing finished, read now
{
BLConfig_WriteMask = 0; // reset configuration bitmask
motor_write = 0; // reset motor write counter for next cycle
twi_state = TWI_STATE_MOTOR_RX;
I2C_WriteByte(TWI_BASE_ADDRESS + TW_READ + (motor_read<<1) ); // select slave address in rx mode
}
else I2C_WriteByte(TWI_BASE_ADDRESS + TW_WRITE + (motor_write<<1) ); // select slave address in tx mode
break;
 
case 1: // Send Data to Slave
I2C_WriteByte(Motor[motor_write].SetPoint); // transmit setpoint
// if old version has been detected
if(!(Motor[motor_write].Version & MOTOR_STATE_NEW_PROTOCOL_MASK))
{
twi_state = 4; //jump over sending more data
}
// the new version has been detected
else if(!( (Motor[motor_write].SetPointLowerBits && (RequiredMotors < 7)) || BLConfig_WriteMask || BLConfig_ReadMask ) )
{ // or LowerBits are zero and no BlConfig should be sent (saves round trip time)
twi_state = 4; //jump over sending more data
}
break;
 
case 2: // lower bits of setpoint (higher resolution)
if ((0x0001<<motor_write) & BLConfig_ReadMask)
{
Motor[motor_write].ReadMode = BL_READMODE_CONFIG; // configuration request
}
else
{
Motor[motor_write].ReadMode = BL_READMODE_STATUS; // normal status request
}
// send read mode and the lower bits of setpoint
I2C_WriteByte((Motor[motor_write].ReadMode<<3)|(Motor[motor_write].SetPointLowerBits & 0x07));
// configuration tranmission request?
if((0x0001<<motor_write) & BLConfig_WriteMask)
{ // redirect tx pointer to configuration data
pBuff = (uint8_t*)&BLConfig; // select config for motor
BuffLen = sizeof(BLConfig_t);
}
else
{ // jump to end of transmission for that motor
twi_state = 4;
}
break;
 
case 3: // send configuration
I2C_WriteByte(*pBuff);
pBuff++;
if(--BuffLen > 0)
twi_state = 3; // if there are some bytes left
break;
 
case 4: // repeat case 0-4 for all motors
if(TWSR == TW_MT_DATA_NACK) // Data transmitted, NACK received
{
if(!missing_motor)
missing_motor = motor_write + 1;
 
if((Motor[motor_write].State & MOTOR_STATE_ERROR_MASK) < MOTOR_STATE_ERROR_MASK)
Motor[motor_write].State++; // increment error counter and handle overflow
}
I2C_Stop(TWI_STATE_MOTOR_TX);
I2CTimeout = 10;
motor_write++; // next motor
I2C_Start(TWI_STATE_MOTOR_TX); // Repeated start -> switch slave or switch Master Transmit -> Master Receive
break;
 
// Master Receive Data
case 5: // TWI_STATE_MOTOR_RX
if(TWSR != TW_MR_SLA_ACK) // SLA+R transmitted but no ACK received
{ // no response from the addressed slave received
Motor[motor_read].State &= ~MOTOR_STATE_PRESENT_MASK; // clear present bit
if(++motor_read >= MAX_MOTORS)
{ // all motors read
motor_read = 0; // restart from beginning
BLConfig_ReadMask = 0; // reset read configuration bitmask
if(++motor_read_temperature >= MAX_MOTORS)
{
motor_read_temperature = 0;
BLFlags &= ~BLFLAG_READ_VERSION;
}
}
BLFlags |= BLFLAG_TX_COMPLETE;
I2C_Stop(TWI_STATE_MOTOR_TX);
I2C_TransferActive = 0;
}
else
{ // motor successfully addressed
Motor[motor_read].State |= MOTOR_STATE_PRESENT_MASK; // set present bit
if(Motor[motor_read].Version & MOTOR_STATE_NEW_PROTOCOL_MASK)
{
// new BL found
switch(Motor[motor_read].ReadMode)
{
case BL_READMODE_CONFIG:
pBuff = (uint8_t*)&BLConfig;
BuffLen = sizeof(BLConfig_t);
break;
 
case BL_READMODE_STATUS:
pBuff = (uint8_t*)&(Motor[motor_read].Current);
if(motor_read == motor_read_temperature) BuffLen = 3; // read Current, MaxPwm & Temp
else BuffLen = 1;// read Current only
break;
}
}
else // old BL version
{
pBuff = (uint8_t*)&(Motor[motor_read].Current);
if((BLFlags & BLFLAG_READ_VERSION) || (motor_read == motor_read_temperature)) BuffLen = 2; // Current & MaxPwm
else BuffLen = 1; // read Current only
}
if(BuffLen == 1)
{
I2C_ReceiveLastByte(); // read last byte
}
else
{
I2C_ReceiveByte(); // read next byte
}
}
MissingMotor = missing_motor;
missing_motor = 0;
break;
 
case 6: // receive bytes
*pBuff = TWDR;
pBuff++;
BuffLen--;
if(BuffLen>1)
{
I2C_ReceiveByte(); // read next byte
}
else if (BuffLen == 1)
{
I2C_ReceiveLastByte(); // read last byte
}
else // nothing left
{
if(BLFlags & BLFLAG_READ_VERSION)
{
// if(!(FC_StatusFlags & FC_STATUS_MOTOR_RUN) && (Motor[motor_read].MaxPWM == 250) ) Motor[motor_read].Version |= MOTOR_STATE_NEW_PROTOCOL_MASK;
if((Motor[motor_read].MaxPWM == 250) ) Motor[motor_read].Version |= MOTOR_STATE_NEW_PROTOCOL_MASK;
else Motor[motor_read].Version = 0;
}
if(++motor_read >= MAX_MOTORS)
{
motor_read = 0; // restart from beginning
BLConfig_ReadMask = 0; // reset read configuration bitmask
if(++motor_read_temperature >= MAX_MOTORS)
{
motor_read_temperature = 0;
BLFlags &= ~BLFLAG_READ_VERSION;
}
}
I2C_Stop(TWI_STATE_MOTOR_TX);
BLFlags |= BLFLAG_TX_COMPLETE;
I2C_TransferActive = 0;
return;
}
twi_state = 6; // if there are some bytes left
break;
 
case 21:
I2C_WriteByte(0x80); // 2nd byte for all channels is 0x80
break;
 
case 22:
I2C_Stop(TWI_STATE_MOTOR_TX);
I2C_TransferActive = 0;
I2CTimeout = 10;
// repeat case 18...22 until all DAC Channels are updated
if(dac_channel < 2)
{
dac_channel ++; // jump to next channel
I2C_Start(TWI_STATE_GYRO_OFFSET_TX); // start transmission for next channel
}
else
{
dac_channel = 0; // reset dac channel counter
BLFlags |= BLFLAG_TX_COMPLETE;
}
break;
 
default:
I2C_Stop(TWI_STATE_MOTOR_TX);
BLFlags |= BLFLAG_TX_COMPLETE;
I2CTimeout = 10;
motor_write = 0;
motor_read = 0;
I2C_TransferActive = 0;
break;
}
 
}
 
 
//--------------------------------------------------------------
uint8_t I2C_WriteBLConfig(uint8_t motor)
{
uint8_t i;
uint16_t timer;
 
// if(MotorenEin || PC_MotortestActive)
// return(BLCONFIG_ERR_MOTOR_RUNNING); // not when motors are running!
 
if(MotorenEin)
return(BLCONFIG_ERR_MOTOR_RUNNING); // not when motors are running!
 
if(motor > MAX_MOTORS)
return (BLCONFIG_ERR_MOTOR_NOT_EXIST); // motor does not exist!
 
if(motor)
{
if(!(Motor[motor-1].State & MOTOR_STATE_PRESENT_MASK))
return(BLCONFIG_ERR_MOTOR_NOT_EXIST); // motor does not exist!
 
if(!(Motor[motor-1].Version & MOTOR_STATE_NEW_PROTOCOL_MASK))
return(BLCONFIG_ERR_HW_NOT_COMPATIBLE); // not a new BL!
}
 
// check BL configuration to send
if(BLConfig.Revision != BLCONFIG_REVISION)
return (BLCONFIG_ERR_SW_NOT_COMPATIBLE); // bad revison
 
i = RAM_Checksum((uint8_t*)&BLConfig, sizeof(BLConfig_t) - 1);
 
if(i != BLConfig.crc)
return(BLCONFIG_ERR_CHECKSUM); // bad checksum
 
timer = SetDelay(2000);
while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
 
// prepare the bitmask
if(!motor) // 0 means all
{
BLConfig_WriteMask = 0xFF; // all motors at once with the same configuration
}
else //only one specific motor
{
BLConfig_WriteMask = 0x0001<<(motor-1);
}
for(i = 0; i < MAX_MOTORS; i++)
{
if((0x0001<<i) & BLConfig_WriteMask)
{
Motor[i].SetPoint = 0;
Motor[i].SetPointLowerBits = 0;
}
}
 
motor_write = 0;
// needs at least MAX_MOTORS loops of 2 ms (12*2ms = 24ms)
do
{
I2C_Start(TWI_STATE_MOTOR_TX); // start an i2c transmission
while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
}
while(BLConfig_WriteMask && !CheckDelay(timer)); // repeat until the BL config has been sent
 
if(BLConfig_WriteMask) return(BLCONFIG_ERR_MOTOR_NOT_EXIST);
return(BLCONFIG_SUCCESS);
}
 
 
//--------------------------------------------------------------
uint8_t I2C_ReadBLConfig(uint8_t motor)
{
uint8_t i;
uint16_t timer;
 
// if(MotorenEin || PC_MotortestActive)
return(BLCONFIG_ERR_MOTOR_RUNNING); // not when motors are running!
 
if(MotorenEin)
return(BLCONFIG_ERR_MOTOR_RUNNING); // not when motors are running!
 
if(motor > MAX_MOTORS)
return (BLCONFIG_ERR_MOTOR_NOT_EXIST); // motor does not exist!
 
if(motor == 0)
return (BLCONFIG_ERR_READ_NOT_POSSIBLE);
 
if(!(Motor[motor-1].State & MOTOR_STATE_PRESENT_MASK))
return(BLCONFIG_ERR_MOTOR_NOT_EXIST); // motor does not exist!
 
if(!(Motor[motor-1].Version & MOTOR_STATE_NEW_PROTOCOL_MASK))
return(BLCONFIG_ERR_HW_NOT_COMPATIBLE); // not a new BL!
 
timer = SetDelay(2000);
while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
 
// prepare the bitmask
BLConfig_ReadMask = 0x0001<<(motor-1);
 
for(i = 0; i < MAX_MOTORS; i++)
{
if((0x0001<<i) & BLConfig_ReadMask)
{
Motor[i].SetPoint = 0;
Motor[i].SetPointLowerBits = 0;
}
}
 
motor_read = 0;
BLConfig.Revision = 0; // bad revision
BLConfig.crc = 0; // bad checksum
// needs at least MAX_MOTORS loops of 2 ms (12*2ms = 24ms)
do
{
I2C_Start(TWI_STATE_MOTOR_TX); // start an i2c transmission
while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
}while(BLConfig_ReadMask && !CheckDelay(timer)); // repeat until the BL config has been received from all motors
// validate result
if(BLConfig.Revision != BLCONFIG_REVISION) return (BLCONFIG_ERR_SW_NOT_COMPATIBLE); // bad revison
i = RAM_Checksum((uint8_t*)&BLConfig, sizeof(BLConfig_t) - 1);
if(i != BLConfig.crc) return(BLCONFIG_ERR_CHECKSUM); // bad checksum
return(BLCONFIG_SUCCESS);
}
 
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/motortest/twimaster.h
0,0 → 1,80
#ifndef _I2C_MASTER_H
#define _I2C_MASTER_H
+
+#include <inttypes.h>
+#include "../mk-data-structs.h"
+
+#define TWI_STATE_MOTOR_TX 0
+#define TWI_STATE_MOTOR_RX 5
+#define TWI_STATE_GYRO_OFFSET_TX 18
+
+extern volatile uint8_t twi_state;
+extern volatile uint8_t motor_write;
+extern volatile uint8_t motor_read;
+extern volatile uint8_t I2C_TransferActive;
+
+extern uint8_t MissingMotor;
+
+#define MAX_MOTORS 12
+#define MOTOR_STATE_PRESENT_MASK 0x80
+#define MOTOR_STATE_ERROR_MASK 0x7F
+#define MOTOR_STATE_NEW_PROTOCOL_MASK 0x01
+#define BLFLAG_TX_COMPLETE 0x01
+#define BLFLAG_READ_VERSION 0x02
+
+extern volatile uint8_t BLFlags;
+extern char MotorenEin;
+unsigned char MotorTest[16];
+#define BL_READMODE_STATUS 0
+#define BL_READMODE_CONFIG 16
+
+
+
+extern MotorData_t Motor[MAX_MOTORS];
+
+#define BLCONFIG_REVISION 2
+
+#define MASK_SET_PWM_SCALING 0x01
+#define MASK_SET_CURRENT_LIMIT 0x02
+#define MASK_SET_TEMP_LIMIT 0x04
+#define MASK_SET_CURRENT_SCALING 0x08
+#define MASK_SET_BITCONFIG 0x10
+#define MASK_RESET_CAPCOUNTER 0x20
+#define MASK_SET_DEFAULT_PARAMS 0x40
+#define MASK_SET_SAVE_EEPROM 0x80
+
+#define BITCONF_REVERSE_ROTATION 0x01
+#define BITCONF_RES1 0x02
+#define BITCONF_RES2 0x04
+#define BITCONF_RES3 0x08
+#define BITCONF_RES4 0x10
+#define BITCONF_RES5 0x20
+#define BITCONF_RES6 0x40
+#define BITCONF_RES7 0x80
+
+
+
+extern BLConfig_t BLConfig;
+
+extern volatile uint16_t I2CTimeout;
+
+void I2C_Init(char); // Initialize I2C
+#define I2C_Start(start_state) {twi_state = start_state; BLFlags &= ~BLFLAG_TX_COMPLETE; TWCR = (1<<TWSTA) | (1<<TWEN) | (1<<TWINT) | (1<<TWIE);}
+#define I2C_Stop(start_state) {twi_state = start_state; TWCR = (1<<TWEN) | (1<<TWSTO) | (1<<TWINT);}
+void I2C_Reset(void); // Reset I2C
+
+#define BLCONFIG_SUCCESS 0
+#define BLCONFIG_ERR_MOTOR_RUNNING 1
+#define BLCONFIG_ERR_MOTOR_NOT_EXIST 2
+#define BLCONFIG_ERR_HW_NOT_COMPATIBLE 3
+#define BLCONFIG_ERR_SW_NOT_COMPATIBLE 4
+#define BLCONFIG_ERR_CHECKSUM 5
+#define BLCONFIG_ERR_READ_NOT_POSSIBLE 6
+
+uint8_t I2C_WriteBLConfig(uint8_t motor);
+uint8_t I2C_ReadBLConfig(uint8_t motor);
+
+#endif
+
+
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/osd/.directory
0,0 → 1,3
[Dolphin]
Timestamp=2013,3,11,20,48,32
ViewMode=1
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/osd/osd.c
0,0 → 1,2725
/*****************************************************************************
* 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*
*****************************************************************************/
 
//############################################################################
//# HISTORY osd.c
//#
//# 10.03.2013 OG
//# - fix: doppelte Degree-Anzeige in OSD_Element_CompassDegree()
//# - add: neuer Screen "MK-Status"
//# - add: 7 neue OSD-Flags
//# - chg: Screen-Refresh Zeit via timer2 (einstellbar durch define OSD_REFRESH_TIME)
//# - chg: mit define OSD_DEBUG_SCREEN kann ein zusaetzlicher Screen verwendet werden zum testen/entwickeln
//# - del: entfernt CFG2_HEIGHT_LIMIT in OSD_Element_AltitudeControl() (bis bessere Loesung gefunden ist)
//#
//# 08.03.2013 OG
//# - del: OSD_Screen_Element() und cleanup in osd.h
//# - add: OSD_Element_UpDown() (steigend/sinken via Pfeilen)
//# - chg: OSD_Element_UpDown() in Screen "General" und "Navigation" hinzugefuegt (rechts neben der Hoehenanzeige)
//# - chg: Screen "General" die Sat-Warnung wurde auf OSD_Element_Flag(OSD_FLAG_S0) geaendert
//# - chg: Anzeige von Flag 'nicht genug GPS-Sateliten' (OSD_FLAG_S0) auf "S!" geändert
//#
//# 07.03.2013 OG
//# - Hinweis bzgl. LowBatt-Anzeige in den Screens "General" und "Navigation":
//# Es gibt zwei unabhängige LowBatt-Warnungen.
//# 1. die PKT LowBatt-Warnung: sie arbeitet mit der im PKT hinterlegten
//# LowBatt Spannung und stellt den Spannungswert inkl. der Einheit "V"
//# invers dar wenn der Warnwert erreicht wurde (inkl. lautem PKT-Peepen)
//# 2. die MK-LowBatt Warnung: hierbeit wird das Flag "BA" angezeigt wenn
//# der MK eine LowBatt Warnung sendet
//# Dadurch hat man nun zwei verschiedene LowBatt Warnungen die man auf Wunsch
//# verschieden einstellen kann. Bei mir ist die PKT-LowBatt etwas niedriger
//# eingestellt als die MK-Warnung und bedeutet "es ist aller hoechste Zeit zu landen".
//# Die Spannung der MK-LowBat ist ein wenig hoeher eingestellt und
//# zeigt mir "es ist bald Zeit zu landen".
//# - del: Kommunikation zu FC - siehe Kommentare in osd()
//# - chg: Kommunikation zu NC - siehe Kommentare in osd()
//# - add: neuer Screen "Navigation"
//# - chg: Layout Screen "Statistics" - Einheiten um zwei Pixel nach rechts verschoben
//# - chg: Layout von Screen "General" modifiziert (u.a. xoffs,yoffs Pixelverschiebungen)
//# - add: OSD_FLAG_BA in Screen "General"
//# - add: die OSD_Element_xyz() Funktionen in osd.h aufgenommen
//# - chg: an verschiedenen Stellen die Char-Drawmode defines MNORMAL, MINVERS, usw. eingebaut
//# - del: Kompatibilitaetscode fuer "3D-Lage" ueber Hauptmenue entfernt
//# - chg: die Funktionen OSD_Element_Switch() und OSD_Element_SwitchLabel() heissen
//# nun OSD_Element_Flag() und OSD_Element_Flag_Label()
//# - chg: die defines OSD_SWITCH_xy heissen jetzt OSD_FLAG_xy
//# - fix: letzte GPS-Koordinaten werden jetzt permanent Config.LastLatitude, Config.LastLongitude gespeichert
//#
//# 03.03.2013 OG
//# - add: delay in Mainloop von osd() um springende Werte abzudaempfen (TEST)
//# - add: Startverzoegerung der Screens bis NaviData sich etwas stabilisiert hat (TEST)
//# - add: OSD Startup Message "connecting MK..."
//# - add: 'Emergency Landing' (EL) Anzeige in Screen "General"
//# - del: OUT1/OUT2 Anzeige in Screen "General"
//# - add: RC-Quality in Screen "General"
//# - add: func: draw_symbol_rc() (alternative RC-Quality Symbol)
//# - fix: Hoehenanzeige fuer Screens "OSD0" und "OSD1"
//# - fix: OSD_Element_SwitchLabel() angepasst fuer x=0 und y=0
//# - add: OSD_Element_Switch/Label() erweitert um OSD_SWITCH_FS
//# - fix: Screen-Redraw nach OSD_Timeout() und anderen Fehlermeldungen
//# - chg: messages.c: STATS_ITEM_0 bis STATS_ITEM_6 angepasst (1 char kuerzer)
//# - chg: Layout von OSD_Info() - mehr background-clear und etwas kleiner
//#
//# 02.03.2013 OG
//# - chg: keine internal func in Screen's wegen warnings bei anderen
//# - del: Screen "OSD3"
//# - fix: Hoehenanzeige in Screen "General" (Minuszeichen)
//# - add: MK LowBat Warning in Screen "General"
//# - add: neues Degree Symbol (als func) in Screen General (kleiner als das Char 0x1E)
//# - add: weitere Flags in OSD_Element_Flag()
//#
//# 01.03.2013 OG
//# - Reskrukturierung Code (+ neuer OSD-Screens und einiges mehr)
//############################################################################
 
 
//############################################################################
//# HINWEISE:
//#
//# 1. define: OSD_DEMO
//# mit define OSD_DEMO wird ein Demo-Modus bei den neuen Screens einge-
//# schaltet - damit werden u.a. alle Flag's angezeigt fuer Scree-Fotos
//#
//# 2. define: OSD_DEBUG_SCREEN
//# mit diesem define wird ein zusaetzlicher Screen "Debug" einkompiliert
//# fuer Test / Experimente / Debug von OSD-Elementen
//#
//# 3. Informationen zum Display
//# DOG: 128 x 64 Pixel with 6x8 Font => 21 x 8
//############################################################################
 
 
#include "../cpu.h"
#include <avr/io.h>
#include <inttypes.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
 
#include "../main.h"
#include "../osd/osd.h"
#include "../lcd/lcd.h"
#include "../timer/timer.h"
#include "../uart/usart.h"
#include "../eeprom/eeprom.h"
#include "../messages.h"
#include "../parameter.h"
#include "../sound/pwmsine8bit.h"
#include "../mk-data-structs.h"
 
 
//#define OSD_DEMO // zeigt Demo-Daten in den OSD-Screens (sofern vom Screen unterstuetzt)
//#define OSD_DEBUG_SCREEN // zusaetzlichen Debug-Screen aktivieren
 
#define OSD_REFRESH_TIME 45 // Screen Refresh; ein Wert von 100 entspricht ca. 1 Sekunde (Steuerung via timer2)
 
#define COSD_WASFLYING 4
#define TIMEOUT 200 // 2 sec
 
 
// Hier Höhenanzeigefehler Korrigieren
#define AltimeterAdjust 1.5
 
 
// global definitions and global vars
NaviData_t *naviData;
mk_param_struct_t *mk_param_struct;
uint8_t Flags_ExtraConfig;
uint8_t Flags_GlobalConfig;
uint8_t Flags_GlobalConfig3;
unsigned char Element;
uint16_t heading_home;
uint8_t drawmode;
 
// flags from last round to check for changes
uint8_t old_FCFlags = 0;
uint8_t old_AngleNick = 0;
uint8_t old_AngleRoll = 0;
uint16_t old_hh = 0;
 
// stats for after flight
int16_t max_Altimeter = 0;
uint16_t max_GroundSpeed = 0;
int16_t max_Distance = 0;
uint8_t min_UBat = 255;
uint16_t max_FlyingTime = 0;
uint16_t max_Current = 0;
uint16_t max_Capacity = 0;
 
// cache old vars for blinking attribute, checkup is faster than full
// attribute write each time
volatile uint8_t last_UBat = 255;
volatile uint8_t last_RC_Quality = 255;
 
volatile uint16_t ftimer = 0;
volatile uint8_t OSD_active;
 
uint8_t Vario_Beep_Up = 0;
uint8_t Vario_Beep_Down = 0;
uint8_t Vario_Beep_Up_Interval = 9;
uint8_t Vario_Beep_Down_Interval = 6;
uint8_t Vario_Threshold = 0;
uint8_t Vario_Threshold_Value = 7;
uint8_t OldWP = 0;
uint8_t NextWP = 0;
 
 
 
//char* rose = "-+-N-+-O-+-S-+-W-+-N-+-O-+-S-+-W-+-N-+-O-+-S-+-W";
const char rose[48] PROGMEM = {
0x0e, 0x0f, 0x0e, 'N', 0x0e, 0x0f, 0x0e, 'O', 0x0e, 0x0f, 0x0e, 'S',
0x0e, 0x0f, 0x0e, 'W', 0x0e, 0x0f, 0x0e, 'N', 0x0e, 0x0f, 0x0e, 'O',
0x0e, 0x0f, 0x0e, 'S', 0x0e, 0x0f, 0x0e, 'W', 0x0e, 0x0f, 0x0e, 'N',
0x0e, 0x0f, 0x0e, 'O', 0x0e, 0x0f, 0x0e, 'S', 0x0e, 0x0f, 0x0e, 'W',
};
 
// the center is char 19 (north), we add the current heading in 8th
// which would be 22.5 degrees, but float would bloat up the code
// and *10 / 225 would take ages... so we take the uncorrect way
 
const char str_NE[] PROGMEM = "NE";
const char str_E[] PROGMEM = "E ";
const char str_SE[] PROGMEM = "SE";
const char str_S[] PROGMEM = "S ";
const char str_SW[] PROGMEM = "SW";
const char str_W[] PROGMEM = "W ";
const char str_NW[] PROGMEM = "NW";
const char str_N[] PROGMEM = "N ";
const char *directions_p[8] PROGMEM = {
str_NE,
str_E,
str_SE,
str_S,
str_SW,
str_W,
str_NW,
str_N
};
 
 
#define MAX_CELL_VOLTAGE 43 // max cell voltage for LiPO
#define MIN_CELL_VOLTAGE 32 // min cell voltage for LiPO
 
// Flags
GPS_Pos_t last5pos[7];
uint8_t COSD_FLAGS2 = 0;
volatile uint8_t error = 0;
uint8_t cells = 0;
uint8_t BattLowVoltageWarning = 0;
uint8_t CellIsChecked = 0;
uint8_t AkkuWarnThreshold = 0;
uint16_t duration = 0;
 
 
 
//###########################################################
//###########################################################
 
//--------------------------------------------------------------
//--------------------------------------------------------------
void variobeep(int16_t vario)
{
{ //start Beep
 
if (vario >0 ) // MK steigt
{
Vario_Beep_Down = 0; // Down Beep freischalten
Vario_Threshold++;
 
if ((Vario_Beep_Up == 0) && (Vario_Threshold >= Vario_Threshold_Value))
{
// set_beep ( 100, 0xffff, BeepNormal);
duration = 52 -vario;
// if (duration =0); duration = 1;
 
// write_ndigit_number_u (0,6,duration,5,0);
 
playTone(300+vario*2,duration,Config.Volume);
// playTone(300,duration,volume);
Vario_Threshold = Vario_Threshold_Value; // auf Maximalwert begrenzen
}
Vario_Beep_Up++; // Interval hochzählen in dem nicht gepiept wird
if (Vario_Beep_Up == Vario_Beep_Up_Interval) Vario_Beep_Up = 0;
}
 
if (vario <0) // MK fällt
{
Vario_Beep_Up = 0; // Up Beep freischalten
Vario_Threshold++;
if ((Vario_Beep_Down == 0) && (Vario_Threshold >= Vario_Threshold_Value))
{
duration = 50 -vario;
// write_ndigit_number_u (0,7,duration,5,0);
// if (duration < vario) ; duration = 0;
// playTone(300,50,volume);
 
 
playTone(300+vario*2,duration,Config.Volume);
Vario_Threshold = Vario_Threshold_Value; // auf Maximalwert begrenzen
}
Vario_Beep_Down++; // Interval hochzählen in dem nicht gepiept wird
if (Vario_Beep_Down == Vario_Beep_Down_Interval) Vario_Beep_Down = 0;
}
 
if (vario == 0) Vario_Threshold = 0; //Startverzögerung löschen
} // end Beep
 
}
 
 
//--------------------------------------------------------------
// Diese Funktion Beept unabhaengig von der Einstellung Config.OSD_VarioBeep
// Aufruf ggf. mit: if( Config.OSD_VarioBeep ) Beep_Vario();
//
// Ansonten:
// -> hier noch aufräumen in Zusammenhang mit func variobeep()
//--------------------------------------------------------------
void Beep_Vario(void)
{
if ( (naviData->FCStatusFlags & FC_STATUS_MOTOR_RUN) && (naviData->FCStatusFlags2 & FC_STATUS2_ALTITUDE_CONTROL))
{ //start Beep
if (naviData->Variometer <0) // MK fällt
{
Vario_Beep_Up = 0; // Up Beep freischalten
Vario_Threshold++;
if ((Vario_Beep_Down == 0) && (Vario_Threshold >= Vario_Threshold_Value))
{
 
if (!Config.HWSound) set_beep ( 300, 0xffff, BeepNormal);
else variobeep(naviData->Variometer);
 
Vario_Threshold = Vario_Threshold_Value; // auf Maximalwert begrenzen
}
Vario_Beep_Down++; // Interval hochzählen in dem nicht gepiept wird
if (Vario_Beep_Down == Vario_Beep_Down_Interval) Vario_Beep_Down = 0;
}
 
if (naviData->Variometer == 0) Vario_Threshold = 0; //Startverzögerung löschen
 
if (naviData->Variometer >0 ) // MK steigt
{
Vario_Beep_Down = 0; // Down Beep freischalten
Vario_Threshold++;
 
if ((Vario_Beep_Up == 0) && (Vario_Threshold >= Vario_Threshold_Value))
{
if (!Config.HWSound) set_beep ( 100, 0xffff, BeepNormal);
else variobeep(naviData->Variometer);
Vario_Threshold = Vario_Threshold_Value; // auf Maximalwert begrenzen
}
Vario_Beep_Up++; // Interval hochzählen in dem nicht gepiept wird
if (Vario_Beep_Up == Vario_Beep_Up_Interval) Vario_Beep_Up = 0;
}
} // end Beep
}
 
 
 
//--------------------------------------------------------------
// Quelle Mikrokopter FC-Software Holger + Ingo
//--------------------------------------------------------------
void CheckMKLipo(void)
{
if(Config.MK_LowBat < 50) // automatische Zellenerkennung
{
if (CellIsChecked <= 2) //Nur beim Start 1x prüfen
{
// up to 6s LiPo, less than 2s is technical impossible
for(cells = 2; cells < 7; cells++)
{
if(naviData->UBat < cells * MAX_CELL_VOLTAGE) break;
}
BattLowVoltageWarning = cells * Config.MK_LowBat;
CellIsChecked++;
}
}
else BattLowVoltageWarning = Config.MK_LowBat;
 
if (naviData->UBat < BattLowVoltageWarning)
{
if (AkkuWarnThreshold <= 4) AkkuWarnThreshold++;
else
{ //Beeper ein
set_beep ( 1000, 0x0020, BeepSevere);
// BeepTime = 3000;
// BeepMuster = 0x0020;
}
}
}
 
 
//--------------------------------------------------------------
// convert the <heading> gotton from NC into an index
uint8_t heading_conv (uint16_t heading)
{
if (heading > 23 && heading < 68)
return 0; //direction = "NE";
else if (heading > 67 && heading < 113)
return 1; //direction = "E ";
else if (heading > 112 && heading < 158)
return 2; //direction = "SE";
else if (heading > 157 && heading < 203)
return 3; //direction = "S ";
else if (heading > 202 && heading < 248)
return 4; //direction = "SW";
else if (heading > 247 && heading < 293)
return 5; //direction = "W ";
else if (heading > 292 && heading < 338)
return 6; //direction = "NW";
 
return 7; //direction = "N ";
}
 
 
//--------------------------------------------------------------
// draw a compass rose at <x>/<y> for <heading>
void draw_compass (uint8_t x, uint8_t y, uint16_t heading)
{
uint8_t front = 19 + (heading / 22);
for (uint8_t i = 0; i < 9; i++)
lcd_putc (x++, y, pgm_read_byte(&rose[front - 4 + i]), 0);
}
 
 
//--------------------------------------------------------------
// variometer
// x, y in Pixel!
//--------------------------------------------------------------
void draw_variometer (uint8_t x, uint8_t y, uint8_t width, uint8_t hight, int16_t variometer)
{
lcd_rect (x, y - ((hight) / 2), width, hight, 1);
lcd_frect (x + 1, y - ((hight) / 2) + 1, width - 2, hight - 2, 0);
lcd_line (x, y, x + width, y, 1);
 
if (variometer > 0) // steigend
{
switch (variometer / 5)
{
case 0:
lcd_line (x + 4, y - 1, x + 6, y - 1, 1); // 1 > 4
break;
 
case 1:
lcd_line (x + 4, y - 1, x + 6, y - 1, 1); // 1 > 4
lcd_frect (x + 3, y - 3, 4, 1, 1); // 5 > 9
break;
 
case 2:
lcd_line (x + 4, y - 1, x + 6, y - 1, 1); // 1 > 4
lcd_frect (x + 3, y - 3, 4, 1, 1); // 5 > 9
lcd_frect (x + 2, y - 5, 6, 1, 1); // 10 > 14
break;
 
default:
lcd_line (x + 4, y - 1, x + 6, y - 1, 1); // 1 > 4
lcd_frect (x + 3, y - 3, 4, 1, 1); // 5 > 9
lcd_frect (x + 2, y - 5, 6, 1, 1); // 10 > 14
lcd_frect (x + 1, y - 6, 8, 1, 1); // 15 >
break;
}
}
else if (variometer < 0) // fallend
{
switch ((variometer) / -5)
{
case 0:
lcd_line (x + 4, y + 1, x + 6, y + 1, 1); // - 1 > - 4
break;
 
case 1:
lcd_line (x + 4, y + 1, x + 6, y + 1, 1); // - 1 > - 4
lcd_frect (x + 3, y + 2, 4, 1, 1); // - 5 > - 9
break;
 
case 2:
lcd_line (x + 4, y + 1, x + 6, y + 1, 1); // - 1 > - 4
lcd_frect (x + 3, y + 2, 4, 1, 1); // - 5 > - 9
lcd_frect (x + 2, y + 4, 6, 1, 1); // -10 > -14
break;
 
default:
lcd_line (x + 4, y + 1, x + 6, y + 1, 1); // - 1 > - 4
lcd_frect (x + 3, y + 2, 4, 1, 1); // - 5 > - 9
lcd_frect (x + 2, y + 4, 6, 1, 1); // -10 > -14
lcd_frect (x + 1, y + 5, 8, 1, 1); // -15 >
break;
}
}
}
 
 
//--------------------------------------------------------------
// variometer 2
//
// x, y in Pixel
// x, y top, left
//--------------------------------------------------------------
/*
void draw_variometer2( uint8_t x, uint8_t y, uint8_t width, uint8_t hight, int16_t variometer)
{
uint8_t max = 5; // max: 5 m/sec == 100%
 
lcd_rect (x, y, width, hight, 1);
lcd_frect(x + 1, y + 1, width - 2, hight - 2, 0);
lcd_line (x, y + ((hight) / 2), x + width, y + ((hight) / 2), 1);
 
}
*/
 
 
//--------------------------------------------------------------
// Home symbol
// draw Homesymbol at <x>/<y>
//--------------------------------------------------------------
void draw_homesymbol (uint8_t x, uint8_t y)
{
x *= 6;
y *= 8;
y += 7;
 
lcd_plot (x,y-4,1);
lcd_line (x+1,y-1,x+1,y-5,1);
lcd_plot (x+2,y-6,1);
lcd_plot (x+3,y-7,1);
lcd_plot (x+4,y-6,1);
lcd_line (x+5,y-1,x+5,y-5,1);
lcd_plot (x+6,y-4,1);
lcd_plot (x+3,y-1,1);
lcd_plot (x+3,y-2,1);
lcd_line (x+1,y,x+5,y,1);
 
}
 
//--------------------------------------------------------------
// Target symbol
// draw Targetsymbol at <x>/<y>
//--------------------------------------------------------------
void draw_targetsymbol (uint8_t x, uint8_t y)
{
x *= 6;
y *= 8;
y += 7;
 
lcd_circle (x+3, y-3, 4, 1);
lcd_line (x,y-3,x+6,y-3,1);
lcd_line (x+3,y,x+3,y-6,1);
lcd_circle (x+3, y-3, 2, 1);
}
 
 
//--------------------------------------------------------------
// Degree symbol
// draw Degreesymbol at <x>/<y>
//
// Ein etwas kleineres Degeree als Char 0x1E
//--------------------------------------------------------------
void draw_symbol_degree (uint8_t x, uint8_t y, int8_t xoffs, int8_t yoffs)
{
x *= 6;
y *= 8;
lcd_rect (x+1+xoffs, y+yoffs, 2, 2, 1);
}
 
 
//--------------------------------------------------------------
// RC symbol
// alternatives Symbol fuer RC-Quality
//--------------------------------------------------------------
void draw_symbol_rc (uint8_t x, uint8_t y)
{
x *= 6;
y *= 8;
y += 1;
x += 1;
lcd_plot ( x+3, y+4, 1);
lcd_line ( x+2, y+2, x+4, y+2, 1);
lcd_line ( x+1, y+0, x+5, y+0, 1);
}
 
 
//--------------------------------------------------------------
void print_position (void)
{
lcd_cls ();
lcd_puts_at(0, 0, strGet(START_LASTPOS1), 2); // Breitengr Längengr
lcd_puts_at(12, 7, strGet(ENDE), 0);
uint8_t ij =0;
 
for(ij=0;ij<6;ij++)
{
uint32_t lon = last5pos[ij].Latitude;
write_ndigit_number_u (1, ij+1, (uint16_t)(lon/10000000), 2, 0,0);
lcd_printp_at (3, ij+1, PSTR("."), 0);
write_ndigit_number_u (4, ij+1, (uint16_t)((lon/1000) % 10000), 4, 1,0);
write_ndigit_number_u (8, ij+1, (uint16_t)((lon/10) % 100), 2, 1,0);
 
uint32_t lat = last5pos[ij].Longitude;
write_ndigit_number_u (12, ij+1, (uint16_t)(lat/10000000), 2, 0,0);
lcd_printp_at (14, ij+1, PSTR("."), 0);
write_ndigit_number_u (15, ij+1, (uint16_t)((lat/1000) % 10000), 4, 1,0);
write_ndigit_number_u (19, ij+1, (uint16_t)((lat/10) % 100), 2, 1,0);
}
 
while (!get_key_press (1 << KEY_ESC))
timer = TIMEOUT;
 
get_key_press(KEY_ALL);
lcd_cls();
}
 
 
//--------------------------------------------------------------
void Show_LastPosition(void)
{
lcd_puts_at(0, 2, strGet(OSD_POS1), 0);
lcd_puts_at(0, 3, strGet(OSD_POS2), 0);
lcd_puts_at(0, 5, strGet(START_LASTPOS1), 0);
uint32_t lon = last5pos[0].Latitude;
write_ndigit_number_u (1, 6, (uint16_t)(lon/10000000), 2, 0,0);
lcd_printp_at (3, 6, PSTR("."), 0);
write_ndigit_number_u (4, 6, (uint16_t)((lon/1000) % 10000), 4, 1,0);
write_ndigit_number_u (8, 6, (uint16_t)((lon/10) % 100), 2, 1,0);
 
uint32_t lat = last5pos[0].Longitude;
write_ndigit_number_u (12, 6, (uint16_t)(lat/10000000), 2, 0,0);
lcd_printp_at (14, 6, PSTR("."), 0);
write_ndigit_number_u (15, 6, (uint16_t)((lat/1000) % 10000), 4, 1,0);
write_ndigit_number_u (19, 6, (uint16_t)((lat/10) % 100), 2, 1,0);
 
}
 
 
//--------------------------------------------------------------
void OSD_Timeout(uint8_t flag)
{
 
// uint8_t flag;
uint8_t tmp_dat;
// flag = 0;
timer = TIMEOUT;
// disable OSD Data from NC
// RS232_request_mk_data (1, 'o', 0);
// tmp_dat = 0;
// SendOutData ('o', ADDRESS_NC, 1, &tmp_dat, 1);
 
mode = 0;
rxd_buffer_locked = FALSE;
 
 
// Bei Verbindungsverlusst werden hier die letzten bekannten Koordinaten ausgegeben!!!
if( flag )
{
// Falls Spannungswarnung an war Beeper aus//
 
set_beep ( 0, 0, BeepOff);
 
lcd_cls ();
WriteLastPosition(last5pos[0].Longitude,last5pos[0].Latitude); // im EEprom speichern
lcd_puts_at(0, 0, strGet(OSD_ERROR), 2); // ERROR: Datenverlust
lcd_puts_at(0, 2, strGet(OSD_POS1), 0); // Letzte bekannte
lcd_puts_at(0, 3, strGet(OSD_POS2), 0); // Position gespeichert.
lcd_puts_at(0, 5, strGet(START_LASTPOS1), 0); // Breitengr Längengr
// lcd_puts_at(12, 7, strGet(ENDE), 0);
// lcd_puts_at(19, 7, strGet(OK), 0);
// if (OSD_RCErrorbeep==true)
// {
set_beep ( 250, 0x0040, BeepNormal);
// }
 
uint32_t lon = last5pos[0].Latitude;
write_ndigit_number_u (1, 6, (uint16_t)(lon/10000000), 2, 0,0);
lcd_printp_at (3, 6, PSTR("."), 0);
write_ndigit_number_u (4, 6, (uint16_t)((lon/1000) % 10000), 4, 1,0);
write_ndigit_number_u (8, 6, (uint16_t)((lon/10) % 100), 2, 1,0);
 
uint32_t lat = last5pos[0].Longitude;
write_ndigit_number_u (12, 6, (uint16_t)(lat/10000000), 2, 0,0);
lcd_printp_at (14, 6, PSTR("."), 0);
write_ndigit_number_u (15, 6, (uint16_t)((lat/1000) % 10000), 4, 1,0);
write_ndigit_number_u (19, 6, (uint16_t)((lat/10) % 100), 2, 1,0);
 
// while (!get_key_press (1 << KEY_ENTER));
// _delay_ms(1000);
timer = TIMEOUT;
// lcd_cls();
// return;
}
else
{
lcd_puts_at(0, 0, strGet(OSD_ERROR), 2);
Show_LastPosition();
if (Config.OSD_RCErrorbeep==true) set_beep ( 200, 0x0080, BeepNormal);
// _delay_ms(2000);
}
 
rxd_buffer_locked = FALSE; // 07.03.2013 OG: fix
// es gab Probleme mit dem Empfang gueltiger NC-Daten, die zu unschoenen Starteffekten bei den
// OSD-Screens gefuehrt haben. Mit rxd_buffer_locked = FALSE vor SwitchToNC() ist das PKT wieder im 'Takt'
 
SwitchToNC();
 
mode = 'O';
 
// disable debug...
// RS232_request_mk_data (0, 'd', 0);
tmp_dat = 0;
SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
 
// request OSD Data from NC every 100ms
// RS232_request_mk_data (1, 'o', 100);
tmp_dat = 10;
SendOutData ('o', ADDRESS_NC, 1, &tmp_dat, 1);
 
//_delay_ms(100);
//rxd_buffer_locked = FALSE;
}
 
 
 
 
//-----------------------------------------------------------
//
void lcd_o_circle (uint16_t x, uint16_t y, int16_t breite, uint8_t mode, int8_t xoffs, int8_t yoffs)
{
breite *= 6;
int16_t radius = breite / 2;
x += 2;
x *= 6;
x += 2;
y += 1;
y *= 8;
y += 3;
 
// 04.03.2012 OG: chg: x-radius von -3 auf -2 (runder auf dem display)
//lcd_ellipse (x, y, radius - 3, radius - 5, mode);
lcd_ellipse( x+xoffs, y+yoffs, radius - 2, radius - 5, mode);
}
 
 
//-----------------------------------------------------------
// lcd_o_circ_line( x, y, breite, deg, rOffset, mode)
//
// x, y : in Chars
// breite : in Chars
// deg : in Pixel
// rOffset: Beeinflusst den Schluss der Linie zum Huellkreis
// 0 = Standard
// >0 naeher zum Huellkreis
// <0 entfernter vom Huellkreis
// mode : siehe: lcd_ellipse_line()
//-----------------------------------------------------------
void lcd_o_circ_line( uint16_t x, uint16_t y, uint8_t breite, uint16_t deg, int8_t rOffset, uint8_t mode, int8_t xoffs, int8_t yoffs)
{
breite *= 6;
int16_t radius = breite / 3;
x += 2;
x *= 6;
x += 2;
y += 1;
y *= 8;
y += 3;
 
// 04.03.2013 OG: der Radius kann mit rOffset >0 vergroessert werden um zum Kreis aufzuschliessen
lcd_ellipse_line( x+xoffs, y+yoffs, radius+rOffset, radius+rOffset, deg, mode);
}
 
 
//--------------------------------------------------------------
void draw_icon_home(uint8_t x, uint8_t y)
{
//lcd_plot( x+0, y+0, 1); // Referenz 0,0
lcd_rect( x+0, y+5, 10, 8, 1); // Mitte
lcd_line( x+5, y+0, x+0, y+5, 1); // Dach Links
lcd_line( x+5, y+0, x+10, y+5, 1); // Dach Rechts
lcd_rect( x+4, y+10, 2, 3, 1); // Tuere
}
 
 
//--------------------------------------------------------------
void draw_icon_sat(uint8_t x, uint8_t y)
{
//lcd_plot( x+0, y+0, 1); // Referenz 0,0
lcd_rect( x+0, y+2, 4, 2, 1); // linker Fluegel
lcd_rect( x+8, y+2, 4, 2, 1); // rechter Fluegel
lcd_rect( x+4, y+0, 4, 6, 1); // Mitte, oben
lcd_line( x+6, y+7, x+2, y+11, 1); // Strahl Links
lcd_line( x+6, y+7, x+10, y+11, 1); // Strahl Rechts
lcd_line( x+1, y+12, x+11, y+12, 1); // Strahl Unten
}
 
 
//--------------------------------------------------------------
void draw_icon_battery(uint8_t x, uint8_t y)
{
//lcd_plot( x+0, y+0, 1); // Referenz 0,0
lcd_rect( x+2, y+0, 2, 2, 1); // der kleine Knubbel oben
lcd_rect( x+0, y+2, 6, 15, 1); // body
}
 
 
 
//##############################################################
//# OSD-ELEMENTS
//##############################################################
 
//--------------------------------------------------------------
// OSD_Element_Flag_Label( xC, yC, item, lOn, xoffs, yoffs)
//
// xC, yC : x,y in Characters
// item : OSD_FLAG_AH, OSD_FLAG_PH, usw.
// lOn : true / false
// xoffs,yoffs : x,y Pixelverschiebung
//--------------------------------------------------------------
void OSD_Element_Flag_Label( uint8_t xC, uint8_t yC, uint8_t item, uint8_t lOn, int8_t xoffs, int8_t yoffs)
{
int8_t x = (xC*6)-2;
int8_t y = (yC*8)-1;
uint8_t w = 14;
uint8_t h = 8;
 
const char *labels[OSD_FLAG_COUNT] =
{
PSTR("AH"), // OSD_FLAG_AH Altitue Hold
PSTR("PH"), // OSD_FLAG_PH Position Hold
PSTR("CF"), // OSD_FLAG_CF Care Free
PSTR("CH"), // OSD_FLAG_CH Coming Home
PSTR("o1"), // OSD_FLAG_O1 Out1
PSTR("o2"), // OSD_FLAG_O2 Out2
PSTR("BA"), // OSD_FLAG_BA LowBat warning (MK)
PSTR("CA"), // OSD_FLAG_CA Calibrate
PSTR("ST"), // OSD_FLAG_ST Start
PSTR("MR"), // OSD_FLAG_MR Motor Run
PSTR("FY"), // OSD_FLAG_FY Fly
PSTR("EL"), // OSD_FLAG_EL Emergency Landing
PSTR("FS"), // OSD_FLAG_FS RX Failsave Active
PSTR("GP"), // OSD_FLAG_GP GPS Ok
PSTR("S!"), // OSD_FLAG_S0 GPS-Sat not ok (GPS NOT ok)
PSTR("TU"), // OSD_FLAG_TU Vario Trim Up
PSTR("TD"), // OSD_FLAG_TD Vario Trim Down
PSTR("FR"), // OSD_FLAG_FR Free
PSTR("RL"), // OSD_FLAG_RL Range Limit
PSTR("SL"), // OSD_FLAG_SL No Serial Link
PSTR("TR"), // OSD_FLAG_TR Target Reached
PSTR("MC") // OSD_FLAG_MC Manual Control
};
 
//lcd_plot( x-2, y-2, 1); // Referenz
if( yC==0 ) { y = 0; h = 7; }
if( xC==0 ) { x = 0; w = 12; }
if( lOn )
{
lcd_frect( x+xoffs, y+yoffs, w, h, 1); // Filler
lcdx_printp_at( xC, yC, labels[item], MINVERS, xoffs,yoffs); // Label
}
else
{
lcd_frect( x+xoffs, y+yoffs, w, h, 0); // clear
}
}
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
void OSD_Element_Flag( uint8_t xC, uint8_t yC, uint8_t item, int8_t xoffs, int8_t yoffs)
{
uint8_t lOn = 0;
 
// FC_StatusFlags 0.88
switch( item )
{
// Altitue Hold
case OSD_FLAG_AH : lOn = (naviData->FCStatusFlags2 & FC_STATUS2_ALTITUDE_CONTROL);
break;
 
// Position Hold
case OSD_FLAG_PH : lOn = (naviData->NCFlags & NC_FLAG_PH);
break;
 
// Coming Home
case OSD_FLAG_CH : lOn = (naviData->NCFlags & NC_FLAG_CH);
break;
 
// Care Free
case OSD_FLAG_CF : lOn = (naviData->FCStatusFlags2 & FC_STATUS2_CAREFREE);
break;
 
// Out1
case OSD_FLAG_O1 : lOn = (naviData->FCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE);
break;
 
// Out2
case OSD_FLAG_O2 : lOn = (naviData->FCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE);
break;
 
// LowBat warning (MK)
case OSD_FLAG_BA : lOn = (naviData->FCStatusFlags & FC_STATUS_LOWBAT);
break;
 
// Calibrate
case OSD_FLAG_CA : lOn = (naviData->FCStatusFlags & FC_STATUS_CALIBRATE);
break;
 
// Start
case OSD_FLAG_ST : lOn = (naviData->FCStatusFlags & FC_STATUS_START);
break;
 
// Motor Run
case OSD_FLAG_MR : lOn = (naviData->FCStatusFlags & FC_STATUS_MOTOR_RUN);
break;
 
// Fly
case OSD_FLAG_FY : lOn = (naviData->FCStatusFlags & FC_STATUS_FLY);
break;
 
// Emergency Landing
case OSD_FLAG_EL : lOn = (naviData->FCStatusFlags & FC_STATUS_EMERGENCY_LANDING);
break;
 
// RC Failsave Active
case OSD_FLAG_FS : lOn = (naviData->FCStatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE);
break;
// GPS ok
case OSD_FLAG_GP : lOn = (naviData->NCFlags & NC_FLAG_GPS_OK);
break;
 
// GPS-Sat not ok (GPS NOT ok)
case OSD_FLAG_S0 : lOn = !(naviData->NCFlags & NC_FLAG_GPS_OK);
break;
 
// Vario Trim Up
case OSD_FLAG_TU : lOn = (naviData->FCStatusFlags & FC_STATUS_VARIO_TRIM_UP);
break;
// Vario Trim Down
case OSD_FLAG_TD : lOn = (naviData->FCStatusFlags & FC_STATUS_VARIO_TRIM_DOWN);
break;
 
// Free
case OSD_FLAG_FR : lOn = (naviData->NCFlags & NC_FLAG_FREE);
break;
 
// Range Limit
case OSD_FLAG_RL : lOn = (naviData->NCFlags & NC_FLAG_RANGE_LIMIT);
break;
 
// No Serial Link
case OSD_FLAG_SL : lOn = (naviData->NCFlags & NC_FLAG_NOSERIALLINK);
break;
 
// Target Reached
case OSD_FLAG_TR : lOn = (naviData->NCFlags & NC_FLAG_TARGET_REACHED);
break;
 
// Manual Control
case OSD_FLAG_MC : lOn = (naviData->NCFlags & NC_FLAG_MANUAL_CONTROL);
break;
 
}
OSD_Element_Flag_Label( xC, yC, item, lOn, xoffs,yoffs);
}
 
 
//--------------------------------------------------------------
// OSD_Element_AltitudeControl( x, y)
//--------------------------------------------------------------
void OSD_Element_AltitudeControl( uint8_t x, uint8_t y )
{
//---------------------------------------------------------
// 10.03.2013 OG:
// CFG2_HEIGHT_LIMIT im Augenblick nicht unterstuetzt
// Siehe Anmerkungen in osd()
//---------------------------------------------------------
/*
if (Flags_ExtraConfig & CFG2_HEIGHT_LIMIT)
{
if (naviData->FCStatusFlags2 & FC_STATUS2_ALTITUDE_CONTROL)
lcd_puts_at (x, y, strGet(OSD_ALTI_1), 0); // Höhe begr.
else
lcd_puts_at (x, y, strGet(OSD_ALTI_0), 0); // Höhe aus
}
else
{
if (naviData->FCStatusFlags2 & FC_STATUS2_ALTITUDE_CONTROL)
lcd_puts_at (x, y, strGet(OSD_VARIO_1), 0); // Vario Höhe
else
lcd_puts_at (x, y, strGet(OSD_VARIO_0), 0); // Vario aus
}
*/
 
if (naviData->FCStatusFlags2 & FC_STATUS2_ALTITUDE_CONTROL)
lcd_puts_at (x, y, strGet(OSD_VARIO_1), 0); // Vario Höhe
else
lcd_puts_at (x, y, strGet(OSD_VARIO_0), 0); // Vario aus
 
}
 
 
//--------------------------------------------------------------
// Anzeige von Steigen / Sinken
//--------------------------------------------------------------
void OSD_Element_UpDown( uint8_t x, uint8_t y, int8_t xoffs, int8_t yoffs)
{
x = (x*6) + xoffs;
y = (y*8) + yoffs;
 
lcd_frect( x, y, 6, 7, 0); // clear
if( naviData->Variometer > 2 ) // steigen mehr als 0.2 m/sec (ein guter Wert muss noch in der Praxis ermittelt werden)
{
lcd_line( x+2, y+0, x+0, y+2, 1);
lcd_line( x+2, y+0, x+4, y+2, 1);
}
else if( naviData->Variometer < -2 ) // sinken mehr als 0.2 m/sec
{
lcd_line( x+2, y+6, x+0, y+4, 1);
lcd_line( x+2, y+6, x+4, y+4, 1);
}
 
}
 
 
//--------------------------------------------------------------
// OSD_Element_Altitude( x, y, nStyle)
// nStyle entspricht dem ehemaligen 'Mode'
//--------------------------------------------------------------
void OSD_Element_Altitude( uint8_t x, uint8_t y, uint8_t nStyle )
{
switch( nStyle )
{
case 0 :
case 1 : //note:lephisto:according to several sources it's /30
if (naviData->Altimeter > (300 / AltimeterAdjust) || naviData->Altimeter < (-300 / AltimeterAdjust)) // above 10m only write full meters
write_ndigit_number_s (x, y, naviData->Altimeter / (30 / AltimeterAdjust), 4, 0,MNORMAL);
else // up to 10m write meters.dm
write_ndigit_number_s_10th (x, y, naviData->Altimeter / (3 / AltimeterAdjust), 3, 0,MNORMAL);
 
lcd_printp_at (x+4, y, PSTR("m"), MNORMAL);
lcd_putc (x+5, y, 0x09, 0); // Hoehensymbol
break;
 
case 2 : //note:lephisto:according to several sources it's /30
if (naviData->Altimeter > (300 / AltimeterAdjust) || naviData->Altimeter < (-300 / AltimeterAdjust)) // above 10m only write full meters
write_ndigit_number_s (x+4, y, naviData->Altimeter / (30 / AltimeterAdjust), 4, 0,MBIG);
else // up to 10m write meters.dm
write_ndigit_number_s_10th (x+4, y, naviData->Altimeter / (3 / AltimeterAdjust), 3, 0,MBIG);
lcd_putc( x+8, y, 'm', MBIG);
lcd_printp_at (x, y, PSTR("Höhe"), MNORMAL);
break;
}
}
 
 
//--------------------------------------------------------------
// fuer: Config.OSD_LipoBar==1
//--------------------------------------------------------------
void OSD_Element_BatteryLevel_Bar( uint8_t x, uint8_t y )
{
uint16_t Balken = 0;
 
drawmode = (naviData->UBat < BattLowVoltageWarning ? 2 : 0);
if( cells > 0 ) // LipobargraphAnzeige nur wenn Anzahl der Lipozellen bekannt sind
{
write_ndigit_number_u (x+6, y, cells, 1, 0, drawmode);
lcd_printp_at (x+7, y, PSTR("S"), drawmode);
 
if( cells==3 )
{
lcd_rect(x*6, y*8, 28, 7, 1); // Rahmen
Balken = ((naviData->UBat-(cells*MIN_CELL_VOLTAGE))*10)/12;
if((Balken > 0) && (Balken <28)) lcd_frect((x*6)+1, (y*8)+1, Balken, 5, 1); // Fuellung
if(Balken <= 26) lcd_frect(Balken+(x*6)+1, (y*8)+1, 26-Balken, 5, 0); // loeschen
}
 
if( cells==4 ||cells==5 )
{
lcd_rect(x*6, y*8, 30, 7, 1); // Rahmen
if (cells == 4) Balken = ((naviData->UBat-(cells*MIN_CELL_VOLTAGE))*10)/15;
if (cells == 5) Balken = ((naviData->UBat-(cells*MIN_CELL_VOLTAGE))*10)/19;
if ((Balken > 0) && (Balken <=29)) lcd_frect((x*6)+1, (y*8)+1, Balken, 5, 1); // Fuellung
if (Balken <= 27) lcd_frect(Balken+(x*6)+1, (y*8)+1, 28-Balken, 5, 0); // loeschen
}
 
} // end if: cells > 0 (TODO: Anzeige fuer cells==0 implementieren)
}
 
 
 
//--------------------------------------------------------------
// fuer die neuen OSD-Screens
//--------------------------------------------------------------
void OSD_Element_BattLevel2( uint8_t x, uint8_t y, int8_t xoffs, int8_t yoffs )
{
drawmode = (naviData->UBat < BattLowVoltageWarning ? MINVERS : MNORMAL);
writex_ndigit_number_u_10th( x, y, naviData->UBat, 3, 0, drawmode, xoffs,yoffs);
lcdx_printp_at( x+4, y, PSTR("V"), drawmode, xoffs+1,yoffs); // Einheit
lcd_line( (x+4)*6, y*8, (x+4)*6, y*8+7, (drawmode==MINVERS ? 1 : 0) ); // filler zwischen Spannung und "V"
}
 
 
//--------------------------------------------------------------
// fuer: Config.OSD_LipoBar==0
// nStyle entspricht dem ehemaligen 'Mode'
//--------------------------------------------------------------
void OSD_Element_BatteryLevel_Text( uint8_t x, uint8_t y, uint8_t nStyle )
{
if( nStyle <= 1)
drawmode = (naviData->UBat < BattLowVoltageWarning ? 2 : 0); // Normal-Schrift
else
drawmode = (naviData->UBat < BattLowVoltageWarning ? 4 : 3); // Fett-Schrift
 
if( nStyle <= 1)
{
write_ndigit_number_u_10th (x, y, naviData->UBat, 3, 0, drawmode);
lcd_printp_at (x+4, y, PSTR("V"), drawmode);
}
else
{
write_ndigit_number_u_10th (x-2, y, naviData->UBat, 3, 0, drawmode);
lcd_printp_at (x+2, y, PSTR("V"), drawmode);
}
}
 
 
//--------------------------------------------------------------
// nStyle entspricht dem ehemaligen 'Mode'
//--------------------------------------------------------------
void OSD_Element_BatteryLevel( uint8_t x, uint8_t y, uint8_t nStyle )
{
if( Config.OSD_LipoBar )
OSD_Element_BatteryLevel_Bar( x, y);
else
OSD_Element_BatteryLevel_Text( x, y, nStyle);
}
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
void OSD_Element_Capacity( uint8_t x, uint8_t y )
{
drawmode = (naviData->UsedCapacity > Config.OSD_mAh_Warning ? 2 : 0);
write_ndigit_number_u (x, y, naviData->UsedCapacity, 5, 0, drawmode);
lcd_printp_at (x+5, y, PSTR("mAh"), drawmode);
// BeepTime = 3000;
// BeepMuster = 0x0020;
}
 
 
//--------------------------------------------------------------
// OSD_Element_CareFree( x, y)
//--------------------------------------------------------------
void OSD_Element_CareFree( uint8_t x, uint8_t y )
{
lcd_puts_at (x, y, strGet( naviData->FCStatusFlags2 & FC_STATUS2_CAREFREE ? OSD_CARE_FREE_1 : OSD_CARE_FREE_0 ), 0);
}
 
 
//--------------------------------------------------------------
// OSD_Element_CompassDegree( x, y, nStyle)
// nStyle entspricht dem ehemaligen 'Mode'
//--------------------------------------------------------------
void OSD_Element_CompassDegree( uint8_t x, uint8_t y, uint8_t nStyle )
{
switch( nStyle )
{
case 0 :
case 1 : write_ndigit_number_u (x, y, naviData->CompassHeading, 3, 0,MNORMAL);
x += 3;
break;
case 2 : write_ndigit_number_u (x, y, naviData->CompassHeading, 3, 0,MBIG);
x += 8;
break;
}
lcd_putc( x, y, 0x1E, MNORMAL); // degree symbol
}
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
void OSD_Element_CompassDirection( uint8_t x, uint8_t y )
{
lcd_printp_at (x, y, (const char *) (pgm_read_word ( &(directions_p[heading_conv(naviData->CompassHeading)]))), 0);
}
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
void OSD_Element_CompassRose( uint8_t x, uint8_t y )
{
draw_compass (x, y, naviData->CompassHeading);
}
 
//--------------------------------------------------------------
//--------------------------------------------------------------
void OSD_Element_Current( uint8_t x, uint8_t y )
{
write_ndigit_number_u_10th (x, y, naviData->Current, 3, 0,0);
lcd_printp_at (x+4, y, PSTR("A"), 0);
}
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
void OSD_Element_FlyingTime( uint8_t x, uint8_t y )
{
write_time (x, y, naviData->FlyingTime);
lcd_printp_at (x+5, y, PSTR("m"), 0);
}
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
void OSD_Element_GroundSpeed( uint8_t x, uint8_t y )
{
write_ndigit_number_u (x, y, (uint16_t) (((uint32_t) naviData->GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 3, 0,0);
lcd_printp_at (x+3, y, PSTR("Kmh"), 0);
}
 
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
void OSD_Element_HomeCircle( uint8_t x, uint8_t y, uint8_t breite, int8_t rOffset, int8_t xoffs, int8_t yoffs )
{
lcd_o_circle( x, y, breite, 1, xoffs,yoffs);
 
if (Config.OSD_HomeMKView==1)
heading_home = (naviData->HomePositionDeviation.Bearing + 360 - naviData->CompassHeading) % 360;
else
heading_home = (naviData->CompassHeading- naviData->HomePositionDeviation.Bearing + 360 ) % 360;
 
lcd_o_circ_line( x, y, breite, old_hh , rOffset, 0, xoffs,yoffs);
lcd_o_circ_line( x, y, breite, heading_home, rOffset, 1, xoffs,yoffs);
old_hh = heading_home;
}
 
 
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
void OSD_Element_HomeDegree( uint8_t x, uint8_t y )
{
write_ndigit_number_u (x, y, heading_home, 3, 0,0);
lcd_putc (x+3, y, 0x1e, 0); // degree symbol
}
 
 
//--------------------------------------------------------------
// OSD_Element_HomeDistance( x, y, nStyle)
//--------------------------------------------------------------
void OSD_Element_HomeDistance( uint8_t x, uint8_t y, uint8_t nStyle )
{
switch( nStyle )
{
case 0 :
case 1 : write_ndigit_number_u (x, y, naviData->HomePositionDeviation.Distance / 10, 3, 0,0);
lcd_putc (x+3, y, 'm', 0);
draw_homesymbol(x+4, y);
break;
case 2 : lcd_printp_at (x, y, PSTR("Home"), 0);
write_ndigit_number_u (x+5, y, naviData->HomePositionDeviation.Distance / 10, 3, 0,0);
lcd_printp_at (x+8, y, PSTR("m -"), 0);
break;
}
}
 
 
//--------------------------------------------------------------
// OSD_Element_LEDOutput( x, y, bitmask)
//
// bitmask: LED1 = FC_STATUS2_OUT1_ACTIVE
// LED2 = FC_STATUS2_OUT2_ACTIVE
//--------------------------------------------------------------
void OSD_Element_LEDOutput( uint8_t x, uint8_t y, uint8_t bitmask )
{
uint8_t lOn;
lOn = (naviData->FCStatusFlags2 & bitmask ? 1 : 0); // Bit gesetzt?
lOn = (Config.OSD_InvertOut ? !lOn : lOn); // Invertieren?
lOn = (lOn ? 1 : 0); // auf 0 oder 1 setzen (hmm, geht auch besser...).
lcd_fcircle (x * 6 + 5, y * 8 + 3, Config.OSD_LEDform, lOn);
lcd_circle (x * 6 + 5, y * 8 + 3, 3, 1);
 
/*
if (!Config.OSD_InvertOut)
{
if (naviData->FCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)
{
lcd_fcircle (x * 6 + 5, y * 8 + 3, Config.OSD_LEDform, 0);
lcd_circle (x * 6 + 5, y * 8 + 3, 3, 1);
}
else
{
lcd_fcircle (x * 6 + 5, y * 8 + 3, Config.OSD_LEDform, 1);
lcd_circle (x * 6 + 5, y * 8 + 3, 3, 1);
}
}
else
{
if (naviData->FCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)
{
lcd_fcircle (x * 6 + 5, y * 8 + 3,Config.OSD_LEDform, 1);
lcd_circle (x * 6 + 5, y * 8 + 3, 3, 1);
}
else
{
lcd_fcircle (x * 6 + 5, y * 8 + 3, Config.OSD_LEDform, 0);
lcd_circle (x * 6 + 5, y * 8 + 3, 3, 1);
}
}
break;
*/
}
 
 
//--------------------------------------------------------------
// OSD_Element_LED1Output( x, y)
//--------------------------------------------------------------
void OSD_Element_LED1Output( uint8_t x, uint8_t y )
{
OSD_Element_LEDOutput( x, y, FC_STATUS2_OUT1_ACTIVE );
}
 
 
//--------------------------------------------------------------
// OSD_Element_LED2Output( x, y)
//--------------------------------------------------------------
void OSD_Element_LED2Output( uint8_t x, uint8_t y )
{
OSD_Element_LEDOutput( x, y, FC_STATUS2_OUT2_ACTIVE );
}
 
 
//--------------------------------------------------------------
// OSD_Element_Manuell( x, y)
//--------------------------------------------------------------
void OSD_Element_Manuell( uint8_t x, uint8_t y )
{
if (naviData->NCFlags & NC_FLAG_MANUAL_CONTROL)
lcd_putc (x, y, 'M', 0); // rc transmitter
else
lcd_putc (x, y, 'X', 0); // clear
}
 
 
//--------------------------------------------------------------
// OSD_Element_NaviMode( x, y)
//--------------------------------------------------------------
void OSD_Element_NaviMode( uint8_t x, uint8_t y )
{
if (naviData->NCFlags & NC_FLAG_FREE)
lcd_puts_at (x, y, strGet(OSD_NAVI_MODE_0), 0); // Navi aus
else if (naviData->NCFlags & NC_FLAG_PH)
lcd_puts_at (x, y, strGet(OSD_NAVI_MODE_1), 0); // Pos. Hold
else if (naviData->NCFlags & NC_FLAG_CH)
lcd_puts_at (x, y, strGet(OSD_NAVI_MODE_2), 0); // Coming Home
}
 
 
//--------------------------------------------------------------
// OSD_Element_RCIntensity( x, y)
//--------------------------------------------------------------
void OSD_Element_RCIntensity( uint8_t x, uint8_t y )
{
write_ndigit_number_u (x, y, naviData->RC_Quality, 3, 0,0);
lcd_printp_at (x+3, y, PSTR("\x1F"), 0); // RC-transmitter
if (naviData->NCFlags & NC_FLAG_NOSERIALLINK)
{
lcd_printpns_at(x+3, y, PSTR(" "), 0); // Clear
}
else
{
lcd_printpns_at(x+3, y, PSTR("PC"), 0);
}
}
 
 
//--------------------------------------------------------------
// OSD_Element_SatsInUse( x, y, nStyle)
//
// nStyle == 0: "00s"
// nStyle == 1: wie 0
// nStyle == 2: "00 Sat"
//
// nStyle entspricht dem ehemaligen 'Mode'
//--------------------------------------------------------------
void OSD_Element_SatsInUse( uint8_t x, uint8_t y, uint8_t nStyle )
{
drawmode = (naviData->NCFlags & NC_FLAG_GPS_OK ? 0 : 2);
switch( nStyle )
{
case 0 :
case 1 : write_ndigit_number_u (x, y, naviData->SatsInUse, 2, 0, drawmode);
lcd_putc (x+2, y, 0x08, drawmode);
break;
case 2 : write_ndigit_number_u (x, y, naviData->SatsInUse, 2, 0, drawmode);
lcd_printp_at (x+2, y, PSTR(" Sat"), drawmode);
break;
}
}
 
 
//--------------------------------------------------------------
// OSD_Element_StatusFlags( x, y)
//--------------------------------------------------------------
void OSD_Element_StatusFlags( uint8_t x, uint8_t y )
{
// FC_StatusFlags 0.88
// #define FC_STATUS_MOTOR_RUN 0x01
// #define FC_STATUS_FLY 0x02
// #define FC_STATUS_CALIBRATE 0x04
// #define FC_STATUS_START 0x08
// #define FC_STATUS_EMERGENCY_LANDING 0x10
// #define FC_STATUS_LOWBAT 0x20
// #define FC_STATUS_VARIO_TRIM_UP 0x40
// #define FC_STATUS_VARIO_TRIM_DOWN 0x80
 
if (naviData->FCStatusFlags & FC_STATUS_CALIBRATE)
lcd_puts_at (x, y, strGet(OSD_FLAGS_1), 0); // Calibrate
else if (naviData->FCStatusFlags & FC_STATUS_START)
lcd_puts_at (x, y, strGet(OSD_FLAGS_2), 0); // Start
else if (naviData->FCStatusFlags & FC_STATUS_MOTOR_RUN)
lcd_puts_at (x, y, strGet(OSD_FLAGS_3), 0); // Run
else if (naviData->FCStatusFlags & FC_STATUS_FLY)
lcd_puts_at (x, y, strGet(OSD_FLAGS_4), 0); // Fly
else if (naviData->FCStatusFlags & FC_STATUS_EMERGENCY_LANDING)
lcd_puts_at (x, y, strGet(OSD_FLAGS_5), 0); // Landing
else if (naviData->FCStatusFlags & FC_STATUS_LOWBAT)
lcd_puts_at (x, y, strGet(OSD_FLAGS_6), 0); // LowBat
else
// lcd_printp_at (x, y, PSTR(" "), 0); // Clear
lcd_puts_at (x, y, strGet(OSD_FLAGS_0), 0); // Clear
}
 
 
//--------------------------------------------------------------
// OSD_Element_Variometer( x, y)
//--------------------------------------------------------------
void OSD_Element_Variometer( uint8_t x, uint8_t y )
{
x *= 6;
y *= 8;
y += 7;
draw_variometer (x, y, 10, 14, naviData->Variometer);
}
 
 
//--------------------------------------------------------------
// OSD_Element_Target( x, y, nStyle)
//
// nStyle entspricht dem ehemaligen 'Mode'
// nStyle = 0,1: "000m"
// nStyle = 2,3: "Ziel 000m -"
//--------------------------------------------------------------
void OSD_Element_Target( uint8_t x, uint8_t y, uint8_t nStyle )
{
if( nStyle <= 1 )
{
write_ndigit_number_u (x, y, naviData->TargetPositionDeviation.Distance / 10, 3, 0,0);
lcd_putc (x+3, y, 'm', 0);
draw_targetsymbol(x+4,y);
}
else
{
lcd_printp_at (x, y, PSTR("Ziel"), 0);
write_ndigit_number_u (x+5, y, naviData->TargetPositionDeviation.Distance / 10, 3, 0,0);
lcd_printp_at (x+8, y, PSTR("m -"), 0);
}
}
 
 
//--------------------------------------------------------------
// TODO:
// - pruefen ob beep hier an richtiger Stelle ist
//--------------------------------------------------------------
void OSD_Element_VarioWert( uint8_t x, uint8_t y )
{
uint8_t FC_Fallspeed;
FC_Fallspeed = (unsigned int)naviData->Variometer;
FC_Fallspeed = 255-FC_Fallspeed;
 
drawmode = ( (naviData->Variometer < 0) && (FC_Fallspeed > Config.OSD_Fallspeed) ? 2 : 0);
 
if( Config.OSD_VarioBeep )
Beep_Vario(); // Beep ???
 
if( drawmode == 2 )
{
if( !Config.HWSound )
set_beep ( 1000, 0x0060, BeepNormal); // muss ein Beep hier hin????
else
variobeep(naviData->Variometer); // muss ein Beep hier hin????
}
 
write_ndigit_number_s_10th (x, y, naviData->Variometer, 3,0, drawmode);
lcd_printpns_at(x+4, y, PSTR("ms"), drawmode);
}
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
void OSD_Element_WayPoint( uint8_t x, uint8_t y )
{
if (!OldWP == naviData->WaypointIndex)
{
// BeepTime = 500;
// BeepMuster = 0x0080;
OldWP = naviData->WaypointIndex;
NextWP = true;
}
if ((NextWP==true)&& naviData->NCFlags & NC_FLAG_TARGET_REACHED)
{
set_beep ( 500, 0x0080, BeepNormal);
NextWP = false;
}
write_ndigit_number_u (x+2, y, naviData->WaypointIndex , 2, 0,0);
 
lcd_printp_at (x, y, PSTR("WP"), 0);
}
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
void OSD_Element_TargetDegree( uint8_t x, uint8_t y )
{
write_ndigit_number_u (x, y, naviData->TargetPositionDeviation.Bearing/ 10, 3, 0,0);
lcd_putc (x+3, y, 0x1e, 0); // degree symbol
}
 
 
 
//##############################################################
//# OSD-SCREENS
//##############################################################
 
//--------------------------------------------------------------
// OSD-Screen "General"
//
// nMode: 0 = update values
// 1 = redraw labels and update values
//--------------------------------------------------------------
const char * OSD_Screen_General( uint8_t nMode )
{
const char *ScreenName = PSTR("General");
 
//-----------------------------------------
// REDRAW
// statische Screen Elemente die nicht
// jedesmal neu gezeichnet werden muessen
//-----------------------------------------
if( nMode == OSD_SCREEN_REDRAW )
{
// Display: 128 x 64 with 6x8 Font => 21 x 8
 
// Linien: Horizontal
lcd_line (0, 28, 127, 28, 1); // mitte
lcd_line (0, 51, 127, 51, 1); // unten
// Linien: Vertikal
lcd_line (65, 0, 65, 50, 1); // mitte
//-----------------------------------------
// Block: Oben - Links
//-----------------------------------------
draw_icon_battery(0,4);
//lcdx_printp_at( 6, 0, PSTR("V") , MNORMAL, 1,0); // Spannung (Volt)
lcdx_printp_at( 7, 2, PSTR(" mA"), MNORMAL, 0,2);
 
//-----------------------------------------
// Block: Oben - Rechts
//-----------------------------------------
lcdx_printp_at( 12, 0, PSTR("Alt:") , MNORMAL, 0,0);
lcdx_printp_at( 12, 1, PSTR("Dir:") , MNORMAL, 0,1);
draw_symbol_degree( 20, 1, 1,1);
lcdx_printp_at( 12, 2, PSTR(" I:") , MNORMAL, 0,2);
lcdx_printp_at( 20, 2, PSTR("A") , MNORMAL, 2,2);
 
//-----------------------------------------
// Block: Unten - Links
//-----------------------------------------
draw_icon_sat(0,33);
lcdx_printp_at( 6, 5, PSTR(" kmh"), MNORMAL, 0,1);
 
//-----------------------------------------
// Block: Unten - Rechts
//-----------------------------------------
draw_icon_home( 70, 32);
lcdx_printp_at( 20, 4, PSTR("m"), MNORMAL, 2,0);
draw_symbol_degree( 20, 5, 1,1);
//lcd_putc( 20, 5, 0x1E, 0); // alternativ: degree symbol
//-----------------------------------------
// unterste Zeile
//-----------------------------------------
draw_symbol_rc(20,7); // RC-transmitter
}
//-----------------
// Batt Level (Volt)
//-----------------
OSD_Element_BattLevel2( 2, 0, 0,0 );
 
//-----------------
// LowBat Warnung MK
//-----------------
OSD_Element_Flag( 8, 0, OSD_FLAG_BA, 0,0 );
 
//-----------------
// Flugzeit
//-----------------
writex_time(2, 1, naviData->FlyingTime, MNORMAL, 0,1);
 
//-----------------
// entnommene Kapazitaet (mAh)
//-----------------
drawmode = (naviData->UsedCapacity > Config.OSD_mAh_Warning ? MINVERS : MNORMAL);
writex_ndigit_number_u( 2, 2, naviData->UsedCapacity, 5, 0, drawmode, 0,2);
//-----------------
// Höhe
//-----------------
if (naviData->Altimeter > (300 / AltimeterAdjust) || naviData->Altimeter < (-300 / AltimeterAdjust)) // above 10m only write full meters
write_ndigit_number_s ( 16, 0, naviData->Altimeter / (30 / AltimeterAdjust), 4, 0, MNORMAL);
else // up to 10m write meters.dm
write_ndigit_number_s_10th( 16, 0, naviData->Altimeter / (3 / AltimeterAdjust), 3, 0, MNORMAL);
 
//-----------------
// steigen / sinken
//-----------------
OSD_Element_UpDown( 20, 0, 2,0);
 
//-----------------
// Compass Degree
//-----------------
writex_ndigit_number_u (17, 1, naviData->CompassHeading, 3, 0,MNORMAL, 0,1);
 
//-----------------
// Strom
//-----------------
//write_ndigit_number_u_10th( 16, 2, naviData->Current, 3, 0,0); // alternativ mit Nachkomma
writex_ndigit_number_u( 17, 2, naviData->Current/10, 3, 0,MNORMAL, 0,2);
 
//-----------------
// Sat Anzahl
//-----------------
write_ndigit_number_u (4, 4, naviData->SatsInUse, 2, 0,MNORMAL);
 
//-----------------
// Sat Warnung "!"
//-----------------
/*
if( naviData->NCFlags & NC_FLAG_GPS_OK )
lcd_printp_at( 9, 4, PSTR(" "), MNORMAL);
else
lcd_printp_at( 9, 4, PSTR("!"), MNORMAL);
*/
OSD_Element_Flag( 8, 4, OSD_FLAG_S0, -1,0 ); // Sat Warnung (GPS not ok)
 
//-----------------
// Geschwindigkeit
//-----------------
writex_ndigit_number_u( 3, 5, (uint16_t) (((uint32_t) naviData->GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 3, 0,MNORMAL, 0,1);
 
//-----------------
// Home Distance
//-----------------
write_ndigit_number_u( 17, 4, naviData->HomePositionDeviation.Distance / 10, 3, 0,MNORMAL);
 
//-----------------
// Home Winkel
//-----------------
writex_ndigit_number_u( 16, 5, heading_home, 4, 0,MNORMAL, 0,1);
 
//-----------------
// Flags
//-----------------
OSD_Element_Flag( 1, 7, OSD_FLAG_CF, 0,0 ); // Care Free
OSD_Element_Flag( 4, 7, OSD_FLAG_AH, 0,0 ); // Altitude Hold
OSD_Element_Flag( 7, 7, OSD_FLAG_PH, 0,0 ); // Position Hold
OSD_Element_Flag( 10, 7, OSD_FLAG_CH, 0,0 ); // Coming Home
OSD_Element_Flag( 13, 7, OSD_FLAG_EL, 0,0 ); // Emergency Landing
 
//-----------------
// RC-Quality (MK)
//-----------------
write_ndigit_number_u( 17, 7, naviData->RC_Quality, 3, 0,MNORMAL);
 
#ifdef OSD_DEMO
//-----------------
// Flags
//-----------------
OSD_Element_Flag_Label( 8, 0, OSD_FLAG_BA, true, 0,0 ); // DEMO: Batterie Warnung
OSD_Element_Flag_Label( 8, 4, OSD_FLAG_S0, true, -1,0 ); // DEMO: Sat Warnung (GPS not ok)
 
OSD_Element_Flag_Label( 1, 7, OSD_FLAG_CF, true, 0,0 ); // DEMO
OSD_Element_Flag_Label( 4, 7, OSD_FLAG_AH, true, 0,0 ); // DEMO
OSD_Element_Flag_Label( 7, 7, OSD_FLAG_PH, true, 0,0 ); // DEMO
OSD_Element_Flag_Label( 10, 7, OSD_FLAG_CH, true, 0,0 ); // DEMO
OSD_Element_Flag_Label( 13, 7, OSD_FLAG_EL, true, 0,0 ); // DEMO
#endif
 
 
return( ScreenName );
}
 
 
//--------------------------------------------------------------
// OSD-Screen "Navigation"
//
// nMode: 0 = update values
// 1 = redraw labels and update values
//--------------------------------------------------------------
const char * OSD_Screen_Navigation( uint8_t nMode )
{
const char *ScreenName = PSTR("Navigation");
int8_t xoffs, yoffs;
 
//-----------------------------------------
// REDRAW
// statische Screen Elemente die nicht
// jedesmal neu gezeichnet werden muessen
//-----------------------------------------
if( nMode == OSD_SCREEN_REDRAW )
{
// do things here for static screen elements like labels and so....
lcd_line ((6*6-4), 0, (6*6-4), 9, 1); // Linie Vertikal links
lcd_line ((15*6+3), 0, (15*6+3), 9, 1); // Linie Vertikal rechts
lcd_line (0, 10, 127, 10, 1); // Linie Horizontal
 
lcdx_printp_at( 0, 2, PSTR("Alt:"), MNORMAL, 0,2); // Hoehe
lcdx_printp_at( 0, 5, PSTR("Home:"), MNORMAL, 0,3); // Home Distance
}
 
 
//-----------------
// Oben: Batt Level (Volt)
//-----------------
OSD_Element_BattLevel2( 0, 0, 0,0 );
 
//-----------------
// Oben: Kompass Rose
//-----------------
OSD_Element_CompassRose( 6, 0);
 
//-----------------
// Oben: Flugzeit
//-----------------
write_time(16, 0, naviData->FlyingTime);
 
//-----------------
// Hoehe
//-----------------
xoffs = 0;
yoffs = 3;
drawmode = MNORMAL;
if (naviData->Altimeter > (300 / AltimeterAdjust) || naviData->Altimeter < (-300 / AltimeterAdjust)) // above 10m only write full meters
writex_ndigit_number_s ( 0, 3, naviData->Altimeter / (30 / AltimeterAdjust), 4, 0, drawmode, xoffs,yoffs);
else // up to 10m write meters.dm
writex_ndigit_number_s_10th( 0, 3, naviData->Altimeter / (3 / AltimeterAdjust), 3, 0, drawmode, xoffs,yoffs);
 
//-----------------
// Steigen / Sinken
//-----------------
OSD_Element_UpDown( 4, 3, 1,yoffs);
 
//-----------------
// Home Distance
//-----------------
yoffs = 3;
writex_ndigit_number_u( 0, 6, naviData->HomePositionDeviation.Distance / 10, 4, 0,MNORMAL, 0,yoffs+1);
lcdx_printp_at( 4, 6, PSTR("m"), MNORMAL, 2,yoffs+1); // Home
//-----------------
// Home Circle
//-----------------
xoffs = 0;
yoffs = 3;
OSD_Element_HomeCircle( 8, 3, 9, 4, xoffs,yoffs); // Home Circle
lcd_frect( (9*6)-3+xoffs, (4*8)-2+yoffs, (3*6)+4, (1*8)+2, 0); // inner clear
lcd_rect ( (9*6)-4+xoffs, (4*8)-3+yoffs, (3*6)+6, (1*8)+4, 1); // inner rect
lcd_frect ( 61+xoffs, 57+yoffs, 2, 2, 1); // bottom mini rect
writex_ndigit_number_u( 9, 4, heading_home, 3, 0,MNORMAL, xoffs,yoffs); // Degree (Winkel)
 
//-----------------
// Variometer
//-----------------
//void draw_variometer (uint8_t x, uint8_t y, uint8_t width, uint8_t hight, int16_t variometer)
//draw_variometer( 95, 38, 7, 30, naviData->Variometer);
//draw_variometer( 94, 38, 7, 21, naviData->Variometer);
//draw_variometer2( 94, 28, 7, 21, naviData->Variometer);
 
//-----------------
// Flags
//-----------------
OSD_Element_Flag( 16, 2, OSD_FLAG_BA, -3, 0); // MK Batt Warning
OSD_Element_Flag( 19, 2, OSD_FLAG_CF, 0, 0); // Carefree
OSD_Element_Flag( 19, 4, OSD_FLAG_AH, 0,-3); // Altitude Hold
OSD_Element_Flag( 19, 6, OSD_FLAG_PH, 0,-6); // Position Hold
OSD_Element_Flag( 19, 7, OSD_FLAG_CH, 0,-1); // Coming Home
OSD_Element_Flag( 16, 7, OSD_FLAG_S0, -3,-1); // GPS-Sat not ok (GPS NOT ok)
 
 
#ifdef OSD_DEMO
//-----------------
// Flags
//-----------------
OSD_Element_Flag_Label( 16, 2, OSD_FLAG_BA, true, -3,0); // DEMO
OSD_Element_Flag_Label( 19, 2, OSD_FLAG_CF, true, 0,0); // DEMO
OSD_Element_Flag_Label( 19, 4, OSD_FLAG_AH, true, 0,-3); // DEMO
OSD_Element_Flag_Label( 19, 6, OSD_FLAG_PH, true, 0,-6); // DEMO
OSD_Element_Flag_Label( 19, 7, OSD_FLAG_CH, true, 0,-1); // DEMO
 
OSD_Element_Flag_Label( 16, 7, OSD_FLAG_S0, true, -3,-1); // DEMO
#endif
 
 
return( ScreenName );
}
 
 
 
 
//--------------------------------------------------------------
// OSD-Screen "Status"
//
// nMode: 0 = update values
// 1 = redraw labels and update values
//--------------------------------------------------------------
const char * OSD_Screen_MKStatus( uint8_t nMode )
{
const char *ScreenName = PSTR("MK-Status");
int8_t xoffs;
 
//-----------------------------------------
// REDRAW
// statische Screen Elemente die nicht
// jedesmal neu gezeichnet werden muessen
//-----------------------------------------
if( nMode == OSD_SCREEN_REDRAW )
{
// do things here for static screen elements like labels and so....
lcd_line ((6*6-3), 0, (6*6-3), 9, 1); // Linie Vertikal links
lcd_line ((15*6+3), 0, (15*6+3), 9, 1); // Linie Vertikal rechts
lcd_line (0, 10, 127, 10, 1); // Linie Horizontal
 
//lcdx_printp_at( 8, 0, PSTR("Status"), MNORMAL, -3,0); // oben, mitte Text
lcdx_printp_at( 13, 0, PSTR("A"), MNORMAL, -4,0); // oben, mitte "A"
}
 
 
//-----------------
// Oben: Batt Level (Volt)
//-----------------
OSD_Element_BattLevel2( 0, 0, 0,0 );
 
//-----------------
// Strom
//-----------------
writex_ndigit_number_u_10th( 7, 0, naviData->Current, 4, 0,MNORMAL, 1,0); // Strom mit Nachkomma
 
//-----------------
// Oben: Flugzeit
//-----------------
write_time(16, 0, naviData->FlyingTime);
//-----------------
// Flags
//-----------------
xoffs = -7;
OSD_Element_Flag( 19, 2, OSD_FLAG_CF, 0+xoffs, 0); // Carefree
OSD_Element_Flag( 19, 4, OSD_FLAG_AH, 0+xoffs,-3); // Altitude Hold
OSD_Element_Flag( 19, 6, OSD_FLAG_PH, 0+xoffs,-6); // Position Hold
OSD_Element_Flag( 19, 7, OSD_FLAG_CH, 0+xoffs,-1); // Coming Home
 
xoffs -= 4;
OSD_Element_Flag( 16, 2, OSD_FLAG_BA, -3+xoffs, 0); // MK Batt Warning
OSD_Element_Flag( 16, 4, OSD_FLAG_EL, -3+xoffs,-3); // Emergency Landing
OSD_Element_Flag( 16, 6, OSD_FLAG_RL, -3+xoffs,-6); // Range Limit
OSD_Element_Flag( 16, 7, OSD_FLAG_S0, -3+xoffs,-1); // GPS-Sat not ok (GPS NOT ok)
 
xoffs -= 4;
OSD_Element_Flag( 12, 2, OSD_FLAG_CA, 0+xoffs, 0); // Calibrate
OSD_Element_Flag( 12, 4, OSD_FLAG_ST, 0+xoffs,-3); // Start
OSD_Element_Flag( 12, 6, OSD_FLAG_MR, 0+xoffs,-6); // Motor Run
OSD_Element_Flag( 12, 7, OSD_FLAG_FY, 0+xoffs,-1); // Fly
 
xoffs -= 4;
OSD_Element_Flag( 9, 2, OSD_FLAG_O1, -2+xoffs, 0); // Out1
OSD_Element_Flag( 9, 4, OSD_FLAG_O2, -2+xoffs,-3); // Out2
OSD_Element_Flag( 9, 6, OSD_FLAG_TR, -2+xoffs,-6); // Target Reached
OSD_Element_Flag( 9, 7, OSD_FLAG_MC, -2+xoffs,-1); // Manual Control
 
xoffs -= 4;
OSD_Element_Flag( 6, 2, OSD_FLAG_TU, -4+xoffs, 0); // Vario Trim Up
OSD_Element_Flag( 6, 4, OSD_FLAG_TD, -4+xoffs,-3); // Vario Trim Down
OSD_Element_Flag( 6, 6, OSD_FLAG_FR, -4+xoffs,-6); // Free
OSD_Element_Flag( 6, 7, OSD_FLAG_SL, -4+xoffs,-1); // No Serial Link
 
 
#ifdef OSD_DEMO
//-----------------
// Flags
//-----------------
/*
PSTR("AH"), // OSD_FLAG_AH Altitue Hold
PSTR("PH"), // OSD_FLAG_PH Position Hold
PSTR("CF"), // OSD_FLAG_CF Care Free
PSTR("CH"), // OSD_FLAG_CH Coming Home
PSTR("o1"), // OSD_FLAG_O1 Out1
PSTR("o2"), // OSD_FLAG_O2 Out2
PSTR("BA"), // OSD_FLAG_BA LowBat warning (MK)
PSTR("CA"), // OSD_FLAG_CA Calibrate
PSTR("ST"), // OSD_FLAG_ST Start
PSTR("MR"), // OSD_FLAG_MR Motor Run
PSTR("FY"), // OSD_FLAG_FY Fly
PSTR("EL"), // OSD_FLAG_EL Emergency Landing
PSTR("FS"), // OSD_FLAG_FS RX Failsave Active
PSTR("GP"), // OSD_FLAG_GP GPS Ok
PSTR("S!") // OSD_FLAG_S0 GPS-Sat not ok (GPS NOT ok)
PSTR("TU"), // OSD_FLAG_TU Vario Trim Up
PSTR("TD"), // OSD_FLAG_TD Vario Trim Down
PSTR("FR"), // OSD_FLAG_FR Free
PSTR("RL"), // OSD_FLAG_RL Range Limit
PSTR("SL"), // OSD_FLAG_SL No Serial Link
PSTR("TR"), // OSD_FLAG_TR Target Reached
PSTR("MC") // OSD_FLAG_MC Manual Control
*/
xoffs = -7;
OSD_Element_Flag_Label( 19, 2, OSD_FLAG_CF, true, 0+xoffs, 0); // DEMO: Carefree
OSD_Element_Flag_Label( 19, 4, OSD_FLAG_AH, true, 0+xoffs,-3); // DEMO: Altitude Hold
OSD_Element_Flag_Label( 19, 6, OSD_FLAG_PH, true, 0+xoffs,-6); // DEMO: Position Hold
OSD_Element_Flag_Label( 19, 7, OSD_FLAG_CH, true, 0+xoffs,-1); // DEMO: Coming Home
 
xoffs -= 4;
OSD_Element_Flag_Label( 16, 2, OSD_FLAG_BA, true, -3+xoffs, 0); // DEMO: MK Batt Warning
OSD_Element_Flag_Label( 16, 4, OSD_FLAG_EL, true, -3+xoffs,-3); // DEMO: Emergency Landing
OSD_Element_Flag_Label( 16, 6, OSD_FLAG_RL, true, -3+xoffs,-6); // DEMO: Range Limit
OSD_Element_Flag_Label( 16, 7, OSD_FLAG_S0, true, -3+xoffs,-1); // DEMO: GPS-Sat not ok (GPS NOT ok)
 
xoffs -= 4;
OSD_Element_Flag_Label( 12, 2, OSD_FLAG_CA, true, 0+xoffs, 0); // DEMO: Calibrate
OSD_Element_Flag_Label( 12, 4, OSD_FLAG_ST, true, 0+xoffs,-3); // DEMO: Start
OSD_Element_Flag_Label( 12, 6, OSD_FLAG_MR, true, 0+xoffs,-6); // DEMO: Motor Run
OSD_Element_Flag_Label( 12, 7, OSD_FLAG_FY, true, 0+xoffs,-1); // DEMO: Fly
 
xoffs -= 4;
OSD_Element_Flag_Label( 9, 2, OSD_FLAG_O1, true, -2+xoffs, 0); // DEMO: Out1
OSD_Element_Flag_Label( 9, 4, OSD_FLAG_O2, true, -2+xoffs,-3); // DEMO: Out2
OSD_Element_Flag_Label( 9, 6, OSD_FLAG_TR, true, -2+xoffs,-6); // DEMO: Target Reached
OSD_Element_Flag_Label( 9, 7, OSD_FLAG_MC, true, -2+xoffs,-1); // DEMO: Manual Control
 
xoffs -= 4;
OSD_Element_Flag_Label( 6, 2, OSD_FLAG_TU, true, -4+xoffs, 0); // DEMO: Vario Trim Up
OSD_Element_Flag_Label( 6, 4, OSD_FLAG_TD, true, -4+xoffs,-3); // DEMO: Vario Trim Down
OSD_Element_Flag_Label( 6, 6, OSD_FLAG_FR, true, -4+xoffs,-6); // DEMO: Free
OSD_Element_Flag_Label( 6, 7, OSD_FLAG_SL, true, -4+xoffs,-1); // DEMO: No Serial Link
 
#endif
 
 
return( ScreenName );
}
 
 
 
//##############################################################
#ifdef OSD_DEBUG_SCREEN
//##############################################################
 
//**************************************************************
//* OSD_DEBUG_SCREEN - Experimental-Code usw.
//* - nicht fuer die Oeffentlichkeit bestimmt
//* - gesteuert ueber define OSD_DEBUG_SCREEN
//**************************************************************
 
 
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// NOTIZEN
//
// 1. Thema: Motorwerte abfragen
//
// ja, auf die gleiche Weise wie man an die Config Parameter kommt.
//
// SwitchToFC();
// SendOutData( 'u', ADDRESS_FC, BL-Adresse, &tmp_dat, 1);
//
// Die Daten kommen dann in der Form:
// typedef struct
// {
// uint8_t Version; // the version of the BL (0 = old)
// uint8_t SetPoint; // written by attitude controller
// uint8_t SetPointLowerBits; // for higher Resolution of new BLs
// uint8_t State; // 7 bit for I2C error counter, highest bit indicates if motor is present
// uint8_t ReadMode; // select data to read
// // the following bytes must be exactly in that order!
// uint8_t Current; // in 0.1 A steps, read back from BL
// uint8_t MaxPWM; // read back from BL -> is less than 255 if BL is in current limit, not running (250) or starting (40)
// int8_t Temperature; // old BL-Ctrl will return a 255 here, the new version the temp. in ?C
// } __attribute__((packed)) MotorData_t;
//
//
// kennst Du die Seite?:http://www.mikrokopter.de/ucwiki/en/SerialProtocol?highlight=%28%28----%28-*%29%28\r%29%3F\n%29%28.*%29CategoryCoding%29#en.2BAC8-SerialCommands.Flight-Ctrl
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
uint8_t xload_setting( uint8_t setting )
{
mode = 'Q'; // Settings
uint8_t timeout = 50;
rxd_buffer_locked = FALSE;
 
while (!rxd_buffer_locked && timeout)
{
SendOutData ('q', ADDRESS_FC, 1, &setting, 1);
// _delay_ms(50);
timer = 20;
while (timer > 0);
timeout--;
}
 
if (timeout != 0)
{
Decode64 ();
setting = *pRxData;
mk_param_struct = (mk_param_struct_t *) (pRxData + 1) ;
}
else
{ // timeout occured
// lcd_printp_at (0, 2, PSTR("Fehler: keine Daten"), 0);
lcd_puts_at(0, 2, strGet(OSD_ERROR), 0);
timer = 100;
while (timer > 0);
setting = 255;
}
return setting;
}
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
const char * OSD_Screen_Debug( uint8_t nMode )
{
const char *ScreenName = PSTR("Debug");
static s16 min_debug = 0;
static s16 max_debug = 0;
static uint16_t debug_count = 0;
 
//-----------------------------------------
// REDRAW
// statische Screen Elemente die nicht
// jedesmal neu gezeichnet werden muessen
//-----------------------------------------
if( nMode == OSD_SCREEN_REDRAW )
{
// do things here for static screen elements like labels and so....
min_debug = 0;
max_debug = 0;
}
 
lcd_printp_at( 0, 0, PSTR("Debug"), 0);
 
 
debug_count++;
 
if( naviData->Variometer < min_debug ) min_debug = naviData->Variometer;
if( naviData->Variometer > max_debug ) max_debug = naviData->Variometer;
 
write_ndigit_number_s ( 8, 1, (naviData->Variometer), 12, 0,MNORMAL); // s16 Variometer;
write_ndigit_number_s ( 8, 2, (min_debug), 12, 0,MNORMAL); // s16 Variometer;
write_ndigit_number_s ( 8, 3, (max_debug), 12, 0,MNORMAL); // s16 Variometer;
 
write_ndigit_number_u ( 8, 5, (debug_count), 12, 0,MNORMAL); //
//write_ndigit_number_u ( 8, 6, (timer), 12, 0,MNORMAL); //
 
//draw_variometer2( 6, 19, 7, 21, naviData->Variometer);
 
return( ScreenName );
}
//##############################################################
#endif // OSD_DEBUG_SCREEN
//##############################################################
 
 
 
//--------------------------------------------------------------
// ehemals: OSD_ALTITUDE,Config.OSD_ScreenMode == 0
//--------------------------------------------------------------
const char * OSD_Screen_OSD0( uint8_t nMode )
{
const char *ScreenName = PSTR("OSD0");
//uint8_t xoffs;
 
//-----------------------------------------
// REDRAW static screen elements
//-----------------------------------------
if( nMode == OSD_SCREEN_REDRAW )
{
// do things here for static screen elements like labels and so....
}
 
OSD_Element_AltitudeControl ( 0, 3);
OSD_Element_Altitude ( 11, 3, 0);
OSD_Element_BatteryLevel ( 0, 7, 0);
OSD_Element_Capacity ( 13, 7);
OSD_Element_Current ( 8, 7);
OSD_Element_CareFree ( 0, 5);
OSD_Element_CompassDegree ( 13, 0, 0);
OSD_Element_CompassDirection( 18, 0);
OSD_Element_CompassRose ( 12, 1);
OSD_Element_FlyingTime ( 0, 1);
OSD_Element_GroundSpeed ( 0, 0);
OSD_Element_HomeCircle ( 16, 4, 5, 0, 0,0);
OSD_Element_HomeDegree ( 12, 4);
OSD_Element_HomeDistance ( 10, 5, 0);
OSD_Element_Target ( 10, 6, 0);
//OSD_Element_TargetDegree ( x, y);
OSD_Element_WayPoint ( 5, 6);
OSD_Element_LED1Output ( 0, 6);
OSD_Element_LED2Output ( 3, 6);
//OSD_Element_Manuell ( x, y);
OSD_Element_NaviMode ( 0, 4);
//OSD_Element_RCIntensity ( x, y);
OSD_Element_VarioWert ( 12, 2);
OSD_Element_SatsInUse ( 18, 2, 0);
OSD_Element_StatusFlags ( 0, 2);
OSD_Element_Variometer ( 9, 0);
 
return( ScreenName );
}
 
 
 
 
//--------------------------------------------------------------
// ehemals: OSD_ALTITUDE,Config.OSD_ScreenMode == 1
//--------------------------------------------------------------
const char * OSD_Screen_OSD1( uint8_t nMode )
{
const char *ScreenName = PSTR("OSD1");
//uint8_t xoffs;
 
//-----------------------------------------
// REDRAW static screen elements
//-----------------------------------------
if( nMode == OSD_SCREEN_REDRAW )
{
// do things here for static screen elements like labels and so....
}
 
//OSD_Element_AltitudeControl( x, y);
OSD_Element_Altitude ( 1, 1, 1);
OSD_Element_BatteryLevel ( 0, 7, 1);
OSD_Element_Capacity ( 13, 7);
OSD_Element_Current ( 8, 7);
//OSD_Element_CareFree ( x, y);
OSD_Element_CompassDegree ( 13, 0, 1);
OSD_Element_CompassDirection( 18, 0);
OSD_Element_CompassRose ( 12, 1);
OSD_Element_FlyingTime ( 7, 6);
OSD_Element_GroundSpeed ( 0, 0);
OSD_Element_HomeCircle ( 1, 3, 7, 0, 0,0);
OSD_Element_HomeDegree ( 8, 3);
OSD_Element_HomeDistance ( 7, 2, 1);
//OSD_Element_Target ( x, y, 1);
//OSD_Element_TargetDegree ( x, y);
//OSD_Element_WayPoint ( x, y);
//OSD_Element_LED1Output ( x, y);
//OSD_Element_LED2Output ( x, y);
//OSD_Element_Manuell ( x, y);
OSD_Element_NaviMode ( 8, 5);
OSD_Element_RCIntensity ( 15, 6);
OSD_Element_VarioWert ( 15, 2);
OSD_Element_SatsInUse ( 8, 4, 1);
//OSD_Element_StatusFlags ( x, y);
OSD_Element_Variometer ( 9, 0);
 
return( ScreenName );
}
 
 
//--------------------------------------------------------------
// ehemals: OSD_ALTITUDE,Config.OSD_ScreenMode == 2
//--------------------------------------------------------------
const char * OSD_Screen_OSD2( uint8_t nMode )
{
const char *ScreenName = PSTR("OSD2");
//uint8_t xoffs;
 
//-----------------------------------------
// REDRAW static screen elements
//-----------------------------------------
if( nMode == OSD_SCREEN_REDRAW )
{
// do things here for static screen elements like labels and so....
}
OSD_Element_AltitudeControl ( 0, 1);
OSD_Element_Altitude ( 0, 4, 2);
OSD_Element_BatteryLevel ( 13, 7, 2);
OSD_Element_Capacity ( 0, 7);
OSD_Element_Current ( 8, 7);
OSD_Element_CareFree ( 0, 3);
OSD_Element_CompassDegree ( 12, 3, 2);
//OSD_Element_CompassDirection( x, y);
//OSD_Element_CompassRose ( x, y);
OSD_Element_FlyingTime ( 15, 5);
//OSD_Element_GroundSpeed ( x, y);
OSD_Element_HomeCircle ( 16, 0, 5, 0, 0,0);
OSD_Element_HomeDegree ( 11, 5);
OSD_Element_HomeDistance ( 0, 5, 2);
OSD_Element_Target ( 0, 6, 2);
OSD_Element_TargetDegree ( 11, 6);
//OSD_Element_WayPoint ( x, y);
OSD_Element_LED1Output ( 12, 2);
OSD_Element_LED2Output ( 14, 2);
//OSD_Element_Manuell ( x, y);
OSD_Element_NaviMode ( 0, 2);
//OSD_Element_RCIntensity ( x, y);
OSD_Element_VarioWert ( 15, 4);
OSD_Element_SatsInUse ( 10, 0, 2);
OSD_Element_StatusFlags ( 0, 0);
//OSD_Element_Variometer ( x, y);
 
return( ScreenName );
}
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
const char * OSD_Screen_3DLage( uint8_t nMode )
{
const char *ScreenName = PSTR("3D Lage");
uint16_t head_home;
uint8_t Nick;
uint8_t Roll;
 
//-----------------------------------------
// REDRAW static screen elements
//-----------------------------------------
if( nMode == OSD_SCREEN_REDRAW )
{
// do things here for static screen elements like labels and so....
}
 
head_home = (naviData->HomePositionDeviation.Bearing + 360 - naviData->CompassHeading) % 360;
 
//lcd_cls ();
 
lcd_line(26,32,100,32,1); // horizontal //
lcd_line(63,0,63,63,1); // vertical //
//lcd_puts_at(12, 7, strGet(KEYLINE5), 0);
 
// 45' Angel
lcd_line(61,11,65,11,1); // -- //
lcd_line(40,30,40,34,1); // | //
lcd_line(86,30,86,34,1); // | //
lcd_line(61,53,65,53,1); // -- //
 
lcd_puts_at(9, 0, strGet(OSD_3D_V), 0); // V
lcd_puts_at(3, 3, strGet(OSD_3D_L), 0); // L
lcd_puts_at(17, 3, strGet(OSD_3D_R), 0); // R
lcd_puts_at(9, 7, strGet(OSD_3D_H), 0); // H
 
lcd_puts_at(0, 0, strGet(OSD_3D_NICK), 0); // Ni
write_ndigit_number_s (2, 0, naviData->AngleNick, 3, 0,0);
lcd_putc (5, 0, 0x1e, 0); // degree symbol
 
lcd_puts_at(0, 7, strGet(OSD_3D_ROLL), 0); // Ro
write_ndigit_number_s (2, 7, naviData->AngleRoll, 3, 0,0);
lcd_putc (5, 7, 0x1e, 0); // degree symbol
 
lcd_puts_at(13, 0, strGet(OSD_3D_COMPASS), 0);
//write_ndigit_number_s (15, 0,head_home, 3, 0);
write_ndigit_number_u (15, 0, naviData->CompassHeading, 3, 0,0);
lcd_putc (18, 0, 0x1e, 0); // degree symbol
lcd_printp_at (19, 0, (const char *) (pgm_read_word ( &(directions_p[heading_conv(naviData->CompassHeading)]))), 0);
 
Nick = ((-naviData->AngleNick/2)+32);
Roll = ((-naviData->AngleRoll/2)+63);
 
lcd_ellipse ( old_AngleRoll, old_AngleNick, 9, 8, 0);
lcd_ellipse_line( old_AngleRoll, old_AngleNick, 8, 7, old_hh, 0);
 
lcd_ellipse ( Roll, Nick, 9, 8, 1);
lcd_ellipse_line( Roll, Nick, 8, 7, head_home, 1);
 
// remember last values (3DL)
old_hh = head_home;
old_AngleNick = Nick;
old_AngleRoll = Roll;
return( ScreenName );
}
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
const char * OSD_Screen_Statistics( uint8_t nMode )
{
const char *ScreenName = PSTR("Statistics");
uint8_t line = 0;
 
//-----------------------------------------
// REDRAW static screen elements
//-----------------------------------------
/*
if( nMode == OSD_SCREEN_REDRAW )
{
// do things here for static screen elements like labels and so....
}
*/
//---------------------------
// max Altitude
lcd_puts_at (0, line, strGet(STATS_ITEM_0), MNORMAL);
write_ndigit_number_s (14, line, max_Altimeter / (30 / AltimeterAdjust), 4, 0,MNORMAL);
lcdx_putc (18, line, 'm', MNORMAL, 2,0);
//---------------------------
// max Speed
// max_GroundSpeed = 1;
lcd_puts_at (0, ++line, strGet(STATS_ITEM_1), MNORMAL);
write_ndigit_number_u (15, line, (uint16_t) (((uint32_t) max_GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 3, 0,MNORMAL);
lcdx_printp_at(18, line, PSTR("kmh"), MNORMAL, 2,0);
 
//---------------------------
// max Distance
// max_Distance = 64512;
lcd_puts_at (0, ++line, strGet(STATS_ITEM_2), MNORMAL);
write_ndigit_number_u (14, line, max_Distance / 10, 4, 0,MNORMAL);
lcdx_putc (18, line, 'm', MNORMAL, 2,0);
//---------------------------
// max time
// max_FlyingTime = 3600;
lcd_puts_at (0, ++line, strGet(STATS_ITEM_4), MNORMAL);
write_time (13, line, max_FlyingTime);
 
//---------------------------
// min voltage
lcd_puts_at (0, ++line, strGet(STATS_ITEM_3), MNORMAL);
if( min_UBat==255 )
lcd_printp_at(14, line, PSTR(" 0"), MNORMAL);
else
write_ndigit_number_u_10th (14, line, min_UBat, 3, 0,MNORMAL);
lcdx_putc (18, line, 'V', MNORMAL, 2,0);
 
//---------------------------
// max Current
// max_Current = 1000;
lcd_puts_at (0, ++line, strGet(STATS_ITEM_5), MNORMAL);
write_ndigit_number_u_10th (13, line, max_Current, 4, 0,MNORMAL);
lcdx_putc (18, line, 'A', MNORMAL, 2,0);
 
//---------------------------
// Used Capacity
lcd_puts_at (0, ++line, strGet(STATS_ITEM_6), MNORMAL);
write_ndigit_number_u (14, line, max_Capacity, 4, 0,MNORMAL);
lcdx_printp_at(18, line, PSTR("mAh"), MNORMAL, 2,0);
return( ScreenName );
}
 
//--------------------------------------------------------------
//--------------------------------------------------------------
void print_statistics (void)
{
lcd_cls ();
lcd_puts_at(12, 7, strGet(ENDE), 0);
 
OSD_Screen_Statistics( OSD_SCREEN_REDRAW );
 
while (!get_key_press (1 << KEY_ESC))
timer = TIMEOUT;
 
COSD_FLAGS2 &= ~COSD_WASFLYING;
get_key_press(KEY_ALL);
lcd_cls();
}
 
 
//-----------------------------------------------------------
//-----------------------------------------------------------
void OSD_Info( uint8_t ScreenNum, const char *ScreenName)
{
lcd_frect( 0, 36, 127, 10, 0); // clear
lcd_frect( 0, 34, 4, 4, 0); // clear links
lcd_frect( 0, 40, 127, 24, 1); // Box
lcd_frect( 10, 36, 108, 4, 1); // Filler oben
lcd_fcircle( 8, 39, 7, 1); // Links
lcd_fcircle( 121, 41, 5, 1); // Rechts
 
lcd_line ( 4, 51, 122, 51, 0); // Linie mitte
 
//-----------------------
// ScreenNummer: ScreenName
//-----------------------
write_ndigit_number_s ( 1, 5, ScreenNum, 2, 1,2);
lcd_printp_at( 3, 5, PSTR(":"), 2);
lcd_printp_at( 5, 5, ScreenName, 2);
 
//-----------------------
// Key's
//-----------------------
lcd_puts_at(0, 7, strGet(KEYLINE3), 2);
lcd_printp_at (17, 7, PSTR("Info"), 2);
do
{
timer = TIMEOUT;
_delay_ms(50);
} while ( !( (get_key_press (1 << KEY_ENTER)) || (get_key_press (1 << KEY_ESC)) || (get_key_press (1 << KEY_PLUS)) || (get_key_press (1 << KEY_MINUS)) ) );
}
 
 
 
//##############################################################
//# OSD MAIN LOOP
//##############################################################
 
//--------------------------------------------------------------
// OSD MAIN LOOP
//--------------------------------------------------------------
void osd( uint8_t ShowMode )
{
uint8_t flag;
uint8_t tmp_dat;
uint8_t ScreenRefresh;
uint8_t MAX_OSD_Screens;
//uint8_t status; // FC Kommunikation
const char *ScreenName = PSTR("");
 
lcd_cls();
 
//----------------------------------------
// NC Hardware needed
//----------------------------------------
if( hardware == FC )
{
lcd_puts_at(0, 3, strGet(ONLY_NC), 0); // Nur mit NC
timer = 100;
while (timer > 0);
return;
}
 
/*
//-----------------------------------------------------------------------------------------------
// 07.03.2013 OG: del
// Dieser Teil hat immer wieder Probleme bereitet bei der Verbindung des PKT-OSD zum MK da
// Timeouts zustande kamen. Eine Recherche im Code ergab, dass die Nutzdaten die
// hierueber bezogen werden sich lediglich auf Flags_ExtraConfig beschraenkten (CFG2_HEIGHT_LIMIT).
// Siehe dazu untere Kommentare.
//
// Der negative Effekt moeglicher Timeouts und Verzoegerungen sind es aktuell nicht Wert
// CFG2_HEIGHT_LIMIT zu unterstuetzen. Dieses Feature ist erstmal raus.
//
// Falls gewuenscht wird, dass CFG2_HEIGHT_LIMIT wieder in das PKT-OSD kommt muss
// es zuverlaessig an anderer Stelle implementiert werden - und zwar nicht in osd.c
// weil es eine statische FC-Information ist (ggf. beim Verbindungsaufbau PKT <-> MK).
//
// Hat auch aktuell Auswirkung auf den Code OSD_Element_AltitudeControl()
//
lcd_printp_at( 0, 3, PSTR("connecting MK..."), 0);
 
SwitchToFC();
 
status = load_setting(0xff);
if( status == 255 )
{
lcd_puts_at(0, 0, strGet(NO_SETTINGS), 0); // Keine Settings
_delay_ms(2000);
}
Flags_ExtraConfig = mk_param_struct->ExtraConfig; // OG: wird in osd.c nur verwendet von: OSD_Element_AltitudeControl()
Flags_GlobalConfig = mk_param_struct->GlobalConfig; // OG: wird nicht in osd.c verwendet
Flags_GlobalConfig3 = mk_param_struct->GlobalConfig3; // OG: wird nicht in osd.c verwendet
*/
 
rxd_buffer_locked = FALSE; // 07.03.2013 OG: fix
// es gab Probleme mit dem Empfang gueltiger NC-Daten, die zu unschoenen Starteffekten bei den
// OSD-Screens gefuehrt haben. Mit rxd_buffer_locked = FALSE vor SwitchToNC() ist das PKT wieder im 'Takt'
SwitchToNC();
 
mode = 'O';
 
// disable debug...
// RS232_request_mk_data (0, 'd', 0);
tmp_dat = 0;
SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
 
// request OSD Data from NC every 100ms
// RS232_request_mk_data (1, 'o', 100);
tmp_dat = 10;
OSD_active = true; // benoetigt für Navidata Ausgabe an SV2
SendOutData( 'o', ADDRESS_NC, 1, &tmp_dat, 1);
 
//-------------------------
// Clear statistics
//-------------------------
max_Altimeter = 0;
max_GroundSpeed = 0;
max_Distance = 0;
min_UBat = 255;
max_FlyingTime = 0;
CellIsChecked = 0;
cells = 0;
AkkuWarnThreshold = 0;
OldWP = 0;
NextWP = false;
 
//-------------------------
//-------------------------
MAX_OSD_Screens = 8;
 
#ifdef OSD_DEBUG_SCREEN
MAX_OSD_Screens += 1;
#endif
if( Config.OSD_ScreenMode >= MAX_OSD_Screens ) Config.OSD_ScreenMode = 0;
 
 
//-------------------------
// Timer & Flags
//-------------------------
ScreenRefresh = OSD_SCREEN_REDRAW;
flag = 0;
timer = TIMEOUT;
abo_timer = ABO_TIMEOUT;
timer2 = OSD_REFRESH_TIME;
 
do
{
if( rxd_buffer_locked )
{
timer = TIMEOUT;
Decode64 ();
naviData = (NaviData_t *) pRxData;
 
 
//----------------------------------
// Winkel zu Home
//----------------------------------
if( Config.OSD_HomeMKView == 1 )
heading_home = (naviData->HomePositionDeviation.Bearing + 360 - naviData->CompassHeading) % 360;
else
heading_home = (naviData->CompassHeading - naviData->HomePositionDeviation.Bearing + 360 ) % 360;
 
 
//----------------------------------
// speichere letzte GPS-Positionen
//----------------------------------
GPS_Pos_t currpos;
currpos.Latitude = naviData->CurrentPosition.Latitude;
currpos.Longitude = naviData->CurrentPosition.Longitude;
 
if((currpos.Latitude != last5pos[0].Latitude)&&(currpos.Longitude != last5pos[0].Longitude))
{
last5pos[6] = last5pos[5];
last5pos[5] = last5pos[4];
last5pos[4] = last5pos[3];
last5pos[3] = last5pos[2];
last5pos[2] = last5pos[1];
last5pos[1] = last5pos[0];
last5pos[0] = currpos;
}
 
// 07.03.2013 OG: Speichere permanent letzte Position in Config
// wurde vorher nur in OSD_TimeOut() gemacht
Config.LastLatitude = currpos.Latitude; // speichere letzte Position in Config
Config.LastLongitude = currpos.Longitude; // speichere letzte Position in Config
 
flag = 1;
 
if (naviData->FCStatusFlags & FC_STATUS_MOTOR_RUN)
{ // should be engines running
// motors are on, assume we were/are flying
COSD_FLAGS2 |= COSD_WASFLYING;
}
 
 
//----------------------------------
// remember statistics (only when engines running)
//----------------------------------
if( naviData->FCStatusFlags & FC_STATUS_MOTOR_RUN )
{
if (naviData->Altimeter > max_Altimeter) max_Altimeter = naviData->Altimeter;
if (naviData->GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData->GroundSpeed;
if (naviData->HomePositionDeviation.Distance > max_Distance) max_Distance = naviData->HomePositionDeviation.Distance;
if (naviData->FlyingTime > max_FlyingTime) max_FlyingTime = naviData->FlyingTime;
if (naviData->UBat < min_UBat) min_UBat = naviData->UBat;
if (naviData->Current > max_Current) max_Current = naviData->Current;
if (naviData->UsedCapacity > max_Capacity) max_Capacity = naviData->UsedCapacity;
}
 
//----------------------------------
// OSD-Screens
//----------------------------------
if( ScreenRefresh == OSD_SCREEN_REDRAW ) lcd_cls();
 
if( timer2 == 0 || ScreenRefresh == OSD_SCREEN_REDRAW)
{
if( Config.OSD_ScreenMode == 0) ScreenName = OSD_Screen_General( ScreenRefresh );
else if( Config.OSD_ScreenMode == 1) ScreenName = OSD_Screen_Navigation( ScreenRefresh );
else if( Config.OSD_ScreenMode == 2) ScreenName = OSD_Screen_MKStatus( ScreenRefresh );
else if( Config.OSD_ScreenMode == 3) ScreenName = OSD_Screen_OSD0( ScreenRefresh );
else if( Config.OSD_ScreenMode == 4) ScreenName = OSD_Screen_OSD1( ScreenRefresh );
else if( Config.OSD_ScreenMode == 5) ScreenName = OSD_Screen_OSD2( ScreenRefresh );
else if( Config.OSD_ScreenMode == 6) ScreenName = OSD_Screen_3DLage( ScreenRefresh );
else if( Config.OSD_ScreenMode == 7) ScreenName = OSD_Screen_Statistics( ScreenRefresh );
 
#ifdef OSD_DEBUG_SCREEN
else if( Config.OSD_ScreenMode == (MAX_OSD_Screens-1) ) ScreenName = OSD_Screen_Debug( ScreenRefresh );
#endif
}
ScreenRefresh = OSD_SCREEN_REFRESH;
if( timer2 == 0 ) timer2 = OSD_REFRESH_TIME;
 
//-----------------------
// Key-Handler
//-----------------------
 
//if (get_key_press (1 << KEY_PLUS))
//{
// print_position ();
//}
if( get_key_press (1 << KEY_ENTER) ) // info
{
OSD_Info( Config.OSD_ScreenMode, ScreenName);
ScreenRefresh = OSD_SCREEN_REDRAW;
}
if (get_key_press (1 << KEY_MINUS)) // previous screen
{
if( Config.OSD_ScreenMode == 0 )
Config.OSD_ScreenMode = MAX_OSD_Screens-1;
else
Config.OSD_ScreenMode--;
ScreenRefresh = OSD_SCREEN_REDRAW;
}
 
if (get_key_press (1 << KEY_PLUS)) // next Screen
{
Config.OSD_ScreenMode++;
Config.OSD_ScreenMode = ( Config.OSD_ScreenMode >= MAX_OSD_Screens ? 0 : Config.OSD_ScreenMode );
ScreenRefresh = OSD_SCREEN_REDRAW;
}
 
 
//-----------------------
// Akku Warnung
//-----------------------
CheckMKLipo();
 
// if (naviData->UBat > MK_LowBat) //bei kurzzeitigen Schwankungen Beeper erst wieder aus wenn UBat 0,2 V höher als Warnschwelle
// { //Beeper aus
// BeepTime = 0;
// BeepMuster = 0xFFFF;
// }
// Akku Warnung Ende
 
 
//-----------------------
// remember last values
//-----------------------
last_RC_Quality = naviData->RC_Quality;
last_UBat = naviData->UBat;
old_FCFlags = naviData->FCStatusFlags;
 
rxd_buffer_locked = FALSE;
 
 
//-----------------------
// abo_timer
//-----------------------
if (!abo_timer)
{ // renew abo every 3 sec
// request OSD Data from NC every 100ms
// RS232_request_mk_data (1, 'o', 100);
tmp_dat = 10;
SendOutData ('o', ADDRESS_NC, 1, &tmp_dat, 1);
abo_timer = ABO_TIMEOUT;
}
} //if (rxd_buffer_locked)
if (!timer)
{
OSD_Timeout(flag);
flag = 0;
ScreenRefresh = OSD_SCREEN_REDRAW;
}
} while (!get_key_press (1 << KEY_ESC));
OSD_active = false;
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/osd/osd.h
0,0 → 1,111
/*****************************************************************************
* 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*
*****************************************************************************/
 
 
#ifndef _OSD_H
#define _OSD_H
 
 
#define OSD_SCREEN_REFRESH 0 // Screen: Werte anzeigen
#define OSD_SCREEN_REDRAW 1 // Screen: Labels und statischer Elemente neu zeichen, Werte anzeigen
 
 
// Flags
#define OSD_FLAG_AH 0 // Altitue Hold
#define OSD_FLAG_PH 1 // Position Hold
#define OSD_FLAG_CF 2 // Care Free
#define OSD_FLAG_CH 3 // Coming Home
#define OSD_FLAG_O1 4 // Out1 (LED 1)
#define OSD_FLAG_O2 5 // Out2 (LED 2)
#define OSD_FLAG_BA 6 // LowBat warning (MK)
#define OSD_FLAG_CA 7 // Calibrate
#define OSD_FLAG_ST 8 // Start
#define OSD_FLAG_MR 9 // Motor Run
#define OSD_FLAG_FY 10 // Fly
#define OSD_FLAG_EL 11 // Emergency Landing
#define OSD_FLAG_FS 12 // RS Failsave Active
#define OSD_FLAG_GP 13 // GPS ok
#define OSD_FLAG_S0 14 // GPS-Sat not ok (GPS NOT ok)
#define OSD_FLAG_TU 15 // Vario Trim Up
#define OSD_FLAG_TD 16 // Vario Trim Down
#define OSD_FLAG_FR 17 // Free
#define OSD_FLAG_RL 18 // Range Limit
#define OSD_FLAG_SL 19 // No Serial Link
#define OSD_FLAG_TR 20 // Target Reached
#define OSD_FLAG_MC 21 // Manual Control
 
#define OSD_FLAG_COUNT 22
 
 
void osd (uint8_t ShowMode);
void vario_beep_output (void);
void OSD_Timeout(uint8_t flag);
void CheckMKLipo(void);
extern volatile uint8_t OSD_active;
extern volatile uint8_t error;
 
void OSD_Element_Flag_Label( uint8_t xC, uint8_t yC, uint8_t item, uint8_t lOn, int8_t xoffs, int8_t yoffs);
void OSD_Element_Flag( uint8_t xC, uint8_t yC, uint8_t item, int8_t xoffs, int8_t yoffs);
void OSD_Element_AltitudeControl( uint8_t x, uint8_t y );
void OSD_Element_Altitude( uint8_t x, uint8_t y, uint8_t nStyle );
void OSD_Element_BattLevel2( uint8_t x, uint8_t y, int8_t xoffs, int8_t yoffs );
void OSD_Element_BatteryLevel_Bar( uint8_t x, uint8_t y );
void OSD_Element_BatteryLevel_Text( uint8_t x, uint8_t y, uint8_t nStyle );
void OSD_Element_BatteryLevel( uint8_t x, uint8_t y, uint8_t nStyle );
void OSD_Element_Capacity( uint8_t x, uint8_t y );
void OSD_Element_CareFree( uint8_t x, uint8_t y );
void OSD_Element_CompassDegree( uint8_t x, uint8_t y, uint8_t nStyle );
void OSD_Element_CompassDirection( uint8_t x, uint8_t y );
void OSD_Element_CompassRose( uint8_t x, uint8_t y );
void OSD_Element_Current( uint8_t x, uint8_t y );
void OSD_Element_FlyingTime( uint8_t x, uint8_t y );
void OSD_Element_GroundSpeed( uint8_t x, uint8_t y );
void OSD_Element_HomeCircle( uint8_t x, uint8_t y, uint8_t breite, int8_t rOffset, int8_t xoffs, int8_t yoffs );
void OSD_Element_HomeDegree( uint8_t x, uint8_t y );
void OSD_Element_HomeDistance( uint8_t x, uint8_t y, uint8_t nStyle );
void OSD_Element_LEDOutput( uint8_t x, uint8_t y, uint8_t bitmask );
void OSD_Element_LED1Output( uint8_t x, uint8_t y );
void OSD_Element_LED2Output( uint8_t x, uint8_t y );
void OSD_Element_Manuell( uint8_t x, uint8_t y );
void OSD_Element_NaviMode( uint8_t x, uint8_t y );
void OSD_Element_RCIntensity( uint8_t x, uint8_t y );
void OSD_Element_SatsInUse( uint8_t x, uint8_t y, uint8_t nStyle );
void OSD_Element_StatusFlags( uint8_t x, uint8_t y );
void OSD_Element_Variometer( uint8_t x, uint8_t y );
void OSD_Element_Target( uint8_t x, uint8_t y, uint8_t nStyle );
void OSD_Element_VarioWert( uint8_t x, uint8_t y );
void OSD_Element_WayPoint( uint8_t x, uint8_t y );
void OSD_Element_TargetDegree( uint8_t x, uint8_t y );
void OSD_Element_UpDown( uint8_t x, uint8_t y, int8_t xoffs, int8_t yoffs);
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/setup/.directory
0,0 → 1,3
[Dolphin]
Timestamp=2013,3,4,21,10,43
ViewMode=1
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/setup/setup.c
0,0 → 1,2518
/*****************************************************************************
* 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*
*****************************************************************************/
 
 
//############################################################################
//# HISTORY setup.c
//#
//# 04.03.2013 Cebra
//# - del: OSD-Sreenmode ,is no longer necessary, last OSD-Screen is saved at shutdown
//############################################################################
 
 
//bt_connect
#include "../cpu.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <string.h>
#include <util/delay.h>
#include "../main.h"
#include "../setup/setup.h"
#include "../lcd/lcd.h"
#include "../eeprom/eeprom.h"
#include "../timer/timer.h"
#include "../menu.h"
#include "../wi232/Wi232.h"
#include "../bluetooth/bluetooth.h"
#include "../connect.h"
#include "../lipo/lipo.h"
#include "../messages.h"
#include "../eeprom/eeprom.h"
#include "../tracking/tracking.h"
#include "../uart/uart1.h"
#include "../osd/osd.h"
#include "../sound/pwmsine8bit.h"
#include "../tracking/servo_setup.h"
#include "../bluetooth/error.h"
#include "../stick/stick_setup.h"
 
 
 
uint8_t spalte;
uint8_t mmode;
uint8_t edit;
uint8_t LCD_Orientation;
uint8_t edit = 0;
uint8_t LCD_Change = 0;
uint8_t PKT_Change = 0;
uint16_t Pre;
uint16_t Pre16;
char EditString[21];
uint8_t bt_name_len;
uint8_t length_tmp;
uint8_t CheckGPS=false;
uint8_t Old_Baudrate = 0; //Merkzelle für alte Baudrate
 
//--------------------------------------------------------------
#define ITEMS_PKT 13
 
const prog_char param_menuitems_pkt[ITEMS_PKT][NUM_LANG][18]= // zeilen,zeichen+1
// German, English, French, Dutch
{
{"Verbindung zum MK","connection to MK ","Aansluiting op MK"},
{"PKT allgemein \x1d","PKT global \x1d","PKT global \x1d"},
{"Wi.232 \x1d","Wi.232 \x1d","Wi.232 \x1d"},
{"BTM-222 \x1d","BTM-222 \x1d","BTM-222 \x1d"},
{"Servo Menü \x1d","servo menu \x1d","servo menu \x1d"},
{"OSD Anzeige \x1d","OSD screen \x1d","OSD screen \x1d"},
{"GPS \x1d","GPS \x1d","GPS \x1d"},
{"Follow Me \x1d","Follow Me \x1d","Follow Me \x1d"},
{"Joystick \x1d","joystick \x1d","joystick \x1d"},
{"PKT-Akku \x1d","PKT-Accu \x1d","PKT-Accu \x1d"},
{"PKT Update ","PKT Update ","PKT Update "},
{"Debug PKT ","Debug PKT ","Debug PKT "},
{"EEProm Reset ","EEProm Reset ","EEProm Reset "},
};
 
#define ITEMS_LCD 11
 
const prog_char param_menuitems_lcd[ITEMS_LCD][NUM_LANG][18]= // zeilen,zeichen+1
// German, English, French, Dutch
{
{"Infos beim Start ","info at startup ","info bij opstart "},
{"OSD Empfangsausf.","OSD receive Error","OSD receive Error"},
{"Sprache ","language ","taal "},
{"Licht aus nach...","light off after ","licht uit na "},
{"Helligkeit ","brightness ","helderheid "},
{"Kontrast ","contrast ","contrast "},
{"Normal/Invers ","normal/inverted ","Normal/inverted "},
{"Orientierung ","orientation ","orientatie "},
{"Vario Ton Erw. ","Vario Sound Ext. ","Vario Sound Ext. "},
{"Hardware Beeper ","Hardware Beeper ","Hardware Beeper "},
{"Lautstärke Ton ","Volume ","Volume "},
};
 
#define ITEMS_WI 9
 
const prog_char param_menuitems_wi[ITEMS_WI][NUM_LANG][18]= // zeilen,zeichen+1
// German, English, French, Dutch
{
{"Modul eingebaut? ","module built in? ","Module geinstal.?"},
{"TX/RX Kanal ","TX/RX Channel ","TX/RX Channel "},
{"NetW. Gruppe ","NetW. Group ","NetW. Group "},
{"NetW. Mode ","NetW. Mode ","NetW. Mode "},
{"TX Timeout ","TX Timeout ","TX Timeout "},
{"TX MTU ","TX MTU ","TX MTU "},
{"Baudrate Wi232/BT","Baudrate Wi232/BT","Baudrate Wi232/BT"},
{"Initialisieren ","initialize ","Initialize "},
{"Konfig. mit PC ","config. with PC ","Config. met PC "},
};
 
 
#define ITEMS_BT 7
 
const prog_char param_menuitems_bt[ITEMS_BT][NUM_LANG][18]= // zeilen,zeichen+1
// German, English, Dutch
{
{"Modul eingebaut? ","module built in? ","module geinstall?"},
{"Name ","name ","Naam "},
{"Pin ","pin ","Pin "},
{"Initialisieren ","initialize ","Initialize "},
{"Bluetooth MAC-Adr","Bluetooth MAC-Adr","Bluetooth MAC-Adr"},
{"RE-ID ","RE-ID ","RE-ID "},
{"Konfig. mit PC ","config. with PC ","Config. met PC "},
};
 
#define ITEMS_Accu 2
 
const prog_char param_menuitems_Accu[ITEMS_Accu][NUM_LANG][18]= // zeilen,zeichen+1
// German, English, French, Dutch
{
{"PKT-Akkutyp ","PKT-Accutyp ","PKT-batterij type"},
{"PKT Akku Messung ","PKT AccuMeasure ","PKT batt. meting "},
};
 
#define ITEMS_GPS 6
 
const prog_char param_menuitems_GPS[ITEMS_GPS][NUM_LANG][18]= // zeilen,zeichen+1
// German, English, French, Dutch
{
{"wähle GPS Maus ","select GPS mouse ","select GPS mouse "},
{"Suche GPS Maus ","search GPS mouse ","search GPS mouse "},
{"GPS Maus Typ ","GPS mouse typ ","GPS mouse typ "},
{"GPS Maus aktiv? ","GPS mouse activ? ","GPS mouse activ? "},
{"Zeige GPS Device ","show GPS device ","show GPS device "},
{"GPS Daten ","GPS data ","GPS data "},
 
};
 
#define ITEMS_FOLLOWME 3
 
const prog_char param_menuitems_FOLLOWME[ITEMS_GPS][NUM_LANG][18]= // zeilen,zeichen+1
// German, English, French, Dutch
{
{"FollowMe Refresh","FollowMe Refresh","FollowMe Refresh"},
{"FollowMe Speed ","FollowMe Speed ","FollowMe Speed "},
{"Toleranz Radius ","Tolerance Radius","Tolerance Radius"},
 
 
};
 
 
 
#define ITEMS_OSD 9
 
const prog_char param_menuitems_OSD[ITEMS_OSD][NUM_LANG][18]= // zeilen,zeichen+1
// German, English, French, Dutch
{
{"OUT1/2 Format ","OUT1/2 format ","OUT1/2 format "},
{"OUT1/2 Polarität ","OUT1/2 polarity ","OUT1/2 polarity "},
{"Navi Daten an SV2","Navi data to SV2 ","Navi data to SV2 "},
{"Max. Sinkrate m/s","max fallspeed m/s","max fallspeed m/s"},
{"Variometer Beep ","Variometer beep ","Variometer beep "},
{"Home aus MK Sicht","home from MK view","home from MK view"},
{"MK LowBat Warnung","MK LowBat warning","MK LoBat alarm "},
{"MK mAh Warnung","MK mAh warning ","MK mAh alarm "},
{"MK Volt Balken","MK volt bargraph ","MK volt bargraph "},
};
 
//--------------------------------------------------------------
void Show_Error_HW12(void)
{
lcd_cls();
lcd_printp_at (0,3,PSTR(" Mit Hardware 1.x "), 2);
lcd_printp_at (0,4,PSTR(" nicht möglich "), 2);
_delay_ms(1000);
 
}
 
void Edit_printout(uint16_t Value,uint16_t min,uint16_t max, uint8_t what)
{
 
switch (what)
{
case Show_uint3: write_ndigit_number_u (16, 2,Value, 3, 0,0);break;
case Show_uint5: write_ndigit_number_u (16, 2,Value, 5, 0,0);break;
case Show_uint10th: write_ndigit_number_u_10th (16, 2,Value, 3, 0,0); break;
case GPSMOUSE:
switch(Value)
{
case GPS_Bluetoothmouse1: lcd_printp_at (12, 2, PSTR("BT-Mouse1"), 0);break;
case GPS_Mikrokopter: lcd_printp_at (12, 2, PSTR("Mikrokopt"), 0);break;
lcd_printp_at (12, 2, PSTR("unknown"), 0);
break;
 
}
break;
 
case Wi_Netmode:
switch (Value)
{
case false :lcd_puts_at(15, 2, strGet(SLAVE), 0);
break;
case true :lcd_puts_at(15, 2, strGet(NORMAL), 0);
break;
break;
}
break;
 
case OnOff:
switch (Value)
 
{
case false :lcd_puts_at(17, 2, strGet(OFF), 0);
break;
case true :lcd_puts_at(17, 2, strGet(ON), 0);
break;
break;
}
break;
 
case YesNo:
switch (Value)
 
{
case false :lcd_puts_at(17, 2, strGet(NOO), 0);
break;
case true :lcd_puts_at(17, 2, strGet(YES), 0);
break;
break;
}
break;
 
case NormRev:
switch (Value)
{
case false :lcd_puts_at(14, 2, strGet(NORMAL), 0);
break;
case true :lcd_puts_at(14, 2, strGet(REVERSE), 0);
break;
break;
}
break;
 
 
 
case Kontrast: {
write_ndigit_number_u (16, 2,Value, 3, 0,0);
if (Value >= max)
{
Value = max;
set_beep ( 200, 0x0080, BeepNormal);
write_ndigit_number_u (16, 2,Value, 3, 0,0);
}
else
{
write_ndigit_number_u (16, 2,Value, 3, 0,0);
cli();
clr_A0 ();
send_byte (0x81);
send_byte (Value); // Daten zum LCD senden
set_A0 ();
sei();
}
 
// break;
 
if (Value == min)
{
write_ndigit_number_u (16, 2,Value, 3, 0,0);
Value = min;
set_beep ( 200, 0x0080, BeepNormal);
}
else
{
write_ndigit_number_u (16, 2,Value, 3, 0,0);
cli();
clr_A0 ();
send_byte (0x81);
send_byte (Value); // Daten zum LCD senden
set_A0 ();
sei();
}
 
}
break;
 
 
case Baudrate:
switch (Value)
 
{
case 0x0 : lcd_printp_at(15, 2, PSTR("2400 "), 0);
break;
case 0x1 : lcd_printp_at(15, 2, PSTR("9600 "), 0);
break;
case 0x2 : lcd_printp_at(15, 2, PSTR("19200 "), 0);
break;
case 0x3 : lcd_printp_at(15, 2, PSTR("38400 "), 0);
break;
case 0x4 : lcd_printp_at(15, 2, PSTR("57600 "), 0);
break;
case 0x5 : lcd_printp_at(15, 2, PSTR("115200"), 0);
break;
case 0x6 : lcd_printp_at(15, 2, PSTR("4800 "), 0);
break;
break;
}
break;
case Language:
switch (Value)
{
case
0x0 : lcd_puts_at(10, 2, strGet(DEUTSCH), 0);//lcd_printp_at (14, 2, PSTR("Deutsch"), 0);
break;
case 0x1 : lcd_puts_at(10, 2, strGet(ENGLISCH), 0);//lcd_printp_at (14, 2, PSTR("English"), 0);
break;
case 0x2 : lcd_puts_at(10, 2, strGet(NETHERL), 0);//lcd_printp_at (14, 2, PSTR("Netherl"), 0);
break;
break;
}
break;
case Sticktype:
switch (Value)
 
{
case false :lcd_puts_at(14, 2, strGet(POTI), 0);
break;
case true :lcd_puts_at(14, 2, strGet(TASTER), 0);
break;
break;
}
break;
 
 
 
break;
}
 
}
 
uint16_t Edit_generic(uint16_t Value, uint16_t min, uint16_t max,uint8_t Text, uint8_t what)
{
Pre = Value;
 
lcd_cls();
lcd_puts_at(0, 2, strGet(Text), 0);
Edit_printout(Value,min,max, what);
lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
 
do
{
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 2)) && (Value < max))
{
edit = 1;
Value++;
Edit_printout(Value,min,max, what);
playTone(500,20,Config.Volume);
}
if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 2)) && (Value > min))
{
edit = 1;
Value--;
Edit_printout(Value,min,max, what);
playTone(500,20,Config.Volume);
}
 
if (get_key_press (1 << KEY_ENTER))
{
 
return Value;
}
}
while (!get_key_press (1 << KEY_ESC));
 
get_key_press(KEY_ALL);
edit = 0;
return Pre;
 
}
 
//--------------------------------------------------------------
uint8_t ChangeWi_SV2(uint8_t Value)
{
Pre = Value;
lcd_cls();
 
lcd_puts_at(0, 1, strGet(CONNECT1), 0);
lcd_puts_at(0, 2, strGet(CONNECT2), 0);
 
if(Config.UseWi == false)
{
lcd_puts_at(0, 1, strGet(CONNECT1), 0);
lcd_puts_at(0, 2, strGet(CONNECT4), 0);
lcd_puts_at(0, 1, strGet(CONNECT5), 0);
lcd_puts_at(0, 2, strGet(CONNECT6), 0);
lcd_puts_at(0, 1, strGet(CONNECT7), 0);
lcd_puts_at(0, 2, strGet(CONNECT8), 0);
lcd_puts_at(0, 1, strGet(CONNECT9), 0);
 
 
// lcd_printp_at (12, 7, PSTR("Ende"), 0);
lcd_puts_at(12, 7, strGet(ENDE), 0);
while (!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
edit = 0;
return Pre;
}
else
{
switch (Value)
{
case 0x0 :lcd_printp_at (14, 2, PSTR("Wi232"), 0);
break;
case 0x1 : lcd_puts_at(14, 2, strGet(KABEL), 0);
 
//lcd_printp_at (14, 2, PSTR("Kabel"), 0);
 
break;
break;
}
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
 
do
{
if(Config.UseWi == true)
{
if ((get_key_press (1 << KEY_PLUS)) && (Value == 0))
{
edit = 1;
Value = 1;
// lcd_printp_at (14, 2, PSTR("Kabel"), 0);
lcd_puts_at(14, 2, strGet(KABEL), 0);
Change_Output(Uart02FC);
}
 
if ((get_key_press (1 << KEY_MINUS)) && (Value == 1))
{
edit = 1;
Value = 0;
lcd_printp_at (14, 2, PSTR("Wi232"), 0);
Change_Output(Uart02Wi);
}
 
if (get_key_press (1 << KEY_ENTER))
{
// lcd_printp_at (0, 4, PSTR("Sie müssen das PKT"), 0);
// lcd_printp_at (0, 5, PSTR("jetzt neu starten!"), 0);
lcd_puts_at(0, 4, strGet(CONNECT10), 0);
lcd_puts_at(0, 5, strGet(CONNECT11), 0);
lcd_cls_line (0, 7, 18);
while (!get_key_press (1 << KEY_ENTER));
return Value;
}
}
}
while (!get_key_press (1 << KEY_ESC));
}
get_key_press(KEY_ALL);
edit = 0;
return Pre;
}
 
 
//--------------------------------------------------------------
uint8_t Edit_DisplayHelligkeit(uint8_t Value, uint8_t min, uint8_t max, uint8_t Text)
{
float ValCorr = 2.55; // (Value * ValCorr) maximal 255
Pre = Value;
OCR2A = Value * ValCorr;
 
lcd_cls();
// lcd_printp_at (0, 2, Text, 0);
lcd_puts_at(0, 2, strGet(Text), 0);
write_ndigit_number_u (16, 2, Value, 3, 0,0);
lcd_printp_at (17, 2, PSTR("%"), 0);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
 
do
{
write_ndigit_number_u (16, 2,Value, 3, 0,0);
lcd_frect ((8*0), (8*4), (Value * (16*8) / 100), 6, 1);
 
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 3)) && (Value < max))
{
Value++;
 
if (Value >= max)
{
Value = max;
set_beep ( 200, 0x0080, BeepNormal);
}
else
OCR2A = Value * ValCorr;
 
}
 
if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 3)) && (Value > min))
{
lcd_frect (((Value - 1) * (16*8) / 100), (8*4), (16*8), 6, 0);
Value--;
 
if (Value == min)
{
Value = min;
set_beep ( 200, 0x0080, BeepNormal);
}
else
OCR2A = Value * ValCorr;
 
}
 
if (get_key_press (1 << KEY_ENTER))
{
edit = 1;
OCR2A = Value * ValCorr;
Config.LCD_Helligkeit = Value;
// WriteParameter();
edit = 0;
return Value;
}
}
 
while (!get_key_press (1 << KEY_ESC));
{
get_key_press(KEY_ALL);
edit = 0;
OCR2A = Pre * ValCorr;
Config.LCD_Helligkeit = Pre;
// WriteParameter();
return Pre;
}
}
 
 
//--------------------------------------------------------------
void Reset_EEprom(void)
{
lcd_cls();
get_key_press(KEY_ALL);
// lcd_printp_at (0, 2, PSTR(" EEProm wirklich"), 0);
// lcd_printp_at (0, 3, PSTR(" löschen?"), 0);
// lcd_printp_at (12, 7, PSTR("Ende OK"), 0);
lcd_puts_at(0, 2, strGet(EEPROM1), 0);
lcd_puts_at(0, 3, strGet(EEPROM2), 0);
lcd_puts_at(12, 7, strGet(ENDOK), 0);
 
 
do
{
 
if (get_key_press (1 << KEY_ENTER))
{
Delete_EEPROM();
clr_V_On();
return;
}
}
while (!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
}
 
 
//--------------------------------------------------------------
void PKT_Setup (void)
{
// uint8_t ii = 0;
// uint8_t Offset = 0;
// uint8_t size = 0;
 
// uint8_t dmode = 0;
uint8_t target_pos=1;
// uint8_t val;
 
lcd_cls ();
mmode = 0;
edit= 0;
val = 0;
 
while(1)
{
size = ITEMS_PKT;
lcd_cls ();
lcd_printp_at (0, 0, PSTR(" PKT-Setup "), 2);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
 
// while(1)
// {
// ii = 0;
//
// if(Offset > 0)
// lcd_printp_at(1,1, PSTR("\x12"), 0);
//
// for(ii = 0;ii < 6 ; ii++)
// {
// if((ii+Offset) < size)
// lcd_printp_at(3,ii+1,param_menuitems_pkt[ii+Offset][Config.DisplayLanguage], 0);
//
// if((ii == 5)&&(ii+Offset < (size-1)))
// lcd_printp_at(1,6, PSTR("\x13"), 0);
//
// }
//
// if(dmode == 0)
// {
// if(Offset == 0)
// {
// if(size > 6)
// val = menu_choose2 (1, 5, target_pos,0,1);
// else
// val = menu_choose2 (1, size, target_pos,0,0);
//
// }
// else
// val = menu_choose2 (2, 5, target_pos,1,1);
//
// }
//
// if(dmode == 1)
// {
// if(Offset+7 > size)
// val = menu_choose2 (2, 6, target_pos,1,0);
// else
// val = menu_choose2 (2, 5, target_pos,1,1);
//
// }
//
// if(val == 254)
// {
// Offset++;
// dmode = 1;
// target_pos = 5;
// }
// else if(val == 253)
// {
// Offset--;
// dmode = 0;
// target_pos = 2;
// }
// else if(val == 255)
// { // Ende mit ESC, speichern
// if (edit == 1)
// {
// WriteParameter();
// edit = 0;
// return;
// }
// return;
// }
// else
// break;
// }
 
val = menu_select(param_menuitems_pkt,size,target_pos);
if (val==255) break;
target_pos = val;
 
//
// {"Verbindung zum MK","connection to MK "," connexion a MK " ,"Aansluiting op MK"},
// {"MK LowBat Warnung","MK LowBat warning","MK LowBat Attent", "MK LoBat alarm "},
// {"Anzeige \x1d","Display \x1d","d'affichage \x1d","Display \x1d"},
// {"Wi.232 \x1d","Wi.232 \x1d","Wi.232 \x1d","Wi.232 \x1d"},
// {"BTM-222 \x1d","BTM-222 \x1d","BTM-222 \x1d","BTM-222 \x1d"},
// {"Antennen Track. \x1d","antenna tracking\x1d","antenna tracking\x1d","antenna tracking\x1d"},
// {"OSD \x1d","OSD \x1d","OSD \x1d","OSD \x1d"},
// {"GPS \x1d","GPS \x1d","GPS \x1d","GPS \x1d"},
// "Follow Me \x1d"
// {"PKT-Akku \x1d","PKT-Accu \x1d","PKT-Accu \x1d","PKT-Accu \x1d"},
// {"PKT Update ","PKT Update ","PKT Mise a jour ","PKT Update "},
// {"Debug PKT ","Debug PKT ","Debug PKT ","Debug PKT "},
// {"EEProm Reset ","EEProm Reset ","EEProm Reinitiali","EEProm Reset "},
 
 
 
if((val + offset) == 1)
{
#ifdef HWVERSION3_9
Config.U02SV2 = ChangeWi_SV2(Config.U02SV2);
 
if (edit == 1)
PKT_Change = 1;
 
#else
Show_Error_HW12();
#endif
}
 
 
if((val + offset) == 2) Display_Setup();
 
if((val + offset) == 3)
{
#if defined HWVERSION3_9 || defined HWVERSION1_2W || defined HWVERSION1_3W
if(Config.UseWi == false)
// Wi_Use();
{
Config.UseWi = Edit_generic(Config.UseWi,0,1,WI2321,YesNo);
if (edit==1)
if (Config.UseWi== true) InitWi232(Config.PKT_Baudrate);
}
 
else
Wi_Setup();
#else
Show_Error_HW12();
#endif
}
 
if((val + offset) == 4)
{
#ifdef HWVERSION3_9
if(Config.UseBT == 0)
{
Config.UseBT = Edit_generic(Config.UseBT,0,1,BT1,YesNo);
if (edit==1)
if (Config.UseBT == 1)
{
if (bt_init()) Config.BTIsSet = true; else Config.BTIsSet = false;
// WriteParameter();
edit = 0;
}
}
else
BT_Setup();
#else
Show_Error_HW12();
#endif
}
 
if((val + offset) == 5) servo_menu();
if((val + offset) == 6) OSD_Setup();
#ifdef HWVERSION3_9
if((val + offset) == 7) GPS_Setup();
 
if((val + offset) == 8) FollowMe_Setup();
if((val + offset) == 9) Joysticks_Setup();
 
if((val + offset) == 10) Accu_Setup();
#else
Show_Error_HW12();
#endif
if((val + offset) == 11) Update_PKT();
 
if((val + offset) == 12) Config.Debug = Edit_generic(Config.Debug,0,1,DEBUGPKT,Show_uint3);
 
if((val + offset) == 13) Reset_EEprom();
 
 
}
}
 
 
//--------------------------------------------------------------
void Display_Setup (void)
{
// uint8_t ii = 0;
// uint8_t Offset = 0;
// uint8_t size = 0;
 
// uint8_t dmode = 0;
uint8_t target_pos = 1;
// uint8_t val;
 
lcd_cls ();
mmode = 0;
edit= 0;
LCD_Change = 0;
// val = 0;
 
while(1)
{
size = ITEMS_LCD;
lcd_cls ();
lcd_puts_at(0, 0, strGet(DISPLAY1), 2);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
 
// while(1)
// {
// ii = 0;
//
// if(Offset > 0)
// lcd_printp_at(1, 1, PSTR("\x12"), 0);
//
// for(ii = 0; ii < 6 ; ii++)
// {
// if((ii + Offset) < size)
// lcd_printp_at(3, ii + 1, param_menuitems_lcd[ii + Offset][Config.DisplayLanguage], 0);
//
// if((ii == 5)&&(ii+Offset < (size - 1)))
// lcd_printp_at(1,6, PSTR("\x13"), 0);
//
// }
//
// if(dmode == 0)
// {
// if(Offset == 0)
// {
// if(size > 6)
// val = menu_choose2 (1, 5, target_pos,0,1);
// else
// val = menu_choose2 (1, size, target_pos,0,0);
//
// }
// else
// val = menu_choose2 (2, 5, target_pos,1,1);
//
// }
//
// if(dmode == 1)
// {
// if(Offset + 7 > size)
// val = menu_choose2 (2, 6, target_pos,1,0);
// else
// val = menu_choose2 (2, 5, target_pos,1,1);
//
// }
//
// if(val == 254)
// {
// Offset++;
// dmode = 1;
// target_pos = 5;
// }
// else if(val == 253)
// {
// Offset--;
// dmode = 0;
// target_pos = 2;
// }
// else if(val == 255)
// { // Ende mit ESC, speichern
// if (edit == 1)
// {
// WriteParameter();
// edit = 0;
// return;
// }
// return;
// }
// else
// break;
// }
 
val = menu_select(param_menuitems_lcd,size,target_pos);
if (val==255) break;
target_pos = val;
 
if((val + offset) == 1)
Config.PKT_StartInfo = Edit_generic(Config.PKT_StartInfo,0,2,DISPLAY2,OnOff);
if((val + offset) == 2)
Config.OSD_RCErrorbeep = Edit_generic(Config.OSD_RCErrorbeep,0,2,DISPLAY9,OnOff);
 
if((val + offset) == 3)
Config.DisplayLanguage = Edit_generic(Config.DisplayLanguage,0,2,DISPLAY3,Language);
 
 
if((val + offset) == 4)
Config.DisplayTimeout = Edit_generic(Config.DisplayTimeout,0,254,DISPLAY4,Show_uint3);
 
if((val + offset) == 5)
{
if (Config.HWSound==0)
{
Config.LCD_Helligkeit = Edit_DisplayHelligkeit(Config.LCD_Helligkeit,0,100,DISPLAY5);
if (edit == 1)
if(!LCD_Change)
LCD_Change =1;
}
 
 
}
 
 
if((val + offset) == 6)
Config.LCD_Kontrast = Edit_generic(Config.LCD_Kontrast,0,63,DISPLAY6,Kontrast);
if (edit == 1)
if(!LCD_Change)
LCD_Change =1;
 
if((val + offset) == 7)
{
Config.LCD_DisplayMode = Edit_generic(Config.LCD_DisplayMode,0,4,DISPLAY7,NormRev);
if (edit == 1)
if(!LCD_Change)
LCD_Change =1;
}
 
if((val + offset) == 8)
{
Config.LCD_ORIENTATION = Edit_generic(Config.LCD_ORIENTATION,0,4,DISPLAY8,NormRev);
if (edit == 1)
if(!LCD_Change)
LCD_Change =1;
}
if((val + offset) == 9)
{
Config.HWSound = Edit_generic(Config.HWSound,0,1,HWSOUND,YesNo);
 
}
if((val + offset) == 10)
{
Config.HWBeeper = Edit_generic(Config.HWBeeper,0,1,HWBEEPER,YesNo);
 
}
if((val + offset) == 11)
Config.Volume = Edit_generic(Config.Volume,0,50,VOLUME,Show_uint3);
 
 
}
}
 
 
//--------------------------------------------------------------
void Wi_Setup (void)
{
// uint8_t ii = 0;
// uint8_t Offset = 0;
// uint8_t size = 0;
 
// uint8_t dmode = 0;
uint8_t target_pos = 1;
// uint8_t val = 0;
 
mmode = 0;
edit = 0;
// WiIsSet = true;
 
lcd_cls ();
 
while(1)
{
size = ITEMS_WI;
lcd_cls ();
lcd_printp_at (0, 0, PSTR(" Wi.232 Setup "), 2);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
 
// while(1)
// {
// ii = 0;
//
// if(Offset > 0)
// lcd_printp_at(1, 1, PSTR("\x12"), 0);
//
// for(ii = 0; ii < 6; ii++)
// {
// if((ii + Offset) < size)
// lcd_printp_at(3, ii+1, param_menuitems_wi[ii+Offset][Config.DisplayLanguage], 0);
//
// if((ii == 5)&&(ii + Offset < (size - 1)))
// lcd_printp_at(1, 6, PSTR("\x13"), 0);
//
// }
//
// if(dmode == 0)
// {
// if(Offset == 0)
// {
// if(size > 6)
// val = menu_choose2 (1, 5, target_pos,0,1);
// else
// val = menu_choose2 (1, size, target_pos,0,0);
//
// }
// else
// val = menu_choose2 (2, 5, target_pos,1,1);
//
// }
//
// if(dmode == 1)
// {
// if(Offset + 7 > size)
// val = menu_choose2 (2, 6, target_pos, 1, 0);
// else
// val = menu_choose2 (2, 5, target_pos, 1, 1);
//
// }
//
// if(val == 254)
// {
// Offset++;
// dmode = 1;
// target_pos = 5;
// }
// else if(val == 253)
// {
// Offset--;
// dmode = 0;
// target_pos = 2;
// }
// else if(val == 255)
// { // Ende mit ESC, speichern
// if (edit == 1)
// {
// if (Config.UseWi==true) InitWi232(Config.PKT_Baudrate);
// //Old_Baudrate = PKT_Baudrate;
// WriteParameter();
// edit = 0;
// }
//
// return;
// }
// else
//
// break;
// }
 
val = menu_select(param_menuitems_wi,size,target_pos);
if (val==255)
{
if (edit == 1)
{
if (Config.UseWi==true) InitWi232(Config.PKT_Baudrate);
//Old_Baudrate = PKT_Baudrate;
// WriteParameter();
edit = 0;
}
break;
}
 
target_pos = val;
 
if((val + offset) == 1)
{
Config.UseWi = Edit_generic(Config.UseWi,0,1,WI2321,YesNo);
}
 
if((val + offset) == 2)
{
Config.WiTXRXChannel = Edit_generic(Config.WiTXRXChannel, 0, 5,WITXRX,Show_uint3);
 
}
 
if((val + offset) == 3)
{
Config.WiNetworkGroup = Edit_generic(Config.WiNetworkGroup, 0, 127, WINETWG,Show_uint3);
 
 
}
 
if((val + offset) == 4)
{
Config.WiNetworkMode = Edit_generic(Config.WiNetworkMode,0,1,WINETWM,Wi_Netmode);
 
 
}
 
if((val + offset) == 5)
{
Config.WiTXTO = Edit_generic(Config.WiTXTO,0,127,WITIMEOUT,Show_uint3);
 
 
}
 
if((val + offset) == 6)
{
Config.WiUartMTU = Edit_generic(Config.WiUartMTU,0,127,WIUART,Show_uint3);
 
 
}
 
if((val + offset) == 7)
{
Old_Baudrate = Config.PKT_Baudrate;
Config.PKT_Baudrate = Edit_generic(Config.PKT_Baudrate,1,6,PKT_BAUDRATE,Baudrate);
Wi232_New_Baudrate = Config.PKT_Baudrate;
BT_New_Baudrate = Config.PKT_Baudrate;
if (edit==1)
{ if (Config.UseBT==true) { set_BTOn(); bt_setbaud(BT_New_Baudrate); set_BTOff();}
if (Config.UseWi==true) InitWi232(Wi232_New_Baudrate);
// WriteParameter();
Old_Baudrate = Config.PKT_Baudrate;
edit = 0;
}
 
 
}
 
 
 
if((val + offset) == 8)
InitWi232(Config.PKT_Baudrate);
if((val + offset) == 9)
Port_USB2CFG_Wi();
}
}
 
 
 
 
uint8_t Edit_String(const char *data, const uint8_t length, uint8_t type, const char *Text)
{
uint8_t y = 1;
uint8_t x = 1;
uint8_t I = 0;
 
lcd_cls();
lcd_printp_at (0, 0, Text, 2);
 
for (uint8_t i = 0; i < length; i++)
{
lcd_putc (y++, 3, data[i], 0);
lcd_printp_at (y++, 3, PSTR(" "), 0);
 
EditString[i] = data[i];
}
 
lcd_rect ((x*6)-3, (8*3)-2, 10, 10, 1);
lcd_printp_at (0, 6, PSTR(" C"), 0);
lcd_printp_at (0, 7, PSTR(" \x17 \x16 \x19 OK"), 0);
 
do
{
if (type == 1) // Name
{
for (uint8_t i = bt_name_length; i > 0; i--)
{
if (EditString[i - 1] != ' ')
{
bt_name_len = i;
break;
}
}
 
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 2)) && EditString[I] < 'z')
{
EditString[I]++;
 
if (EditString[I] >= 0x00 && EditString[I] < ' ')
EditString[I] = ' ';
 
if (EditString[I] > ' ' && EditString[I] < '0')
EditString[I] = '0';
 
if (EditString[I] > '9' && EditString[I] < 'A')
EditString[I] = 'A';
 
if (EditString[I] > 'Z' && EditString[I] < 'a')
EditString[I] = 'a';
 
lcd_putc (x, 3, EditString[I], 0);
edit = 1;
}
 
if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 2)) && EditString[I] > ' ')
{
EditString[I]--;
 
if (EditString[I] < 'a' && EditString[I] > 'Z')
EditString[I] = 'Z';
 
if (EditString[I] < 'A' && EditString[I] > '9')
EditString[I] = '9';
 
if (EditString[I] < '0' && EditString[I] > ' ')
EditString[I] = ' ';
 
lcd_putc (x, 3, EditString[I], 0);
edit = 1;
}
}
else if (type == 2) // PIN
{
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 1)) && (EditString[I] < '9'))
{
EditString[I]++;
 
if (EditString[I] >= 0x00 && EditString[I] < ' ')
EditString[I] = ' ';
 
if (EditString[I] > ' ' && EditString[I] < '0')
EditString[I] = '0';
 
lcd_putc (x, 3, EditString[I], 0);
edit = 1;
}
 
if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 1)) && (EditString[I] > '0'))
{
EditString[I]--;
 
if (EditString[I] < 'A' && EditString[I] > '9')
EditString[I] = '9';
 
lcd_putc (x, 3, EditString[I], 0);
edit = 1;
}
}
 
if (get_key_long (1 << KEY_ESC))
{
if (type == 1) // Name
EditString[I] = ' '; // Zeichen l�schen
else if (type == 2) // Pin
EditString[I] = '0'; // Zeichen setzen
lcd_putc (x, 3, EditString[I], 0);
edit = 1;
}
 
if (get_key_short (1 << KEY_ESC))
{
if (type == 1)
length_tmp = bt_name_length;
else if (type == 2)
length_tmp = bt_pin_length;
 
if ((x / 2) + 2 > length_tmp)
{
lcd_rect ((x*6)-3, (8*3)-2, 10, 10, 0);
x = 1;
lcd_rect ((x*6)-3, (8*3)-2, 10, 10, 1);
I = 0;
}
else
{
lcd_rect ((x*6)-3, (8*3)-2, 10, 10, 0);
x++;
x++;
lcd_rect ((x*6)-3, (8*3)-2, 10, 10, 1);
I++; //Zeiger auf Zeichen
}
}
}
while (!get_key_press (1 << KEY_ENTER));
{
return 1;
}
}
 
 
void BT_SelectDevice (void)
{
uint8_t ii = 0;
uint8_t Offset = 0;
uint8_t size = 0;
 
 
uint8_t dmode = 0;
uint8_t target_pos = 1;
uint8_t val = 0;
 
mmode = 0;
edit = 0;
 
 
lcd_cls ();
 
while(1)
{
size = bt_devicecount;
lcd_cls ();
lcd_printp_at (0, 0, PSTR(" BT select Device "), 2);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
 
while(1)
{
ii = 0;
 
if(Offset > 0)
lcd_printp_at(1, 1, PSTR("\x12"), 0);
 
for(ii = 0; ii < 6; ii++)
{
if((ii + Offset) < size)
{
if (strncmp (device_list[ii + Offset].mac, Config.gps_UsedMac, 14) == 0)
{
lcd_puts_at(3, ii+1, device_list[ii + Offset].DevName, 2);
// lcd_puts_at(3, 4, strGet(KEYLINE1), 0);
}
else
{
lcd_puts_at(3, ii+1, device_list[ii + Offset].DevName, 0);
// lcd_puts_at(3, 5, strGet(KEYLINE1), 0);
}
}
 
if((ii == 5)&&(ii + Offset < (size - 1)))
lcd_printp_at(1, 6, PSTR("\x13"), 0);
 
}
 
if(dmode == 0)
{
if(Offset == 0)
{
if(size > 6)
val = menu_choose2 (1, 5, target_pos,0,1);
else
val = menu_choose2 (1, size, target_pos,0,0);
 
}
else
val = menu_choose2 (2, 5, target_pos,1,1);
 
}
 
if(dmode == 1)
{
if(Offset + 7 > size)
val = menu_choose2 (2, 6, target_pos, 1, 0);
else
val = menu_choose2 (2, 5, target_pos, 1, 1);
 
}
 
if(val == 254)
{
Offset++;
dmode = 1;
target_pos = 5;
}
else if(val == 253)
{
Offset--;
dmode = 0;
target_pos = 2;
}
else if(val == 255)
{ // Ende mit ESC, speichern
if (edit == 1)
{
// WriteParameter();
edit = 0;
}
 
return;
}
else
 
break;
}
target_pos = val;
 
if(val > 0 )
{
for(uint8_t i = 0; i < 14; i++)
{
Config.gps_UsedMac[i] = device_list[val-1].mac[i];
}
for(uint8_t i = 0; i < 20; i++)
{
Config.gps_UsedDevName[i] = device_list[val-1].DevName[i];
}
edit = 1;
}
}
}
 
 
//--------------------------------------------------------------
//
void BT_Setup (void)
{
// uint8_t ii = 0;
uint8_t z = 0;
// uint8_t Offset = 0;
// uint8_t size = 0;
 
// uint8_t dmode = 0;
uint8_t target_pos = 1;
// uint8_t val;
char string[20];
 
mmode = 0;
edit = 0;
// val = 0;
// BTIsSet = true;
 
lcd_cls ();
 
while(1)
{
size = ITEMS_BT;
lcd_cls ();
lcd_puts_at(0, 0, strGet(BT1), 2);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
 
// while(1)
// {
// ii = 0;
//
// if(Offset > 0)
// lcd_printp_at(1,1, PSTR("\x12"), 0);
//
// for(ii = 0; ii < 6; ii++)
// {
// if((ii + Offset) < size)
// {
// lcd_printp_at(3, ii + 1, param_menuitems_bt[ii+Offset][Config.DisplayLanguage], 0);
// if ((ii+Offset)==5)
// {
// for (uint8_t i = 0; i < RE_ID_length; i++)
// {
// lcd_putc (10+i, ii+1, Config.RE_ID[i], 0);
//
// }
// }
// }
//
//
// if((ii == 5) && (ii + Offset < (size - 1)))
// lcd_printp_at(1,6, PSTR("\x13"), 0);
//
// }
//
// if(dmode == 0)
// {
// if(Offset == 0)
// {
// if(size > 6)
// val = menu_choose2 (1, 5, target_pos, 0, 1);
// else
// val = menu_choose2 (1, size, target_pos, 0, 0);
//
// }
// else
// val = menu_choose2 (2, 5, target_pos, 1, 1);
//
// }
//
// if(dmode == 1)
// {
// if(Offset + 7 > size)
// val = menu_choose2 (2, 6, target_pos, 1, 0);
// else
// val = menu_choose2 (2, 5, target_pos, 1, 1);
// }
//
// if(val == 254)
// {
// Offset++;
// dmode = 1;
// target_pos = 5;
// }
// else if(val == 253)
// {
// Offset--;
// dmode = 0;
// target_pos = 2;
// }
// else if(val == 255)
// { // Ende mit ESC, speichern
// if (edit == 1)
// {
// if (Config.UseBT == 1);
// if (bt_init()) Config.BTIsSet = true; else Config.BTIsSet = false;
// WriteParameter();
// return;
// }
// return;
// }
// else
// break;
// }
val = menu_select(param_menuitems_bt,size,target_pos);
if (val==255)
{
if (edit == 1)
{
if (Config.UseBT == 1);
if (bt_init()) Config.BTIsSet = true; else Config.BTIsSet = false;
}
break;
}
target_pos = val;
if((val + offset) == 1)
 
Config.UseBT = Edit_generic(Config.UseBT,0,1,BT4,YesNo);
 
if((val + offset) == 2)
{
for (uint8_t i = 0; i < bt_name_length; i++)
{
string[i] = Config.bt_name[i];
}
string[bt_name_length] = 0;
Edit_String(string, bt_name_length, 1, PSTR(" Bluetooth Name "));
if (edit == 1)
{
for (uint8_t i = 0; i < bt_name_len; i++)
{
Config.bt_name[i] = EditString[i];
// WriteParameter();
}
 
if (bt_name_len < 10)
{
for (uint8_t i = bt_name_len; i < 10; i++)
{
Config.bt_name[i] = ' ';
// WriteParameter();
}
}
}
}
 
if((val + offset) == 3)
{
for (uint8_t i = 0; i < bt_pin_length; i++)
{
string[i] = Config.bt_pin[i];
}
string[bt_pin_length] = 0;
Edit_String(string, bt_pin_length, 2, PSTR(" Bluetooth Pin "));
if (edit == 1)
{
for (uint8_t i = 0; i < bt_pin_length; i++)
{
Config.bt_pin[i] = EditString[i];
// WriteParameter();
}
}
}
 
if((val + offset) == 4)
{
// if (edit == 1)
// if(BTIsSet)
// BTIsSet = false;
 
if (bt_init() == true)
{
lcd_printp_at (0, 3, PSTR("BT Init ok"), 0);
WriteBTInitFlag();
}
else
{
lcd_printp_at (0, 3, PSTR("BT Init Error"), 0);
Config.BTIsSet = false;
set_beep ( 1000, 0x0040, BeepNormal);
 
}
}
 
 
if((val + offset) == 5)
{
lcd_cls ();
lcd_printp_at (0, 0, PSTR(" BTM-222 MAC-Adresse "), 2);
lcd_puts_at(18, 7, strGet(OK), 0);
lcd_printp_at (0, 4, PSTR("MAC:"), 0);
z = 0;
for(uint8_t i = 0; i < 13; i++)
{
lcd_putc (z, 5, Config.bt_Mac[i],0);
if ((i%2==1)&&(i<11))
{
z++;
lcd_printp_at(z, 5, PSTR(":"),0);
}
z++;
}
 
while (!get_key_press (1 << KEY_ENTER));
 
}
 
if((val + offset) == 6)
{
for (uint8_t i = 0; i < RE_ID_length; i++)
{
string[i] = Config.RE_ID[i];
}
string[RE_ID_length] = 0;
Edit_String(string, RE_ID_length, 2, PSTR(" RE-ID Notiz "));
if (edit == 1)
{
for (uint8_t i = 0; i < RE_ID_length; i++)
{
Config.RE_ID[i] = EditString[i];
// WriteParameter();
}
}
}
 
 
 
 
 
if((val + offset) == 7)
Port_FC2CFG_BT();
 
 
}
}
 
 
void GPS_Setup (void)
{
// uint8_t ii = 0;
// uint8_t Offset = 0;
// uint8_t size = 0;
 
// uint8_t dmode = 0;
uint8_t target_pos = 1;
// uint8_t val;
uint8_t BT_WhasOn = 0;
uint8_t status;
// uint16_t uart_bytes;
 
mmode = 0;
edit = 0;
val = 0;
lcd_cls ();
 
while(1)
{
size = ITEMS_GPS;
lcd_cls ();
lcd_puts_at(0, 0, strGet(GPS1), 2);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
 
// while(1)
// {
// ii = 0;
//
// if(Offset > 0)
// lcd_printp_at(1,1, PSTR("\x12"), 0);
//
// for(ii = 0; ii < 6; ii++)
// {
// if((ii + Offset) < size)
// lcd_printp_at(3, ii + 1, param_menuitems_GPS[ii+Offset][Config.DisplayLanguage], 0);
//
// if((ii == 5) && (ii + Offset < (size - 1)))
// lcd_printp_at(1,6, PSTR("\x13"), 0);
//
// }
//
// if(dmode == 0)
// {
// if(Offset == 0)
// {
// if(size > 6)
// val = menu_choose2 (1, 5, target_pos, 0, 1);
// else
// val = menu_choose2 (1, size, target_pos, 0, 0);
//
// }
// else
// val = menu_choose2 (2, 5, target_pos, 1, 1);
//
// }
//
// if(dmode == 1)
// {
// if(Offset + 7 > size)
// val = menu_choose2 (2, 6, target_pos, 1, 0);
// else
// val = menu_choose2 (2, 5, target_pos, 1, 1);
// }
//
// if(val == 254)
// {
// Offset++;
// dmode = 1;
// target_pos = 5;
// }
// else if(val == 253)
// {
// Offset--;
// dmode = 0;
// target_pos = 2;
// }
// else if(val == 255)
// { // Ende mit ESC, speichern
// if (edit == 1)
// {
// WriteParameter();
// if (BT_WhasOn)
// {
// set_BTOn();
//// bt_set_mode(SLAVE);
// bt_init();
// set_BTOff();
// }
//
// return;
// }
// return;
// }
// else
// break;
// }
 
val = menu_select(param_menuitems_GPS,size,target_pos);
if (val==255)
{
if (edit == 1)
{
// WriteParameter();
if (BT_WhasOn)
{
set_BTOn();
// bt_set_mode(SLAVE);
bt_init();
set_BTOff();
}
}
break;
}
 
target_pos = val;
//
// {"Suche GPS Maus ","search GPS mouse ","search GPS mouse ","search GPS mouse "},
// {"GPS Maus Typ ","GPS mouse typ ","GPS mouse typ ","GPS mouse typ "},
// {"GPS Maus aktiv? ","GPS mouse activ? ","GPS mouse activ? ","GPS mouse activ? "},
// {"Zeige GPS Device ","show GPS device ","show GPS device ","show GPS device "},
//
 
if((val + offset) == 1)
{
if (bt_devicecount ==0)
{
lcd_cls ();
lcd_printp_at (0, 0, PSTR("wähle BT Device"), 0);
set_BTOn();
BT_WhasOn = true;
// _delay_ms(2000);
bt_downlink_init();
bt_searchDevice();
set_BTOff();
BT_SelectDevice();
}
else
BT_SelectDevice();
// if (edit == 1) WriteParameter();
}
 
 
 
 
 
if((val + offset) == 2)
{
lcd_cls ();
lcd_printp_at (0, 0, PSTR("suche BT Device"), 0);
set_BTOn();
BT_WhasOn = true;
bt_downlink_init();
bt_searchDevice();
set_BTOff();
BT_SelectDevice();
}
 
 
if((val + offset) == 3)
{
Config.gps_UsedGPSMouse = Edit_generic(Config.gps_UsedGPSMouse,0,1,GPS_MOUSETYP,GPSMOUSE);
if (edit == 1) {
// WriteParameter();
edit = 0;
}
 
}
 
 
 
if((val + offset) == 4)
{
Config.gps_UseGPS = Edit_generic(Config.gps_UseGPS,0,1,GPS3,YesNo);
if (edit == 1) {
// WriteParameter();
edit = 0;
}
}
 
if((val + offset) == 5)
{
lcd_cls ();
lcd_puts_at(0, 0, strGet(GPS2), 2);
lcd_puts_at(18, 7, strGet(OK), 0);
lcd_printp_at (0, 1, PSTR("Device:"), 0);
lcd_printp_at (0, 4, PSTR("MAC:"), 0);
 
lcd_puts_at (0, 2,Config.gps_UsedDevName, 0);
 
for(uint8_t i = 0; i < 12; i++)
{
lcd_putc (i, 5, Config.gps_UsedMac[i],0);
}
 
while (!get_key_press (1 << KEY_ENTER));
 
}
 
 
if((val + offset) == 6)
{
get_key_press(KEY_ALL);
lcd_cls ();
lcd_puts_at(18, 7, strGet(OK), 0);
lcd_puts_at (0, 0,Config.gps_UsedDevName, 2);
set_BTOn();
BT_WhasOn = true;
if (Config.BTIsSlave==true)
{
bt_downlink_init();
}
lcd_printp_at (0, 1, PSTR("try to connect"), 0);
status = bt_connect(Config.gps_UsedMac);
 
lcd_printp_at (0, 2, PSTR("connect status"), 0);
write_ndigit_number_u (14, 2, status, 2, 0,0);
 
 
 
 
if (status==true)
{
lcd_printp_at (0, 1, PSTR("connected "), 0);
receiveNMEA = true;
}
else
{
lcd_printp_at (0, 2, PSTR("connect Error"), 0);
write_ndigit_number_u (14, 2, status, 2, 0,0);
 
}
//---OG:BEGIN---
if (receiveNMEA==true)
{
lcd_cls();
 
// BT-Device Name
lcd_puts_at(0, 0,Config.gps_UsedDevName, 2);
 
// Labels
lcd_printp_at( 0, 1, PSTR("Sat: "), 0);
lcd_printp_at(11, 1, PSTR("XErr: "), 0);
 
lcd_printp_at( 0, 2, PSTR("Fix: "), 0);
lcd_printp_at(11, 2, PSTR("HDOP: "), 0);
 
lcd_printp_at( 0, 3, PSTR(" Latitude Longitude"), 2);
 
lcd_printp_at( 0, 6, PSTR("Alt: "), 0);
 
// Bottom-Line: OK
lcd_puts_at(18, 7, strGet(OK), 0);
 
bt_rx_ready = 0;
do
{
CheckGPS = true;
if (!bt_receiveNMEA()){ receiveNMEA = false; break;}
 
Tracking_NMEA();
 
//---------------------------------------------------------------------
 
// Line 1 L: Sat-Anzahl
write_ndigit_number_u (5, 1, NMEAsatsInUse, 2, 0,0);
 
// Line 1 R: BT RX Error's
write_ndigit_number_u (17, 1, bt_rxerror, 4, 0,0);
 
//---------------------------------------------------------------------
 
// Line 2 L: Fix
write_ndigit_number_u (5, 2, posfix, 2, 0,0);
 
// Line 2 R: HDOP
if( HDOP == 0 )
lcd_printp_at(16, 2, PSTR(" ---"), 0);
else
write_ndigit_number_u_10th (16, 2, HDOP, 4, 0,0);
 
//---------------------------------------------------------------------
 
// Line 4 L: Latitude
write_ndigit_number_u (1, 4, (uint16_t)(NMEAlatitude/10000000), 2, 0,0);
lcd_printp_at (3, 4, PSTR("."), 0);
write_ndigit_number_u (4, 4, (uint16_t)((NMEAlatitude/1000) % 10000), 4, 1,0);
write_ndigit_number_u (8, 4, (uint16_t)((NMEAlatitude/10) % 100), 2, 1,0);
 
// Line 4 R: Longitude
write_ndigit_number_u (12, 4, (uint16_t)(NMEAlongitude/10000000), 2, 0,0);
lcd_printp_at (14, 4, PSTR("."), 0);
write_ndigit_number_u (15, 4, (uint16_t)((NMEAlongitude/1000) % 10000), 4, 1,0);
write_ndigit_number_u (19, 4, (uint16_t)((NMEAlongitude/10) % 100), 2, 1,0);
 
//---------------------------------------------------------------------
 
// Line 6 L: Altitude
write_ndigit_number_u_10th (5, 6, NMEAaltitude, 5, 0,0);
lcd_printp_at (11, 6, PSTR("m"), 0);
 
// Line 6 R: GPS Time
lcd_puts_at (13, 6, NMEAtime, 0);
 
//---------------------------------------------------------------------
 
} while (!get_key_press (1 << KEY_ENTER) || !receiveNMEA==true);
 
CheckGPS = false;
 
lcd_cls();
 
if (!receiveNMEA) {
lcd_printp_at (0, 1, PSTR("lost BT data"), 0);
set_beep ( 400, 0x0080, BeepNormal);
}
lcd_printp_at (0, 3, PSTR("GPS trennen"), 0);
lcd_printp_at (0, 4, PSTR("bitte warten..."), 0);
}
else
{
lcd_printp_at (0, 3, PSTR("Error connecting!"), 0);
while (!get_key_press (1 << KEY_ENTER));
}
receiveNMEA = false;
CheckGPS = false;
if (!bt_disconnect()) lcd_printp_at (0, 3, PSTR("Error disconnecting!"), 0);
//---OG:END---
 
// if (receiveNMEA==true)
// {
// lcd_printp_at (0, 3, PSTR(" Latitude Longitude"), 2);
// bt_rx_ready = 0;
// do
// {
// CheckGPS = true;
// if (!bt_receiveNMEA()){ receiveNMEA = false; break;}
//
//
// Tracking_NMEA();
//
//
// write_ndigit_number_u (1, 4, (uint16_t)(NMEAlatitude/10000000), 2, 0,0);
// lcd_printp_at (3, 4, PSTR("."), 0);
// write_ndigit_number_u (4, 4, (uint16_t)((NMEAlatitude/1000) % 10000), 4, 1,0);
// write_ndigit_number_u (8, 4, (uint16_t)((NMEAlatitude/10) % 100), 2, 1,0);
//
//
// write_ndigit_number_u (12, 4, (uint16_t)(NMEAlongitude/10000000), 2, 0,0);
// lcd_printp_at (14, 4, PSTR("."), 0);
// write_ndigit_number_u (15, 4, (uint16_t)((NMEAlongitude/1000) % 10000), 4, 1,0);
// write_ndigit_number_u (19, 4, (uint16_t)((NMEAlongitude/10) % 100), 2, 1,0);
// lcd_printp_at (0, 2, PSTR("GPS Time: "), 0);
// lcd_puts_at (10, 2, NMEAtime, 0);
// lcd_printp_at (0, 6, PSTR("Satellite: "), 0);
// write_ndigit_number_u (11, 6, NMEAsatsInUse, 2, 1,0);
// lcd_printp_at (0, 5, PSTR("Fix: "), 0);
// write_ndigit_number_u (5, 5, posfix, 1, 1,0);
// lcd_printp_at (8, 5, PSTR("HDOP: "), 0);
// write_ndigit_number_u_10th (14, 5, HDOP, 4, 0,0);
// lcd_printp_at (0, 7, PSTR("Alitude: "), 0);
// write_ndigit_number_u_10th (9, 7, NMEAaltitude, 5, 0,0);
// lcd_printp_at (15, 7, PSTR("m"), 0);
// lcd_printp_at (0, 1, PSTR(" BT RX Error: "), 0);
// write_ndigit_number_u (13, 1, bt_rxerror, 3, 1,0);
//// write_ndigit_number_u (13, 1, UART1_RxError, 5, 1,0);
//
//// uart_bytes = uart1_available();
//// lcd_printp_at (0, 1, PSTR(" UartAvail: "), 0);
//// write_ndigit_number_u (13, 1,uart_bytes , 4, 1,0);
// }
//
//
// while (!get_key_press (1 << KEY_ENTER) || !receiveNMEA==true);
//
// CheckGPS = false;
// lcd_cls_line(0,1,21);
// lcd_cls_line(0,2,21);
// lcd_cls_line(0,3,21);
// lcd_cls_line(0,4,21);
// lcd_cls_line(0,5,21);
// lcd_cls_line(0,6,21);
// lcd_cls_line(0,7,21);
// if (!receiveNMEA) lcd_printp_at (0, 2, PSTR("lost BT data"), 0);
// lcd_printp_at (0, 3, PSTR("GPS trennen"), 0);
// lcd_printp_at (0, 4, PSTR("bitte warten"), 0);
// }
// else
// {
// lcd_printp_at (0, 4, PSTR("Error at connecting"), 0);
// while (!get_key_press (1 << KEY_ENTER));
// }
// receiveNMEA = false;
// CheckGPS = false;
// if (!bt_disconnect()) lcd_printp_at (0, 3, PSTR("Fehler beim Trennen"), 0);
 
set_BTOff();
 
}
 
 
}
}
 
 
 
 
//--------------------------------------------------------------
uint8_t Edit_PKT_Accu(uint8_t Value, uint8_t min, uint8_t max)
{
Pre = Value;
lcd_cls();
// lcd_printp_at (0, 2, Text, 0);
lcd_puts_at(0, 2, strGet(LIPO2), 0);
switch (Value)
{
case false :lcd_printp_at (15, 2, PSTR("LiIo"), 0);
break;
case true :lcd_printp_at (15, 2, PSTR("LiPo"), 0);
break;
break;
}
 
lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
 
do
{
if ((get_key_press (1 << KEY_PLUS)) && (Value == 0))
{
Value = 1;
lcd_printp_at (15, 2, PSTR("LiPo"), 0);
}
 
if ((get_key_press (1 << KEY_MINUS)) && (Value == 1))
{
Value = 0;
lcd_printp_at (15, 2, PSTR("LiIo"), 0);
}
 
if (get_key_press (1 << KEY_ENTER))
{
edit = 1;
 
Config.PKT_Accutyp = Value;
 
 
return Value;
}
}
 
while (!get_key_press (1 << KEY_ESC));
{
get_key_press(KEY_ALL);
edit = 0;
Config.PKT_Accutyp = Pre;
return Pre;
}
 
}
 
//--------------------------------------------------------------
uint16_t Edit_LipoOffset(uint16_t Value, uint16_t min, uint16_t max)
{
lcd_cls();
lcd_puts_at(0, 2, strGet(LIPO3), 0);
lcd_puts_at(0, 5, strGet(LIPO5), 0);
lcd_puts_at(0, 6, strGet(LIPO6), 0);
Pre16 = Value;
write_ndigit_number_u (16, 2, Value, 4, 0,0);
lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
 
do
{
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 2)) && (Value < max-10))
{
edit = 1;
Value = Value +10;
Config.Lipo_UOffset = Value;
write_ndigit_number_u (16, 2,Value, 4, 0,0);
 
}
 
if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 2)) && (Value > min))
{
edit = 1;
Value=Value -10;
Config.Lipo_UOffset = Value;
write_ndigit_number_u (16, 2,Value, 4, 0,0);
}
 
if (get_key_press (1 << KEY_ENTER))
return Value;
show_Lipo();
write_ndigit_number_u_100th(8, 3, volt_avg, 0, 0);
lcd_printp_at(3, 3, PSTR("Volt"), 0);
 
}
while (!get_key_press (1 << KEY_ESC));
{
get_key_press(KEY_ALL);
edit = 0;
Config.Lipo_UOffset = Pre16;
return Pre16;
}
}
 
//--------------------------------------------------------------
void Accu_Setup (void)
{
// uint8_t ii = 0;
// uint8_t Offset = 0;
// uint8_t size = 0;
 
// uint8_t dmode = 0;
uint8_t target_pos = 1;
// uint8_t val;
 
mmode = 0;
edit = 0;
val = 0;
lcd_cls ();
 
while(1)
{
size = ITEMS_Accu;
lcd_cls ();
lcd_puts_at(0, 0, strGet(LIPO1), 2);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
 
// while(1)
// {
// ii = 0;
//
// if(Offset > 0)
// lcd_printp_at(1,1, PSTR("\x12"), 0);
//
// for(ii = 0; ii < 6; ii++)
// {
// if((ii + Offset) < size)
// lcd_printp_at(3, ii + 1, param_menuitems_Accu[ii+Offset][Config.DisplayLanguage], 0);
//
// if((ii == 5) && (ii + Offset < (size - 1)))
// lcd_printp_at(1,6, PSTR("\x13"), 0);
//
// }
//
// if(dmode == 0)
// {
// if(Offset == 0)
// {
// if(size > 6)
// val = menu_choose2 (1, 5, target_pos, 0, 1);
// else
// val = menu_choose2 (1, size, target_pos, 0, 0);
//
// }
// else
// val = menu_choose2 (2, 5, target_pos, 1, 1);
//
// }
//
// if(dmode == 1)
// {
// if(Offset + 7 > size)
// val = menu_choose2 (2, 6, target_pos, 1, 0);
// else
// val = menu_choose2 (2, 5, target_pos, 1, 1);
// }
//
// if(val == 254)
// {
// Offset++;
// dmode = 1;
// target_pos = 5;
// }
// else if(val == 253)
// {
// Offset--;
// dmode = 0;
// target_pos = 2;
// }
// else if(val == 255)
// { // Ende mit ESC, speichern
// if (edit == 1)
// {
// WriteParameter();
// edit = 0;
// return;
// }
// return;
// }
// else
// break;
// }
val = menu_select(param_menuitems_Accu,size,target_pos);
if (val==255) break;
target_pos = val;
if((val + offset) == 1)
{
Config.PKT_Accutyp= Edit_PKT_Accu(Config.PKT_Accutyp,0,1);
if (edit == 1) {
// WriteParameter();
edit = 0;
}
}
 
if((val + offset) == 2)
{
Config.Lipo_UOffset = Edit_LipoOffset(Config.Lipo_UOffset,0,9999);
if (edit == 1) {
// WriteParameter();
edit = 0;
}
}
 
}
}
 
 
//--------------------------------------------------------------
uint8_t Edit_LED_Form (uint8_t Value, uint8_t min, uint8_t max, uint8_t Text)
{
Pre = Value;
lcd_cls();
lcd_puts_at(0, 2, strGet(Text), 0);
 
switch (Value)
{
case 0x1:
lcd_circle (14 * 6 + 5, 2 * 8 + 3, 3, 1); // kreis
 
lcd_fcircle (16 * 6 + 5, 2 * 8 + 3, 3, 0); // löschen
lcd_circle (16 * 6 + 5, 2 * 8 + 3, 3, 1); // kreis
lcd_fcircle (16 * 6 + 5, 2 * 8 + 3, 1, 1); // plus
break;
case 0x3 :
lcd_circle (14 * 6 + 5, 2 * 8 + 3, 3, 1); // kreis
 
lcd_fcircle (16 * 6 + 5, 2 * 8 + 3, 3, 1); // schwarz
break;
break;
}
 
lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
 
do
{
if ((get_key_press (1 << KEY_PLUS)) && (Value == 1))
{
Value = 3;
lcd_circle (14 * 6 + 5, 2 * 8 + 3, 3, 1); // kreis
 
lcd_fcircle (16 * 6 + 5, 2 * 8 + 3, 3, 1); // schwarz
}
 
if ((get_key_press (1 << KEY_MINUS)) && (Value == 3))
{
Value = 1;
lcd_circle (14 * 6 + 5, 2 * 8 + 3, 3, 1); // kreis
 
lcd_fcircle (16 * 6 + 5, 2 * 8 + 3, 3, 0); // löschen
lcd_circle (16 * 6 + 5, 2 * 8 + 3, 3, 1); // kreis
lcd_fcircle (16 * 6 + 5, 2 * 8 + 3, 1, 1); // plus
}
 
if (get_key_press (1 << KEY_ENTER))
{
edit = 1;
Config.OSD_LEDform = Value;
// WriteParameter();
edit = 0;
return Value;
}
}
 
while (!get_key_press (1 << KEY_ESC));
{
get_key_press(KEY_ALL);
edit = 0;
Config.OSD_LEDform = Pre;
return Pre;
}
}
 
 
//--------------------------------------------------------------
void OSD_Setup (void)
{
// uint8_t ii = 0;
// uint8_t Offset = 0;
// uint8_t size = 0;
 
// uint8_t dmode = 0;
uint8_t target_pos = 1;
// uint8_t val;
 
mmode = 0;
edit = 0;
val = 0;
lcd_cls ();
 
while(1)
{
size = ITEMS_OSD;
lcd_cls ();
lcd_puts_at(0, 0, strGet(OSD_Screen), 2);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
 
// while(1)
// {
// ii = 0;
//
// if(Offset > 0)
// lcd_printp_at(1,1, PSTR("\x12"), 0);
//
// for(ii = 0; ii < 6; ii++)
// {
// if((ii + Offset) < size)
// lcd_printp_at(3, ii + 1, param_menuitems_OSD[ii+Offset][Config.DisplayLanguage], 0);
//
// if((ii == 5) && (ii + Offset < (size - 1)))
// lcd_printp_at(1,6, PSTR("\x13"), 0);
//
// }
//
// if(dmode == 0)
// {
// if(Offset == 0)
// {
// if(size > 6)
// val = menu_choose2 (1, 5, target_pos, 0, 1);
// else
// val = menu_choose2 (1, size, target_pos, 0, 0);
//
// }
// else
// val = menu_choose2 (2, 5, target_pos, 1, 1);
//
// }
//
// if(dmode == 1)
// {
// if(Offset + 7 > size)
// val = menu_choose2 (2, 6, target_pos, 1, 0);
// else
// val = menu_choose2 (2, 5, target_pos, 1, 1);
// }
//
// if(val == 254)
// {
// Offset++;
// dmode = 1;
// target_pos = 5;
// }
// else if(val == 253)
// {
// Offset--;
// dmode = 0;
// target_pos = 2;
// }
// else if(val == 255)
// { // Ende mit ESC, speichern
// if (edit == 1)
// {
// WriteParameter();
// edit = 0;
// return;
// }
// return;
// }
// else
// break;
// }
val = menu_select(param_menuitems_OSD,size,target_pos);
if (val==255) break;
target_pos = val;
//4.3.13 CB if((val + Offset) == 1) Config.OSD_ScreenMode = Edit_generic(Config.OSD_ScreenMode, 0, OSD_MaxScreen, OSD_SCREENMODE,Show_uint);
if((val + offset) == 1) Config.OSD_LEDform = Edit_LED_Form(Config.OSD_LEDform, 1, 3, OSD_LED_Form);
if((val + offset) == 2) Config.OSD_InvertOut = Edit_generic(Config.OSD_InvertOut, 0, 1, OSD_Invert_Out,YesNo);
if((val + offset) == 3) Config.OSD_SendOSD = Edit_generic(Config.OSD_SendOSD, 0, 1,OSD_Send_OSD ,YesNo);
if((val + offset) == 4) Config.OSD_Fallspeed = Edit_generic(Config.OSD_Fallspeed,0,247,FALLSPEED,Show_uint10th);
if((val + offset) == 5) Config.OSD_VarioBeep = Edit_generic(Config.OSD_VarioBeep,0,1,OSD_VARIOBEEP,YesNo);
if((val + offset) == 6) Config.OSD_HomeMKView = Edit_generic(Config.OSD_HomeMKView,0,1,OSD_HOMEMKVIEW,YesNo);
if((val + offset) == 7) Config.MK_LowBat = Edit_generic(Config.MK_LowBat,32,247,LOWBAT,Show_uint10th);
if((val + offset) == 8) Config.OSD_mAh_Warning = Edit_generic(Config.OSD_mAh_Warning,0,30000,OSD_MAHWARNING, Show_uint5);
if((val + offset) == 9)Config.OSD_LipoBar = Edit_generic(Config.OSD_LipoBar, 0, 1, OSD_LIPOBAR,YesNo);
 
 
}
}
//--------------------------------------------------------------
void FollowMe_Setup (void)
{
// uint8_t ii = 0;
// uint8_t Offset = 0;
// uint8_t size = 0;
// uint8_t dmode = 0;
uint8_t target_pos = 1;
// uint8_t val;
 
mmode = 0;
edit = 0;
val = 0;
lcd_cls ();
 
while(1)
{
size = ITEMS_FOLLOWME;
lcd_cls ();
lcd_puts_at(0, 0, strGet(FOLLOWME_0), 2);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
 
// while(1)
// {
// ii = 0;
//
// if(Offset > 0)
// lcd_printp_at(1,1, PSTR("\x12"), 0);
//
// for(ii = 0; ii < 6; ii++)
// {
// if((ii + Offset) < size)
// lcd_printp_at(3, ii + 1, param_menuitems_FOLLOWME[ii+Offset][Config.DisplayLanguage], 0);
//
// if((ii == 5) && (ii + Offset < (size - 1)))
// lcd_printp_at(1,6, PSTR("\x13"), 0);
//
// }
//
// if(dmode == 0)
// {
// if(Offset == 0)
// {
// if(size > 6)
// val = menu_choose2 (1, 5, target_pos, 0, 1);
// else
// val = menu_choose2 (1, size, target_pos, 0, 0);
//
// }
// else
// val = menu_choose2 (2, 5, target_pos, 1, 1);
//
// }
//
// if(dmode == 1)
// {
// if(Offset + 7 > size)
// val = menu_choose2 (2, 6, target_pos, 1, 0);
// else
// val = menu_choose2 (2, 5, target_pos, 1, 1);
// }
//
// if(val == 254)
// {
// Offset++;
// dmode = 1;
// target_pos = 5;
// }
// else if(val == 253)
// {
// Offset--;
// dmode = 0;
// target_pos = 2;
// }
// else if(val == 255)
// { // Ende mit ESC, speichern
// if (edit == 1)
// {
// WriteParameter();
// edit = 0;
// return;
// }
// return;
// }
// else
// break;
// }
val = menu_select(param_menuitems_FOLLOWME,size,target_pos);
if (val==255) break;
target_pos = val;
if((val + offset) == 1) Config.FM_Refresh = Edit_generic(Config.FM_Refresh, 250, 60000, FOLLOWME_1, Show_uint3);
if((val + offset) == 2) Config.FM_Speed = Edit_generic(Config.FM_Speed, 0, 100, FOLLOWME_2, Show_uint3);
if((val + offset) == 3) Config.FM_Radius = Edit_generic(Config.FM_Radius, 1,20, FOLLOWME_3, Show_uint3);
 
}
}
 
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/setup/setup.h
0,0 → 1,70
/*****************************************************************************
* 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*
*****************************************************************************/
 
 
#ifndef _setup_H
#define _setup_H
 
 
typedef enum //Varianten für die Anzeige der Werte im Setupmenü
{
Show_uint3,Show_uint5,Show_uint10th,GPSMOUSE,Wi_Netmode,OnOff,YesNo,Orientation,NormRev,Kontrast,Baudrate,Language,Sticktype,
} EditMode;
 
 
 
 
 
 
void PKT_Setup (void);
void Display_Setup (void);
void Wi_Use (void);
void Wi_Setup (void);
void BT_Use (void);
void BT_Setup (void);
void Show_Error_HW12(void);
void Accu_Setup (void);
void BT_SelectDevice (void);
void GPS_Setup (void);
void OSD_Setup (void);
void FollowMe_Setup (void);
 
uint8_t Edit_Language(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text);
uint16_t Edit_generic(uint16_t Value, uint16_t min, uint16_t max,uint8_t Text, uint8_t what);
 
extern uint8_t bt_name_len;
extern uint8_t length_tmp;
extern uint8_t Old_Baudrate; //Merkzelle für alte Baudrate
extern uint8_t edit;
extern uint8_t CheckGPS;
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/sound/.directory
0,0 → 1,3
[Dolphin]
Timestamp=2013,1,22,0,36,37
ViewMode=1
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/sound/pwmsine8bit.c
0,0 → 1,278
//file pwmsine8bit.c
//generate 8 bit sinewave using wavetable lookup
//12khz sample rate, 62500 hz pwm on pd5 oc1a
//for ere co embmega32 16Mhz 38400
 
//May 3 07 Bob G initial edit 8 bit
//May 5 07 Bob G add traffic tones
//Jan 18 08 Bob G compile with 7.15
 
//#include <stdio.h>
//#include <stdlib.h>
 
#include <ctype.h>
#include <math.h> //sin
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <string.h>
#include <stdint.h>
#include "../timer/timer.h"
 
//#include "../bluetooth/fifo.h"
 
#define INTR_OFF() asm("CLI")
#define INTR_ON() asm("SEI")
 
 
//------vars in bss-------
 
volatile unsigned char sindat[256]; //8 bit sine table
//unsigned int addat[8]; //internal 10 bit
unsigned int idesfreq;
unsigned char iattenfac; //0-255
unsigned char dispon;
unsigned char freqincipart,freqincfpart;
unsigned char waveptipart,waveptfpart;
unsigned char tics;
unsigned char generate;
 
float basefreq;
float freqratio;
float sampfreq; //12khz
float samppd; //83.33usec
float fdesfreq;
float attendb; //0-50
float attenfac; //.999-0
const float pi=3.141592654;
 
 
 
#define MSB(w) ((char*) &w)[1]
#define LSB(w) ((char*) &w)[0]
 
#define TONE_BUFFER_SIZE 64
#define TONE_BUFFER_MASK ( TONE_BUFFER_SIZE - 1)
 
static volatile unsigned char ToneBuf[TONE_BUFFER_SIZE];
static volatile unsigned char ToneBufHead;
static volatile unsigned char ToneBufTail;
 
 
//-------------------------------
void cvtfreq2frac(void){
//calc freq ratio, separate into integer and fractional parts
fdesfreq=idesfreq;
freqratio=fdesfreq/basefreq; //calc freq ratio from basefreq
freqincipart=(int)freqratio; //calc integer part
freqincfpart=(freqratio-freqincipart)*256; //calc fractional part
// cprintf("ipart %02x fpart %02x\n",freqincipart,freqincfpart);
}
 
//-------------------------------
void cvtdb2fac(void){
//cvt db to attenuation factor
 
attenfac=pow(10.0,-attendb/20.0); //10^0=1
iattenfac=(unsigned char)(attenfac*255.0);
// cprintf("attenfac %#7.5f\n",attenfac);
// cprintf("iattenfac %02x\n",iattenfac);
}
 
//-------------------------
void initsindat(void){
//init 8 bit signed sin table 0-ff in ram 36dB s/n 46Hz basefreq
unsigned int n;
 
for(n=0; n < 256; n++){
sindat[n]=(signed char)127.0*sin(2.0*pi*n/256.0); //256 sin points
}
}
 
 
//-------------------------
void initvars(void){
//init vars
 
// sampfreq=12000.0; //hz
sampfreq=19530.0; //hz
// printf("samp freq %#7.1f hz\n\r",sampfreq);
// printf("samp freq %#7.1f hz\n\r",1234567.1);
samppd=1.0/sampfreq; //83.33usec
// printf("samppd %#7.1f usec \n\r",samppd*1e6);
basefreq=sampfreq/256.0; //46.875hz
// printf("basefreq %#7.5f hz\n\r",basefreq);
idesfreq=400;
cvtfreq2frac();
cvtdb2fac(); //0db =.9999= 0xff
}
 
 
//---------------------
 
 
 
 
void tone1(int hz)
//tone at hz for ms
 
{
 
uint8_t volume = 0;
// TCNT2=0;
// sound_timer = ms/5;
// soundpause_timer = soundpause/5;
 
idesfreq=hz;
cvtfreq2frac();
attendb=volume;
cvtdb2fac();
if (hz ==0) generate=0;
else { generate = 1;
// TIMSK2 |= _BV(TOIE2); // Interrupt freigeben
}
 
}
 
 
 
//-------------------------------
void tone_handler(void) // wird aus Timerinterrupt aufgerufen
 
{
uint16_t f_Hz=0;
uint16_t dur_ms=0;
char volume=0;
char tmp_high = 0;
char tmp_low = 0;
unsigned char tmptail;
 
 
if ( ToneBufHead != ToneBufTail) {
/* calculate and store new buffer index */
tmptail = (ToneBufTail + 1) & TONE_BUFFER_MASK;
ToneBufTail = tmptail;
/* get one byte from buffer */
tmp_low = ToneBuf[tmptail]; /* f_Hz low */
}else{
 
return;
}
if ( ToneBufHead != ToneBufTail) {
/* calculate and store new buffer index */
tmptail = (ToneBufTail + 1) & TONE_BUFFER_MASK;
ToneBufTail = tmptail;
/* get one byte from buffer */
tmp_high = ToneBuf[tmptail]; /* f_Hz high */
}else{
return;
}
 
f_Hz = (((uint16_t) tmp_high) << 8) | tmp_low;
 
if ( ToneBufHead != ToneBufTail) {
/* calculate and store new buffer index */
tmptail = (ToneBufTail + 1) & TONE_BUFFER_MASK;
ToneBufTail = tmptail;
/* get one byte from buffer*/
volume = ToneBuf[tmptail]; /* volume */
}else{
return;
}
 
if ( ToneBufHead != ToneBufTail) {
/* calculate and store new buffer index */
tmptail = (ToneBufTail + 1) & TONE_BUFFER_MASK;
ToneBufTail = tmptail;
/* get one byte from buffer */
tmp_low = ToneBuf[tmptail]; /* low Duratuion */
}else{
return;
}
if ( ToneBufHead != ToneBufTail) {
/* calculate and store new buffer index */
tmptail = (ToneBufTail + 1) & TONE_BUFFER_MASK;
ToneBufTail = tmptail;
/* get one byte from buffer*/
tmp_high = ToneBuf[tmptail]; /* high Duration */
}else{
return;
}
 
dur_ms = (((uint16_t) tmp_high) << 8) | tmp_low;
 
sound_timer = dur_ms/10;
// TCNT2=0;
idesfreq= f_Hz;
cvtfreq2frac();
attendb= volume;
cvtdb2fac();
 
if (f_Hz ==0) generate=0;
else { generate = 1;
// TIMSK2 |= _BV(TOIE2); // Interrupt freigeben
}
 
 
 
// printf("tone_handler f_Hz: %i dur_ms: %i volume: %i\n\r", f_Hz,dur_ms,volume);
 
}
 
 
void tone_putc(unsigned char data)
{
unsigned char tmphead;
 
tmphead = (ToneBufHead + 1) & TONE_BUFFER_MASK;
 
while ( tmphead == ToneBufTail ){
;/* wait for free space in buffer */
}
 
ToneBuf[tmphead] = data;
ToneBufHead = tmphead;
 
}/* tone_putc */
 
 
void playTone(uint16_t f_Hz, uint16_t dur_ms, uint8_t volume)
 
{
 
// printf("Playtone f_Hz: %i dur_ms: %i volume: %i\n\r", f_Hz,dur_ms,volume);
 
tone_putc(LSB(f_Hz));
tone_putc( MSB(f_Hz));
tone_putc( volume);
tone_putc(LSB(dur_ms));
tone_putc(MSB(dur_ms));
 
 
}
 
 
//-----------------
void InitSound(void){//main program
 
 
 
ToneBufHead = 0;
ToneBufTail = 0;
 
initvars();
initsindat();
 
Timer2_Init();
Timer3_Init();
 
 
 
 
}
 
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/sound/pwmsine8bit.h
0,0 → 1,22
/*
* pwmsine8bit.h
*
* Created on: 01.09.2012
* Author: cebra
*/
 
#ifndef PWMSINE8BIT_H_
#define PWMSINE8BIT_H_
 
extern unsigned char freqincipart,freqincfpart;
extern unsigned char waveptipart,waveptfpart;
extern unsigned char iattenfac; //0-255
extern unsigned char generate;
extern volatile unsigned char sindat[256]; //8 bit sine table
void InitSound(void);
void tone(int hz,uint8_t volume, uint16_t ms, uint16_t soundpause);
void tone1(int hz);
void playTone(uint16_t f_Hz, uint16_t dur_ms, uint8_t volume);
void tone_handler(void);
 
#endif /* PWMSINE8BIT_H_ */
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/stick/stick.c
0,0 → 1,507
/*****************************************************************************
* 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 *
* Copyright (C) 2012 Martin Runkel *
* *
* 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 <string.h>
#include <stdlib.h>
 
#include "../lcd/lcd.h"
#include "../timer/timer.h"
#include "../tracking/servo.h"
#include "../messages.h"
#include "../lipo/lipo.h"
#include "stick.h"
#include "stick_setup.h"
#include "../eeprom/eeprom.h"
#include "../setup/setup.h"
 
#define SERVO_CORRECT 3.125
 
 
#include <util/delay.h>
#include <inttypes.h>
#include <stdlib.h>
 
#include "../main.h"
#include "../uart/uart1.h"
#include "../uart/usart.h"
 
 
#define LIMIT_MIN_MAX(value, min, max) {if(value <= min) value = min; else if(value >= max) value = max;}
 
int16_t Pos_Stick[12]; // 1,5mS
int16_t Pos_alt[5]; //
 
uint8_t BalkenPos = 0;
uint8_t Stick_Display = 0;
//uint8_t serialChannelRichtung = 0;
//uint8_t serialChannelNeutral = 0;
//uint8_t serialChannelConfig = 2;
 
 
//--------------------------------------------------------------
//
void joystick (void)
{
// uint8_t chg = 0;
// uint8_t Pos_Stick = 150; // 1,5mS
// uint8_t Pos_alt = 150; //
//int16_t Pos_Stick[12]; // 1,5mS
uint8_t chg = 0;
//uint8_t BalkenPos = 0;
uint8_t Stick_Nr = 0;
//uint8_t Stick_Display = 0;
uint8_t i = 0;
 
memset (Pos_Stick, 150, 3); // füllt 3+1 Byte vom Pos_Stick[12] mit 150
//int16_t Pos_alt[5]; //
int16_t Poti_Summe[5]; //
memset (Poti_Summe, 0, 5); // füllt 3+1 Byte mit 0
int16_t Poti_Neutral[5]; //
 
 
// ADC- init
//if (Config.Lipomessung == true)
//{
 
//}
//for (uint8_t i = 0; i < 4; i++)
 
if (Config.stick_typ[0] == 0) // Poti
{
PORTA &= ~(1<<PORTA0);
DDRA &= ~(1<<DDA0);
}
else // Taster
{
PORTA |= (1<<PORTA0);
DDRA |= (1<<DDA0);
}
if (Config.Lipomessung == false)
{
if (Config.stick_typ[1] == 0) // Poti
{
PORTA &= ~(1<<PORTA1);
DDRA &= ~(1<<DDA1);
}
else // Taster
{
PORTA |= (1<<PORTA1);
DDRA |= (1<<DDA1);
}
}
if (Config.stick_typ[2] == 0)
{
PORTA &= ~(1<<PORTA2);
DDRA &= ~(1<<DDA2);
}
else
{
PORTA |= (1<<PORTA2);
DDRA |= (1<<DDA2);
}
if (Config.stick_typ[3] == 0)
{
PORTA &= ~(1<<PORTA3);
DDRA &= ~(1<<DDA3);
}
else
{
PORTA |= (1<<PORTA3);
DDRA |= (1<<DDA3);
}
 
//if (Config.stick_dir[i] == 0) serialChannelRichtung &= ~(1<<i); else serialChannelRichtung |= (1<<i);
//if (Config.stick_neutral[i] == 0) serialChannelNeutral &= ~(1<<i); else serialChannelNeutral |= (1<<i);
 
//if (Config.Lipomessung == true)
 
//serialChannelConfig
 
 
// Ermittlung der Neutralposition
for (uint8_t i = 0; i < 4; i++)
{
ADMUX = (1<<REFS0)|(0<<MUX0); // Multiplexer selection Register: AVCC with external capacitor at AREF pin , ADC1
ADMUX = (ADMUX & ~(0x1F)) | (i & 0x1F); // ADC[i] verwenden
 
timer = 50;
while (timer > 0);
 
ADCSRA = (1<<ADEN)|(1<<ADSC)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); // ADC Enable, ADC Start, Prescaler 128
 
 
while (ADCSRA & (1<<ADSC)); // wenn ADC fertig
 
Poti_Neutral[i] = ((ADCW>>2)&0xff);
LIMIT_MIN_MAX (Poti_Neutral[i],108,148);
 
ADMUX = (ADMUX & ~(0x1F)) | (i & 0x1F); // ADC[i] verwenden
// Stick_Nr 1,2,3 = Potis, Stick_Nr 1= Lipo
ADCSRA |= (1<<ADSC); // ADC Start
 
while (ADCSRA & (1<<ADSC)); // wenn ADC fertig
 
Poti_Neutral[i] = ((ADCW>>2)&0xff);
LIMIT_MIN_MAX (Poti_Neutral[i],108,148);
}
Stick_Nr = 0;
ADMUX = (ADMUX & ~(0x1F)) | (Stick_Nr & 0x1F); // ADC[i] verwenden
ADCSRA |= (1<<ADSC); // ADC Start
 
/*
Stick_Nr = 0;
ADMUX = (1<<REFS0)|(0<<MUX0); // Multiplexer selection Register: AVCC with external capacitor at AREF pin , ADC1
ADMUX = (ADMUX & ~(0x1F)) | (Stick_Nr & 0x1F); // ADC[Stick_Nr] verwenden
timer = 50;
while (timer > 0);
ADCSRA = (1<<ADEN)|(1<<ADSC)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); // ADC Enable, ADC Start, Prescaler 128
 
// Stick-Neutralposition bestimmen
 
while (ADCSRA & (1<<ADSC)); // wenn ADC fertig
Poti_Neutral[Stick_Nr] = ((ADCW>>2)&0xff);
LIMIT_MIN_MAX (Poti_Neutral[Stick_Nr],108,148);
Stick_Nr = 2 ;
ADMUX = (ADMUX & ~(0x1F)) | (Stick_Nr & 0x1F); // ADC[i] verwenden
// Stick_Nr 1,2,3 = Potis, Stick_Nr 1= Lipo
ADCSRA |= (1<<ADSC); // ADC Start
while (ADCSRA & (1<<ADSC)); // wenn ADC fertig
Poti_Neutral[Stick_Nr] = ((ADCW>>2)&0xff);
LIMIT_MIN_MAX (Poti_Neutral[Stick_Nr],108,148);
Stick_Nr = 0;
ADMUX = (ADMUX & ~(0x1F)) | (Stick_Nr & 0x1F); // ADC[i] verwenden
// Stick_Nr 1,2,3 = Potis, Stick_Nr 1= Lipo
ADCSRA |= (1<<ADSC); // ADC Start
*/
 
 
 
//OCR1A = 150 * SERVO_CORRECT; // Servomitte
 
lcd_cls ();
// Kopfzeile und Rahmen zeichnen
lcd_printp (PSTR(" serielle Potis 1-5 "), 2);
//lcd_printp_at (7, 5, PSTR("%"), 0);
//lcd_printp_at (16, 5, PSTR("mS"), 0);
 
lcd_puts_at(0, 7, strGet(KEYLINE3), 0);
lcd_printp_at (18, 7, PSTR("\x19O\x18"), 0);
for (i=0 ; i< 5 ; i++)
{
BalkenPos = 12 + (i*8) ;
 
lcd_rect(3,BalkenPos, 120, 6, 1); // +-150% Rahmen
lcd_line(23,BalkenPos,23,(BalkenPos+6),1); // -100%
lcd_line(43,BalkenPos,43,(BalkenPos+6),1); // -50%
lcd_frect(62,BalkenPos, 2, 6, 1); // 0%
lcd_line(83,BalkenPos,83,(BalkenPos+6),1); // +50%
lcd_line(103,BalkenPos,103,(BalkenPos+6),1); // +100%
}
// Reset auf Mittelstellung
Pos_Stick[0] = 150;
Poti_Summe[0] = 0;
Pos_Stick[2] = 150;
Poti_Summe[2] = 0;
Pos_Stick[4] = 150;
Poti_Summe[4] = 0;
chg = 255;
 
do
{
if (!(ADCSRA & (1<<ADSC))) // wenn ADC fertig
{
//Pos_Stick[Stick_Nr] = 150 + 128 - ((ADCW>>2)&0xff);
//if (serialChannelRichtung & (1<<Stick_Nr))
if (Config.stick_dir[Stick_Nr] > 0)
Pos_Stick[Stick_Nr] = Poti_Neutral[Stick_Nr] - ((ADCW>>2)&0xff);
else
Pos_Stick[Stick_Nr] = ((ADCW>>2)&0xff) - Poti_Neutral[Stick_Nr];
 
 
LIMIT_MIN_MAX (Pos_Stick[Stick_Nr],-120,120);
//if ((Stick_Nr==0) || (Stick_Nr==2)) // nur die Potis 1,2 sind nicht neutralisierend
if (Config.stick_neutral[Stick_Nr]==0) // nicht neutralisierend
{
Poti_Summe[Stick_Nr] += (Pos_Stick[Stick_Nr]/8) * abs(Pos_Stick[Stick_Nr]/8);
LIMIT_MIN_MAX (Poti_Summe[Stick_Nr],-(120*128),(120*128));
Pos_Stick[Stick_Nr]= Poti_Summe[Stick_Nr] / 128; // nicht neutralisierend
}
Pos_Stick[Stick_Nr] += 150;
//LIMIT_MIN_MAX (Pos_Stick[Stick_Nr],30,270); // war 75 , 225
LIMIT_MIN_MAX (Pos_Stick[Stick_Nr],Config.stick_min[Stick_Nr],Config.stick_max[Stick_Nr]); // war 30, 270
if (Pos_Stick[Stick_Nr] != Pos_alt[Stick_Nr]) // nur bei Änderung
{
chg |= (1<<Stick_Nr) ;
//Pos_alt=Pos_Stick ; // verschoben
}
Stick_Nr ++ ;
//if (Stick_Nr==1) Stick_Nr=2; // Lipo überspringen
if (Stick_Nr==3) // Taster
{
if (Config.stick_dir[Stick_Nr] > 0)
{
if (PINA & (1 << KEY_EXT)) Pos_Stick[Stick_Nr] = Config.stick_min[Stick_Nr];
else Pos_Stick[Stick_Nr] = Config.stick_max[Stick_Nr];
}
else
{
if (PINA & (1 << KEY_EXT)) Pos_Stick[Stick_Nr] = Config.stick_max[Stick_Nr];
else Pos_Stick[Stick_Nr] = Config.stick_min[Stick_Nr];
}
if (Pos_Stick[Stick_Nr] != Pos_alt[Stick_Nr])
{
chg |= (1<<Stick_Nr) ;
}
Stick_Nr=0;
}
/*
#ifndef ohne_Lipo // MartinR
Stick_Nr = 1; // MartinR AD-Kanal 1 überspringen wegen Lipo Überwachung
#endif
*/
 
ADMUX = (ADMUX & ~(0x1F)) | (Stick_Nr & 0x1F); // ADC[i] verwenden
// Stick_Nr 1,2,3 = Potis, Stick_Nr 0= Lipo
ADCSRA |= (1<<ADSC); // ADC Start
//serialPotis ();
}
 
if ((get_key_press (1 << KEY_PLUS) | get_key_long_rpt_sp ((1 << KEY_PLUS), 3)))
//if (get_key_press (1 << KEY_PLUS))
//if (PINA & (1 << KEY_PLUS))
{
if (Config.stick_neutral[4]==0) // nicht neutralisierend
{
if (Config.stick_dir[4] == 0) Pos_Stick[4] ++ ; else Pos_Stick[4] -- ;
LIMIT_MIN_MAX (Pos_Stick[4],Config.stick_min[4],Config.stick_max[4]); // war 30, 270
}
else
{
if (Config.stick_dir[4] == 0) Pos_Stick[4] = Config.stick_max[4] ; else Pos_Stick[4] = Config.stick_min[4] ;
}
chg |= (1<<4) ;
}
else if ((get_key_press (1 << KEY_MINUS) | get_key_long_rpt_sp ((1 << KEY_MINUS), 3)))
{
if (Config.stick_neutral[4]==0) // nicht neutralisierend
{
if (Config.stick_dir[4] == 0) Pos_Stick[4] -- ; else Pos_Stick[4] ++ ;
LIMIT_MIN_MAX (Pos_Stick[4],Config.stick_min[4],Config.stick_max[4]); // war 30, 270
//LIMIT_MIN_MAX (Pos_Stick[Stick_Nr],30,270); // war 75 , 225
}
else
{
if (Config.stick_dir[4] == 0) Pos_Stick[4] = Config.stick_min[4] ; else Pos_Stick[4] = Config.stick_max[4] ;
}
chg |= (1<<4) ;
}
 
if (Config.stick_neutral[4]!= 0 && Pos_Stick[4]!= 150 && (PINA &(1 << KEY_PLUS)) && (PINA &(1 << KEY_MINUS)))
{
Pos_Stick[4] = 150 ;
chg |= (1<<4) ;
}
 
if (get_key_press (1 << KEY_ENTER))
{
/*
for (i=0 ; i< 4 ; i++)
{
BalkenPos = 12 + (i*8) ;
lcd_frect (4, (BalkenPos+1), 118, 4, 0); // Balken löschen
lcd_frect(62, BalkenPos, 2, 6, 1); // 0%
}
*/
Pos_Stick[0] = 150;
Poti_Summe[0] = 0;
Pos_Stick[2] = 150;
Poti_Summe[2] = 0;
Pos_Stick[4] = 150;
Poti_Summe[4] = 0;
BeepTime = 200;
BeepMuster = 0x0080;
chg = 255;
}
 
if (chg)
{
if (chg & (1<<0)); // Stick 1
{
BalkenPos = 12 + (0*8) ;
Stick_Display = 0;
Balken_Zeichnen () ;
Pos_alt[Stick_Display]=Pos_Stick[Stick_Display];
}
// Stick 2 = Lipo
if (chg & (1<<1)); // Stick 2
{
BalkenPos = 12 + (1*8) ;
Stick_Display = 1;
//if (serialChannelConfig & (0<<1)) Balken_Zeichnen () ; // nur wenn keine Lipo-Spannung
if (Config.Lipomessung == false) Balken_Zeichnen () ; // nur wenn keine Lipo-Spannung
Pos_alt[Stick_Display]=Pos_Stick[Stick_Display];
}
if (chg & (1<<2)); // Stick 3
{
BalkenPos = 12 + (2*8) ;
Stick_Display = 2;
Balken_Zeichnen () ;
Pos_alt[Stick_Display]=Pos_Stick[Stick_Display];
}
if (chg & (1<<3)); // Stick 4 = Taster
{
BalkenPos = 12 + (3*8) ;
Stick_Display = 3;
Balken_Zeichnen () ;
Pos_alt[Stick_Display]=Pos_Stick[Stick_Display];
}
if (chg & (1<<4)); // Stick 5 = Taster vom PKT
{
BalkenPos = 12 + (4*8) ;
Stick_Display = 4;
Balken_Zeichnen () ;
//OCR1A = (((Pos_Stick[Stick_Display]-150)/1.6)+150) * SERVO_CORRECT; // Servostellung , 1.6=0.8*0.5
Pos_alt[Stick_Display]=Pos_Stick[Stick_Display];
}
chg = 0;
serialPotis ();
}
}
while (!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
//#ifdef HWVERSION3_9
//#ifndef ohne_Lipo // MartinR
if (Config.Lipomessung == true) // MartinR: geändert
{
//DDRA &= ~(1<<DDA1); // Eingang: PKT Lipo Messung
//PORTA &= ~(1<<PORTA1);
ADC_Init(); // ADC für Lipomessung wieder aktivieren
}
 
//ADC_Init(); // ADC für Lipomessung wieder aktivieren
//#endif
//#endif
 
}
 
//--------------------------------------------------------------
//
void serialPotis (void)
{
uint8_t i = 0;
memset (buffer, 0, 12); // füllt die 12+1 Byte vom buffer mit 0
 
for (i=0 ; i< 5 ; i++)
{
buffer[i] = Pos_Stick[i]-150 ;
}
SendOutData('y', ADDRESS_FC, 1, buffer, 12);
}
//--------------------------------------------------------------
//
void Balken_Zeichnen (void)
{
// Balken löschen
if ((Pos_Stick[Stick_Display] > Pos_alt[Stick_Display])&&(Pos_alt[Stick_Display] < 150)) // Balken links löschen
lcd_frect ((63-((150 -Pos_alt[Stick_Display]) * 0.5)), (BalkenPos+1), (63-((150- Pos_Stick[Stick_Display]) * 0.5)), 4, 0);
if ((Pos_Stick[Stick_Display] < Pos_alt[Stick_Display])&&(Pos_alt[Stick_Display] > 150)) // Balken rechts löschen
lcd_frect ((63+((Pos_Stick[Stick_Display] - 150) * 0.5)), (BalkenPos+1), (63+((Pos_alt[Stick_Display] - 150) * 0.5)), 4, 0);
// Balken zeichnen
if (Pos_Stick[Stick_Display] >= 150)
{
lcd_frect (63, (BalkenPos+1), ((Pos_Stick[Stick_Display] - 150) * 0.5), 4, 1);
//write_ndigit_number_u (4, 5, ((Pos_Stick[Stick_Display] - 150) * 1.25), 3, 0, 0); // Pulse width in %
lcd_frect(62, (BalkenPos), 2, 6, 1); // 0%
}
else
{
lcd_frect (63 - ((150 - Pos_Stick[Stick_Display]) * 0.5), (BalkenPos+1), ((150 - Pos_Stick[Stick_Display]) * 0.5), 4, 1);
//write_ndigit_number_u (4, 5, ((150 - Pos_Stick[Stick_Display]) * 1.25), 3, 0, 0); // Pulse width in %
lcd_frect(62, (BalkenPos), 2, 6, 1); // 0%
}
// Raster zeichnen
lcd_line(3, BalkenPos,3, (BalkenPos+6),1); // -150%
lcd_line(23, BalkenPos,23, (BalkenPos+6),1); // -100%
lcd_line(43, BalkenPos,43, (BalkenPos+6),1); // -50%
lcd_line(83, BalkenPos,83, (BalkenPos+6),1); // +50%
lcd_line(103,BalkenPos,103,(BalkenPos+6),1); // +100%
lcd_line(123,BalkenPos,123,(BalkenPos+6),1); // +150%
}
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/stick/stick.c_f
0,0 → 1,392
/*****************************************************************************
* 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 *
* Copyright (C) 2012 Martin Runkel *
* *
* 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 <string.h>
#include <stdlib.h>
 
#include "../lcd/lcd.h"
#include "../timer/timer.h"
#include "../tracking/servo.h"
#include "../messages.h"
#include "../lipo/lipo.h"
#include "stick.h"
 
#define SERVO_CORRECT 3.125
 
 
#include <util/delay.h>
#include <inttypes.h>
#include <stdlib.h>
 
#include "../main.h"
#include "../uart/uart1.h"
#include "../uart/usart.h"
#include "../eeprom/eeprom.h"
 
 
#define LIMIT_MIN_MAX(value, min, max) {if(value <= min) value = min; else if(value >= max) value = max;}
 
int16_t Pos_Stick[12]; // 1,5mS
int16_t Pos_alt[5]; //
 
uint8_t BalkenPos = 0;
uint8_t Stick_Display = 0;
uint8_t serialChannelRichtung = 0;
uint8_t serialChannelConfig = 2;
 
 
//--------------------------------------------------------------
//
void joystick (void)
{
// uint8_t chg = 0;
// uint8_t Pos_Stick = 150; // 1,5mS
// uint8_t Pos_alt = 150; //
//int16_t Pos_Stick[12]; // 1,5mS
uint8_t chg = 0;
//uint8_t BalkenPos = 0;
uint8_t Stick_Nr = 0;
//uint8_t Stick_Display = 0;
uint8_t i = 0;
 
memset (Pos_Stick, 150, 3); // füllt 3+1 Byte vom Pos_Stick[12] mit 150
//int16_t Pos_alt[5]; //
int16_t Poti_Summe[5]; //
memset (Poti_Summe, 0, 5); // füllt 3+1 Byte mit 0
int16_t Poti_Neutral[5]; //
 
 
// ADC- init
Stick_Nr = 0;
ADMUX = (1<<REFS0)|(0<<MUX0); // Multiplexer selection Register: AVCC with external capacitor at AREF pin , ADC1
ADMUX = (ADMUX & ~(0x1F)) | (Stick_Nr & 0x1F); // ADC[Stick_Nr] verwenden
timer = 50;
while (timer > 0);
ADCSRA = (1<<ADEN)|(1<<ADSC)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); // ADC Enable, ADC Start, Prescaler 128
 
// Stick-Neutralposition bestimmen
 
while (ADCSRA & (1<<ADSC)); // wenn ADC fertig
Poti_Neutral[Stick_Nr] = ((ADCW>>2)&0xff);
//CB LIMIT_MIN_MAX (Poti_Neutral[Stick_Nr],108,148);
LIMIT_MIN_MAX (Poti_Neutral[Stick_Nr],stick_min[Stick_Nr],stick_max[Stick_Nr]);
Stick_Nr = 2 ;
ADMUX = (ADMUX & ~(0x1F)) | (Stick_Nr & 0x1F); // ADC[i] verwenden
// Stick_Nr 1,2,3 = Potis, Stick_Nr 1= Lipo
ADCSRA |= (1<<ADSC); // ADC Start
while (ADCSRA & (1<<ADSC)); // wenn ADC fertig
Poti_Neutral[Stick_Nr] = ((ADCW>>2)&0xff);
//CB LIMIT_MIN_MAX (Poti_Neutral[Stick_Nr],108,148);
LIMIT_MIN_MAX (Poti_Neutral[Stick_Nr],stick_min[Stick_Nr],stick_max[Stick_Nr]);
Stick_Nr = 0;
ADMUX = (ADMUX & ~(0x1F)) | (Stick_Nr & 0x1F); // ADC[i] verwenden
// Stick_Nr 1,2,3 = Potis, Stick_Nr 1= Lipo
ADCSRA |= (1<<ADSC); // ADC Start
 
 
 
//OCR1A = 150 * SERVO_CORRECT; // Servomitte
 
lcd_cls ();
// Kopfzeile und Rahmen zeichnen
lcd_printp (PSTR(" serielle Potis 1-5 "), 2);
//lcd_printp_at (7, 5, PSTR("%"), 0);
//lcd_printp_at (16, 5, PSTR("mS"), 0);
 
lcd_puts_at(0, 7, strGet(KEYLINE3), 0);
lcd_printp_at (18, 7, PSTR("\x19O\x18"), 0);
for (i=0 ; i< 5 ; i++)
{
BalkenPos = 12 + (i*8) ;
 
lcd_rect(3,BalkenPos, 120, 6, 1); // +-150% Rahmen
lcd_line(23,BalkenPos,23,(BalkenPos+6),1); // -100%
lcd_line(43,BalkenPos,43,(BalkenPos+6),1); // -50%
lcd_frect(62,BalkenPos, 2, 6, 1); // 0%
lcd_line(83,BalkenPos,83,(BalkenPos+6),1); // +50%
lcd_line(103,BalkenPos,103,(BalkenPos+6),1); // +100%
}
// Reset auf Mittelstellung
Pos_Stick[0] = 150;
Poti_Summe[0] = 0;
Pos_Stick[2] = 150;
Poti_Summe[2] = 0;
Pos_Stick[4] = 150;
Poti_Summe[4] = 0;
chg = 255;
 
do
{
if (!(ADCSRA & (1<<ADSC))) // wenn ADC fertig
{
//Pos_Stick[Stick_Nr] = 150 + 128 - ((ADCW>>2)&0xff);
//CB if (serialChannelRichtung & (1<<Stick_Nr))
if (stick_dir[Stick_Nr] & (1<<Stick_Nr))
Pos_Stick[Stick_Nr] = Poti_Neutral[Stick_Nr] - ((ADCW>>2)&0xff);
else
Pos_Stick[Stick_Nr] = ((ADCW>>2)&0xff) - Poti_Neutral[Stick_Nr];
// LIMIT_MIN_MAX (Pos_Stick[Stick_Nr],-120,120);
LIMIT_MIN_MAX (Pos_Stick[Stick_Nr],stick_min[Stick_Nr],stick_max[Stick_Nr]);
 
if ((Stick_Nr==0) || (Stick_Nr==2)) // nur die Potis 1,2 sind nicht neutralisierend
{
Poti_Summe[Stick_Nr] += (Pos_Stick[Stick_Nr]/8) * abs(Pos_Stick[Stick_Nr]/8);
LIMIT_MIN_MAX (Poti_Summe[Stick_Nr],-(120*128),(120*128));
Pos_Stick[Stick_Nr]= Poti_Summe[Stick_Nr] / 128; // nicht neutralisierend
}
Pos_Stick[Stick_Nr] += 150;
// LIMIT_MIN_MAX (Pos_Stick[Stick_Nr],30,270); // war 75 , 225
LIMIT_MIN_MAX (Pos_Stick[Stick_Nr],stick_min[Stick_Nr],stick_max[Stick_Nr]); // war 75 , 225
if (Pos_Stick[Stick_Nr] != Pos_alt[Stick_Nr]) // nur bei Änderung
{
chg |= (1<<Stick_Nr) ;
//Pos_alt=Pos_Stick ; // verschoben
}
Stick_Nr ++ ;
//if (Stick_Nr==1) Stick_Nr=2; // Lipo überspringen
//CB if (Stick_Nr==3) // Taster
if (stick_typ[Stick_Nr]==1) // Taster
{
// if (get_key_press (1 << KEY_EXT)) Pos_Stick[Stick_Nr] = 225;
//CB if (serialChannelRichtung & (1<<Stick_Nr))
if (stick_dir[Stick_Nr] & (1<<Stick_Nr))
{
if (PINA & (1 << KEY_EXT)) Pos_Stick[Stick_Nr] = 30;
else Pos_Stick[Stick_Nr] = 270;
}
else
{
if (PINA & (1 << KEY_EXT)) Pos_Stick[Stick_Nr] = 270;
else Pos_Stick[Stick_Nr] = 30;
}
if (Pos_Stick[Stick_Nr] != Pos_alt[Stick_Nr])
{
chg |= (1<<Stick_Nr) ;
}
Stick_Nr=0;
}
/*
#ifndef ohne_Lipo // MartinR
Stick_Nr = 1; // MartinR AD-Kanal 1 überspringen wegen Lipo Überwachung
#endif
*/
ADMUX = (ADMUX & ~(0x1F)) | (Stick_Nr & 0x1F); // ADC[i] verwenden
// Stick_Nr 1,2,3 = Potis, Stick_Nr 0= Lipo
ADCSRA |= (1<<ADSC); // ADC Start
//serialPotis ();
}
 
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 3)) && (Pos_Stick[4] < 271))
{
Pos_Stick[4] ++ ;
//LIMIT_MIN_MAX (Pos_Stick[Stick_Nr],30,270); // war 75 , 225
chg |= (1<<4) ;
}
else if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 3)) && (Pos_Stick[4] > 29))
{
Pos_Stick[4] -- ;
//LIMIT_MIN_MAX (Pos_Stick[Stick_Nr],30,270); // war 75 , 225
chg |= (1<<4) ;
}
else if (get_key_press (1 << KEY_ENTER))
{
/*
for (i=0 ; i< 4 ; i++)
{
BalkenPos = 12 + (i*8) ;
lcd_frect (4, (BalkenPos+1), 118, 4, 0); // Balken löschen
lcd_frect(62, BalkenPos, 2, 6, 1); // 0%
}
*/
Pos_Stick[0] = 150;
Poti_Summe[0] = 0;
Pos_Stick[2] = 150;
Poti_Summe[2] = 0;
Pos_Stick[4] = 150;
Poti_Summe[4] = 0;
BeepTime = 200;
BeepMuster = 0x0080;
chg = 255;
}
 
if (chg)
{
if (chg & (1<<0)); // Stick 1
{
BalkenPos = 12 + (0*8) ;
Stick_Display = 0;
Balken_Zeichnen () ;
Pos_alt[Stick_Display]=Pos_Stick[Stick_Display];
}
// Stick 2 = Lipo
if (chg & (1<<1)); // Stick 2
{
BalkenPos = 12 + (1*8) ;
Stick_Display = 1;
if (serialChannelConfig & (0<<1)) Balken_Zeichnen () ; // nur wenn keine Lipo-Spannung
Pos_alt[Stick_Display]=Pos_Stick[Stick_Display];
}
if (chg & (1<<2)); // Stick 3
{
BalkenPos = 12 + (2*8) ;
Stick_Display = 2;
Balken_Zeichnen () ;
Pos_alt[Stick_Display]=Pos_Stick[Stick_Display];
}
if (chg & (1<<3)); // Stick 4 = Taster
{
BalkenPos = 12 + (3*8) ;
Stick_Display = 3;
Balken_Zeichnen () ;
Pos_alt[Stick_Display]=Pos_Stick[Stick_Display];
}
if (chg & (1<<4)); // Stick 5 = Taster vom PKT
{
BalkenPos = 12 + (4*8) ;
Stick_Display = 4;
Balken_Zeichnen () ;
//OCR1A = (((Pos_Stick[Stick_Display]-150)/1.6)+150) * SERVO_CORRECT; // Servostellung , 1.6=0.8*0.5
Pos_alt[Stick_Display]=Pos_Stick[Stick_Display];
}
chg = 0;
serialPotis ();
}
}
while (!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
#ifdef HWVERSION3_9
#ifndef ohne_Lipo // MartinR
ADC_Init(); // ADC für Lipomessung wieder aktivieren
#endif
#endif
 
}
 
//--------------------------------------------------------------
//
void serialPotis (void)
{
uint8_t i = 0;
memset (buffer, 0, 12); // füllt die 12+1 Byte vom buffer mit 0
 
for (i=0 ; i< 5 ; i++)
{
buffer[i] = Pos_Stick[i]-150 ;
}
SendOutData('y', ADDRESS_FC, 1, buffer, 12);
}
//--------------------------------------------------------------
//
void Balken_Zeichnen (void)
{
// Balken löschen
if ((Pos_Stick[Stick_Display] > Pos_alt[Stick_Display])&&(Pos_alt[Stick_Display] < 150)) // Balken links löschen
lcd_frect ((63-((150 -Pos_alt[Stick_Display]) * 0.5)), (BalkenPos+1), (63-((150- Pos_Stick[Stick_Display]) * 0.5)), 4, 0);
if ((Pos_Stick[Stick_Display] < Pos_alt[Stick_Display])&&(Pos_alt[Stick_Display] > 150)) // Balken rechts löschen
lcd_frect ((63+((Pos_Stick[Stick_Display] - 150) * 0.5)), (BalkenPos+1), (63+((Pos_alt[Stick_Display] - 150) * 0.5)), 4, 0);
// Balken zeichnen
if (Pos_Stick[Stick_Display] >= 150)
{
lcd_frect (63, (BalkenPos+1), ((Pos_Stick[Stick_Display] - 150) * 0.5), 4, 1);
//write_ndigit_number_u (4, 5, ((Pos_Stick[Stick_Display] - 150) * 1.25), 3, 0, 0); // Pulse width in %
lcd_frect(62, (BalkenPos), 2, 6, 1); // 0%
}
else
{
lcd_frect (63 - ((150 - Pos_Stick[Stick_Display]) * 0.5), (BalkenPos+1), ((150 - Pos_Stick[Stick_Display]) * 0.5), 4, 1);
//write_ndigit_number_u (4, 5, ((150 - Pos_Stick[Stick_Display]) * 1.25), 3, 0, 0); // Pulse width in %
lcd_frect(62, (BalkenPos), 2, 6, 1); // 0%
}
// Raster zeichnen
lcd_line(3, BalkenPos,3, (BalkenPos+6),1); // -150%
lcd_line(23, BalkenPos,23, (BalkenPos+6),1); // -100%
lcd_line(43, BalkenPos,43, (BalkenPos+6),1); // -50%
lcd_line(83, BalkenPos,83, (BalkenPos+6),1); // +50%
lcd_line(103,BalkenPos,103,(BalkenPos+6),1); // +100%
lcd_line(123,BalkenPos,123,(BalkenPos+6),1); // +150%
}
 
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/stick/stick.h
0,0 → 1,42
/*****************************************************************************
* 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*
*****************************************************************************/
 
 
#ifndef _STICK_H
#define _STICK_H
 
void joystick (void);
void serialPotis (void);
void Balken_Zeichnen (void);
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/stick/stick.h_f
0,0 → 1,42
/*****************************************************************************
* 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*
*****************************************************************************/
 
 
#ifndef _STICK_H
#define _STICK_H
 
void joystick (void);
void serialPotis (void);
void Balken_Zeichnen (void);
 
#endif
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/stick/stick_setup.c
0,0 → 1,311
 
/****************************************************************/
/* Setup für die Sticks */
/* 2013 Cebra */
/****************************************************************/
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "../cpu.h"
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include "../main.h"
#include "../timer/timer.h"
#include "stick_setup.h"
#include "../lcd/lcd.h"
#include "../timer/timer.h"
#include "../menu.h"
#include "../messages.h"
#include "../mk-data-structs.h"
#include "../eeprom/eeprom.h"
#include "../setup/setup.h"
 
 
//--------------------------------------------------------------
#define ITEMS_STICKS 7
 
const prog_char stick_menuitems[ITEMS_STICKS][NUM_LANG][18]= // Zeilen,Zeichen+1
{
{"Übersicht ","summary ","summary "},
{"Stick 1 \x1d","stick 1 \x1d","stick 1 \x1d"},
{"Stick 2 \x1d","stick 2 \x1d","stick 2 \x1d"},
{"Stick 3 \x1d","stick 3 \x1d","stick 3 \x1d"},
{"Stick 4 \x1d","stick 4 \x1d","stick 4 \x1d"},
{"Stick 5 \x1d","stick 5 \x1d","stick 5 \x1d"},
{"PKT Lipomessung ","PKT Lipo measure.","PKT Lipo measure."},
 
};
 
//--------------------------------------------------------------
 
#define ITEMS_STICK 5
 
const prog_char sticks_menuitems[ITEMS_STICK][NUM_LANG][18]= // Zeilen,Zeichen+1
{
{"Minimal Wert ","minimal value ","minimal value "},
{"Maximal Wert ","maximal value ","maximal value "},
{"Type ","type ","type "},
{"Richtung ","direction ","direction "},
{"Neutralisiered","neutralizing ","neutralizing "},
};
 
//--------------------------------------------------------------
 
 
void Joysticks_Uebersicht(void)
{
lcd_cls ();
lcd_printpns_at(0, 0, PSTR(" Joystick Setup "), 2);
lcd_printpns_at(0, 1, PSTR("S Min Max Typ Dir N"), 0);
 
for (uint8_t i = 0; i < 5; i++) {
 
write_ndigit_number_u (0, 2+i,i+1, 1, 0,0);
write_ndigit_number_u (2, 2+i,Config.stick_min[i], 3, 0,0);
write_ndigit_number_u (6, 2+i,Config.stick_max[i], 3, 0,0);
if (Config.stick_typ[i] == 0) lcd_printpns_at(10, 2+i, PSTR("Poti"), 0); else lcd_printpns_at(10, 2+i, PSTR("Tast"), 0);
//if (Config.stick_typ[i] == 0) // MartinR: geändert
//{
if (Config.stick_dir[i] == 0) lcd_printpns_at(15, 2+i, PSTR("Norm"), 0); else lcd_printpns_at(15, 2+i, PSTR("Rev"), 0);
if (Config.stick_neutral[i] == 0) lcd_printpns_at(20, 2+i, PSTR("N"), 0); else lcd_printpns_at(20, 2+i, PSTR("Y"), 0);
//}
if (i == 1) if (Config.Lipomessung == true) lcd_printpns_at(3, 2+i, PSTR("PKT Lipomessung "), 0);
 
}
 
 
lcd_printp_at (18, 7, PSTR("OK"), 0);
 
do{}
while (!(get_key_press (1 << KEY_ENTER)));
 
 
}
 
 
 
//--------------------------------------------------------------
 
void Joysticks_Setup(void)
{
size = ITEMS_STICKS;
// uint8_t ii = 0;
// uint8_t Offset = 0;
// uint8_t dmode = 0;
uint8_t target_pos = 1;
// uint8_t val = 0;
edit =0;
while(1)
{
size = ITEMS_STICKS;
lcd_cls ();
lcd_printpns_at(0, 0, PSTR(" Joystick Setup "), 2);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
// while(2)
// {
// ii = 0;
// if(Offset > 0)
// {
// lcd_printp_at(1,1, PSTR("\x12"), 0);
// }
// for(ii = 0;ii < 6 ; ii++)
// {
// if((ii+Offset) < size)
// {
// lcd_printp_at(3,ii+1,stick_menuitems[ii+Offset][Config.DisplayLanguage], 0);
// }
// if((ii == 5)&&(ii+Offset < (size-1)))
// {
// lcd_printp_at(1,6, PSTR("\x13"), 0);
// }
// }
// if(dmode == 0)
// {
// if(Offset == 0)
// {
// if(size > 6)
// {
// val = menu_choose2 (1, 5, target_pos,0,1);
// }
// else
// {
// val = menu_choose2 (1, size, target_pos,0,0);
// }
// }
// else
// {
// val = menu_choose2 (2, 5, target_pos,1,1);
// }
// }
// if(dmode == 1)
// {
// if(Offset+7 > size)
// {
// val = menu_choose2 (2, 6, target_pos,1,0);
// }
// else
// {
// val = menu_choose2 (2, 5, target_pos,1,1);
// }
// }
// if(val == 254)
// {
// Offset++;
// dmode = 1;
// target_pos = 5;
// }
// else if(val == 253)
// {
// Offset--;
// dmode = 0;
// target_pos = 2;
// }
// else if(val == 255)
// {
// if (edit == 1)
// {
// WriteParameter();
// edit = 0;
// return;
// }
// return;
// }
// else
// {
// break;
// }
// }
val = menu_select(stick_menuitems,size,target_pos);
if (val==255) break;
target_pos = val;
 
if((val + offset)== 1 ) Joysticks_Uebersicht();
if((val + offset)== 2 ) stick_menu(0); //Stick 1
if((val + offset)== 3 ) {
if (Config.Lipomessung == true) {
lcd_cls ();
lcd_puts_at(0, 3, strGet(LIPO_MESSUNG), 2);
_delay_ms(1000);
}
else stick_menu(1); //Stick 2
}
if((val + offset)== 4 ) stick_menu(2); //Stick 3
if((val + offset)== 5 ) stick_menu(3); //Stick 4
if((val + offset)== 6 ) stick_menu(4); //Stick 5
if((val + offset)== 7 ) Config.Lipomessung = Edit_generic(Config.Lipomessung,0,1,LIPO_MESSUNG,YesNo);
}
}
 
 
//--------------------------------------------------------------
 
void stick_menu(uint8_t stick)
{
 
// uint8_t ii = 0;
// uint8_t Offset = 0;
// uint8_t dmode = 0;
uint8_t target_pos = 1;
// uint8_t val = 0;
edit =0;
 
while(1)
{
size = ITEMS_STICK;
lcd_cls ();
lcd_printpns_at(0, 0, PSTR("Joystick "), 2);
write_ndigit_number_u (9, 0,stick+1, 1, 0,2);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
// while(2)
// {
// ii = 0;
// if(Offset > 0)
// {
// lcd_printp_at(1,1, PSTR("\x12"), 0);
// }
// for(ii = 0;ii < 6 ; ii++)
// {
// if((ii+Offset) < size)
// {
// lcd_printp_at(3,ii+1,sticks_menuitems[ii+Offset][Config.DisplayLanguage], 0);
// }
// if((ii == 5)&&(ii+Offset < (size-1)))
// {
// lcd_printp_at(1,6, PSTR("\x13"), 0);
// }
// }
// if(dmode == 0)
// {
// if(Offset == 0)
// {
// if(size > 6)
// {
// val = menu_choose2 (1, 5, target_pos,0,1);
// }
// else
// {
// val = menu_choose2 (1, size, target_pos,0,0);
// }
// }
// else
// {
// val = menu_choose2 (2, 5, target_pos,1,1);
// }
// }
// if(dmode == 1)
// {
// if(Offset+7 > size)
// {
// val = menu_choose2 (2, 6, target_pos,1,0);
// }
// else
// {
// val = menu_choose2 (2, 5, target_pos,1,1);
// }
// }
// if(val == 254)
// {
// Offset++;
// dmode = 1;
// target_pos = 5;
// }
// else if(val == 253)
// {
// Offset--;
// dmode = 0;
// target_pos = 2;
// }
// else if(val == 255)
// {
// if (edit == 1)
// {
// WriteParameter();
// edit = 0;
// return;
// }
// return;
// }
// else
// {
// break;
// }
// }
val = menu_select(sticks_menuitems,size,target_pos);
if (val==255) break;
target_pos = val;
 
if((val + offset) == 1 ) Config.stick_min[stick]= Edit_generic(Config.stick_min[stick],0,300,STICK_MIN,Show_uint3);
if((val + offset) == 2 ) Config.stick_max[stick]= Edit_generic(Config.stick_max[stick],0,300,STICK_MAX,Show_uint3);
if((val + offset) == 3 ) Config.stick_typ[stick]= Edit_generic(Config.stick_typ[stick],0,1,STICK_TYPE,Sticktype);
if((val + offset) == 4 ) Config.stick_dir[stick]= Edit_generic(Config.stick_dir[stick],0,1,STICK_DIR,NormRev);
if((val + offset) == 5 ) Config.stick_neutral[stick]= Edit_generic(Config.stick_neutral[stick],0,1,STICK_NEUTRAL,YesNo);
}
}
 
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/stick/stick_setup.h
0,0 → 1,7
#ifndef _STICK_SETUP_H_
#define _STICK_SETUP_
 
void Joysticks_Setup(void);
void stick_menu(uint8_t stick);
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/timer/timer.c
0,0 → 1,676
/*****************************************************************************
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de *
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* based on the key handling by Peter Dannegger *
* see www.mikrocontroller.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*
*****************************************************************************/
 
//############################################################################
//# HISTORY timer.c
//#
//# 09.03.2013 OG
//# - add: timer2 (auch in timer.h)
//############################################################################
 
 
#include "../cpu.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <string.h>
#include <util/delay.h>
#include <inttypes.h>
 
 
#include "../main.h"
#include "../timer/timer.h"
#include "../eeprom/eeprom.h"
#include "../lcd/lcd.h"
#include "../uart/uart1.h"
#include "../bluetooth/bluetooth.h"
#include "../setup/setup.h"
#include"../tracking/tracking.h"
#include "../sound/pwmsine8bit.h"
 
 
#if defined HWVERSION1_2W || defined HWVERSION1_2
#include "HAL_HW1_2.h"
#endif
 
#if defined HWVERSION1_3W || defined HWVERSION1_3
#include "HAL_HW1_3.h"
#endif
 
#ifdef HWVERSION3_9
#include "../HAL_HW3_9.h"
#endif
 
volatile uint16_t timer;
volatile uint16_t timer2;
volatile uint16_t abo_timer;
volatile uint16_t sound_timer;
volatile uint16_t soundpause_timer;
volatile static unsigned int tim_main;
 
uint8_t key_state = 0; // debounced and inverted key state:
// bit = 1: key pressed
uint8_t key_press = 0; // key press detect
uint8_t key_long = 0; // key long press
uint8_t key_rpt = 0; // key repeat
uint8_t key_lrpt = 0; // key long press and repeat
uint8_t key_rpts = 0; // key long press and speed repeat
uint8_t repeat_speed = 0;
 
uint16_t DisplayTime = 0; // Leuchtdauer
volatile uint16_t IdleTimer = 0; // InaktivitÀtsTimer
 
 
//uint8_t servo = 0;
volatile uint16_t WarnCount = 0; // Zähler der LIPO Warnzeit
volatile uint16_t WarnToggle = 0; // Togglezähler zum blinken
volatile uint16_t WarnTime = 10; // Länge der LIPO Warnzeit 10 Sek.
volatile uint16_t PoffTime = 30; // Länge der Wartezeit vor Abschalten 30 Sek.
 
 
volatile uint8_t Display_on;// Flag Display on/off
 
unsigned int BeepTime = 0;
unsigned int BeepMuster = 0xffff;
unsigned int BeepPrio = 0;
 
volatile unsigned int CountMilliseconds = 0;
 
// Size of Buffer for Converting unsigned int Value to ASCII
#define STRING_BUFFER_SIZE 5
 
// Buffer for Converting unsigned int Value to ASCII
char String_Buffer[STRING_BUFFER_SIZE];
 
 
//--------------------------------------------------------------
//
void Timer0_Init (void) // System (100Hz)
{
timer = 0;
 
TCCR0A = (1 << WGM01);
TCCR0B = (1 << CS02) | (1 << CS00);
OCR0A = (F_CPU / (100L * 1024L)) ;
 
TIMSK0 |= (1 << OCIE0A); // enable interrupt for OCR
}
//--------------------------------------------------------------
//
//void Timer1_Init (void) // Timer 1-A
//{
// // löschen
// TCCR1A = 0;
// TCCR1B = 0;
// TIMSK1 = 0;
//
// // setzen
// TCCR1A |= (1 << COM1A1) | (1 << WGM11);
// TCCR1B |= (1 << CS11) | (1 << CS10) | (1 << WGM13) | (1 << WGM12);
//
// ICR1 = (F_CPU / 64) * 20 / 1000;
//
// OCR1A = 470; // ca. Servomitte
//}
 
 
 
 
//--------------------------------------------------------------
ISR(TIMER2_COMPA_vect)
{
PORTD |= (1 << PD7);
}
ISR(TIMER2_COMPB_vect)
{
PORTD &= ~(1 << PD7);
}
 
//--------------------------------------------------------------
 
////*****************************************************************************
void Timer2_Init (void)
{
if (Config.HWSound == 1)
{ /*Sound PWM*/
TCCR2A = 0x00; //stop
ASSR = 0x00; //set async mode
TCNT2 = 0x00; //setup
OCR2A = 0xff;
//Fast PWM 0xFF BOTTOM MAX
//Set OC2A on Compare Match
//clkT2S/8 (From prescaler)
TCCR2A |= (1 << WGM20) | (1 << WGM21) |(1 << COM2A1) | (1 << COM2A0);
TCCR2B |= (1 << CS20);
}
else
{ /* Displayhelligkeit*/
DDRD |= (1 << DDD7); // PD7 output
TCCR2A |= (1 << WGM21) | (1 << WGM20) | (1 << COM2A1); // non invers
TCCR2B |= (1 << CS20); // Prescaler 1/1
TIMSK2 |= (1 << OCIE2A) | (1 << OCIE2B);
 
OCR2A = 255;
}
 
 
}
//*****************************************************************************
//--------------------------------------------------------------
void Timer3_Init (void) // Sound, Timer CTC
{
 
TCCR3A = 0x00; //stop
TCNT3H = 0xF8; //set count
TCNT3L = 0x00; //set count
OCR3AH = 0x07; //set compare
OCR3AL = 0xFF; //set compare
TCCR3A |= (1 << WGM31);
TCCR3B |= (1 << CS30);
TIMSK3 |= (1 << OCIE3A); //timer interrupt sources 2=t0 compare
}
 
 
ISR(TIMER3_COMPA_vect) // Sound
{
//void timer0_comp_isr(void){
//was 8 KHz 125usec sampling rate
//now 12 KHz 83usec sampling rate
unsigned char oldfpart;
signed char fullsamp;
signed int tmp;
 
TCNT3=0;
// tics++; //8 bit... atomic
 
if(generate){
 
DDRD |= (1<<DDD7); // Port aus Ausgang
oldfpart=waveptfpart; //remember fractional part
waveptfpart+=freqincfpart; //add frac part of freq inc to wave pointer
if(waveptfpart < oldfpart){ //did it walk off the end?
waveptipart++; //yes, bump integer part
}
waveptipart+=freqincipart; //add int part of freq increment to wave pointer
fullsamp=sindat[waveptipart]; //get 8 bit sin sample from table (signed)
tmp=fullsamp*iattenfac; //cvt 7 bit x 8 = 15 bit
OCR2A=(tmp >> 8)+128; //cvt 15 bit signed to 8 bit unsigned
}
else
 
DDRD &= ~(1 << DDD7); //Port auf Eingang, sperrt das Rauschen
 
 
}
 
 
 
//--------------------------------------------------------------
ISR(TIMER0_COMPA_vect) // Timer-Interrupt (100 Hz)
{
static uint8_t ct0 = 0;
static uint8_t ct1 = 0;
static uint8_t k_time_l = 0;
static uint8_t k_time_r = 0;
static uint8_t k_time_lr = 0;
static uint8_t k_time_rs = 0;
uint8_t i;
 
static unsigned char cnt_1ms = 1,cnt = 0;
unsigned char beeper_ein = 0;
// unsigned char pieper_ein = 0;
 
// Key handling by Peter Dannegger
// see www.mikrocontroller.net
 
i = key_state ^ ~KEY_PIN; // key changed ?
ct0 = ~(ct0 & i); // reset or count ct0
ct1 = ct0 ^ (ct1 & i); // reset or count ct1
i &= (ct0 & ct1); // count until roll over ?
key_state ^= i; // then toggle debounced state
key_press |= (key_state & i); // 0->1: key press detect
 
// if (PKT_IdleBeep == 1)
// {
// IdleTimer ++; // nix zu tun? Timer hochzÀhlen
// if (IdleTimer == 12000) // Warnhinweis
// {
// set_beep ( 200, 0x0080, BeepNormal);
// IdleTimer = 0;
// }
// }
 
if (!cnt--)
{
cnt = 9;
CountMilliseconds++;
cnt_1ms++;
}
 
if (i!=0)
{ // Displaylicht einschalten, und bzw. TimeoutzÀhlerreset wenn Taste gedrÌckt wurde
if (((Config.HWBeeper==1)&&(PCB_Version == PKT39m))||((Config.HWBeeper==0)&&(PCB_Version == PKT39x))) // entweder Beeper oder Display ein/aus
{
if (Display_on == 0)
set_D_LIGHT();
 
 
Display_on = 1; // Flag Display on
DisplayTime = 0; // Timer Reset
IdleTimer = 0; // Idletimeout Reset
}
}
 
if (Config.DisplayTimeout > 0)
{
if (((Config.HWBeeper==1)&&(PCB_Version == PKT39m))||((Config.HWBeeper==0)&&(PCB_Version == PKT39x))) // entweder Beeper oder Display ein/aus
{
if (Display_on == 1)
{
DisplayTime++;
if ((DisplayTime / 100) == Config.DisplayTimeout) // ISR läuft mit 100Hz
{ // Displaylicht ausschalten
clr_D_LIGHT();
Display_on = 0; // Flag Display off
 
}
}
}
}
 
//--------------------------------------------------------------
#ifdef HWVERSION3_9
// LipoCheck(); // Lipo prüfen
#endif
 
//--------------------------------------------------------------
if (Config.HWBeeper==1)
{
if (BeepTime)
{
if (BeepTime > 10)
BeepTime -= 10;
else
{
BeepTime = 0;
 
}
 
if (BeepTime & BeepMuster)
beeper_ein = 1;
else beeper_ein = 0;
 
 
}
else
{
beeper_ein = 0;
BeepMuster = 0xffff;
BeepPrio = BeepNormal;
}
 
if (beeper_ein==1)
set_BEEP();
else
clr_BEEP();
}
 
//Tonausgabe ***********************************************************************************************
 
if (sound_timer > 0) // Ton spielen
{
sound_timer --;
}
 
else
{
// TIMSK2 &= ~_BV(TOIE2); // Interrupt sperren, verhindert Störgeräusche
// TCCR2A = 0x00; //stop
generate=0; // Sound aus
tone_handler();
if (soundpause_timer > 0)
{
soundpause_timer --; // Ton pause
}
}
 
//***********************************************************************************************
//--------------------------------------------------------------
if ((key_state & LONG_MASK) == 0) // check long key function
k_time_l = REPEAT_START; // start delay
 
if (--k_time_l == 0) // long countdown
key_long |= (key_state & LONG_MASK);
 
//--------------------------------------------------------------
if ((key_state & REPEAT_MASK) == 0) // check repeat function
k_time_r = 1; // kein delay
 
if (--k_time_r == 0)
{
k_time_r = REPEAT_NEXT; // repeat delay
key_rpt |= (key_state & REPEAT_MASK);
}
 
//--------------------------------------------------------------
if ((key_state & LONG_REPEAT_MASK) == 0) // check repeat function
k_time_lr = REPEAT_START; // start delay
 
if (--k_time_lr == 0)
{
k_time_lr = REPEAT_NEXT; // repeat delay
key_lrpt |= (key_state & LONG_REPEAT_MASK);
}
 
//--------------------------------------------------------------
if ((key_state & LONG_REPEAT_SP_MASK) == 0) // check repeatX function
k_time_rs = REPEAT_START; // start delay
 
if (--k_time_rs == 0) // repeat countdown
{
if (repeat_speed == 1)
{
k_time_rs = REPEAT_SPEED_1;
key_rpts |= (key_state & LONG_REPEAT_SP_MASK);
}
else if (repeat_speed == 2)
{
k_time_rs = REPEAT_SPEED_2;
key_rpts |= (key_state & LONG_REPEAT_SP_MASK);
}
else if (repeat_speed == 3)
{
k_time_rs = REPEAT_SPEED_3;
key_rpts |= (key_state & LONG_REPEAT_SP_MASK);
}
}
 
if (timer > 0)
timer --;
 
if (timer2 > 0)
timer2 --;
 
if (abo_timer > 0)
abo_timer --;
 
//24.8.2012
// if (receiveNMEA==true)
// {
// if (bt_receiveNMEA()) Tracking_NMEA();
// else receiveNMEA = false;
//
// }
 
}
 
 
#ifdef HWVERSION3_9
 
void LipoCheck (void) // Lowbatpin des Spannungswandlers prüfen
// LBO des LT1308 wechselt zum Ende der Batterielaufzeit häufig seinen Zustand in der Übergangsphase zum LowBat
// Die Akkuspannung schwankt auch abhängig vom momentanen Stromverbrauch
{
if (WarnToggle == 1) // Beim ersten Auftreten Warnung ausgeben, Rythmus 5/10 Sekunden
{
 
set_beep ( 1000, 0x0020, BeepNormal);
lcd_printp_at (0, 0, PSTR(" LIPO !!Warnung!! "), 2);
}
 
if (WarnToggle == WarnTime * 100)
WarnToggle = 0; // erstmal bis hier warnen
 
if (WarnToggle > 0)
WarnToggle++; // weiter hochzählen
 
if (PINC & (1 << LowBat)) // Kurzzeitige Unterspannung bearbeiten und Warnung ausgeben
{
WarnCount = 0;
// if (WarnCount > 0)
// WarnCount--; // Bei LIPO OK erstmal runterzählen, LT1308 überlegt sich noch genauer ob nun ok oder nicht
}
 
if (!(PINC & (1 << LowBat)) ) // LT1308 hat Unterspannung erkannt
{
WarnCount++; // solange LBO low ist Zähler hochzählen
if (WarnCount == 10 && WarnToggle == 0) // mit "10" etwas unempfindlicher gegen kurze Impulse machen
WarnToggle = 1; // Warnhinweis starten
}
 
if ((WarnCount) == PoffTime * 100)
clr_V_On(); // Spannung abschalten
}
 
#endif
 
 
 
 
//--------------------------------------------------------------
unsigned int SetDelay (unsigned int t)
{
return(CountMilliseconds + t + 1);
}
 
 
//--------------------------------------------------------------
char CheckDelay(unsigned int t)
{
return(((t - CountMilliseconds) & 0x8000) >> 9);
}
 
 
//--------------------------------------------------------------
void Delay_ms(unsigned int w)
{
unsigned int akt;
akt = SetDelay(w);
while (!CheckDelay(akt));
}
 
 
//--------------------------------------------------------------
//
uint8_t get_key_press (uint8_t key_mask)
{
uint8_t sreg = SREG;
 
// disable all interrupts
cli();
 
key_mask &= key_press; // read key(s)
key_press ^= key_mask; // clear key(s)
 
SREG = sreg; // restore status register
 
return key_mask;
}
 
 
//--------------------------------------------------------------
//
uint8_t get_key_short (uint8_t key_mask)
{
uint8_t ret;
uint8_t sreg = SREG;
 
// disable all interrupts
cli();
 
ret = get_key_press (~key_state & key_mask);
 
SREG = sreg; // restore status register
 
return ret;
}
 
 
//--------------------------------------------------------------
//
uint8_t get_key_long (uint8_t key_mask)
{
uint8_t sreg = SREG;
 
// disable all interrupts
cli();
 
key_mask &= key_long; // read key(s)
key_long ^= key_mask; // clear key(s)
 
SREG = sreg; // restore status register
 
return get_key_press (get_key_rpt (key_mask));
}
 
 
//--------------------------------------------------------------
//
uint8_t get_key_rpt (uint8_t key_mask)
{
uint8_t sreg = SREG;
 
// disable all interrupts
cli();
 
key_mask &= key_rpt; // read key(s)
key_rpt ^= key_mask; // clear key(s)
 
SREG = sreg; // restore status register
 
return key_mask;
}
 
 
//--------------------------------------------------------------
//
uint8_t get_key_long_rpt (uint8_t key_mask)
{
uint8_t sreg = SREG;
 
// disable all interrupts
cli();
 
key_mask &= key_lrpt; // read key(s)
key_lrpt ^= key_mask; // clear key(s)
 
SREG = sreg; // restore status register
 
return get_key_rpt (~key_press^key_mask);
}
 
 
//--------------------------------------------------------------
//
uint8_t get_key_long_rpt_sp (uint8_t key_mask, uint8_t key_speed)
{
uint8_t sreg = SREG;
 
// disable all interrupts
cli();
 
key_mask &= key_rpts; // read key(s)
key_rpts ^= key_mask; // clear key(s)
 
repeat_speed = key_speed;
 
SREG = sreg; // restore status register
 
return key_mask;
}
 
void set_beep ( uint16_t Time, uint16_t Muster, uint8_t Prio)
{
if (Config.HWBeeper==1)
{
if (Prio == BeepNormal)
{
if (BeepPrio == BeepNormal) // nur setzen wenn keine hohe Prio schon aktiv ist
{
BeepTime = Time;
BeepMuster = Muster;
}
}
 
if (Prio == BeepSevere)
{
if (!BeepPrio == BeepSevere)
{
BeepPrio = BeepSevere; // hohe Prio setzen
BeepTime = Time;
BeepMuster = Muster;
}
}
 
if (Prio == BeepOff)
{
BeepPrio = BeepNormal; // Beep hohe Prio aus
BeepTime = 0;
BeepMuster = 0;
}
}
else
{
 
if (Prio == BeepNormal)
{
if (BeepPrio == BeepNormal) // nur setzen wenn keine hohe Prio schon aktiv ist
{
playTone(900,Time/10,0);
}
}
 
if (Prio == BeepSevere)
{
if (!BeepPrio == BeepSevere)
{
playTone(1200,Time/10,0);
playTone(1100,Time/10,0);
}
}
 
if (Prio == BeepOff)
{
playTone(0,0,0);
}
 
}
 
 
 
 
}
 
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/timer/timer.h
0,0 → 1,96
/*****************************************************************************
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de *
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* based on the key handling by Peter Dannegger *
* see www.mikrocontroller.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*
*****************************************************************************/
 
#ifndef _TIMER_H
#define _TIMER_H
 
#include "../cpu.h"
#include "../main.h"
 
#define KEY_ALL ((1 << KEY_PLUS) | (1 << KEY_MINUS) | (1 << KEY_ENTER) | (1 << KEY_ESC))
#define LONG_MASK ((1 << KEY_PLUS) | (1 << KEY_MINUS) | (1 << KEY_ENTER) | (1 << KEY_ESC))
#define REPEAT_MASK ((1 << KEY_PLUS) | (1 << KEY_MINUS) | (1 << KEY_ENTER) | (1 << KEY_ESC))
#define LONG_REPEAT_MASK ((1 << KEY_PLUS) | (1 << KEY_MINUS) | (1 << KEY_ENTER) | (1 << KEY_ESC))
#define LONG_REPEAT_SP_MASK ((1 << KEY_PLUS) | (1 << KEY_MINUS) | (1 << KEY_ENTER) | (1 << KEY_ESC))
 
#define REPEAT_START 70 // after 700ms
#define REPEAT_NEXT 15 // every 150ms
#define REPEAT_SPEED_1 20 // every 200ms
#define REPEAT_SPEED_2 8 // every 80ms
#define REPEAT_SPEED_3 1 // every 10ms
 
#define BeepNormal 0 // Normal Beep
#define BeepSevere 1 // schwerer Fehler, Beep nicht unterbrechbar
#define BeepOff 2 // Beep aus
 
#define ABO_TIMEOUT 300 // 3 sec
extern volatile uint8_t Display_on;
extern volatile uint16_t IdleTimer;
 
extern volatile uint16_t timer;
extern volatile uint16_t timer2;
extern volatile uint16_t abo_timer;
extern volatile uint16_t sound_timer;
extern volatile uint16_t soundpause_timer;
//extern volatile uint16_t WarnCount;
 
 
 
 
//extern volatile unsigned int BeepTime;
extern unsigned int BeepTime;
extern unsigned int BeepMuster;
 
void Timer0_Init (void); // Systeminterrupt
void Timer1_Init (void); // Servotester
void Timer2_Init (void); // Displayhelligkeit
void Timer3_Init (void); // Überwachung
uint8_t get_key_press (uint8_t key_mask); // sofort beim drücken
uint8_t get_key_short (uint8_t key_mask); // erst beim loslassen
uint8_t get_key_long (uint8_t key_mask); // verzögert
uint8_t get_key_rpt (uint8_t key_mask); // mit verzögerung
uint8_t get_key_long_rpt (uint8_t key_mask); //
uint8_t get_key_long_rpt_sp (uint8_t key_mask, uint8_t key_speed); // mit verzögerung und 3 versch. geschw.
void set_beep ( uint16_t Time, uint16_t Muster, uint8_t Prio);
extern volatile unsigned int CountMilliseconds;
 
 
void Delay_ms(unsigned int);
unsigned int SetDelay (unsigned int t);
char CheckDelay (unsigned int t);
void LipoCheck (void); // Lowbatpin des Spannungswandlers prüfen
 
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/tracking/.directory
0,0 → 1,3
[Dolphin]
Timestamp=2013,1,9,0,38,51
ViewMode=1
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/tracking/filedetails.pdf
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/tracking/mymath.c
0,0 → 1,187
/****************************************************************/
/* */
/* NG-Video 5,8GHz */
/* */
/* Copyright (C) 2011 - gebad */
/* */
/* This code is distributed under the GNU Public License */
/* which can be found at http://www.gnu.org/licenses/gpl.txt */
/* */
/****************************************************************/
 
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <avr/pgmspace.h>
 
#include "mymath.h"
 
// http://www.mikrocontroller.net/articles/AVR_Arithmetik#avr-gcc_Implementierung_.2832_Bit.29
unsigned int sqrt32(uint32_t q)
{ uint16_t r, mask;
uint16_t i = 8*sizeof (r) -1;
r = mask = 1 << i;
for (; i > 0; i--) {
mask >>= 1;
if (q < (uint32_t) r*r)
r -= mask;
else
r += mask;
}
if (q < (uint32_t) r*r)
r -= 1;
return r;
}
 
// aus Orginal MK source code
// sinus with argument in degree at an angular resolution of 1 degree and a discretisation of 13 bit.
const uint16_t sinlookup[91] = {0, 143, 286, 429, 571, 714, 856, 998, 1140, 1282, 1423, 1563, 1703, \
1843, 1982, 2120, 2258, 2395, 2531, 2667, 2802, 2936, 3069, 3201, 3332, \
3462, 3591, 3719, 3846, 3972, 4096, 4219, 4341, 4462, 4581, 4699, 4815, \
4930, 5043, 5155, 5266, 5374, 5482, 5587, 5691, 5793, 5893, 5991, 6088, \
6183, 6275, 6366, 6455, 6542, 6627, 6710, 6791, 6870, 6947, 7022, 7094, \
7165, 7233, 7299, 7363, 7424, 7484, 7541, 7595, 7648, 7698, 7746, 7791, \
7834, 7875, 7913, 7949, 7982, 8013, 8041, 8068, 8091, 8112, 8131, 8147, \
8161, 8172, 8181, 8187, 8191, 8192};
 
//double c_cos_8192(int16_t angle)
int16_t c_cos_8192(int16_t angle)
{
int8_t m,n;
int16_t sinus;
 
angle = 90 - angle;
// avoid negative angles
if (angle < 0)
{
m = -1;
angle = -angle;
}
else m = +1;
 
// fold angle to interval 0 to 359
angle %= 360;
 
// check quadrant
if (angle <= 90) n = 1; // first quadrant
else if ((angle > 90) && (angle <= 180)) {angle = 180 - angle; n = 1;} // second quadrant
else if ((angle > 180) && (angle <= 270)) {angle = angle - 180; n = -1;} // third quadrant
else {angle = 360 - angle; n = -1;} //fourth quadrant
// get lookup value
sinus = sinlookup[angle];
// calculate sinus value
return (sinus * m * n);
}
 
/* ----------------------------------------------------------------------------------------------
 
atan2.S
 
Author: Reiner Patommel
atan2.S uses CORDIC, an algorithm which was developed in 1956 by Jack Volder.
CORDIC can be used to calculate trigonometric, hyperbolic and linear
functions and is until today implemented in most pocket calculators.
The algorithm makes only use of simple integer arithmetic.
 
The CORDIC equations in vectoring mode for trigonometric functions are:
Xi+1 = Xi - Si * (Yi * 1 / 2^i)
Yi+1 = Yi + Si * (Xi * 1 / 2^i)
Zi+1 = Zi - Si * atan(1 / 2^i)
where Si = +1 if Yi < 0 else Si = -1
The rotation angles are limited to -PI/2 and PI/2 i.e.
-90 degrees ... +90 degrees
 
For the calculation of atan2(x,y) we need a small pre-calculated table of
angles or radians with the values Tn = atan(1/2^i).
We rotate the vector(Xo,Yo) in steps to the x-axis i.e. we drive Y to 0 and
accumulate the rotated angles or radians in Z. The direction of the rotation
will be positive or negative depending on the sign of Y after the previous
rotation and the rotation angle will decrease from step to step. (The first
step is 45 degrees, the last step is 0.002036 degrees for n = 15).
 
After n rotations the variables will have the following values:
Yn = ideally 0
Xn = c*sqrt(Xo^2+Yo^2) (magnitude of the vector)
Zn = Zo+atan(Yo/Xo) (accumulated rotation angles or radians)
 
c, the cordic gain, is the product Pn of sqrt(1+2^(-2i)) and amounts to
approx. 1.64676 for n = 15.
 
In order to represent X, Y and Z as integers we introduce a scaling factor Q
which is chosen as follows:
1. We normalize Xo and Yo (starting values) to be less than or equal to 1*Q and
set Zo = 0 i.e. Xomax = 1*Q, Yomax = 1*Q, Zo = 0.
2. With Xo = 1*Q and Yo = 1*Q, Xn will be Xnmax = Q*c*sqrt(2) = 2.329*Q
3. In order to boost accuracy we only cover the rotation angles between 0 and PI/2
i.e. X and Z are always > 0 and therefore can be unsigned.
(We do the quadrant correction afterwards based on the initial signs of x and y)
4. If X is an unsigned int, Xnmax = 65536, and Q = 65536/2.329 = 28140.
i.e.
Xnmax = 65536 --> unsigned int
Ynmax = +/- 28140 --> signed int
Znmax = PI/2 * 28140 = 44202 --> unsigned int
The systematic error is 90/44202 = 0.002036 degrees or 0.0000355 rad.
Below is atan2 and atan in C: */
 
#define getAtanVal(x) (uint16_t)pgm_read_word(&atantab[x])
 
uint16_t atantab[T] PROGMEM = {22101,13047,6894,3499,1756,879,440,220,110,55,27,14,7,3,2,1};
 
int16_t my_atan2(int32_t y, int32_t x)
{ unsigned char i;
uint32_t xQ;
int32_t yQ;
uint32_t angle = 0;
uint32_t tmp;
double x1, y1;
 
x1 = abs(x);
y1 = abs(y);
 
if (y1 == 0) {
if (x < 0)
return (180);
else
return 0;
}
if (x1 < y1) {
x1 /= y1;
y1 = 1;
}
else {
y1 /= x1;
x1 = 1;
}
xQ = SCALED(x1);
yQ = SCALED(y1);
 
for (i = 0; i < T-1; i++) {
tmp = xQ >> i;
if (yQ < 0) {
xQ -= yQ >> i;
yQ += tmp;
angle -= getAtanVal(i);
}
else {
xQ += yQ >> i;
yQ -= tmp;
angle += getAtanVal(i);
}
}
 
angle = RAD_TO_DEG * angle/Q;
if (x <= 0)
angle = 180 - angle;
if (y <= 0)
return(-angle);
return(angle);
}
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/tracking/mymath.h
0,0 → 1,15
#ifndef _MYMATH_H_
#define _MYMATH_H_
 
#include <avr/io.h>
 
#define T 16
#define Q 28140
#define SCALED(X) ((int32_t)((X) * Q))
#define RAD_TO_DEG 57.2957795 // radians to degrees = 180 / PI
 
uint16_t sqrt32(uint32_t qzahl);
int16_t c_cos_8192(int16_t angle);
int16_t my_atan2(int32_t y, int32_t x);
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/uart/.directory
0,0 → 1,3
[Dolphin]
Timestamp=2013,2,17,15,38,3
ViewMode=1
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/wi232/Text File
0,0 → 1,177
// wi232.c:
//
// Call fopen_wi232() to set up the wi232 as an input output data stream.
// If fopen_wi232() is the first fopen command called, then the wi232
// becomes stdin and stdout and stderr.
// The
//
// Uses Interupts to handle data streaming. The wi232 uses USART0, which uses:
// Rx = PORTE0 = pin 2
// Tx = PORTE1 = pin 3
// CTS = PORTE2 = pin 4
#include <inttypes.h>
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
 
#include "wi232.h"
#include "circularqueue.h"
#include "usart.h"
 
const int _baud_rate_c = 38400;
const int _tx_buffer_size_c = 256;
const int _rx_buffer_size_c = 256;
const uint8_t _cts_pin_c = _BV( PINE2 );
 
volatile char wi232_tx_buffer[ _tx_buffer_size_c ];
volatile char wi232_rx_buffer[ _rx_buffer_size_c ];
 
// circular queues used for the USART
CircularQueue< volatile char > wi232_tx_q( wi232_tx_buffer, _tx_buffer_size_c );
CircularQueue< volatile char > wi232_rx_q( wi232_rx_buffer, _rx_buffer_size_c );
 
// prototype
int wi232_putchar( char );
int wi232_getchar();
void initialize_baud_rate();
void command( bool enable );
void write_register( uint8_t reg, uint8_t value );
bool _cts();
 
// use BAUD_RATE baud 8N1 RX & TX on USART0
// to transmit to the wi232
FILE* fopen_wi232()
{
// enable Rx, Tx & Rx interupt
// (Tx buffer empty interupt is enabled when we actually send something)
UCSR0B = _BV( RXEN0 ) |
_BV( TXEN0 ) |
_BV( RXCIE0 );
// UCSC00 = 1 & UCSC01 = 1 -> 8-bit data
UCSR0C = _BV( UCSZ00 ) | _BV( UCSZ01 );
initialize_baud_rate();
wi232_tx_q.clear();
wi232_rx_q.clear();
 
// set wi232_putchar as the stdout stream character Tx-er
// set wi232_getchar as the stdin stream chacacter Rx-er
return fdevopen( wi232_putchar, wi232_getchar, 0 );
}
 
inline void initialize_baud_rate()
{
// enable command pin as output
DDRE |= _BV( PORTE3 );
command( true );
usart0_set_baud_rate( 2400 );
sei();
write_register( 78, 3 ); // set baud rate to 38400
wait(100);
cli();
usart0_set_baud_rate( 38400 );
command( false );
}
 
inline void command( bool enable )
{
if ( enable )
PORTE &= ~_BV( PORTE3 );
else
PORTE |= _BV( PORTE3 );
}
 
inline void write_register( uint8_t reg, uint8_t value )
{
if ( value < 0x80 )
{
// data = [ 0xFF, 2, reg, value ]
wi232_putchar( 0xFF );
wi232_putchar( 2 );
wi232_putchar( reg );
wi232_putchar( value );
}
else // value >= 0x80
{
// data = [ 0xFF, 3, reg, 0xFE, (value - 0x80) ]
wi232_putchar( 0xFF );
wi232_putchar( 3 );
wi232_putchar( reg );
wi232_putchar( 0xFE );
wi232_putchar( value - 0x80 );
}
}
 
int wi232_putchar( char x )
{
wi232_tx_q.put( x );
// enable the "data register empty" interupt
// (it may already be enabled in which case no harm is done)
UCSR0B |= _BV( UDRIE0 );
 
// return -1 if overflow is true, otherwise return 0
// return wi232_tx_q.overflow() ? -1 : 0;
return 0; // for now, screw overflow - just ignore it
}
 
int wi232_getchar()
{
// wait until the queue is no longer empty
while ( wi232_rx_q.is_empty() );
 
char x = wi232_rx_q.get();
return x;
}
 
uint16_t wi232_data_available()
{
return wi232_rx_q.length();
}
 
bool wi232_is_empty()
{
return wi232_rx_q.is_empty();
}
 
// returns true when CTS is low,
// i.e. it is true when it is okay to send data
inline bool _cts()
{
return !(PINE & _cts_pin_c);
}
 
// we received some data on USART0
// put this data into the received data queue
SIGNAL( SIG_UART0_RECV )
{
wi232_rx_q.put( UDR0 );
}
 
// the USART is ready to queue another byte to send
SIGNAL( SIG_UART0_DATA )
{
if ( !wi232_tx_q.is_empty() )
{
if ( !_cts() )
{
sei();
// wait until CTS is true
while ( !_cts() );
}
 
// if the queue is not empty, put the next character in the buffer
// this also resets the interupt flag automatically
UDR0 = wi232_tx_q.get();
}
else
{
// disable the interupt
UCSR0B &= ~_BV( UDRIE0 );
}
}
 
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/wi232/Wi232.c
0,0 → 1,621
/*****************************************************************************
* 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/pgmspace.h>
#include <util/delay.h>
#include <stdlib.h>
#include <string.h>
#include "../lcd/lcd.h"
#include "../uart/usart.h"
#include "../uart/uart1.h"
#include "../main.h"
#include "../wi232/Wi232.h"
#include "../timer/timer.h"
#include "../eeprom/eeprom.h"
#include "../setup/setup.h"
 
 
 
 
 
#if defined HWVERSION1_3W || defined HWVERSION3_9 || defined HWVERSION1_2W
 
uint8_t Wi232_hardware = 0;
uint8_t InitErr=0;
uint8_t Wi232_Baudrate = 0; //Merkzelle für aktuelle Baudrate
uint8_t Wi232_New_Baudrate = 0; //Merkzelle für zu setzende Baudrate
 
 
uint16_t SearchWi232(uint8_t Baudrate) // Suche Wi232 mit entsprechender Baudrate
 
// Return = 0, Wi232 not found
 
{
int16_t RegisterWi232;
 
SetBaudUart0(Baudrate);
lcd_printpns_at (0, 1, PSTR(" with Baud"),0);
switch (Baudrate)
{
case Baud_2400: lcd_printpns_at (6, 1, PSTR(" 2400"),0);break;
case Baud_9600: lcd_printpns_at (6, 1, PSTR(" 9600"),0);break;
case Baud_19200: lcd_printpns_at (6, 1, PSTR(" 19200"),0);break;
case Baud_38400: lcd_printpns_at (6, 1, PSTR(" 38400"),0);break;
case Baud_57600: lcd_printpns_at (6, 1, PSTR(" 57600"),0);break;
case Baud_115200:lcd_printpns_at (6, 1, PSTR("115200"),0);break;
break;
}
 
RegisterWi232 = ReadWi232(regDiscover);
lcd_print_hex_at(0,2,RegisterWi232,0);
if (RegisterWi232 > 0 && RegisterWi232 < 0xFF)
{ Wi232_hardware = 2;
Wi232_Baudrate = Baudrate;
}
return RegisterWi232;
}
 
 
/*************************************************************************
Function: discoverWI232()
Purpose: check if Wi232 available
Returns: Version or 0 = timeout
 
**************************************************************************/
void discoverWi232(uint8_t DiscBaudrate)
 
{
 
int16_t RegisterWi232=0;
SwitchToWi232(); /* Serielle Kanäle Wi232 mit USB verbinden*/
set_WI232CMD();
_delay_ms(200);
lcd_cls();
SetBaudUart0( DiscBaudrate);
 
lcd_printpns_at (0, 0, PSTR("search Wi.232 Modul"),0);
 
{
while (RegisterWi232==0)
{
RegisterWi232=SearchWi232(DiscBaudrate); if (RegisterWi232 !=0) {Wi232_hardware = 1; continue;}
RegisterWi232=SearchWi232(Baud_2400); if (RegisterWi232 !=0) continue;
RegisterWi232=SearchWi232(Baud_9600); if (RegisterWi232 !=0) continue;
RegisterWi232=SearchWi232(Baud_19200); if (RegisterWi232 !=0) continue;
RegisterWi232=SearchWi232(Baud_38400); if (RegisterWi232 !=0) continue;
RegisterWi232=SearchWi232(Baud_57600); if (RegisterWi232 !=0) continue;
RegisterWi232=SearchWi232(Baud_115200); if (RegisterWi232 !=0) continue;
break;
}
// _delay_ms(1000);
 
}
 
if (RegisterWi232 == 0)
{
lcd_cls();
lcd_printpns_at (0, 0, PSTR("no Wi.232 found"),0);
Wi232_hardware = 0;
_delay_ms(2000);
}
 
if (RegisterWi232 == 0xFF)
{
lcd_cls();
lcd_printpns_at (0, 0, PSTR("Wi.232 Sytaxerror "),0);
set_beep ( 1000, 0x0040, BeepNormal);
_delay_ms(2000);
RegisterWi232 = 0;
}
 
if (RegisterWi232 > 0 && RegisterWi232 < 0xFF)
{
lcd_cls();
SetBaudUart0(Wi232_Baudrate);
 
if (Wi232_hardware ==1) // alles ok , Baudrate Wi232 passt
lcd_printpns_at (0, 0, PSTR("Wi.232 found "),0);
 
if (Wi232_hardware ==2) // Wi232 gefunden, aber falsche Baudrate
{
Config.WiIsSet= false; //wenn hier 2400 gefunden wurde, ist Wi232 nicht initialisiert
lcd_printpns_at (0, 0, PSTR("Wi.232 wrong Baudrate"),0);
if (WriteWi232(regNVDATARATE,Config.PKT_Baudrate)!=0) /* NV-Ram auf PKT-Baudrate setzen*/
{
lcd_printpns_at (0, 1, PSTR("Error set NV-RAM"),0);
set_beep ( 1000, 0x0040, BeepNormal);
_delay_ms(2000);
}
// else
// {
//// _delay_ms(1000);
// lcd_printpns_at (0, 1, PSTR("NV-RAM is set to "),0);
// lcd_printpns_at (0, 2, PSTR("given Baudrate"),0);
// _delay_ms(2000);
// }
 
if (WriteWi232(regDATARATE,Config.PKT_Baudrate)!=0) /* Ram auf PKT_Baudrate setzen*/
{
lcd_printpns_at (0, 3, PSTR("Error set RAM "),0);
set_beep ( 1000, 0x0040, BeepNormal);
_delay_ms(2000);
}
// else
// {
//// _delay_ms(1000);
// lcd_printpns_at (0, 1, PSTR("RAM is set to "),0);
// lcd_printpns_at (0, 2, PSTR("given Baudrate"),0);
// _delay_ms(2000);
// }
 
SetBaudUart0(Config.PKT_Baudrate);
Old_Baudrate = Config.PKT_Baudrate;
 
}
lcd_cls_line (0,1,21);
lcd_printpns_at (0, 1, PSTR("Version:"),0);
lcd_print_hex_at(9,1,RegisterWi232,0);
}
clr_WI232CMD();
}
 
 
/*************************************************************************
Function: InitWI232()
Purpose: set Wi232Register for Mikrokopter
Returns: 0 = ACK, FF = NAK
 
**************************************************************************/
void InitWi232(uint8_t InitBaudrate)
{
 
uint8_t i = 0;
#ifdef HWVERSION3_9
Change_Output(Uart02Wi); // Verbindung zu Wi232 herstellen
#endif
 
discoverWi232(Old_Baudrate); // Check if Wi232 available
 
if (Wi232_hardware != 0)
{
lcd_printpns_at (0, 2, PSTR("Init Wi232 wait...."),0);
set_WI232CMD();
_delay_ms(200);
SwitchToWi232(); /* Serielle Kanäle Wi232 mit USB verbinden*/
if (WriteWi232(regNETGRP,126)!=0) /*damit Wi232 nix mehr vom Kopter schickt erstmal Networkgroup ins Nirwana setzen */
lcd_printpns_at (i++,4,PSTR("."),0);
// InitErr =12;
// Grund:
//If RF packets are received while the CMD line is active,
//they are still processed and presented to the module’s UART for transmission.
 
// wenn sich ein EEPROM-Wert ändert wird auch das Ram beschrieben damit die Änderung sofort wirksam wird
if (WriteWi232(regNVTXCHANNEL,Config.WiTXRXChannel)!=0)
InitErrorWi232(1); /*TX Channel*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regTXCHANNEL,Config.WiTXRXChannel)!=0)
InitErrorWi232(2);/*TX Channel*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVRXCHANNEL,Config.WiTXRXChannel)!=0)
InitErrorWi232(3);/* RX Channel*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regRXCHANNEL,Config.WiTXRXChannel)!=0)
InitErrorWi232(4);/* RX Channel*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVSLPMODE ,Sleep_Awake)!=0)
InitErrorWi232(5);/* Sleepmode*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVPWRMODE,WbModeP15)!=0)
InitErrorWi232(6);/* Transceiver Mode/Powermode */
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVTXTO,Config.WiTXTO)!=0)
InitErrorWi232(7);/* UART Timeout */
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regTXTO,Config.WiTXTO)!=0)
InitErrorWi232(8);/* UART Timeout */
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVUARTMTU,Config.WiUartMTU)!=0)
InitErrorWi232(9);/* UART Buffer*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regUARTMTU,Config.WiUartMTU)!=0)
InitErrorWi232(10);/* UART Buffer*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVNETMODE,Config.WiNetworkMode)!=0)
InitErrorWi232(11);/* Networkmode*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNETMODE,Config.WiNetworkMode)!=0)
InitErrorWi232(12);/* Networkmode*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVUSECRC ,CRC_Enable)!=0)
InitErrorWi232(13);/* CRC*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVCSMAMODE,CSMA_En)!=0)
InitErrorWi232(14);/* CSMA*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVNETGRP,Config.WiNetworkGroup)!=0)
InitErrorWi232(15);/* Networkgroup */
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNETGRP,Config.WiNetworkGroup)!=0)
InitErrorWi232(15);/* Networkgroup */
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVDATARATE,InitBaudrate)!=0)
InitErrorWi232(16);/* Baudrate*/
lcd_printpns_at (i++,4,PSTR("."),0);
_delay_ms(200);
 
if (WriteWi232(regDATARATE,InitBaudrate)!=0)
InitErrorWi232(17);/* Baudrate*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
 
clr_WI232CMD();
 
if (InitErr !=0)
{
lcd_printpns_at (0, 2, PSTR("Wi232 InitError "),0);
lcd_print_hex(InitErr,0);
set_beep ( 1000, 0x0040, BeepNormal);
_delay_ms(2000);
}
else
{
lcd_printpns_at (0, 2, PSTR("Wi232 Init ok...."),0);
WriteWiInitFlag(); // Init merken
lcd_print_hex(InitBaudrate,0);
}
SetBaudUart0(InitBaudrate);
_delay_ms(2000);
}
}
 
/*************************************************************************
Function: InitErrorWI232()
Purpose: Show Wi232 Error, Value
Returns:
**************************************************************************/
void InitErrorWi232(uint8_t Error)
{
 
lcd_printpns_at (0, 3, PSTR("Wi232 InitError "),0);
lcd_print_hex(Error,0);
InitErr=Error;
set_beep ( 500, 0x0040, BeepNormal);
_delay_ms(500);
 
}
 
 
 
 
/*************************************************************************
Function: WriteWI232()
Purpose: set Register to Wi232, Register, Value
Returns: 0 = ACK, FF = NAK
ACHTUNG nur für Value <0x80
**************************************************************************/
int16_t WriteWi232(uint8_t Wi232Register, uint8_t RegisterValue)
 
{
uint8_t timeout=10;
uint8_t tc=0;
unsigned int v;
 
if ( RegisterValue < 0x80 )
{
USART_putc(0xff);
USART_putc(0x02);
USART_putc(Wi232Register);
USART_putc(RegisterValue);
}
else // RegisterValue >= 0x80
{
USART_putc(0xff);
USART_putc(0x03);
USART_putc(Wi232Register);
USART_putc(0xfe);
USART_putc(RegisterValue - 0x80);
}
 
 
do
{
v = USART_getc(); /*ACK erwartet*/
_delay_ms(100);
tc ++;
}
while (v==0 && tc!=timeout);
 
// lcd_print_hex(v,0);
if (v != 0x06)
{
lcd_printpns_at (0, 2, PSTR("Wi.232 NAK"),0);
set_beep ( 1000, 0x0040, BeepNormal);
_delay_ms(2000);
return 0xFF;
}
 
if (v==0x06)
return 0;
 
return 0xFF;
}
 
 
/*************************************************************************
Function: ReadWI232()
Purpose: send Readcommand to Wi232,
Returns: Registervalue, 0 = timeout 0xFF = Syntaxerror
 
**************************************************************************/
int16_t ReadWi232(uint16_t Wi232Register)
 
{
uint8_t timeout=10;
uint8_t tc=0;
 
 
unsigned int v;
 
v = USART_getc(); /*Zeichen löschen*/
USART_putc(0xff);
USART_putc(0x02);
USART_putc(0xfe);
USART_putc(Wi232Register);
_delay_ms(50);
// lcd_printpns_at (0, 2, PSTR("read Wi232"),0);
 
 
do
{
v = USART_getc(); /*ACK erwartet*/
_delay_ms(100);
tc ++;
}
while (v==0 && tc!=timeout);
 
if (tc == timeout)
return 0; /* Timeout*/
 
if (v != 0x06)
return 0xFF; /* Syntaxerror*/
 
// lcd_print_hex(v,0);
// v = USART_getc(); /*Register*/
// lcd_print_hex(v,0);
// v = USART_getc(); /*Value*/
// lcd_print_hex(v,0);
 
return v;
 
}
 
 
 
///*************************************************************************
//Function: EscapeString()
//Purpose:
//Returns:
//Quelle: Radiotronix Wi.232 Manual
//**************************************************************************/
//
//
//int EscapeString(char *src, char src_len, char *dest)
//{
// // The following function copies and encodes the first
// // src_len characters from *src into *dest. This
// // encoding is necessary for Wi.232 command formats.
// // The resulting string is null terminated. The size
// // of this string is the function return value.
// // ---------------------------------------------------
// uint8_t src_idx, dest_idx;
// // Save space for the command header and size bytes
// // ------------------------------------------------
// dest_idx = 2;
// // Loop through source string and copy/encode
// // ------------------------------------------
// for (src_idx = 0; src_idx < src_len; src_idx++)
// {
// if (src[src_idx] > 127)
// {
// dest[dest_idx++] = 0xFE;
// }
// dest[dest_idx++] = (src[src_idx] & 0x7F);
// }
// // Add null terminator
// // -------------------
// dest[dest_idx] = 0;
// // Add command header
// // ------------------
// dest[0] = 0xFF;
// dest[1] = dest_idx-2;
//
// // Return escape string size
// // -------------------------
// return dest_idx;
//}
 
 
//#if defined HWVERSION1_3W || defined HWVERSION3_9
///*************************************************************************
//Function: Wi232USB()
//Purpose: Connect Wi232 Programmmode to PKT USB,
//Returns:
//
//**************************************************************************/
//void Wi232_USB(void)
//
//
//{
// unsigned int c0,c1;
//
// if (Wi232_hardware==1)
// {
//// USART_Init (UART_BAUD_SELECT(57600,F_CPU));
//// uart1_init( UART_BAUD_SELECT(57600,F_CPU) );
//// USART_Init (UART_BAUD_SELECT(2400,F_CPU));
//// uart1_init( UART_BAUD_SELECT(2400,F_CPU) );
// }
//
// if (Wi232_hardware==2)
// {
// USART_Init (UART_BAUD_SELECT(2400,F_CPU));
// uart1_init( UART_BAUD_SELECT(2400,F_CPU) );
// }
//
// lcd_cls ();
//// SwitchToWi232(); /* Serielle Kanäle Wi232 mit USB verbinden*/
//
// set_WI232CMD();
//
// lcd_printpns_at (0, 0, PSTR("Wi.232 Konfiguration "),0);
// lcd_printpns_at (0, 1, PSTR("PC mit USB verbinden"),0);
// lcd_printpns_at (0, 2, PSTR("Wi.232"),0);
// lcd_printpns_at (0, 3, PSTR("Programm starten"),0);
// lcd_printpns_at (17, 7, PSTR("Exit"),0);
//
// c1 = 0;
//
// for(;;)
// {
// c0 = uart1_getc(); /* from USB*/
// if ( c0 & UART_NO_DATA )
// {
// c1 = USART_getc();
//
// if (c1 == 0)
// {}
// else
// {
//// lcd_print_hex(c1,0);
// uart1_putc (c1); /*to USB*/;
// }
// }
// else
// {
// USART_putc(c0 ); /* to Wi232*/
//// lcd_print_hex(c0,0);
//// _delay_ms(1);
// }
//
// if ((get_key_press (1 << KEY_ENTER)))
// {
// clr_WI232CMD();
//// uart1_init( UART_BAUD_SELECT(57600,F_CPU) );
//// USART_Init( UART_BAUD_SELECT(57600,F_CPU) );
//// SwitchToFC();
// return;
// }
//
// }
//}
///*************************************************************************
//Function: Wi232_FC()
//Purpose: Connect Wi232 to PKT USB, Transparent
//Returns:
//
//**************************************************************************/
//void Wi232_FC(void)
//
//
//{
// unsigned int c0,c1;
//
//
//// USART_Init (UART_BAUD_SELECT(PKT_Baudrate,F_CPU));
//// uart1_init( UART_BAUD_SELECT(PKT_Baudrate,F_CPU) );
// SetBaudUart0(Config.PKT_Baudrate);
// SetBaudUart1(Config.PKT_Baudrate);
//
//
// lcd_cls ();
//// SwitchToWi232(); /* Serielle Kanäle Wi232 mit USB verbinden*/
//
//
// lcd_printpns_at (0, 0, PSTR("Wi.232 to FC "),0);
// lcd_printpns_at (0, 1, PSTR("PC mit USB verbinden"),0);
// lcd_printpns_at (0, 2, PSTR("und Mikrokoptertool"),0);
// lcd_printpns_at (0, 3, PSTR("starten"),0);
// lcd_printpns_at (17, 7, PSTR("Exit"),0);
//
// c1 = 0;
//
// for(;;)
// {
// c0 = uart1_getc(); /* from USB*/
// if ( c0 & UART_NO_DATA )
// {
// c1 = USART_getc();
// if (c1 == 0)
// {}
// else
// {
//// lcd_print_hex(c1,0);
// uart1_putc (c1); /*to USB*/;
//
// }
// }
// else
// {
// USART_putc(c0 ); /* to Wi232*/
//// lcd_print_hex(c0,0);
//// _delay_ms(1);
// }
//
// if ((get_key_press (1 << KEY_ENTER)))
// {
// return;
// }
// }
//}
 
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/wi232/Wi232.h
0,0 → 1,178
/*****************************************************************************
* 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*
*****************************************************************************/
 
#ifndef WI232_H_
#define WI232_H_
 
 
void discoverWi232(uint8_t Baudrate);
void InitWi232(uint8_t Baudrate);
int16_t WriteWi232(uint8_t Wi232Register, uint8_t RegisterValue);
int16_t ReadWi232(uint16_t Wi232Register);
void InitErrorWi232(uint8_t Error);
extern uint8_t Wi232_hardware;
extern uint8_t Wi232_New_Baudrate; //Merkzelle für zu setzende Baudrate
 
 
// Non-volatile Registers
// Name Address Description Default
#define regNVTXCHANNEL 0x00 // Transmit channel setting ## 0 ##
#define regNVRXCHANNEL 0x01 // Receive channel setting ## 0 ##
#define regNVPWRMODE 0x02 // Operating mode settings ## +13 dBm widebandmode ##
#define regNVDATARATE 0x03 // UART data rate ## 2400bps ##
#define regNVNETMODE 0x04 // Network mode (Normal/Slave) ## Normal ##
#define regNVTXTO 0x05 // Transmit wait timeout ## ~16ms ##
#define regNVNETGRP 0x06 // Network group ID ## 0x00 ##
#define regNVUSECRC 0x08 // Enable/Disable CRC ## Enabled ##
#define regNVUARTMTU 0x09 // Minimum transmission unit. ## 64 bytes ##
#define regNVSHOWVER 0x0A // Enable/Disable start-up message ## Enabled ##
#define regNVCSMAMODE 0x0B // Enable/Disable CSMA ## Enabled ##
#define regNVSLPMODE 0x0D // Power state of module ## Awake ##
#define regNVACKONWAKE 0x0E // Send ACK character to host on wake
 
 
// Non-volatile Read Only Registers
// Name Address Description
#define regMAC0 0x22 // These registers form the unique 48-bit MAC address.
#define regMAC1 0x23 // MAC
#define regMAC2 0x24 // MAC
#define regOUI0 0x25 // MAC
#define regOUI1 0x26 // MAC
#define regOUI2 0x27 // MAC
 
#define regDiscover 0x78 // Versionsregister
 
 
// Volatile Read/Write Registers
// Name Address Description
#define regTXCHANNEL 0x4B // Transmit channel setting
#define regRXCHANNEL 0x4C // Receive channel setting
#define regPWRMODE 0x4D // Operating mode settings
#define regDATARATE 0x4E // UART data rate
#define regNETMODE 0x4F // Network mode (Normal or Slave)
#define regTXTO 0x50 // Transmit wait timeout
#define regNETGRP 0x51 // Network group ID
#define regUSECRC 0x53 // Enable/Disable CRC
#define regUARTMTU 0x54 // Minimum transmission unit.
#define regSHOWVER 0x55 // Enable/Disable start-up message
#define regCSMAMODE 0x56 // Enable/disable CSMA
#define regSLPMODE 0x58 // Power state of module
#define regACKONWAKE 0x59 // Send ACK character to host on wake
 
 
// Wideband Channels
// regNVTXCHAN (0x00) regTXCHAN (0x4B)
// Channel Number Frequency
#define wChan0 0x00 // 868.300 MHz
#define wChan1 0x01 // 868.95 MHz ## MK ##
 
// Narrowband Channels
// regNVRXCHAN (0x01) regRXCHAN (0x4C)
// Channel Number Frequency
#define nChan0 0x00 // 868.225 MHz
#define nChan1 0x01 // 868.375 MHz ## MK ##
#define nChan2 0x02 // 868.850 MHz
#define nChan3 0x03 // 869.050 MHz
#define nChan4 0x04 // 869.525 MHz
#define nChan5 0x05 // 869.850 MHz
 
// Power Mode
// regNVPWRMODE (0x02) regPWRMODE (0x4D)
// PM1 PM1 PM0 Mode
#define NbModeN0 0x00 // 0 0 0 Narrowband Mode 0dBm power setting (typical)
#define WbModeP5 0x01 // 0 0 1 Wideband Mode +5dBm power setting (typical)
#define WbModeP10 0x02 // 0 1 0 Wideband Mode +10dBm power setting (typical)
#define WbModeP15 0x03 // 0 1 1 Wideband Mode +15dBm power setting (typical) ## MK ##
#define WbModeN0 0x04 // 1 0 0 Wideband Mode 0dBm power setting (typical)
#define NbModeP5 0x05 // 1 0 1 Narrowband Mode +5dBm power setting (typical)
#define NbModeP10 0x06 // 1 1 0 Narrowband Mode +10dBm power setting (typical)
#define NbModeP15 0x07 // 1 1 1 Narrowband Mode +15dBm power setting (typical)
 
// Wi232 UART Baudrate
// regNVDATARATE (0x03) regDATARATE (0x4E)
// Baud Rate BR2 BR1 BR0
#define Wi232_2400 Baud_2400 // 0 0 0* (default 2400)
#define Wi232_9600 Baud_9600 // 0 0 1
#define Wi232_19200 Baud_19200 // 0 1 0
#define Wi232_38400 Baud_38400 // 0 1 1
#define Wi232_57600 Baud_57600 // 1 0 0 ## MK ##
#define Wi232_115200 Baud_115200 // 1 0 1
#define Wi232_10400 0x06 // 1 1 0
#define Wi232_31250 0x07 // 1 1 1
 
// NetworkMode
// regNVNETMODE (0x04) regNETMODE (0x4F)
#define NetMode_Slave 0x00 // Slavemode
#define NetMode_Normal 0x01 // Normalmode (default)
 
// Transmit Wait Timeout
// regNVTXTO (0x05) regTXTO (0x50)
#define TWaitTimeFull 0x00 // full Buffer required
#define TWaitTime16 0x10 // 16 ms Delay (default)
 
// Network Group
// regNVNETGRP (0x06) regNETGRP (0x51)
#define NetWorkGroup 66 // default = 0, valid 0-127 ## MK = 66 ##
 
// CRC Control
// regNVUSECRC (0x08) regUSECRC (0x53)
#define CRC_Disable 0x00 // no CRC check
#define CRC_Enable 0x01 // CRC check (default)
 
// UART minimum transmission unit
// regNVUARTMTU (0x09) regUARTMTU (0x54)
#define UartMTU64 64 // default=64, valid 1-144
 
// Verbose mode
// regNVSHOWVER (0x0A)
#define ShowVers_Dis 0x00 // do not show Startupmessage ## MK = 66 ##
#define ShowVers_En 0x01 // show Startupmessage (default)
 
// CSMA enable
// regNVCSMAMODE (0x0B) regCSMAMODE (0x56)
#define CSMA_Dis 0x00 // disable CSMA Carrier-sense multiple access
#define CSMA_En 0x01 // enable CSMA (default)
 
// Sleep control
// regNVSLPMODE (0x0D) regSLPMODE (0x58)
#define Sleep_Awake 0x00 // Sleepmode = Awake (default)
#define Sleep 0x01 // Sleepmode = Sleep
#define Sleep_Stby 0x02 // Sleepmode = Standby
 
// ACK on Wake
// regNVACKONWAKE (0x0D) regACKONWAKE (0x59)
#define ACKwake_Dis 0x00 // disable ACK on Wake
#define ACKwake_En 0x01 // enable ACK on Wake (default)
 
 
#endif // WI232_H_
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property