Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 1514 → Rev 1515

/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/TODO.txt
0,0 → 1,12
24.8.2011 Cebra
Waypointlisten speichern und zum MK übertragen
Menüs überarbeiten um die Varianten der Schnittstellen einfacher handhaben zu können
Touchsreen entfällt, bring keine wirklichen Vorteile, kostet nur viel Speicher
 
22.7.2011 Cebra
 
HArdwareplatine mit Stick und Schalter zum Steuern der seriellen Kanäle.
 
22.6.2011 Cebra
- erl. I2C Motortest für BL-Controller
- erl. zur Zeit sind durch einen Layoutfehler noch die Tasten vertauscht, in timer.h zu ändern
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/Wi232.c
0,0 → 1,562
/*****************************************************************************
* 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.h"
#include "usart.h"
#include "uart1.h"
#include "main.h"
#include "Wi232.h"
#include "timer.h"
#include "eeprom.h"
#if defined HWVERSION1_3W || defined HWVERSION3_9
 
uint8_t Wi232_hardware = 0;
uint8_t InitErr=0;
 
/*************************************************************************
Function: discoverWI232()
Purpose: check if Wi232 available
Returns: Version or 0 = timeout
 
**************************************************************************/
void discoverWi232(void)
 
{
int16_t RegisterWi232;
 
SwitchToWi232(); /* Serielle Kanäle Wi232 mit USB verbinden*/
set_WI232CMD();
_delay_ms(200);
 
USART_Init( UART_BAUD_SELECT(57600,F_CPU) ); /* erstmal mit 57600 versuchen*/
lcd_printpns_at (0, 0, PSTR("search Wi.232 Modul"),0);
lcd_printpns_at (0, 1, PSTR("with 57600 Baud "),0);
RegisterWi232 = ReadWi232(regDiscover);
Wi232_hardware = 1;
 
if (RegisterWi232 == 0)
{
USART_Init( UART_BAUD_SELECT(2400,F_CPU) ); /* neues Modul mit 2400 suchen*/
lcd_printpns_at (0, 1, PSTR("with 2400 Baud "),0);
RegisterWi232 = ReadWi232(regDiscover);
Wi232_hardware = 2;
}
 
if (RegisterWi232 == 0)
{
lcd_cls();
lcd_printpns_at (0, 0, PSTR("no Wi.232 found "),0);
Wi232_hardware = 0;
}
 
if (RegisterWi232 == 0xFF)
{
lcd_cls();
lcd_printpns_at (0, 0, PSTR("Wi.232 Sytaxerror "),0);
BeepTime = 1000;
BeepMuster = 0x0040;
_delay_ms(2000);
}
 
if (RegisterWi232 != 0)
{
lcd_cls();
if (Wi232_hardware ==1)
lcd_printpns_at (0, 0, PSTR("Wi.232 found 57600"),0);
 
if (Wi232_hardware ==2) // bei 2400 Baud
{
WiIsSet= false; //wenn hier 2400 gefunden wurde ist Wi232 nicht initialisiert
lcd_printpns_at (0, 0, PSTR("Wi.232 found 2400"),0);
if (WriteWi232(regNVDATARATE,Wi232_57600)!=0) /* NV-Ram auf 57600 setzen*/
{
lcd_printpns_at (0, 1, PSTR("Error set NV-RAM"),0);
BeepTime = 1000;
BeepMuster = 0x0040;
_delay_ms(2000);
}
else
{
_delay_ms(1000);
lcd_printpns_at (0, 1, PSTR("NV-RAM set to 57600"),0);
lcd_printpns_at (0, 2, PSTR("ok "),0);
_delay_ms(2000);
}
 
if (WriteWi232(regDATARATE,Wi232_57600)!=0) /* Ram auf 57600 setzen*/
{
lcd_printpns_at (0, 3, PSTR("Error set RAM "),0);
BeepTime = 1000;
BeepMuster = 0x0040;
_delay_ms(2000);
}
else
{
_delay_ms(1000);
lcd_printpns_at (0, 1, PSTR("RAM set to 57600 "),0);
lcd_printpns_at (0, 2, PSTR("ok "),0);
_delay_ms(2000);
}
USART_Init( UART_BAUD_SELECT(57600,F_CPU) );
}
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(void)
{
 
uint8_t i = 0;
 
Change_Output(Uart02Wi); // Verbindung zu Wi232 herstellen
 
discoverWi232(); // 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*/
USART_Init( UART_BAUD_SELECT(57600,F_CPU) ); /* erstmal mit 57600 versuchen*/
 
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,WiTXRXChannel)!=0)
InitErrorWi232(1); /*TX Channel*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regTXCHANNEL,WiTXRXChannel)!=0)
InitErrorWi232(2);/*TX Channel*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVRXCHANNEL,WiTXRXChannel)!=0)
InitErrorWi232(3);/* RX Channel*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regRXCHANNEL,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,WiTXTO)!=0)
InitErrorWi232(7);/* UART Timeout */
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regTXTO,WiTXTO)!=0)
InitErrorWi232(8);/* UART Timeout */
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVUARTMTU,WiUartMTU)!=0)
InitErrorWi232(9);/* UART Buffer*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regUARTMTU,WiUartMTU)!=0)
InitErrorWi232(10);/* UART Buffer*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVNETMODE,WiNetworkMode)!=0)
InitErrorWi232(11);/* Networkmode*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNETMODE,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(regNVDATARATE,Wi232_57600)!=0)
InitErrorWi232(15);/* Baudrate*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regDATARATE,Wi232_57600)!=0)
InitErrorWi232(16);/* Baudrate*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVNETGRP,WiNetworkGroup)!=0)
InitErrorWi232(17);/* Networkgroup */
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNETGRP,WiNetworkGroup)!=0)
InitErrorWi232(18);/* Networkgroup */
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);
BeepTime = 1000;
BeepMuster = 0x0040;
_delay_ms(2000);
}
else
{
lcd_printpns_at (0, 2, PSTR("Wi232 Init ok...."),0);
WriteWiInitFlag(); // Init merken
}
USART_Init (UART_BAUD_SELECT(57600,F_CPU));
_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;
BeepTime = 500;
BeepMuster = 0x0040;
_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;
 
USART_putc(0xff);
USART_putc(0x02);
USART_putc(Wi232Register);
USART_putc(RegisterValue);
// lcd_print_hex(Wi232Register,0);
// lcd_print_hex(RegisterValue,0);
 
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);
BeepTime = 1000;
BeepMuster = 0x0040;
_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(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) );
 
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/GPL_PKT_V3_5_8b_FC086/Wi232.h
0,0 → 1,177
/*****************************************************************************
* 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(void);
void InitWi232(void);
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;
 
 
// 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 0x00 // 0 0 0* (default 2400)
#define Wi232_9600 0x01 // 0 0 1
#define Wi232_19200 0x02 // 0 1 0
#define Wi232_38400 0x03 // 0 1 1
#define Wi232_57600 0x04 // 1 0 0 ## MK ##
#define Wi232_115200 0x05 // 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
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/bluetooth.c
0,0 → 1,876
/**
* source for the Bluetooth driver
* @file bluetooth.c
* @author Linus Lotz<lotz@in.tum.de>
* @author Salomon Sickert
*/
 
 
 
#include "cpu.h"
#include <string.h>
#include <util/delay.h>
#include "bluetooth.h"
#include "main.h"
#ifdef HWVERSION3_9
#include "uart1.h"
#include "usart.h"
#include "fifo.h"
#include "error.h"
#include "lcd.h"
#include "eeprom.h"
#include "error.h"
#include "setup.h"
 
 
//#define SaveMem
 
//
// Baudrate for the UART-connection to the BTM-222 on SQUIRREL
//
 
#define SQUIRREL
 
#ifdef SQUIRREL
#define UART_BAUD_RATE 19200
#endif
 
#ifdef NUT
#define UART_BAUD_RATE 19200
#endif
 
 
typedef enum {
BT_RAW,
BT_DATA,
BT_CMD,
BT_NOECHO,
BT_NOANSWER
} communication_mode_t;
 
#define BT_CMD_TIMEOUT_MS 2000
 
typedef enum {
BT_TEST, // AT
BT_CONNECT, // ATA
BT_DISCONNECT, // ATH
BT_CLEAR_ADDRESS, // ATD0
BT_SET_ADDRESS, // ATD=_____
BT_FIND_DEVICES, // ATF?
BT_DISABLE_AUTOCONNECT, // ATO1
BT_SET_MASTER, // ATR0
BT_SET_SLAVE, // ATR1
BT_SET_PIN, // ATP=1234
BT_SET_57600, // ATL4 Baudrate 57600
BT_SET_NOANSWER, // ATQ1 Rückmeldungen aus
BT_SET_NOECHO, // ATE0 ECHO deaktivieren
BT_SET_ANSWER, // ATQ0 Rückmeldungen
BT_SET_ECHO, // ATE1 ECHO aktivieren
BT_SET_DEFAULT, // Defaultwerte setzen
BT_SET_NAME, // Devicename
BT_SET_DISPWRDOWN // disable auto Powerdown
} bt_cmd_t;
 
#ifdef SQUIRREL
#define IN_FIFO_SIZE 100
#endif
 
#ifdef NUT
#define IN_FIFO_SIZE 65
#endif
 
static uint8_t bt_buffer[IN_FIFO_SIZE];
static fifo_t in_fifo;
 
static bt_mode_t bt_mode = BLUETOOTH_SLAVE;
static communication_mode_t comm_mode = BT_CMD;
 
uint8_t i = 0;
uint8_t NoEcho = 0;
uint8_t NoAnswer = 0;
 
 
 
// Set a timeout of Y ms and a Conditon X, which have to be true while timeout
#define while_timeout(X, Y) for(uint16_t __timeout = 0; __timeout++ <= Y && (X); Delay_MS(Y ? 1 : 0))
 
//--------------------------------------------------------------
void Delay_MS(int count)
{
for (int i = 0; i < count; i++)
_delay_ms(1);
}
 
 
//--------------------------------------------------------------
static void uart_receive(void)
{
unsigned int uart_data;
 
while (!fifo_is_full(&in_fifo))
{
uart_data = uart1_getc();
 
// USART_puts(".");
 
switch (uart_data & 0xFF00) {
// Framing Error detected, i.e no stop bit detected
case UART_FRAME_ERROR:
#ifdef DEBUG
warn_pgm(PSTR("FRM ERR"));
#endif
return;
 
// Overrun, a character already presend in the UART UDR register was
// not read by the interrupt handler before the next character arrived,
// one or more received characters have been dropped
//
case UART_OVERRUN_ERROR:
#ifdef DEBUG
warn_pgm(PSTR("OVR ERR"));
#endif
return;
 
// We are not reading the receive buffer fast enough,
// one or more received character have been dropped
//
case UART_BUFFER_OVERFLOW:
#ifdef DEBUG
warn_pgm(PSTR("BUF ERR"));
#endif
return;
 
// UART Inputbuffer empty, nothing to do
case UART_NO_DATA:
return;
 
default:
{
fifo_write(&in_fifo, uart_data);
// USART_putc(uart_data);
}
}
}
#ifdef DEBUG
warn_pgm(PSTR("FIFO OVR ERR"));
#endif
}
 
 
//--------------------------------------------------------------
static void uart_send(const char *data, const uint8_t length)
{
#ifdef DEBUG
debug_pgm(PSTR("bt_uart_send"));
#endif
 
char echo;
 
lcd_printp_at (i++, 1, PSTR("."), 0);
for (uint8_t i = 0; i < length; i++)
{
 
#ifdef DEBUG
USART_putc((data[i])); //test
#endif
// debug_pgm(PSTR("bt_init_S"));
 
if (uart1_putc(data[i]) == 0)
{
#ifdef DEBUG
warn_pgm(PSTR("UART: Remote not ready"));
#endif
return;
}
 
if (comm_mode == BT_RAW)
_delay_ms(50);
 
if (comm_mode == BT_DATA)
_delay_ms(1);
 
if (comm_mode == BT_NOECHO)
_delay_ms(1);
 
if (comm_mode == BT_CMD)
{
uint8_t x = 0;
for (; x < 3; x++)
{
// // while_timeout(X, Y) for(uint16_t __timeout = 0; __timeout++ <= Y && (X); _delay_ms(Y ? 1 : 0))
// while_timeout(fifo_is_empty(&in_fifo), 200)
for(uint16_t __timeout = 0; __timeout++ <= 200 && (fifo_is_empty(&in_fifo)); _delay_ms(200 ? 1 : 0))
{
uart_receive();
}
 
fifo_read(&in_fifo, &echo);
 
if (echo != data[i]) {
if (uart1_putc(data[i]) == 0)
{
warn_pgm(PSTR ("UART: Remote not ready"));
return;
}
}
else
break;
}
 
if (x == 3)
{
error_putc(data[i]);
error_pgm(PSTR("BT: WRONG ECHO"));
}
}
}
}
 
 
//--------------------------------------------------------------
static uint16_t send_cmd(const bt_cmd_t command, const char *data)
{
_delay_ms(500); // org 500 300 zu wenig
char full_command[20]; // Maximum command size
 
switch (command)
{
case BT_SET_PIN:
strcpy_P(full_command, PSTR("ATP="));
for (uint8_t i = 0; i < bt_pin_length; i++)
{
full_command[i+4] = bt_pin[i];
}
full_command[(bt_pin_length+4)] =0;
break;
 
case BT_SET_DEFAULT:
strcpy_P(full_command, PSTR("ATZ0"));
break;
 
case BT_SET_57600:
strcpy_P(full_command, PSTR("ATL4"));
break;
 
case BT_SET_NOANSWER:
strcpy_P(full_command, PSTR("ATQ1"));
break;
 
case BT_SET_NOECHO:
strcpy_P(full_command, PSTR("ATE0"));
break;
 
case BT_SET_ANSWER:
strcpy_P(full_command, PSTR("ATQ0"));
break;
 
case BT_SET_ECHO:
strcpy_P(full_command, PSTR("ATE1"));
break;
 
case BT_TEST:
strcpy_P(full_command, PSTR("AT"));
break;
 
case BT_CONNECT:
strcpy_P(full_command, PSTR("ATA"));
break;
 
case BT_DISCONNECT:
strcpy_P(full_command, PSTR("ATH"));
break;
 
case BT_CLEAR_ADDRESS:
strcpy_P(full_command, PSTR("ATD0"));
break;
 
case BT_SET_ADDRESS:
strcpy_P(full_command, PSTR("ATD="));
memcpy((full_command + strlen(full_command)), data, 12);
full_command[16] = 0;
break;
 
case BT_FIND_DEVICES:
strcpy_P(full_command, PSTR("ATF?"));
break;
 
case BT_DISABLE_AUTOCONNECT:
strcpy_P(full_command, PSTR("ATO1"));
break;
 
case BT_SET_MASTER:
strcpy_P(full_command, PSTR("ATR0"));
break;
 
case BT_SET_SLAVE:
strcpy_P(full_command, PSTR("ATR1"));
break;
 
case BT_SET_NAME:
strcpy_P(full_command, PSTR("ATN="));
for (uint8_t i = 0; i < bt_name_len; i++)
{
full_command[i + 4] = bt_name[i];
}
full_command[(bt_name_len + 4)] = 0;
break;
 
case BT_SET_DISPWRDOWN:
strcpy_P(full_command, PSTR("ATS1"));
break;
 
default:
warn_pgm(PSTR("CMD UNK"));
return false;
}
 
strcat_P(full_command, PSTR("\r"));
 
// throw away your television
uart_receive();
fifo_clear(&in_fifo);
// debug_pgm(PSTR("bt_init3"));
// send command
uart_send(full_command, strlen(full_command));
 
if (command== BT_SET_ECHO)
return true;
 
if (command== BT_SET_ANSWER)
return true;
 
// get response
while_timeout(true, BT_CMD_TIMEOUT_MS)
{
uart_receive();
if (fifo_strstr_pgm(&in_fifo, PSTR("OK\r\n")))
{
info_pgm(PSTR("CMD SEND: OK"));
return true;
}
 
if (fifo_strstr_pgm(&in_fifo, PSTR("ERROR\r\n")))
{
#ifdef DEBUG
info_pgm(PSTR("CMD SEND: Error"));
#endif
return false;
}
}
 
#ifdef DEBUG
if (command != BT_TEST)
warn_pgm(PSTR("CMD SEND: TIMEOUT"));
#endif
 
 
return false;
}
 
 
//--------------------------------------------------------------
void test(void)
{
comm_mode = BT_RAW;
for (uint8_t i = 0; i < 3; i++)
if (send_cmd(BT_TEST, NULL))
break;
comm_mode = BT_CMD;
}
 
 
#ifndef SaveMem
 
//--------------------------------------------------------------
static void clean_line(void)
{
while_timeout(true, 50)
uart_receive();
fifo_strstr_pgm(&in_fifo, PSTR("\r\n"));
}
 
static communication_mode_t update_comm_mode(uint16_t timeout_ms)
{
while_timeout(true, timeout_ms)
{
uart_receive();
 
if (fifo_strstr_pgm(&in_fifo, PSTR("DISCONNECT")))
{
clean_line();
test();
comm_mode = BT_CMD;
return comm_mode;
}
 
if (fifo_strstr_pgm(&in_fifo, PSTR("CONNECT")))
{
_delay_ms(100); //don't delete this, else there will be no success!!!!!!!!!
comm_mode = BT_DATA;
return comm_mode;
}
 
if (fifo_strstr_pgm (&in_fifo, PSTR("Time out,Fail to connect!")))
{
clean_line();
#ifdef DEBUG
debug_pgm(PSTR("CONNECT FAILED"));
#endif
test();
comm_mode = BT_CMD;
return comm_mode;
}
}
 
return comm_mode;
}
#endif
 
 
//--------------------------------------------------------------
uint16_t bt_init(void)
{
uint8_t init_error = false;
uint8_t BT_found = 0;
i = 0;
 
set_BTOn();
 
lcd_cls();
lcd_printp_at (0, 0, PSTR("BT initialisieren.."), 0);
_delay_ms(200);
 
for (uint8_t z = (bt_name_length); z > 0; z--)
{
if (bt_name[z - 1] != ' ')
{
bt_name_len = z;
break;
}
}
 
uart1_init(UART_BAUD_SELECT(57600, F_CPU));
fifo_init(&in_fifo, bt_buffer, IN_FIFO_SIZE);
_delay_ms(100);
// debug_pgm(PSTR("bt_init"));
uart_receive();
// debug_pgm(PSTR("bt_init1"));
fifo_clear(&in_fifo);
send_cmd(BT_TEST, NULL);
comm_mode = BT_NOECHO;
send_cmd(BT_SET_ECHO, NULL);
send_cmd(BT_SET_ANSWER, NULL);
 
// debug_pgm(PSTR("bt_init2"));
#ifdef DEBUG
debug_pgm(PSTR("Check with 57600"));
#endif
// send_cmd(BT_TEST, NULL); // Schrott löschen
 
if (send_cmd(BT_TEST, NULL)) // Test mit 57600
{
#ifdef DEBUG
debug_pgm(PSTR("BT found 57600 Baud"));
#endif
BT_found = 1;
}
 
if (BT_found == 0)
{
#ifdef DEBUG
debug_pgm(PSTR("Check with 19200"));
#endif
uart1_init(UART_BAUD_SELECT(19200, F_CPU));// Test mit 19200
_delay_ms(100);
send_cmd(BT_TEST, NULL); // Schrott löschen
send_cmd(BT_SET_ANSWER, NULL);
send_cmd(BT_SET_ECHO, NULL);
 
if (send_cmd(BT_TEST, NULL))
{
debug_pgm(PSTR("19200 OK"));
if (send_cmd(BT_TEST, NULL))
{
#ifdef DEBUG
debug_pgm(PSTR("BT found 19200 Baud"));
#endif
BT_found = 2;
}
}
}
 
if (BT_found == 0)
{
#ifdef DEBUG
debug_pgm(PSTR("Check with 9600"));
#endif
uart1_init(UART_BAUD_SELECT(9600, F_CPU));//test mit 9600
_delay_ms(100);
send_cmd(BT_TEST, NULL);
send_cmd(BT_SET_ANSWER, NULL);
send_cmd(BT_SET_ECHO, NULL);
if (send_cmd(BT_TEST, NULL));
{
#ifdef DEBUG
debug_pgm(PSTR("9600 OK"));
#endif
if (send_cmd(BT_TEST, NULL))
{
#ifdef DEBUG
debug_pgm(PSTR("BT found 9600 Baud"));
#endif
BT_found = 3;
}
}
}
 
if (BT_found > 0)
{
/* Set comm_mode to CMD */
comm_mode = BT_CMD;
// test();
/* Set BTM Baudrate */
if (!(send_cmd(BT_SET_57600, NULL)))
init_error = true;
uart1_init(UART_BAUD_SELECT(57600, F_CPU));
_delay_ms(100);
// test();
/* Clear remote address */
if(!(send_cmd(BT_CLEAR_ADDRESS, NULL)))
init_error = true;
// test();
/* Set BTM to SLAVE */
if (!(send_cmd(BT_SET_SLAVE, NULL)))
init_error = true;
// test();
/* Set BTM PIN */
if(!(send_cmd(BT_SET_PIN, NULL)))
init_error = true;
// test();
/* Set BTM Name */
if(!(send_cmd(BT_SET_NAME, NULL)))
init_error = true;
_delay_ms(300);
// test();
if(!(send_cmd(BT_SET_DISPWRDOWN, NULL)))
init_error = true;
// test();
/* Set BTM Echo aus */
send_cmd(BT_SET_NOECHO, NULL);
// test();
comm_mode = BT_NOECHO;
/* Set BTM Answer aus */
send_cmd(BT_SET_NOANSWER, NULL);
// test();
 
bt_mode = BLUETOOTH_SLAVE;
 
set_USBOn();
 
if (!init_error)
{
WriteBTInitFlag(); // Init merken
return true;
}
else
return false;
}
else
{
set_USBOn();
return false;
}
 
}
 
 
#ifndef SaveMem
 
//--------------------------------------------------------------
uint16_t bt_set_mode(const bt_mode_t mode)
{
if (update_comm_mode(0) == BT_DATA)
return false;
 
if (mode == bt_mode)
return true;
 
if (mode == BLUETOOTH_MASTER)
if (send_cmd(BT_SET_MASTER, NULL))
{
bt_mode = BLUETOOTH_MASTER;
test();
send_cmd(BT_DISABLE_AUTOCONNECT, NULL);
}
 
if (mode == BLUETOOTH_SLAVE)
if (send_cmd(BT_SET_SLAVE, NULL))
{
bt_mode = BLUETOOTH_SLAVE;
}
 
test();
return mode == bt_mode;
}
 
 
//--------------------------------------------------------------
uint16_t bt_receive(void *data, uint8_t length, uint16_t timeout_ms)
{
uint8_t rec_length = 0;
uint8_t i = 0;
 
// while_timeout(true, timeout_ms);
for(uint16_t __timeout = 0; __timeout++ <= true && (timeout_ms); _delay_ms(true ? 1 : 0))
{
if (i == length)
return true;
 
uart_receive();
 
if (fifo_is_empty(&in_fifo))
continue;
 
if (update_comm_mode(0) != BT_DATA)
{
#ifdef DEBUG
debug_pgm(PSTR("not connected"));
#endif
return false;
}
// We have a connection
if (timeout_ms == 0)
timeout_ms += 2000;
 
if (fifo_is_empty(&in_fifo))
continue;
 
// Find starting point of packet
if (!rec_length)
{
fifo_read(&in_fifo, (char *)&rec_length);
 
if (rec_length != length)
{
rec_length = 0;
}
else
{
// You've got mail!
timeout_ms += 2000;
}
}
else
{
fifo_read(&in_fifo, (char *)data + i);
i++;
}
}
return false;
}
 
#endif
 
#ifndef SaveMem
 
 
//--------------------------------------------------------------
uint16_t bt_send(void *data, const uint8_t length)
{
if (update_comm_mode(0) == BT_CMD)
return false;
 
uart_send((const char *)&length, 1);
uart_send((char *)data, length);
return (update_comm_mode(0) == BT_DATA);
}
 
 
#ifdef SQUIRREL
 
//--------------------------------------------------------------
uint16_t bt_connect(const char *address)
{
// Maybe we already disconnected???
if (BT_DATA == update_comm_mode(0))
{
#ifdef DEBUG
debug_pgm(PSTR("We are still connected..."));
#endif
return false;
}
test();
 
if (!send_cmd(BT_DISABLE_AUTOCONNECT, address))
return false;
 
test();
#ifdef DEBUG
debug_pgm (PSTR ("SET_ADD"));
#endif
 
if (!send_cmd(BT_SET_ADDRESS, address))
return false;
 
test();
#ifdef DEBUG
debug_pgm (PSTR ("CONNECT"));
#endif
 
if (!send_cmd(BT_CONNECT, NULL))
return false;
#ifdef DEBUG
debug_pgm (PSTR ("WAIT FOR COMM"));
#endif
return (BT_DATA == update_comm_mode(60000));
}
 
 
//--------------------------------------------------------------
uint16_t bt_disconnect(void)
{
/* Bluetooth reseten */
// set_bit(PORTC.DIR, 4);
// set_bit(PORTC.OUT, 4);
_delay_ms(500);
// clear_bit(PORTC.OUT, 4);
// return bt_init();
 
#if 1
if (BT_CMD == update_comm_mode(0))
{
fifo_clear(&in_fifo);
return true;
}
 
// Switch to online cmd mode
for (uint8_t i = 0; i < 4; i++)
{
const char plus = '+';
uart_send(&plus, 1);
_delay_ms(1500);
}
 
//comm_mode = BT_CMD;
 
if (!send_cmd(BT_DISCONNECT, NULL))
return false;
 
test();
if (!send_cmd(BT_CLEAR_ADDRESS, NULL))
return false;
test();
 
if (BT_CMD == update_comm_mode(10000))
{
fifo_clear(&in_fifo);
return true;
}
#ifdef DEBUG
debug_pgm(PSTR("Still in DATA??"));
#endif
return false;
#endif
}
 
 
//--------------------------------------------------------------
void copy_address(const char *src, char *dst)
{
uint8_t off = 0;
 
for (uint8_t i = 0; i < 14; i++)
{
if (src[i + off] == '-')
off++;
 
dst[i] = src[i + off];
}
}
 
 
//--------------------------------------------------------------
uint16_t bt_discover(char result[8][12])
 
// 14.8.2011 ist noch nicht getestet, wird für PKT auch nicht benötigt, Cebra
{
// update_callback(20);
test();
if (!bt_set_mode(BLUETOOTH_MASTER))
return false;
 
if (!send_cmd(BT_FIND_DEVICES, NULL))
return false;
 
char buffer[255]; //oversized, but who cares?
char *bufferhead = buffer;
uint8_t pos = 0;
uint16_t Timeout = 20000;
uint8_t pos1 = 0;
 
do
{
uart_receive();
Timeout--;
pos1++;
_delay_ms(1);
 
}
while ((Timeout > 0) ||(!fifo_strstr_pgm(&in_fifo, PSTR("Inquiry Results:\r\n"))));
 
// byte_to_hex(Timeout);
 
assert_pgm((!fifo_strstr_pgm(&in_fifo, PSTR("Inquiry Results:\r\n"))),PSTR("INQ Result false"));
 
info_pgm (PSTR ("Rec1"));
 
for (uint16_t i = 0; i < 60000; i++)
{
//if ((i % 1000) == 0)
//update_callback(40 + i / 1000);
uart_receive();
// lcd_printp(".", 0);
_delay_ms(1);
}
 
info_pgm (PSTR ("Rec2"));
 
//update_callback(100);
 
while (!fifo_is_empty(&in_fifo))
{
// Get next line
while (!fifo_cmp_pgm(&in_fifo, PSTR("\r\n")))
{
fifo_read(&in_fifo, bufferhead);
bufferhead++;
}
// terminate string
*bufferhead = 0;
 
//reset bufferhead
bufferhead = buffer;
 
if (strlen(buffer) == 0)
continue; //the empty line before end of inquiry
 
if (strstr_P(buffer, PSTR("Inquiry End")))
{
fifo_clear(&in_fifo);
test();
return true;
}
 
if (strncmp_P(PSTR("0012"), &buffer[21], 4))
{
copy_address(&buffer[21], result[pos]);
pos++;
}
}
 
return false;
}
 
#endif
#endif
#endif /* SQUIRREL */
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/bluetooth.h
0,0 → 1,127
/*****************************************************************************
* 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 _BLUETOOTH_H_
#define _BLUETOOTH_H_
 
#include <avr/io.h>
//#include <common.h>
 
 
#define SQUIRREL
#define NUTS_LIST 16
#define EXTENSIONS_LIST 16
 
//void InitBT(void);
 
typedef struct _device_info device_info;
 
// device info struct, holds mac , class and extensions + values of a device
struct _device_info
{
char mac[12];
 
uint8_t class;
uint8_t extension_types[EXTENSIONS_LIST];
uint16_t values_cache[EXTENSIONS_LIST];
};
 
extern device_info device_list[NUTS_LIST];
 
#define valid(num) (num < NUTS_LIST && (device_list[num].mac[0] != 0 || device_list[num].mac[1] != 0 || device_list[num].mac[2] != 0 || device_list[num].mac[3] != 0 || device_list[num].mac[4] != 0 || device_list[num].mac[5] != 0 || device_list[num].mac[6] != 0 || device_list[num].mac[7] != 0 || device_list[num].mac[8] != 0 || device_list[num].mac[9] != 0 || device_list[num].mac[10] != 0 || device_list[num].mac[11] != 0))
 
 
 
// Bluetooth mode ENUM
typedef enum
{
BLUETOOTH_MASTER, // < Master Mode (to create outgoinng connections).
BLUETOOTH_SLAVE // < Slave Mode (to wait for incoming connections).
} bt_mode_t;
 
 
// init bluetooth driver
// @return always true
//
//extern uint16_t bt_init (void (*upate_percentage) (uint16_t));
extern uint16_t bt_init (void);
 
// Set the Bluetooth mode
// @param mode bt_mode_t Bluetooth Mode ENUM (BLUETOOTH_MASTER or BLUETOOTH_SLAVE)
// @return true if mode change was succesful, false if not
//
extern uint16_t bt_set_mode (const bt_mode_t mode);
 
// recieve data over bluetooth
// @param data pointer to memory for data storage
// @param length value of length after call holds the actual recived data length
// @param timeout_ms timeout in ms after the recive function aborts and returns with false
// @return false if recived length > length parameter or it timeouted, true otherwise
//
extern uint16_t bt_receive (void * data, uint8_t length, uint16_t timeout_ms);
 
// send data over bluetooth
// @param data pointer to the data to send
// @param length length of the data to be send
// @return true if sendingn was successful, false otherwise
//
extern uint16_t bt_send (void * data, const uint8_t length);
 
// squirrelt only functions
#ifdef SQUIRREL
 
// open bluetoot connection (only one at a time possible)
// @param address connection is opened to this device mac address
// @return true if connection was established, false otherwise
//
extern uint16_t bt_connect (const char *address);
 
// closes bluetooth connection
// @return false if failed, true otherwise
//
extern uint16_t bt_disconnect (void);
 
// discover bluetooth devices
// @param result in a 2 dimensional array first index are devicecs (max 8) second is mac address string
// @param update_callback to inform of progress (in % from 0 to 100)
// @return true if successful, false if error occured
//
extern uint16_t bt_discover (char result[8][12]);
//extern uint16_t bt_discover (char result[8][12], void (*update_callback)(const uint16_t progress));
 
#endif // SQUIRREL
 
 
#endif
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/connect.c
0,0 → 1,381
/*****************************************************************************
* 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/pgmspace.h>
#include "lcd.h"
#include "timer.h"
#include "eeprom.h"
#include "messages.h"
 
#if defined HWVERSION1_3W || defined HWVERSION3_9
//--------------------------------------------------------------
void Change_Output(uint8_t UartMode) // Schaltet die Rx/Tx Richtungen
{
// hiermit werden die 74HTC125 (IC5) Gatter geschaltet
clr_USB2FC(); // PC2 aus
clr_USB2Wi(); // PB0 aus
clr_Uart02FC(); // PC6 aus
clr_Uart02Wi(); // PC5 aus
 
 
switch (UartMode)
{
case USB2FC:
UCSR1B &= ~(1<<RXEN1);
UCSR1B &= ~(1<<TXEN1);
UCSR1B &= ~(1<<RXCIE1);
 
DDRD &= ~(1<<DDD2); // Pins auf Eingang setzen
DDRD &= ~(1<<DDD3);
PORTD &= ~(1<<PD2); // Pullup aus
PORTD &= ~(1<<PD3);
 
set_USB2FC();
break;
 
case Uart02Wi:
set_Uart02Wi();
break;
 
case Uart02FC:
set_Uart02FC();
break;
 
case USB2Wi:
UCSR1B &= ~(1<<RXEN1);
UCSR1B &= ~(1<<TXEN1);
UCSR1B &= ~(1<<RXCIE1);
 
DDRD &= ~(1<<DDD2); // Pins auf Eingang setzen
DDRD &= ~(1<<DDD3);
PORTD &= ~(1<<PD2); // Pullup aus
PORTD &= ~(1<<PD3);
 
set_USB2Wi();
break;
}
 
}
 
 
//--------------------------------------------------------------
// Function: BT2FC()
// Purpose: Connect BT direct to FC-Kabel (SV2 as MKUSB)
// Returns:
//--------------------------------------------------------------
void Port_BT2FC(void)
{
lcd_cls ();
 
if(UseBT == true)
{
// lcd_printp_at (0, 0, PSTR(" MK-USB Funktion "), 2);
lcd_puts_at(0, 0, strGet(CONNECT14), 2);
// lcd_printp_at (0, 1, PSTR(" BT --> Kabel an FC "), 2);
lcd_puts_at(0, 1, strGet(CONNECT15), 0);
// lcd_printp_at (0, 3, PSTR("PC mit BT verb."), 0);
lcd_puts_at(0, 3, strGet(CONNECT16), 0);
// lcd_printp_at (0, 4, PSTR("PKT-Kabel an FC"), 0);
lcd_puts_at(0, 4, strGet(CONNECT17), 0);
// lcd_printp_at (0, 5, PSTR("MK-Tool starten"), 0);
// lcd_printp_at (12, 7, PSTR("Esc"), 0);
lcd_puts_at(0, 5, strGet(CONNECT23), 0);
lcd_puts_at(12, 7, strGet(ESC), 0);
set_BTOn();
 
Change_Output(USB2FC);
 
while(!get_key_press (1 << KEY_ESC));
 
get_key_press(KEY_ALL);
if (U02SV2 == 1)
Change_Output(Uart02FC);
else
Change_Output(Uart02Wi);
 
set_USBOn();
return;
}
else
{
// lcd_printp_at (0, 0, PSTR("Es ist kein BTM-222 "), 0);
// lcd_printp_at (0, 1, PSTR("Modul eingebaut! "), 0);
// lcd_printp_at (0, 3, PSTR("Wenn doch, dann bitte"), 0);
// lcd_printp_at (0, 4, PSTR("das Modul zuerst im "), 0);
// lcd_printp_at (0, 5, PSTR("Setupmenü aktivieren."), 0);
lcd_puts_at(0, 1, strGet(CONNECT12), 0);
lcd_puts_at(0, 1, strGet(CONNECT13), 0);
lcd_puts_at(0, 2, strGet(CONNECT7), 0);
lcd_puts_at(0, 3, strGet(CONNECT8), 0);
lcd_puts_at(0, 4, strGet(CONNECT9), 0);
lcd_puts_at(12, 7, strGet(ENDE), 0);
// lcd_printp_at (12, 7, PSTR("Ende"), 0);
 
while(!get_key_press (1 << KEY_ESC));
 
get_key_press(KEY_ALL);
return;
}
}
 
 
//--------------------------------------------------------------
// Function: BT2Wi()
// Purpose: Connect BT direct to Wi.232
// Returns:
//--------------------------------------------------------------
void Port_BT2Wi(void)
{
 
lcd_cls ();
 
// if((UseBT == true) && (UseWi == true))6.1.2012 CB Abfrage entfernt, damit die Funktion auch ohne Module geht
{
// lcd_printp_at (0, 0, PSTR(" MK-USB Funktion "), 2);
lcd_puts_at(0, 0, strGet(CONNECT14), 2);
// lcd_printp_at (0, 1, PSTR(" BT --> Wi.232 "), 2);
lcd_puts_at(0, 1, strGet(CONNECT18), 2);
// lcd_printp_at (0, 3, PSTR("PC mit BT verbinden "), 0);
lcd_puts_at(0, 3, strGet(CONNECT16), 0);
// lcd_printp_at (0, 4, PSTR("Wi.232 an FC "), 0);
lcd_puts_at(0, 4, strGet(CONNECT19), 0);
// lcd_printp_at (0, 5, PSTR("MK-Tool starten "), 0);
lcd_puts_at(0, 5, strGet(CONNECT23), 0);
 
// lcd_printp_at (12, 7, PSTR("Esc"), 0);
lcd_puts_at(12, 7, strGet(ESC), 0);
set_BTOn();
 
Change_Output(USB2Wi);
 
while(!get_key_press (1 << KEY_ESC));
 
get_key_press(KEY_ALL);
if (U02SV2 == 1)
Change_Output(Uart02FC);
else
Change_Output(Uart02Wi);
 
set_USBOn();
return;
}
// else
// {
//// lcd_printp_at (0, 0, PSTR("Es ist kein BTM-222 "), 0);
//// lcd_printp_at (0, 1, PSTR("Modul eingebaut! "), 0);
//// lcd_printp_at (0, 3, PSTR("Wenn doch, dann bitte"), 0);
//// lcd_printp_at (0, 4, PSTR("das Modul zuerst im "), 0);
//// lcd_printp_at (0, 5, PSTR("Setupmenü aktivieren."), 0);
//
// lcd_puts_at(0, 0, strGet(CONNECT12), 0);
// lcd_puts_at(0, 1, strGet(CONNECT13), 0);
// lcd_puts_at(0, 2, strGet(CONNECT7), 0);
// lcd_puts_at(0, 3, strGet(CONNECT8), 0);
// lcd_puts_at(0, 4, strGet(CONNECT9), 0);
// lcd_puts_at(12, 7, strGet(ENDE), 0);
//// lcd_printp_at (12, 7, PSTR("Ende"), 0);
//
// while(!get_key_press (1 << KEY_ESC));
// get_key_press(KEY_ALL);
//
// return;
// }
}
 
 
//--------------------------------------------------------------
// Function: FC2CFG_BT()
// Purpose: Connect FC (Tx1 Pin3, Rx1 Pin4) direct to BT
// Returns:
//--------------------------------------------------------------
void Port_FC2CFG_BT(void)
{
 
lcd_cls ();
lcd_printp_at (0, 0, PSTR("BTM-222 Konfigurieren"), 2);
lcd_printp_at (0, 1, PSTR("FC > MK-USB > BTM-222"), 2);
lcd_printp_at (0, 3, PSTR("MK-USB an PC anschl. "), 0);
lcd_printp_at (0, 4, PSTR("Zwischen MK-USB und "), 0);
lcd_printp_at (0, 5, PSTR("PKT ein gekreuztes "), 0);
lcd_printp_at (0, 6, PSTR("Kabel anschliessen. "), 0);
lcd_puts_at(12, 7, strGet(ESC), 0);
// lcd_printp_at (12, 7, PSTR("Esc"), 0);
 
set_BTOn();
Change_Output(USB2FC);
 
while(!get_key_press (1 << KEY_ESC));
 
get_key_press(KEY_ALL);
if (U02SV2 == 1)
Change_Output(Uart02FC);
else
Change_Output(Uart02Wi);
 
set_USBOn();
return;
}
 
 
//--------------------------------------------------------------
// Function: USB2FC()
// Purpose: Connect USB direct to FC-Kabel (SV2 as MKUSB)
// Returns:
//--------------------------------------------------------------
void Port_USB2FC(void)
{
lcd_cls ();
// lcd_printp_at (0, 0, PSTR(" MK-USB Funktion "), 2);
lcd_puts_at(0, 0, strGet(CONNECT14), 2);
// lcd_printp_at (0, 1, PSTR(" USB --> Kabel an FC "), 2);
lcd_puts_at(0, 1, strGet(CONNECT20), 0);
// lcd_printp_at (0, 3, PSTR("PC mit USB verbinden "), 0);
lcd_puts_at(0, 3, strGet(CONNECT21), 0);
// lcd_printp_at (0, 4, PSTR("PKT-Kabel an FC "), 0);
lcd_puts_at(0, 4, strGet(CONNECT17), 0);
// lcd_printp_at (0, 5, PSTR("MK-Tool starten "), 0);
// lcd_printp_at (12, 7, PSTR("Esc"), 0);
lcd_puts_at(0, 5, strGet(CONNECT23), 0);
lcd_puts_at(12, 7, strGet(ESC), 0);
Change_Output(USB2FC);
 
while(!get_key_press (1 << KEY_ESC));
 
get_key_press(KEY_ALL);
if (U02SV2 == 1)
Change_Output(Uart02FC);
else
Change_Output(Uart02Wi);
 
return;
}
 
//--------------------------------------------------------------
// Function: USB2Wi()
// Purpose: Connect USB direct to Wi.232
// Returns:
//--------------------------------------------------------------
void Port_USB2Wi(void)
{
 
lcd_cls ();
// if(UseWi == true) // 6.1.2012 CB Abfrage entfernt, damit die Funktion auch ohne Module geht
{
// lcd_printp_at (0, 0, PSTR(" MK-USB Funktion "), 2);
lcd_puts_at(0, 0, strGet(CONNECT14), 2);
// lcd_printp_at (0, 1, PSTR(" USB --> Wi.232 "), 2);
lcd_puts_at(0, 1, strGet(CONNECT22), 2);
// lcd_printp_at (0, 3, PSTR("PC mit USB verbinden "), 0);
lcd_puts_at(0, 3, strGet(CONNECT21), 0);
// lcd_printp_at (0, 4, PSTR("Wi.232 an FC "), 0);
lcd_puts_at(0, 4, strGet(CONNECT19), 0);
// lcd_printp_at (0, 5, PSTR("MK-Tool starten "), 0);
lcd_puts_at(0, 5, strGet(CONNECT23), 0);
lcd_puts_at(12, 7, strGet(ESC), 0);
// lcd_printp_at (12, 7, PSTR("Esc"), 0);
 
Change_Output(USB2Wi);
 
while(!get_key_press (1 << KEY_ESC));
 
get_key_press(KEY_ALL);
if (U02SV2 == 1)
Change_Output(Uart02FC);
else
Change_Output(Uart02Wi);
 
return;
}
// else
// {
//// lcd_printp_at (0, 0, PSTR("Es ist kein Wi.232 "), 0);
//// lcd_printp_at (0, 1, PSTR("Modul eingebaut! "), 0);
//// lcd_printp_at (0, 3, PSTR("Wenn doch, dann bitte"), 0);
//// lcd_printp_at (0, 4, PSTR("das Modul zuerst im "), 0);
//// lcd_printp_at (0, 5, PSTR("Setupmenü aktivieren."), 0);
//// lcd_printp_at (12, 7, PSTR("Ende"), 0);
// lcd_puts_at(0, 0, strGet(CONNECT5), 0);
// lcd_puts_at(0, 1, strGet(CONNECT6), 0);
// lcd_puts_at(0, 2, strGet(CONNECT7), 0);
// lcd_puts_at(0, 3, strGet(CONNECT8), 0);
// lcd_puts_at(0, 4, strGet(CONNECT9), 0);
// lcd_puts_at(12, 7, strGet(ENDE), 0);
// while(!get_key_press (1 << KEY_ESC));
// get_key_press(KEY_ALL);
//
// return;
// }
}
 
//--------------------------------------------------------------
// Function: USB2CFG_Wi()
// Purpose: Connect USB direct to Wi.232 in Progmode
// Returns:
//--------------------------------------------------------------
void Port_USB2CFG_Wi(void)
{
 
lcd_cls ();
// lcd_printp_at (0, 0, PSTR(" Wi.232 Konfigurieren"), 2);
lcd_puts_at(0, 0, strGet(CONNECT24), 2);
// lcd_printp_at (0, 1, PSTR(" USB --> Wi.232 "), 2);
lcd_puts_at(0, 1, strGet(CONNECT22), 2);
// lcd_printp_at (0, 3, PSTR("PC mit USB verbinden."), 0);
lcd_puts_at(0, 3, strGet(CONNECT21), 0);
lcd_printp_at (0, 4, PSTR("Radiotronix Wi.232DTS"), 0);
lcd_printp_at (0, 5, PSTR("Evaluation (868MHz) "), 0);
// lcd_printp_at (0, 6, PSTR("Programm starten. "), 0);
lcd_puts_at(0, 6, strGet(CONNECT25), 0);
lcd_puts_at(12, 7, strGet(ESC), 0);
// lcd_printp_at (12, 7, PSTR("Esc"), 0);
 
Change_Output(USB2Wi);
 
set_WI232CMD(); // Port D6 = CMD
 
while(!get_key_press (1 << KEY_ESC));
 
get_key_press(KEY_ALL);
clr_WI232CMD(); // Port D6 = CMD
 
if (U02SV2 == 1)
Change_Output(Uart02FC);
else
Change_Output(Uart02Wi);
 
return;
}
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/connect.h
0,0 → 1,48
/*****************************************************************************
* 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 _CONNECT_H
#define _CONNECT_H
 
void Change_Output(uint8_t UartMode);
 
void Port_BT2Wi(void);
void Port_BT2FC(void);
void Port_FC2CFG_BT(void);
 
void Port_USB2FC(void);
void Port_USB2Wi(void);
void Port_USB2CFG_Wi(void);
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/cpu.h
0,0 → 1,41
/*****************************************************************************
* 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 _CPU_H
#define _CPU_H
 
// Quarz Frequenz in Hz
#define F_CPU 20000000UL
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/debug.c
0,0 → 1,370
/*****************************************************************************
* 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 <string.h>
 
#include "main.h"
//#include "menu.h"
#include "lcd.h"
#include "usart.h"
#include "debug.h"
#include "timer.h"
#include "messages.h"
 
#include "mk-data-structs.h"
 
#define TIMEOUT 200 // 2 sec
#define ANALOGTIME 20 // 200 ms
 
// WARNING: this work for NC & FC only
// if current_hardware == MK3MAG or MKGPS the access is outside of the array...
uint8_t AnalogNames[2][32][16 + 1]; // 32 names, 16 characters + 1 0x00
uint8_t AnalogNamesRead[2] = {0,0};
 
//--------------------------------------------------------------
//
void GetAnalogNames (void)
{
uint8_t i = AnalogNamesRead[current_hardware - 1];
uint8_t t = 0;
 
lcd_cls ();
lcd_printp_at (0, 3, PSTR("Reading"), 0);
lcd_printp_at (0, 4, PSTR("Analog Names: "), 0);
 
mode = 'A'; // read Names
_delay_ms(200);
rxd_buffer_locked = FALSE;
 
timer = ANALOGTIME;
 
while (i < 32)
{
SendOutData ('a', ADDRESS_ANY, 1, &i, 1);
while (!rxd_buffer_locked && timer);
if (timer)
{
Decode64 ();
if (i == *pRxData)
{
write_ndigit_number_u(14, 4, i, 2, 0);
memcpy (AnalogNames[current_hardware - 1][*pRxData], (uint8_t *) pRxData + 1, 16);
AnalogNames[current_hardware - 1][*pRxData][16] = 0;
i++;
t = 0;
}
else
{
_delay_ms (100);
}
 
timer = ANALOGTIME;
rxd_buffer_locked = FALSE;
}
else
{ // timeout occured
t++;
timer = ANALOGTIME;
 
if (t >= 50)
{
lcd_printp_at (0, 2, PSTR("ERROR: no data"), 0);
 
timer = 100;
while (timer > 0);
break;
}
}
}
 
AnalogNamesRead[current_hardware - 1] = i;
 
#if 0
if (timer)
{
for (page = 0; page < 5; page++)
{
for (i = 0; i < 7; i++)
{
lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 7], 0);
}
while (!get_key_press (1 << KEY_ESC)); // ESC
get_key_press(KEY_ALL);
}
}
//return;
#endif
}
 
 
//--------------------------------------------------------------
//
void display_debug (void)
{
uint8_t i = 0;
uint8_t tmp_dat;
uint8_t page = 0;
 
DebugData_t *DebugData;
 
lcd_cls ();
 
timer = TIMEOUT;
 
if (AnalogNamesRead[current_hardware - 1] < 32)
{
GetAnalogNames ();
}
 
if (!timer)
{
return;
}
 
mode = 'D'; // Debug Data
rxd_buffer_locked = FALSE;
timer = TIMEOUT;
 
tmp_dat = 10;
SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
abo_timer = ABO_TIMEOUT;
 
for (i = 0; i < 7; i++)
{
lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 7], 0);
if (page == 4 && i > 3)
{
for (i = 4; i < 7; i++) // Linie 4, 5, 6 loeschen
{
lcd_cls_line (0, i, 21);
}
i = 7;
}
}
 
do
{
if (rxd_buffer_locked)
{
Decode64 ();
DebugData = (DebugData_t *) pRxData;
 
// lcd_printp_at (0, 7, PSTR(KEY_LINE_3), 0);
lcd_puts_at(0, 7, strGet(KEYLINE3), 0);
lcd_write_number_u_at (5, 7, page + 1);
switch (current_hardware)
{
case FC:
lcd_printp_at (3, 7, PSTR("FC"), 0);
lcd_printp_at (19, 7, PSTR("NC"), 0);
break;
 
case NC:
lcd_printp_at (3, 7, PSTR("NC"), 0);
lcd_printp_at (19, 7, PSTR("FC"), 0);
break;
 
default:
lcd_printp_at (19, 7, PSTR("?"), 0);
break;
}
 
for (i = 0; i < 7; i++)
{
//lcd_print_at (0, i, AnalogNames[i + page * 7], 0);
uint8_t size =0;
if( DebugData->Analog[i + page * 7] < -9999)
{
size = 6;
}
else if ( DebugData->Analog[i + page * 7] < -999)
{
size = 5;
}
else if ( DebugData->Analog[i + page * 7] < -99)
{
size = 4;
}
else if ( DebugData->Analog[i + page * 7] < 999)
{
size = 3;
}
else if ( DebugData->Analog[i + page * 7] < 9999)
{
size = 4;
}
else
{
size = 5;
}
write_ndigit_number_s (21-size, i, DebugData->Analog[i + page * 7], size, 0);
if (page == 4 && i > 3)
{
for (i = 4; i < 7; i++) // Linie 4, 5, 6 loeschen
{
lcd_cls_line (0, i, 21);
}
i = 7;
}
}
timer = TIMEOUT;
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 ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
 
abo_timer = ABO_TIMEOUT;
}
 
if (get_key_press (1 << KEY_MINUS))
{
page--;
if (page > 4)
{
page = 4;
}
lcd_cls ();
for (i = 0; i < 7; i++)
{
lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 7], 0);
if (page == 4 && i > 3)
{
for (i = 4; i < 7; i++) // Linie 4, 5, 6 loeschen
{
lcd_cls_line (0, i, 21);
}
i = 7;
}
}
}
else if (get_key_press (1 << KEY_PLUS))
{
page++;
if (page > 4)
{
page = 0;
}
lcd_cls ();
for (i = 0; i < 7; i++)
{
lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 7], 0);
if (page == 4 && i > 3)
{
for (i = 4; i < 7; i++) // Linie 4, 5, 6 loeschen
{
lcd_cls_line (0, i, 21);
}
i = 7;
}
}
}
if ((hardware == NC) && get_key_press (1 << KEY_ENTER))
{
tmp_dat = 0;
SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
 
_delay_ms (200);
 
if (current_hardware == NC)
{
SwitchToFC();
 
timer = TIMEOUT;
}
else
{
SwitchToNC();
 
timer = TIMEOUT;
}
 
_delay_ms (200);
 
if (AnalogNamesRead[current_hardware - 1] < 32)
{
GetAnalogNames ();
}
 
mode = 'D'; // Debug Data
rxd_buffer_locked = FALSE;
timer = TIMEOUT;
 
tmp_dat = 10;
SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
 
lcd_cls ();
page = 0;
 
for (i = 0; i < 7; i++)
{
lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 7], 0);
if (page == 4 && i > 3)
{
for (i = 4; i < 7; i++) // Linie 4, 5, 6 loeschen
{
lcd_cls_line (0, i, 21);
}
i = 7;
}
}
}
}
while (!get_key_press (1 << KEY_ESC) && timer); // ESC
get_key_press(KEY_ALL);
 
tmp_dat = 0;
SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
 
mode = 0;
rxd_buffer_locked = FALSE;
 
if (!timer)
{ // timeout occured
lcd_cls ();
lcd_printp_at (0, 2, PSTR("ERROR: no data"), 0);
 
timer = 100;
while (timer > 0);
}
SwitchToNC();
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/debug.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 _DEBUG_H
#define _DEBUG_H
 
extern uint8_t AnalogNamesRead[2];
 
void display_debug(void);
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/display.c
0,0 → 1,180
/*****************************************************************************
* 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 "main.h"
#include "lcd.h"
#include "usart.h"
#include "timer.h"
#include "messages.h"
 
#include "mk-data-structs.h"
 
#define TIMEOUT 500 // 5 sec
 
 
void display_data (void)
{
uint8_t cmd;
uint8_t flag = 0;;
 
mode = 'H';
 
lcd_cls ();
// lcd_printp_at (0, 7, PSTR(KEY_LINE_3), 0);
lcd_puts_at(0, 7, strGet(KEYLINE3), 0);
if (current_hardware == NC)
{
lcd_printp_at (0, 0, PSTR(" Navi-Ctrl Display "), 2);
lcd_printp_at (19, 7, PSTR("FC"), 0);
}
else
{
if (hardware == FC)
{
lcd_printp_at (0, 0, PSTR(" Display "), 2);
lcd_printp_at (19, 7, PSTR(" "), 0);
}
else
{
lcd_printp_at (0, 0, PSTR(" Flight-Ctrl Display "), 2);
lcd_printp_at (19, 7, PSTR("NC"), 0);
}
}
 
rxd_buffer_locked = FALSE;
timer = TIMEOUT;
cmd = 0xfc; // Home = first page
 
do
{
SendOutData('h', ADDRESS_ANY, 1, &cmd, 1);
cmd = 0xff;
//LED6_TOGGLE;
_delay_ms (250);
 
if (rxd_buffer_locked)
{
Decode64 ();
flag = 1;
 
if (!hardware)
{ // hardware was not detected at startup
hardware = rxd_buffer[1] - 'a';
if (hardware == NC)
{
lcd_printp_at (0, 0, PSTR(" Navi-Ctrl Display "), 2);
lcd_printp_at (19, 7, PSTR("FC"), 0);
current_hardware = NC;
}
else
{
lcd_printp_at (0, 0, PSTR(" Display "), 2);
lcd_printp_at (19, 7, PSTR(" "), 0);
current_hardware = FC;
}
}
 
#if 0
rxd_buffer[24] = 0;
 
lcd_print_at (0, rxd_buffer[3] + 1, (uint8_t *) &rxd_buffer[4], 0);
#else
rxd_buffer[83] = 0;
 
print_display_at (0, 2, (uint8_t *) &rxd_buffer[3]);
#endif
 
rxd_buffer_locked = FALSE;
timer = TIMEOUT;
}
 
if (get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 2))
{
cmd = 0xfe; // next page
//SendOutData('h', ADDRESS_ANY, 1, &cmd, 1);
//cmd = 0;
}
else if (get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 2))
{
cmd = 0xfd; // previous page
//SendOutData('h', ADDRESS_ANY, 1, &cmd, 1);
//cmd = 0;
}
else if ((hardware == NC) && get_key_press (1 << KEY_ENTER))
{
if (current_hardware == NC)
{
SwitchToFC();
 
//timer = TIMEOUT;
lcd_printp_at (0, 0, PSTR(" Flight-Ctrl Display "), 2);
lcd_printp_at (19, 7, PSTR("NC"), 0);
}
else
{
SwitchToNC();
 
//timer = TIMEOUT;
lcd_printp_at (0, 0, PSTR(" Navi-Ctrl Display "), 2);
lcd_printp_at (19, 7, PSTR("FC"), 0);
}
cmd = 0xfc; // Home = first page
//SendOutData('h', ADDRESS_ANY, 1, &cmd, 1);
//cmd = 0;
}
}
while (!get_key_press (1 << KEY_ESC) && timer);
get_key_press(KEY_ALL);
 
mode = 0;
rxd_buffer_locked = FALSE;
 
if (!timer)
{ // timeout occured
if (flag)
{
lcd_cls ();
}
lcd_printp_at (0, 2, PSTR("Fehler: Keine Daten"), 0);
 
timer = 100;
while (timer > 0);
}
SwitchToNC();
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/display.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 _DISPLAY_H
#define _DISPLAY_H
 
void display_data (void);
 
#endif
 
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/eeprom.c
0,0 → 1,356
/*****************************************************************************
* 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 <avr/eeprom.h>
#include <stdbool.h>
#include <avr/wdt.h>
#include "lcd.h"
#include "main.h"
#include "timer.h"
#include "eeprom.h"
#include "Wi232.h"
#include "mk-data-structs.h"
#include "connect.h"
 
 
//--------------------------------------------------------------
//
 
uint8_t EE_LowBat EEMEM = 137; // 13,7V
uint8_t EE_DisplayTimeout EEMEM = 0; // Display immer an
uint8_t EE_DisplayLanguage EEMEM = 254; // Default ungesetzt
uint8_t EE_WiTXRXChannel EEMEM = 1; // Kanal 1 MK Standard
uint8_t EE_WiNetworkGroup EEMEM = 66; // Gruppe 66 MK Standard
uint8_t EE_WiNetworkMode EEMEM = NetMode_Normal; // MK Standard;
uint8_t EE_WiTXTO EEMEM = TWaitTime16; // MK Standard
uint8_t EE_WiUartMTU EEMEM = UartMTU64; // MK Standard
uint8_t EE_LCD_Orientation EEMEM = 0; // normale Ansicht
uint8_t EE_LCD_DisplayMode EEMEM = 0; // Normal
uint8_t EE_LCD_Kontrast EEMEM = 27; // Kontrast normal
uint8_t EE_LCD_Helligkeit EEMEM = 100; // Helligkeit in %gkeit in %
uint8_t EE_USBBT EEMEM = 0; // USB Betrieb
uint8_t EE_U02SV2 EEMEM = 1; // SV2 (Kabel) Standard
uint8_t EE_Debug EEMEM = 0; // kein Debug
uint8_t EE_UseWi EEMEM = true; // Wi.232 eingebaut?
uint8_t EE_UseBT EEMEM = true; // BT-222 eingebaut?
uint8_t EE_WiIsSet EEMEM = false; // Flag für die Initialisierung Wi232
uint8_t EE_BTIsSet EEMEM = false; // Flag für die Initialisierung Bluetooth
uint8_t EE_PKT_IdleBeep EEMEM = 0; // kein Piepsen bei Inaktivität
uint8_t EE_PKT_StartInfo EEMEM = true; // Startinformationen anzeigen
uint16_t EE_Lipo_UOffset EEMEM = 0; // Offset für die Lipospannugsmessung
uint8_t EE_PKT_Accutyp EEMEM = true; // True = Lipo, False = LiON
uint8_t EEMEM EE_BTPin[bt_pin_length + 1];
uint8_t EEMEM EE_BTName[bt_name_length + 1];
uint32_t EE_LastLongitude EEMEM = 0;
uint32_t EE_LastLatitude EEMEM = 0;
 
WPListDirectory EEWPDirectory[NumberOfWPLists] EEMEM;
WayPoints EEWayPointList[NumberOfWaypoints] EEMEM;
 
 
uint8_t EE_PKTVersion EEMEM = EEpromVersion;
 
 
volatile uint8_t DisplayTimeout;
volatile uint8_t DisplayLanguage;
volatile uint8_t WiTXRXChannel;
volatile uint8_t WiNetworkGroup;
volatile uint8_t WiNetworkMode;
volatile uint8_t WiTXTO;
volatile uint8_t WiUartMTU;
volatile uint8_t LCD_ORIENTATION;
volatile uint8_t LCD_DisplayMode;
volatile uint8_t LCD_Kontrast;
volatile uint8_t LCD_Helligkeit;
volatile uint8_t USBBT;
volatile uint8_t U02SV2;
volatile uint8_t Debug;
volatile uint8_t UseWi; // Wi232 wird genutzt
volatile uint8_t UseBT; // BT wird genutzt
volatile uint8_t WiIsSet; // Wi232 ist initialisiert
volatile uint8_t BTIsSet; // BT ist initialisiert
char bt_pin[bt_pin_length + 1]; // BT Pinnummer
char bt_name[bt_name_length + 1]; // BT Name
 
volatile uint32_t LastLongitude; // Letzte Position
volatile uint32_t LastLatitude;
volatile uint8_t PKT_IdleBeep;
volatile uint8_t PKT_StartInfo;
volatile uint16_t Lipo_UOffset; // Offset für die Lipospannugsmessung
volatile uint8_t PKT_Accutyp; // verwendeter Akkutyp
volatile WayPoints PKTWayPoint; // Waypointdaten für einen Waypoint
volatile WPListDirectory PKTWayPointDirectory; // Inhaltsverzeichnis der Listen
 
 
 
//--------------------------------------------------------------
//
void WriteWiInitFlag(void)
{
WiIsSet = true;
eeprom_write_byte(&EE_WiIsSet, WiIsSet);
 
}
 
 
//--------------------------------------------------------------
//
void WriteBTInitFlag(void)
{
BTIsSet = true;
eeprom_write_byte(&EE_BTIsSet, BTIsSet);
 
}
 
 
//--------------------------------------------------------------
//
void ReadLastPosition(void)
 
{
LastLongitude = eeprom_read_dword(&EE_LastLongitude);
LastLatitude = eeprom_read_dword(&EE_LastLatitude);
}
 
 
//--------------------------------------------------------------
//
void WriteLastPosition(uint32_t ELongitude,uint32_t ELatitude)
 
{
 
eeprom_write_dword(&EE_LastLongitude,ELongitude);
eeprom_write_dword(&EE_LastLatitude,ELatitude);
}
 
 
//--------------------------------------------------------------
//
void ReadParameter (void)
{
if (eeprom_read_byte(&EE_PKTVersion) == EEpromVersion)
 
{
MK_LowBat = eeprom_read_byte (&EE_LowBat);
DisplayTimeout = eeprom_read_byte (&EE_DisplayTimeout);
DisplayLanguage = eeprom_read_byte (&EE_DisplayLanguage);
WiTXRXChannel = eeprom_read_byte (&EE_WiTXRXChannel);
WiNetworkGroup = eeprom_read_byte (&EE_WiNetworkGroup);
WiNetworkMode = eeprom_read_byte (&EE_WiNetworkMode);
WiTXTO = eeprom_read_byte (&EE_WiTXTO);
WiUartMTU = eeprom_read_byte (&EE_WiUartMTU);
LCD_ORIENTATION = eeprom_read_byte (&EE_LCD_Orientation);
LCD_DisplayMode = eeprom_read_byte (&EE_LCD_DisplayMode);
LCD_Kontrast = eeprom_read_byte (&EE_LCD_Kontrast);
LCD_Helligkeit = eeprom_read_byte (&EE_LCD_Helligkeit);
USBBT = eeprom_read_byte (&EE_USBBT);
U02SV2 = eeprom_read_byte (&EE_U02SV2);
Debug = eeprom_read_byte (&EE_Debug);
UseWi = eeprom_read_byte (&EE_UseWi);
UseBT = eeprom_read_byte (&EE_UseBT);
WiIsSet = eeprom_read_byte (&EE_WiIsSet);
BTIsSet = eeprom_read_byte (&EE_BTIsSet);
PKT_IdleBeep = eeprom_read_byte (&EE_PKT_IdleBeep);
PKT_StartInfo = eeprom_read_byte (&EE_PKT_StartInfo);
Lipo_UOffset = eeprom_read_word (&EE_Lipo_UOffset);
PKT_Accutyp = eeprom_read_byte (&EE_PKT_Accutyp);
eeprom_read_block ((void*)&bt_pin, (const void*)&EE_BTPin, bt_pin_length);
eeprom_read_block ((void*)&bt_name, (const void*)&EE_BTName, bt_name_length);
LastLongitude = eeprom_read_dword (&EE_LastLongitude);
LastLatitude = eeprom_read_dword (&EE_LastLatitude);
}
 
else
Delete_EEPROM();
 
}
 
//--------------------------------------------------------------
void Delete_EEPROM(void)
{
// EEPROM auf Default setzen
 
lcd_cls();
lcd_printp_at (0, 0, PSTR(" EEPROM Parameter "), 2);
lcd_printp_at (0, 1, PSTR("werden auf"), 0);
lcd_printp_at (0, 2, PSTR("Standardwerte gesetzt"), 0);
 
MK_LowBat = 137; // 13,7V
DisplayTimeout = 0; // Display immer an
DisplayLanguage = 1; // default englisch
WiTXRXChannel = 1; // Kanal 1 MK Standard
WiNetworkGroup = 66; // Gruppe 66 MK Standard
WiNetworkMode = NetMode_Normal; // MK Standard
WiTXTO = TWaitTime16; // MK Standard
WiUartMTU = UartMTU64; // MK Standard
LCD_ORIENTATION = 0; // normale Ansicht
LCD_DisplayMode = 0; // Normal
LCD_Kontrast = 20; // Kontrast normal
LCD_Helligkeit = 100; // Helligkeit in %
USBBT = 0; // USB Betrieb
U02SV2 = 0; // SV2 (Kabel) Standard
Debug = 0; // kein Debug
UseWi = true; // Wi.232 eingebaut?
UseBT = true; // BT-222 eingebaut?
WiIsSet = false; // Flag für die Initialisierung Wi232
BTIsSet = false; // Flag für die Initialisierung Bluetooth
PKT_IdleBeep = 0; // kein Piepsen bei Inaktivität
PKT_StartInfo = true; // Startnformationen anzeigen
PKT_Accutyp = true; // True = Lipo, False= LiON
Lipo_UOffset = 6000; // Offset für PKT-Lipomessung
LastLongitude = 88199720;
LastLatitude = 522039630;
eeprom_write_dword(&EE_LastLongitude,LastLongitude);
eeprom_write_dword(&EE_LastLatitude,LastLatitude);
 
strcpy_P(bt_pin, PSTR("1234"));
eeprom_write_block ((const void*)&bt_pin, (void*)&EE_BTPin, bt_pin_length);
 
strcpy_P(bt_name, PSTR("PKT Cebra ")); // Wenn Name kürzer als "bt_name_length" mit Leerzeichen auffüllen
eeprom_write_block ((const void*)&bt_name, (void*)&EE_BTName, bt_name_length);
 
eeprom_write_byte(&EE_WiIsSet,WiIsSet);
eeprom_write_byte(&EE_BTIsSet,BTIsSet);
eeprom_write_byte(&EE_PKTVersion,EEpromVersion);
 
WriteParameter();
 
// lcd_printp_at (0, 4, PSTR("Waypoints loeschen"), 0);
// EEWayPointList_Clear();
 
lcd_printp_at (0, 6, PSTR("!!Check Parameter!! "), 0);
lcd_printp_at (18, 7, PSTR("OK"), 0);
BeepTime = 200;
BeepMuster = 0x0080;
do{}
while (!(get_key_short (1 << KEY_ENTER)));
// _delay_ms(500);
//#if defined HWVERSION3_9
// clr_V_On();
//#else
//
// wdt_enable( WDTO_250MS );
// while (1)
// {;}
//#endif
}
 
 
//--------------------------------------------------------------
//
void WriteParameter (void)
{
eeprom_write_byte (&EE_LowBat, MK_LowBat);
eeprom_write_byte (&EE_DisplayTimeout, DisplayTimeout);
eeprom_write_byte (&EE_DisplayLanguage, DisplayLanguage);
eeprom_write_byte (&EE_WiTXRXChannel, WiTXRXChannel);
eeprom_write_byte (&EE_WiNetworkGroup, WiNetworkGroup);
eeprom_write_byte (&EE_WiNetworkMode, WiNetworkMode);
eeprom_write_byte (&EE_WiTXTO, WiTXTO);
eeprom_write_byte (&EE_WiUartMTU, WiUartMTU);
eeprom_write_byte (&EE_LCD_Orientation, LCD_ORIENTATION);
eeprom_write_byte (&EE_LCD_DisplayMode, LCD_DisplayMode);
eeprom_write_byte (&EE_LCD_Kontrast, LCD_Kontrast);
eeprom_write_byte (&EE_LCD_Helligkeit, LCD_Helligkeit);
eeprom_write_byte (&EE_USBBT, USBBT);
eeprom_write_byte (&EE_U02SV2, U02SV2);
eeprom_write_byte (&EE_Debug, Debug);
eeprom_write_byte (&EE_UseWi, UseWi);
eeprom_write_byte (&EE_UseBT, UseBT);
eeprom_write_byte (&EE_WiIsSet, WiIsSet);
eeprom_write_byte (&EE_BTIsSet, BTIsSet);
eeprom_write_byte (&EE_PKT_IdleBeep, PKT_IdleBeep);
eeprom_write_byte (&EE_PKT_StartInfo, PKT_StartInfo);
eeprom_write_word (&EE_Lipo_UOffset,Lipo_UOffset);
eeprom_write_byte (&EE_PKT_Accutyp, PKT_Accutyp);
 
eeprom_write_block ((const void*)&bt_pin, (void*)&EE_BTPin, bt_pin_length);
eeprom_write_block ((const void*)&bt_name, (void*)&EE_BTName, bt_name_length);
 
}
 
 
 
 
//--------------------------------------------------------------
//
void EEWayPointList_Clear(void) // löschen der Waypointliste im EEProm
{
uint8_t i;
PKTWayPoint.Waypoint.Position.Latitude = 0;
PKTWayPoint.Waypoint.Position.Longitude = 0;
PKTWayPoint.Waypoint.Position.Altitude = 0;
PKTWayPoint.Waypoint.Heading = 361;
 
for(i = 0; i < MAX_WPLIST_LEN; i++)
{
PKTWayPointDirectory.WPList.WPDirectory[i] = 0;
}
 
for(i = 0; i < NumberOfWaypoints; i++)
{
lcd_printp (PSTR("."), 0);
eeprom_write_byte (&EEWayPointList[i].WPIndex, i);
eeprom_write_byte (&EEWayPointList[i].Waypoint.Position.Status, INVALID);
eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Position.Latitude, (void*)&EEWayPointList[i].Waypoint.Position.Latitude, sizeof(EEWayPointList[i].Waypoint.Position.Latitude));
eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Position.Longitude, (void*)&EEWayPointList[i].Waypoint.Position.Longitude, sizeof(EEWayPointList[i].Waypoint.Position.Longitude));
eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Position.Altitude, (void*)&EEWayPointList[i].Waypoint.Position.Altitude, sizeof(EEWayPointList[i].Waypoint.Position.Altitude));
eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Heading, (void*)&EEWayPointList[i].Waypoint.Heading, sizeof(EEWayPointList[i].Waypoint.Heading));
 
eeprom_write_byte (&EEWayPointList[i].Waypoint.ToleranceRadius, 0); // in meters, if the MK is within that range around the target, then the next target is triggered
eeprom_write_byte (&EEWayPointList[i].Waypoint.HoldTime, 0); // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before the next WP is triggered
eeprom_write_byte (&EEWayPointList[i].Waypoint.Type, POINT_TYPE_INVALID);
eeprom_write_byte (&EEWayPointList[i].Waypoint.Event_Flag, 0); // future implementation
eeprom_write_byte (&EEWayPointList[i].Waypoint.AltitudeRate, 0); // no change of setpoint
}
 
for(i = 0; i < NumberOfWPLists; i++)
{
lcd_printp (PSTR("."), 0);
eeprom_write_byte (&EEWPDirectory[i].WPList.WPListnumber, i);
eeprom_write_byte (&EEWPDirectory[i].WPList.WPListAktiv, false);
eeprom_write_byte (&EEWPDirectory[i].WPList.POI_CAM_NICK_CTR, 0);
eeprom_write_byte (&EEWPDirectory[i].WPList.UsePOI, 0);
eeprom_write_block ((const void*)&PKTWayPointDirectory.WPList.WPDirectory, (void*)&EEWPDirectory[i].WPList.WPDirectory, sizeof(EEWPDirectory[i].WPList.WPDirectory));
 
}
lcd_printp (PSTR("\r\n"), 0);
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/eeprom.h
0,0 → 1,148
/*****************************************************************************
* 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 _EEPROM_H
#define _EEPROM_H
 
#include <stdbool.h>
#include "mk-data-structs.h"
#include "connect.h"
 
 
 
 
//[General]
//FileVersion = 2
//NumberOfWaypoints = 15
//UsePOI = 0
//POI_CAM_NICK_CTRL = 0
 
//[POI]
//Altitude = 1
//Latitude = 46.7140763
//Longitude = 19.2507334
 
//[Waypoint1]
//Latitude = 46.7145686
//Longitude = 19.2515702
//Radius = 10
//Altitude = 15
//ClimbRate = 0
//DelayTime = 4
//WP_Event_Channel_Value = 96
//Heading = 180
 
 
#define EEpromVersion 0x58 //Summe aus Soft.vers. ohne erste Ziffer zB 3.5.5 = 55
 
#define NumberOfWaypoints 55 //Anzahl der Waypoints in der EEPromliste
#define NumberOfWPLists 5 //Anzahl WP Listen im PKT
#define bt_pin_length 4
#define bt_name_length 10
 
 
#define POINT_TYPE_INVALID 255
#define POINT_TYPE_WP 0
#define POINT_TYPE_POI 1
#define INVALID 0x00
#define MAX_WPLIST_LEN 31
 
 
 
 
 
typedef struct
{
uint8_t WPIndex; // Index in der EEpromliste
Point_t Waypoint; // Waypoint
} WayPoints;
 
typedef struct
{
uint8_t WPListnumber; // Nummer der WP Liste im PKT
uint8_t WPListAktiv; // Liste aktiv
uint8_t WPDirectory[31]; // Enthält die Indexe der Waypoints im EEPROM
uint8_t UsePOI;
uint8_t POI_CAM_NICK_CTR;
 
} WPListHeader;
 
typedef struct
{
WPListHeader WPList; // Waypointliste im PKT
} WPListDirectory;
 
 
 
 
 
 
void ReadParameter (void);
void WriteParameter (void);
void ReadLastPosition(void);
void WriteLastPosition(uint32_t ELongitude,uint32_t ELatitude);
void WriteWiInitFlag(void);
void WriteBTInitFlag(void);
void Delete_EEPROM(void);
void EEWayPointList_Clear(void); // l�schen der Waypointliste im EEProm
 
 
uint8_t MK_LowBat;
extern volatile uint8_t LCD_ORIENTATION;
extern volatile uint8_t LCD_DisplayMode;
extern volatile uint8_t LCD_Kontrast;
extern volatile uint8_t LCD_Helligkeit;
extern volatile uint8_t DisplayTimeout;
extern volatile uint8_t DisplayLanguage;
extern volatile uint8_t WiTXRXChannel;
extern volatile uint8_t WiNetworkGroup;
extern volatile uint8_t WiNetworkMode;
extern volatile uint8_t WiTXTO;
extern volatile uint8_t WiUartMTU;
extern volatile uint8_t USBBT;
extern volatile uint8_t U02SV2;
extern volatile uint8_t Debug;
extern volatile uint8_t UseWi; // Wi232 wird genutzt
extern volatile uint8_t UseBT; // BT wird genutzt
extern volatile uint8_t WiIsSet; // Wi232 ist initialisiert
extern volatile uint8_t BTIsSet; // BT ist initialisiert
extern char bt_pin[bt_pin_length + 1]; // BT Pinnummer
extern char bt_name[bt_name_length + 1]; // BT Name
extern volatile uint32_t LastLongitude;
extern volatile uint32_t LastLatitude;
extern volatile uint8_t PKT_IdleBeep;
extern volatile uint8_t PKT_StartInfo;
extern volatile uint16_t Lipo_UOffset; // Offset für die Lipospannugsmessung
extern volatile uint8_t PKT_Accutyp;
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/error.c
0,0 → 1,206
/*
___ ___ ___ ___ _____
/ /\ /__/\ / /\ /__/\ / /::\
/ /::\ | |::\ / /::\ \ \:\ / /:/\:\
/ /:/\:\ ___ ___ | |:|:\ / /:/\:\ \ \:\ / /:/ \:\
/ /:/~/::\ /__/\ / /\ __|__|:|\:\ / /:/ \:\ _____\__\:\ /__/:/ \__\:|
/__/:/ /:/\:\ \ \:\ / /:/ /__/::::| \:\ /__/:/ \__\:\ /__/::::::::\ \ \:\ / /:/
\ \:\/:/__\/ \ \:\ /:/ \ \:\~~\__\/ \ \:\ / /:/ \ \:\~~\~~\/ \ \:\ /:/
\ \::/ \ \:\/:/ \ \:\ \ \:\ /:/ \ \:\ ~~~ \ \:\/:/
\ \:\ \ \::/ \ \:\ \ \:\/:/ \ \:\ \ \::/
\ \:\ \__\/ \ \:\ \ \::/ \ \:\ \__\/
\__\/ \__\/ \__\/ \__\/
___ ___ ___ ___ ___ ___
/ /\ / /\ /__/\ /__/\ / /\ /__/\
/ /:/ / /::\ | |::\ | |::\ / /::\ \ \:\
/ /:/ / /:/\:\ | |:|:\ | |:|:\ / /:/\:\ \ \:\
/ /:/ ___ / /:/ \:\ __|__|:|\:\ __|__|:|\:\ / /:/ \:\ _____\__\:\
/__/:/ / /\ /__/:/ \__\:\ /__/::::| \:\ /__/::::| \:\ /__/:/ \__\:\ /__/::::::::\
\ \:\ / /:/ \ \:\ / /:/ \ \:\~~\__\/ \ \:\~~\__\/ \ \:\ / /:/ \ \:\~~\~~\/
\ \:\ /:/ \ \:\ /:/ \ \:\ \ \:\ \ \:\ /:/ \ \:\ ~~~
\ \:\/:/ \ \:\/:/ \ \:\ \ \:\ \ \:\/:/ \ \:\
\ \::/ \ \::/ \ \:\ \ \:\ \ \::/ \ \:\
\__\/ \__\/ \__\/ \__\/ \__\/ \__\/
 
 
**
* Error handling functions
*/
 
#include <stdbool.h>
//#include "ftdi.h"
 
#include <avr/pgmspace.h>
#include "error_driver.h"
 
//--------------------------------------------------------------
inline void _send_msg(const char *msg)
{
for (uint8_t i=0; i<255 && msg[i]!='\0'; i++)
{
error_driver_write_c(msg[i]);
}
error_driver_write_c('\n');
}
 
 
//--------------------------------------------------------------
void send_pgm(const prog_char *msg)
{
uint8_t myByte;
myByte = pgm_read_byte(msg);
for(int i = 1; myByte != '\0'; i++)
{
error_driver_write_c(myByte);
myByte = pgm_read_byte(msg+i);
}
}
 
#ifdef DEBUG
 
 
//--------------------------------------------------------------
void error_init(void)
{
error_driver_Init();
}
 
 
//--------------------------------------------------------------
void error_putc(const char c)
{
error_driver_write_c(c);
}
 
 
//--------------------------------------------------------------
void assert (bool condition, const char *msg)
{
if (!condition)
{
send_pgm(PSTR("ASS:"));
_send_msg(msg);
}
}
 
 
//--------------------------------------------------------------
void info (const char *msg)
{
send_pgm(PSTR("INF:"));
_send_msg(msg);
}
 
 
//--------------------------------------------------------------
void warn (const char *msg)
{
send_pgm(PSTR("WARN:"));
_send_msg(msg);
}
 
 
//--------------------------------------------------------------
void debug (const char *msg)
{
send_pgm(PSTR("DBG:"));
_send_msg(msg);
}
 
 
//--------------------------------------------------------------
void Error (const char *msg)
{
send_pgm(PSTR("ERR:"));
_send_msg(msg);
}
#endif
 
#ifdef DEBUG
 
//--------------------------------------------------------------
void assert_pgm(bool condition, const prog_char *msg)
{
if (condition) {
send_pgm(PSTR("ASS:"));
send_pgm(msg);
error_driver_write_c('\n');
}
}
 
 
//--------------------------------------------------------------
void info_pgm(const prog_char *msg)
{
send_pgm(PSTR("INF:"));
send_pgm(msg);
error_driver_write_c('\n');
}
 
 
//--------------------------------------------------------------
void warn_pgm(const prog_char *msg)
{
send_pgm(PSTR("WARN:"));
send_pgm(msg);
error_driver_write_c('\n');
}
 
 
//--------------------------------------------------------------
void error_pgm(const prog_char *msg)
{
send_pgm(PSTR("ERR:"));
send_pgm(msg);
error_driver_write_c('\n');
}
 
 
//--------------------------------------------------------------
void debug_pgm(const prog_char *msg)
{
send_pgm(PSTR("DBG:"));
send_pgm(msg);
error_driver_write_c('\n');
}
 
 
//--------------------------------------------------------------
void print_hex(uint8_t num)
{
if (num<10)
error_putc(num+48);
else
{
switch (num)
{
case 10:
error_putc('A'); break;
case 11:
error_putc('B'); break;
case 12:
error_putc('C'); break;
case 13:
error_putc('D'); break;
case 14:
error_putc('E'); break;
case 15:
error_putc('F'); break;
default:
error_putc('#'); break;
}
}
}
 
 
//--------------------------------------------------------------
void byte_to_hex(uint8_t byte)
{
uint8_t b2 = (byte & 0x0F);
uint8_t b1 = ((byte & 0xF0)>>4);
print_hex(b1);
print_hex(b2);
}
 
#endif
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/error.h
0,0 → 1,75
/*
___ ___ ___ ___ _____
/ /\ /__/\ / /\ /__/\ / /::\
/ /::\ | |::\ / /::\ \ \:\ / /:/\:\
/ /:/\:\ ___ ___ | |:|:\ / /:/\:\ \ \:\ / /:/ \:\
/ /:/~/::\ /__/\ / /\ __|__|:|\:\ / /:/ \:\ _____\__\:\ /__/:/ \__\:|
/__/:/ /:/\:\ \ \:\ / /:/ /__/::::| \:\ /__/:/ \__\:\ /__/::::::::\ \ \:\ / /:/
\ \:\/:/__\/ \ \:\ /:/ \ \:\~~\__\/ \ \:\ / /:/ \ \:\~~\~~\/ \ \:\ /:/
\ \::/ \ \:\/:/ \ \:\ \ \:\ /:/ \ \:\ ~~~ \ \:\/:/
\ \:\ \ \::/ \ \:\ \ \:\/:/ \ \:\ \ \::/
\ \:\ \__\/ \ \:\ \ \::/ \ \:\ \__\/
\__\/ \__\/ \__\/ \__\/
___ ___ ___ ___ ___ ___
/ /\ / /\ /__/\ /__/\ / /\ /__/\
/ /:/ / /::\ | |::\ | |::\ / /::\ \ \:\
/ /:/ / /:/\:\ | |:|:\ | |:|:\ / /:/\:\ \ \:\
/ /:/ ___ / /:/ \:\ __|__|:|\:\ __|__|:|\:\ / /:/ \:\ _____\__\:\
/__/:/ / /\ /__/:/ \__\:\ /__/::::| \:\ /__/::::| \:\ /__/:/ \__\:\ /__/::::::::\
\ \:\ / /:/ \ \:\ / /:/ \ \:\~~\__\/ \ \:\~~\__\/ \ \:\ / /:/ \ \:\~~\~~\/
\ \:\ /:/ \ \:\ /:/ \ \:\ \ \:\ \ \:\ /:/ \ \:\ ~~~
\ \:\/:/ \ \:\/:/ \ \:\ \ \:\ \ \:\/:/ \ \:\
\ \::/ \ \::/ \ \:\ \ \:\ \ \::/ \ \:\
\__\/ \__\/ \__\/ \__\/ \__\/ \__\/
 
 
*
* Error handling functions.
*/
 
#ifndef __ERROR__
#define __ERROR__
 
#include <avr/pgmspace.h>
#include <stdbool.h>
#include "main.h"
 
 
void error_init(void);
 
void error_putc(const char c);
 
void assert (bool condition, const char *msg);
void info (const char *msg);
void warn(const char *msg);
void debug(const char *msg);
void Error(const char *msg);
 
void assert_pgm(bool condition, const prog_char *msg);
void info_pgm (const prog_char *msg);
void warn_pgm(const prog_char *msg);
void debug_pgm(const prog_char *msg);
void error_pgm(const prog_char *msg);
 
void byte_to_hex(uint8_t byte);
 
#else
 
#define error_init() {}
 
 
#define error_putc(c) {}
 
#define assert(cond, msg) {}
#define info(msg) {}
#define warn(msg) {}
#define debug(msg) {}
#define error(msg) {}
 
#define assert_pgm(cond, msg) {}
#define info_pgm(msg) {}
#define warn_pgm(msg) {}
#define debug_pgm(msg) {}
#define error_pgm(msg) {}
#define byte_to_hex(byte) {}
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/error_driver.c
0,0 → 1,21
#include "cpu.h"
#include "error_driver.h"
#include "main.h"
 
#ifdef DEBUG
 
#include "usart.h"
#include "uart1.h"
 
 
void error_driver_write_c(uint8_t c)
{
USART_putc(c);
}
 
void error_driver_Init(void)
{
// USART_Init(UART_BAUD_SELECT(USART_BAUD,F_CPU));
}
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/error_driver.h
0,0 → 1,22
/*
* Functions to write error message to FTDI or USART
*/
 
#ifndef __ERROR_DRIVER__
#define __ERROR_DRIVER__
 
#include <avr/io.h>
#include "main.h"
 
 
 
#ifdef DEBUG
extern void error_driver_write_c(uint8_t c);
extern void error_driver_Init(void);
#else
#define error_driver_write_c(c) {}
#define error_driver_init() {}
#endif
 
 
#endif //__ERROR_DRIVER__
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/fifo.c
0,0 → 1,114
/**
* a simple Fifo
* @file fifo.c
* @author Pascal Schnurr
*/
 
#include "fifo.h"
 
//--------------------------------------------------------------
void fifo_init (fifo_t * fifo, uint8_t * buffer, uint16_t size)
{
fifo->size = size;
fifo->buffer = buffer;
fifo->head = 0;
fifo->count = 0;
}
 
//--------------------------------------------------------------
bool fifo_is_empty (const fifo_t * fifo)
{
return (fifo->count == 0);
}
 
//--------------------------------------------------------------
bool fifo_is_full (const fifo_t * fifo)
{
return (fifo->size - fifo->count == 0);
}
 
//--------------------------------------------------------------
bool fifo_read (fifo_t * fifo, char *data)
{
if (fifo_is_empty (fifo))
return false;
 
uint8_t *head = fifo->buffer + fifo->head;
 
*data = (char) * head;
 
fifo->head = ( (fifo->head + 1) % fifo->size);
 
fifo->count--;
 
return true;
}
 
//--------------------------------------------------------------
bool fifo_write (fifo_t * fifo, const char data)
{
if (fifo_is_full (fifo))
return false;
 
uint8_t *end = fifo->buffer + ( (fifo->head + fifo->count) % fifo->size);
 
*end = (uint8_t) data;
 
fifo->count++;
 
return true;
}
 
//--------------------------------------------------------------
bool fifo_clear (fifo_t * fifo)
{
fifo->count = 0;
fifo->head = 0;
return true;
}
 
//--------------------------------------------------------------
static bool fifo_cmp_pgm_at (fifo_t * fifo, const prog_char * pgm, const uint16_t index)
{
uint16_t i;
uint8_t fifo_byte;
uint8_t pgm_byte;
 
for (i = 0; pgm_read_byte (pgm + i) != 0; i++)
{
if (fifo->count <= (i + index))
return false;
 
pgm_byte = pgm_read_byte (pgm + i);
 
fifo_byte = * (fifo->buffer + ( (fifo->head + i + index) % fifo->size));
 
if (fifo_byte != pgm_byte)
return false;
}
 
// We found the string, lets move the pointer
fifo->head = ( (fifo->head + i + index) % fifo->size);
 
fifo->count -= (i + index);
 
return true;
}
 
//--------------------------------------------------------------
bool fifo_cmp_pgm (fifo_t * fifo, const prog_char * pgm)
{
return fifo_cmp_pgm_at (fifo, pgm, 0);
}
 
//--------------------------------------------------------------
bool fifo_strstr_pgm (fifo_t * fifo, const prog_char * pgm)
{
for (uint16_t i = 0; i < fifo->count; i++)
{
if (fifo_cmp_pgm_at (fifo, pgm, i))
return true;
}
 
return false;
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/fifo.h
0,0 → 1,83
/**
* a simple Fifo
* @file fifo.h
* @author Pascal Schnurr
*/
 
#include <avr/pgmspace.h>
#include <stdbool.h>
#ifndef _FIFO_H_
#define _FIFO_H_
 
/**
*fifo data structure all vital fifo information
*/
typedef struct
{
uint16_t count; /**< current number of elements */
uint16_t head; /**< position of the head element */
uint16_t size; /**< size equals max number of entrys*/
uint8_t* buffer; /**< pointer to memory area where the fifo is to be saved */
} fifo_t;
 
 
/** \brief initialize of a fifo
* sets all the information in your given fifo structure
* @param fifo pointer to an allocated fifo_t structure
* @param buffer pointer to an a allocated memory space for the fifo of size = sizeof(uint8_t) * size
* @param size max number of entrys the fifo will hold
*/
void fifo_init (fifo_t *fifo, uint8_t *buffer, uint16_t size);
 
/** \brief checks if fifo is empty
* @param fifo pointer to your initialized fifo_t structure
* @return true if empty otherwise false
*/
bool fifo_is_empty (const fifo_t *fifo);
 
/** \brief checks if fifo is full
* @param fifo pointer to your initialized fifo_t structure
* @return true if full otherwise false
*/
bool fifo_is_full (const fifo_t *fifo);
 
/** \brief clears the fifo
* resets your fifo structure to 0 elements
* @param fifo pointer to your initialized fifo_t structure
* @return always true (never fails)
*/
bool fifo_clear (fifo_t *fifo);
 
/** \brief reads head of fifo
* reads the first element and removes it
* @param fifo pointer to your initialized fifo_t structure
* @return false if fifo is empty false otherwise
*/
bool fifo_read (fifo_t *fifo, char *data);
 
/** \brief inserts a char into the fifo
* adds a char to the end of the fifo
* @param fifo pointer to your initialized fifo_t structure
* @param data the char data to be inserted
* @return false if fifo is full true otherwise
*/
bool fifo_write (fifo_t *fifo, const char data);
 
/** \brief compares first elements with prog_char string
* if pgm equals the first elements of the fifo these elements are removed
* @param fifo pointer to your initialized fifo_t structure
* @param pgm a prog_char string for comparison
* @return true if pgm is equal to the first entrys in the fifo, false otherwise
*/
bool fifo_cmp_pgm (fifo_t* fifo, const prog_char* pgm);
 
/** \brief searches a string in the whole fifo
* starts at the beginning and searches for the pgm string in the fifo,
* if they are found previous entrys and the string are removed from the fifo
* @param fifo pointer to your initialized fifo_t structure
* @param pgm a prog_char with the search string
* @return true if found, false otherwise
*/
bool fifo_strstr_pgm (fifo_t *fifo, const prog_char *pgm);
 
#endif /* _FIFO_H_ */
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/font8x6.c
0,0 → 1,171
/*****************************************************************************
* 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] =
{
{ 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 'ß'
{ 0x00,0x00,0x00,0x00,0x00,0x00 }, // ASCII - 8 08
{ 0x00,0x00,0x00,0x00,0x00,0x00 }, // ASCII - 9 09
{ 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/GPL_PKT_V3_5_8b_FC086/font8x6.h
0,0 → 1,29
/*****************************************************************************
* 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];
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/gps.c
0,0 → 1,364
/*****************************************************************************
* 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.h"
#include "timer.h"
#include "usart.h"
 
#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);
write_ndigit_number_u (col+4, line, UBX_buffer[12 + 12*i], 2, 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]);
 
uint16_t acc = (uint16_t)join_4_bytes(&UBX_buffer[24]);
write_ndigit_number_u (11, 2, acc, 5, 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);
lcd_printp_at (13,3, PSTR("."), 0);
write_ndigit_number_u (14, 3, (pdop % 100),2, 1);
}
 
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);
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);
lcd_printp_at (12,5, PSTR("."), 0);
write_ndigit_number_u (13, 5, (uint16_t)((lon/1000) % 10000), 4, 1);
write_ndigit_number_u (17, 5, (uint16_t)((lon/10) % 100), 2, 1);
 
uint32_t lat = join_4_bytes(&UBX_buffer[8]);
write_ndigit_number_u (10, 6, (uint16_t)(lat/10000000), 2, 0);
lcd_printp_at (12,6, PSTR("."), 0);
write_ndigit_number_u (13, 6, (uint16_t)((lat/1000) % 10000), 4, 1);
write_ndigit_number_u (17, 6, (uint16_t)((lat/10) % 100), 2, 1);
 
uint16_t height = (uint16_t)(join_4_bytes(&UBX_buffer[16])/1000);
write_ndigit_number_u (11, 7, height, 4, 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;
}
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/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/GPL_PKT_V3_5_8b_FC086/servo.c
0,0 → 1,156
/*****************************************************************************
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de *
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net *
* Copyright (C) 2011 Harald Bongartz *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
* *
* Credits to: *
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN *
* http://www.mikrokopter.de *
* Gregor "killagreg" Stobrawa for his version of the MK code *
* Thomas Kaiser "thkais" for the original project. See *
* http://www.ft-fanpage.de/mikrokopter/ *
* http://forum.mikrokopter.de/topic-4061-1.html *
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code *
* http://www.mylifesucks.de/oss/c-osd/ *
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility*
*****************************************************************************/
 
 
#include "cpu.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
 
#include "lcd.h"
#include "timer.h"
#include "servo.h"
#include "messages.h"
 
#define SERVO_CORRECT 3.125
 
 
//--------------------------------------------------------------
//
void servo_test (void)
{
 
uint8_t chg = 0;
uint8_t Pos = 150; // 1,5mS
 
OCR1A = 150 * SERVO_CORRECT; // Servomitte
 
lcd_cls ();
 
lcd_printp (PSTR(" Servo Tester "), 2);
lcd_printp_at (7, 5, PSTR("%"), 0);
lcd_printp_at (16, 5, PSTR("mS"), 0);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_3), 0);
lcd_puts_at(0, 7, strGet(KEYLINE3), 0);
lcd_printp_at (18, 7, PSTR("\x19O\x18"), 0);
 
lcd_rect(3, 23, 120, 8, 1); // +-150% Rahmen
lcd_line(23,23,23,31,1); // -100%
lcd_line(43,23,43,31,1); // -50%
lcd_frect(61, 23, 3, 8, 1); // 0%
lcd_line(83,23,83,31,1); // +50%
lcd_line(103,23,103,31,1); // +100%
 
write_ndigit_number_u (4, 5, 0, 3, 0); // Pulse width in %
write_ndigit_number_u_100th(12, 5, 150, 3, 0); // Pulse width in ms
 
do
{
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 3)) && (Pos < 225))
{
if (Pos < 150)
lcd_frect ((63 - ((150 - Pos) * 0.8)), 24, 1, 6, 0);
 
Pos++;
if (Pos == 75 || Pos == 100 || Pos == 125 || Pos == 150 || Pos == 175 || Pos == 200 || Pos == 225)
{
BeepTime = 200;
BeepMuster = 0x0080;
}
 
if (Pos >= 225)
Pos = 225;
 
chg++;
}
else if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 3)) && (Pos > 75))
{
if (Pos > 150)
lcd_frect ((((Pos - 150) * 0.8) + 63), 24, ((Pos - 150) * 0.8), 6, 0);
 
Pos--;
if (Pos == 75 || Pos == 100 || Pos == 125 || Pos == 150 || Pos == 175 || Pos == 200 || Pos == 225)
{
BeepTime = 200;
BeepMuster = 0x0080;
}
 
if (Pos <= 75)
Pos = 75;
 
chg++;
}
else if (get_key_press (1 << KEY_ENTER))
{
lcd_frect (4, 24, 118, 6, 0); // Balken löschen
lcd_frect(61, 23, 3, 8, 1); // 0%
Pos = 150;
BeepTime = 200;
BeepMuster = 0x0080;
chg++;
}
 
if (chg)
{
chg = 0;
 
if (Pos >= 150)
{
lcd_frect (63, 24, ((Pos - 150) * 0.8), 6, 1);
write_ndigit_number_u (4, 5, ((Pos - 150) * 2), 3, 0); // Pulse width in %
lcd_frect(62, 23, 2, 8, 1); // 0%
}
else
{
lcd_frect (63 - ((150 - Pos) * 0.8), 24, ((150 - Pos) * 0.8), 6, 1);
write_ndigit_number_u (4, 5, ((150 - Pos) * 2), 3, 0); // Pulse width in %
lcd_frect(61, 23, 2, 8, 1); // 0%
}
write_ndigit_number_u_100th(12, 5, Pos, 3, 0); // Pulse width in ms
 
lcd_line(3, 23,3, 31,1); // -150%
lcd_line(23, 23,23, 31,1); // -100%
lcd_line(43, 23,43, 31,1); // -50%
lcd_line(83, 23,83, 31,1); // +50%
lcd_line(103,23,103,31,1); // +100%
lcd_line(123,23,123,31,1); // +150%
 
 
OCR1A = Pos * SERVO_CORRECT; // Servostellung
 
}
}
while (!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/servo.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 _SERVO_H
#define _SERVO_H
 
void servo_test (void);
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/setup.c
0,0 → 1,1969
/*****************************************************************************
* 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 <util/delay.h>
#include "main.h"
#include "setup.h"
#include "lcd.h"
#include "eeprom.h"
#include "timer.h"
#include "menu.h"
#include "Wi232.h"
#include "bluetooth.h"
#include "connect.h"
#include "lipo.h"
#include "messages.h"
#include "eeprom.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;
uint8_t Pre;
uint16_t Pre16;
char EditString[21];
uint8_t bt_name_len;
 
 
//--------------------------------------------------------------
#define ITEMS_PKT 9
 
prog_char param_menuitems_pkt[ITEMS_PKT][NUM_LANG][18]= // zeilen,zeichen+1
// German, English, French, Dutch
{
{"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"},
{"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 "},
};
 
#define ITEMS_LCD 7
 
prog_char param_menuitems_lcd[ITEMS_LCD][NUM_LANG][18]= // zeilen,zeichen+1
// German, English, French, Dutch
{
{"Infos beim Start ","info at startup ","Infor. sur lancer","info bij opstart "},
{"Sprache ","language ","Langue ","taal "},
{"Licht aus nach...","light off after ","Lumiere au bout ","licht uit na "},
{"Helligkeit ","brightness ","luminosite ","helderheid "},
{"Kontrast ","contrast ","contraste ","contrast "},
{"Normal/Invers ","normal/inverted ","Normal / inverse ","Normal/inverted "},
{"Orientierung ","orientation ","orientation ","orientatie "},
 
};
 
#define ITEMS_WI 8
 
prog_char param_menuitems_wi[ITEMS_WI][NUM_LANG][18]= // zeilen,zeichen+1
// German, English, French, Dutch
{
{"Modul eingebaut? ","module built in? ","Module installé ","Module geinstal.?"},
{"TX/RX Kanal ","TX/RX Channel ","TX/RX Channel ","TX/RX Channel "},
{"NetW. Gruppe ","NetW. Group ","NetW. Group ","NetW. Group "},
{"NetW. Mode ","NetW. Mode ","NetW. Mode ","NetW. Mode "},
{"TX Timeout ","TX Timeout ","TX Timeout ","TX Timeout "},
{"TX MTU ","TX MTU ","TX MTU ","TX MTU "},
{"Initialisieren ","initialize ","initialiser ","Initialize "},
{"Konfig. mit PC ","config. with PC ","Config. avec PC ","Config. met PC "},
};
 
 
#define ITEMS_BT 5
 
prog_char param_menuitems_bt[ITEMS_BT][NUM_LANG][18]= // zeilen,zeichen+1
// German, English, French, Dutch
{
{"Modul eingebaut? ","module built in? ","Module installé ","module geïnstall?"},
{"Name ","name ","Nom ","Naam "},
{"Pin ","pin ","Pin ","Pin "},
{"Initialisieren ","initialize ","initialiser ","Initialize "},
{"Konfig. mit PC ","config. with PC ","Config. avec PC ","Config. met PC "},
};
 
#define ITEMS_Accu 2
 
prog_char param_menuitems_Accu[ITEMS_Accu][NUM_LANG][18]= // zeilen,zeichen+1
// German, English, French, Dutch
{
{"PKT-Akkutyp ","PKT-Accutyp ","PKT-Type de batt.","PKT-batterij type"},
{"PKT Akku Messung ","PKT AccuMeasure ","batt. de mesure ","PKT batt. meting "},
};
 
//--------------------------------------------------------------
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);
 
}
 
 
//--------------------------------------------------------------
uint8_t Edit_Int10th_Value(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text)
{
Pre = Value;
lcd_cls();
// lcd_printp_at (0, 2, Text, 0);
lcd_puts_at(0, 2, strGet(Text), 0);
write_ndigit_number_u_10th (16, 2,Value, 3, 0);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 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), 3)) && (Value < max))
{
edit = 1;
Value++;
write_ndigit_number_u_10th (16, 2,Value, 3, 0);
}
 
if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 3)) && (Value > min))
{
edit = 1;
Value--;
write_ndigit_number_u_10th (16, 2,Value, 3, 0);
}
 
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 Edit_Int_Value(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text)
{
lcd_cls();
// lcd_printp_at (0, 2, Text, 0);
lcd_puts_at(0, 2, strGet(Text), 0);
Pre = Value;
write_ndigit_number_u (16, 2, Value, 3, 0);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 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))
{
edit = 1;
Value++;
write_ndigit_number_u (16, 2,Value, 3, 0);
}
 
if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 2)) && (Value > min))
{
edit = 1;
Value--;
write_ndigit_number_u (16, 2,Value, 3, 0);
}
 
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;
}
}
#if defined HWVERSION3_9 ||HWVERSION1_3W
//--------------------------------------------------------------
uint8_t ChangeWi_SV2(uint8_t Value)
{
Pre = Value;
lcd_cls();
// lcd_printp_at (0, 1, PSTR("Verbinde das PKT mit"), 0);
// lcd_printp_at (0, 2, PSTR("dem MK über:"), 0);
lcd_puts_at(0, 1, strGet(CONNECT1), 0);
lcd_puts_at(0, 2, strGet(CONNECT2), 0);
 
if(UseWi == false)
{
// lcd_printp_at (0, 0, PSTR("Verbinde das PKT mit "), 0);
// lcd_printp_at (0, 1, PSTR("dem MK über: Kabel, "), 0);
// lcd_printp_at (0, 2, PSTR("da kein Wi.232 Modul "), 0);
// lcd_printp_at (0, 3, PSTR("eingebaut ist. "), 0);
// lcd_printp_at (0, 4, PSTR("Wenn doch, dann bitte"), 0);
// lcd_printp_at (0, 5, PSTR("das Modul zuerst im "), 0);
// lcd_printp_at (0, 6, PSTR("Setupmenü aktivieren."), 0);
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(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;
}
 
#endif
//--------------------------------------------------------------
uint8_t Edit_Wi_NetMode_Value(uint8_t Value)
{
Pre = Value;
lcd_cls();
// lcd_printp_at (0, 2, PSTR("Wi NetW. Mode:"), 0);
lcd_puts_at(0, 2, strGet(WINETWM), 0);
 
switch (Value)
{
case 0x0 :lcd_puts_at(15, 2, strGet(SLAVE), 0);//lcd_printp_at (15, 2, PSTR("Slave "), 0);
break;
case 0x1 :lcd_puts_at(15, 2, strGet(NORMAL), 0);//lcd_printp_at (15, 2, PSTR("Normal"), 0);
break;
break;
}
 
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
 
do
{
if ((get_key_press (1 << KEY_PLUS)) && (Value == 0))
{
edit = 1;
Value = NetMode_Normal;
// lcd_printp_at (15, 2, PSTR("Normal"), 0);
lcd_puts_at(15, 2, strGet(NORMAL), 0);
 
}
 
if ((get_key_press (1 << KEY_MINUS)) && (Value == 1))
{
edit = 1;
Value = NetMode_Slave;
// lcd_printp_at (15, 2, PSTR("Slave "), 0);
lcd_puts_at(15, 2, strGet(SLAVE), 0);
}
 
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 Edit_StartInfo(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text)
 
{
Pre = Value;
lcd_cls();
// lcd_printp_at (0, 2,Text, 0);
lcd_puts_at(0, 2, strGet(Text), 0);
 
switch (Value)
{
case false :lcd_puts_at(17, 2, strGet(OFF), 0);//lcd_printp_at (17, 2, PSTR("Aus"), 0);
break;
case true :lcd_puts_at(17, 2, strGet(ON), 0);//cd_printp_at (17, 2, PSTR("Ein"), 0);
break;
break;
}
 
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
 
do
{
if ((get_key_press (1 << KEY_PLUS)) && (Value == 0))
{
Value = 1;
// lcd_printp_at (17, 2, PSTR("Ein"), 0);
lcd_puts_at(17, 2, strGet(ON), 0);
}
 
if ((get_key_press (1 << KEY_MINUS)) && (Value == 1))
{
Value = 0;
// lcd_printp_at (17, 2, PSTR("Aus"), 0);
lcd_puts_at(17, 2, strGet(OFF), 0);
}
 
if (get_key_press (1 << KEY_ENTER))
{
edit = 1;
 
PKT_StartInfo = Value;
WriteParameter();
 
return Value;
}
}
 
while (!get_key_press (1 << KEY_ESC));
{
get_key_press(KEY_ALL);
edit = 0;
PKT_StartInfo = Pre;
return Pre;
}
 
}
 
//--------------------------------------------------------------
uint8_t Edit_YesNo(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text)
 
{
Pre = Value;
lcd_cls();
// lcd_printp_at (0, 2,Text, 0);
lcd_puts_at(0, 2, strGet(Text), 0);
 
switch (Value)
{
case false :lcd_puts_at(17, 2, strGet(NOO), 0);//lcd_printp_at (17, 2, PSTR("Aus"), 0);
break;
case true :lcd_puts_at(17, 2, strGet(YES), 0);//cd_printp_at (17, 2, PSTR("Ein"), 0);
break;
break;
}
 
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
 
do
{
if ((get_key_press (1 << KEY_PLUS)) && (Value == 0))
{
Value = 1;
// lcd_printp_at (17, 2, PSTR("Ein"), 0);
lcd_puts_at(17, 2, strGet(YES), 0);
}
 
if ((get_key_press (1 << KEY_MINUS)) && (Value == 1))
{
Value = 0;
// lcd_printp_at (17, 2, PSTR("Aus"), 0);
lcd_puts_at(17, 2, strGet(NOO), 0);
}
 
if (get_key_press (1 << KEY_ENTER))
{
edit = 1;
 
// PKT_StartInfo = Value;
// WriteParameter();
 
return Value;
}
}
 
while (!get_key_press (1 << KEY_ESC));
{
get_key_press(KEY_ALL);
edit = 0;
// PKT_StartInfo = Pre;
return Pre;
}
 
}
//--------------------------------------------------------------
//uint8_t Edit_Language(uint8_t Value, uint8_t min, uint8_t max,const char *Text)
uint8_t Edit_Language(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text)
{
Pre = Value;
lcd_cls();
// lcd_printp_at (0, 2, Text, 0);
lcd_puts_at(0, 2,strGet(Text), 0);
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(FRANCE), 0);//lcd_printp_at (14, 2, PSTR("France "), 0);
break;
case 0x3 : lcd_puts_at(10, 2, strGet(NETHERL), 0);//lcd_printp_at (14, 2, PSTR("Netherl"), 0);
break;
break;
}
 
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
 
do
{
if ((get_key_press (1 << KEY_PLUS)) && (Value < max))
{
edit = 1;
Value++;
//DisplayLanguage = Value;
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(FRANCE), 0);//lcd_printp_at (14, 2, PSTR("France "), 0);
break;
case 0x3 : lcd_puts_at(10, 2, strGet(NETHERL), 0);//lcd_printp_at (14, 2, PSTR("Netherl"), 0);
break;
break;
}
}
 
if ((get_key_press (1 << KEY_MINUS)) && (Value > min))
{
edit = 1;
Value--;
//DisplayLanguage = Value;
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(FRANCE), 0);//lcd_printp_at (14, 2, PSTR("France "), 0);
break;
case 0x3 : lcd_puts_at(10, 2, strGet(NETHERL), 0);//lcd_printp_at (14, 2, PSTR("Netherl"), 0);
break;
break;
}
}
 
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 Edit_Orientation(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text)
{
Pre = Value;
lcd_cls();
// lcd_printp_at (0, 2, Text, 0);
lcd_puts_at(0, 2, strGet(Text), 0);
 
switch (Value)
{
case 0x0 :lcd_puts_at(14, 2, strGet(NORMAL), 0);//lcd_printp_at (14, 2, PSTR("Normal "), 0);
break;
case 0x4 :lcd_puts_at(14, 2, strGet(REVERSE), 0);//lcd_printp_at (14, 2, PSTR("Reverse"), 0);
break;
break;
}
 
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
 
do
{
if ((get_key_press (1 << KEY_PLUS)) && (Value == 0))
{
Value=4;
// lcd_printp_at (14, 2, PSTR("Reverse"), 0);
lcd_puts_at(14, 2, strGet(REVERSE), 0);
}
 
if ((get_key_press (1 << KEY_MINUS)) && (Value == 4))
{
Value = 0;
// lcd_printp_at (14, 2, PSTR("Normal "), 0);
lcd_puts_at(14, 2, strGet(NORMAL), 0);
}
 
if (get_key_press (1 << KEY_ENTER))
{
edit = 1;
cli();
clr_A0 ();
 
if (Value == 0)
{
send_byte (0xA1); // normal
send_byte (0xC0); // normal
}
else
{
send_byte (0xA0); // reverse
send_byte (0xC8); // reverse
}
set_A0 ();
sei();
LCD_Orientation = Value;
WriteParameter();
return Value;
}
}
 
while (!get_key_press (1 << KEY_ESC));
{
get_key_press(KEY_ALL);
edit = 0;
return Pre;
}
}
 
 
//--------------------------------------------------------------
uint8_t Edit_DisplayMode(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text)
{
Pre = Value;
lcd_cls();
//lcd_printp_at (0, 2, Text, 0);
lcd_puts_at(0, 2, strGet(Text), 0);
 
switch (Value)
{
case 0x0 :lcd_puts_at(14, 2, strGet(NORMAL), 0);//lcd_printp_at (14, 2, PSTR("Normal "), 0);
break;
case 0x4 :lcd_puts_at(14, 2, strGet(REVERSE), 0);//lcd_printp_at (14, 2, PSTR("Reverse"), 0);
break;
break;
}
 
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
 
do
{
if ((get_key_press (1 << KEY_PLUS)) && (Value == 0))
{
Value=4;
// lcd_printp_at (14, 2, PSTR("Inverse"), 0);
lcd_puts_at(14, 2, strGet(REVERSE), 0);
}
 
if ((get_key_press (1 << KEY_MINUS)) && (Value == 4))
{
Value=0;
// lcd_printp_at (14, 2, PSTR("Normal "), 0);
lcd_puts_at(14, 2, strGet(NORMAL), 0);
}
 
if (get_key_press (1 << KEY_ENTER))
{
edit = 1;
cli();
clr_A0 ();
 
if (Value == 0)
send_byte (0xA6); // normal
else
send_byte (0xA7); // inverse
 
set_A0 ();
sei();
LCD_DisplayMode = Value;
WriteParameter();
 
return Value;
}
}
 
while (!get_key_press (1 << KEY_ESC));
{
get_key_press(KEY_ALL);
edit = 0;
LCD_DisplayMode = Pre;
return Pre;
}
}
 
 
//--------------------------------------------------------------
uint8_t Edit_DisplayKontrast(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text)
{
Pre = Value;
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);
// 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);
lcd_frect ((8*0), (8*4), (Value * (16*8) / 64), 6, 1);
 
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 2)) && (Value < max))
{
Value++;
 
if (Value >= max)
{
Value = max;
BeepTime = 200;
BeepMuster = 0x0080;
}
else
{
cli();
clr_A0 ();
send_byte (0x81);
send_byte (Value); // Daten zum LCD senden
set_A0 ();
sei();
}
}
 
if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 2)) && (Value > min))
{
lcd_frect (((Value - 1) * (16*8) / 64), (8*4), (16*8), 6, 0);
Value--;
 
if (Value == min)
{
Value = min;
BeepTime = 200;
BeepMuster = 0x0080;
}
else
{
// edit = 1;
cli();
clr_A0 ();
send_byte (0x81);
send_byte (Value); // Daten zum LCD senden
set_A0 ();
sei();
}
}
write_ndigit_number_u (16, 2,Value, 3, 0);
 
if (get_key_press (1 << KEY_ENTER))
{
edit = 1;
LCD_Kontrast = Value;
WriteParameter();
return Value;
}
}
 
while (!get_key_press (1 << KEY_ESC));
{
get_key_press(KEY_ALL);
cli();
clr_A0 ();
send_byte (0x81);
send_byte (Pre); // Daten zum LCD senden
set_A0 ();
sei();
edit = 0;
LCD_Kontrast = Pre;
WriteParameter();
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);
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);
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;
BeepTime = 200;
BeepMuster = 0x0080;
}
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;
BeepTime = 200;
BeepMuster = 0x0080;
}
else
OCR2A = Value * ValCorr;
 
}
 
if (get_key_press (1 << KEY_ENTER))
{
edit = 1;
OCR2A = Value * ValCorr;
LCD_Helligkeit = Value;
WriteParameter();
return Value;
}
}
 
while (!get_key_press (1 << KEY_ESC));
{
get_key_press(KEY_ALL);
edit = 0;
OCR2A = Pre * ValCorr;
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();
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;
size = ITEMS_PKT;
uint8_t dmode = 0;
uint8_t target_pos = 1;
uint8_t val;
 
lcd_cls ();
mmode = 0;
edit= 0;
val = 0;
 
while(1)
{
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][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();
return;
}
return;
}
else
break;
}
target_pos = val;
 
if((val + Offset) == 1)
{
#ifdef HWVERSION3_9
U02SV2 = ChangeWi_SV2(U02SV2);
 
if (edit == 1)
PKT_Change = 1;
 
#else
Show_Error_HW12();
#endif
}
 
if((val + Offset) == 2)
MK_LowBat = Edit_Int10th_Value(MK_LowBat,33,247,LOWBAT);
 
if((val + Offset) == 3)
Display_Setup();
 
if((val + Offset) == 4)
{
#if defined HWVERSION3_9 || defined HWVERSION1_2W || defined HWVERSION1_3W
if(UseWi == false)
// Wi_Use();
{
UseWi = Edit_YesNo(UseWi,0,1,WI2321);
if (edit==1)
if (UseWi== true) InitWi232();
}
 
else
Wi_Setup();
#else
Show_Error_HW12();
#endif
}
 
if((val + Offset) == 5)
{
#ifdef HWVERSION3_9
if(UseBT == 0)
{
UseBT = Edit_YesNo(UseBT,0,1,BT1);
if (edit==1)
if (UseBT == 1)
{
if (bt_init()) BTIsSet = true; else BTIsSet = false;
WriteParameter();
}
}
else
BT_Setup();
#else
Show_Error_HW12();
#endif
}
 
if((val + Offset) == 6)
#ifdef HWVERSION3_9
Accu_Setup();
#else
Show_Error_HW12();
#endif
if((val + Offset) == 7)
Update_PKT();
 
if((val + Offset) == 8)
Debug = Edit_Int_Value(Debug,0,1,DEBUGPKT);
 
if((val + Offset) == 9)
Reset_EEprom();
 
}
}
 
 
//--------------------------------------------------------------
void Display_Setup (void)
{
uint8_t ii = 0;
uint8_t Offset = 0;
uint8_t size = 0;
size = ITEMS_LCD;
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)
{
lcd_cls ();
// lcd_printp_at (0, 0, PSTR(" Display Setup "), 2);
lcd_puts_at(0, 0, strGet(DISPLAY1), 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_lcd[ii + Offset][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();
return;
}
return;
}
else
break;
}
target_pos = val;
 
if((val + Offset) == 1)
PKT_StartInfo = Edit_StartInfo(PKT_StartInfo,0,2,DISPLAY2);
 
if((val + Offset) == 2)
DisplayLanguage = Edit_Language(DisplayLanguage,0,3,DISPLAY3);
// Edit_Language(DisplayLanguage,0,3,DISPLAY3);
 
if((val + Offset) == 3)
DisplayTimeout = Edit_Int_Value(DisplayTimeout,0,254,DISPLAY4);
 
if((val + Offset) == 4)
LCD_Helligkeit = Edit_DisplayHelligkeit(LCD_Helligkeit,0,100,DISPLAY5);
if (edit == 1)
if(!LCD_Change)
LCD_Change =1;
 
if((val + Offset) == 5)
LCD_Kontrast = Edit_DisplayKontrast(LCD_Kontrast,0,63,DISPLAY6);
if (edit == 1)
if(!LCD_Change)
LCD_Change =1;
 
if((val + Offset) == 6)
{
LCD_DisplayMode = Edit_DisplayMode(LCD_DisplayMode,0,4,DISPLAY7);
if (edit == 1)
if(!LCD_Change)
LCD_Change =1;
}
 
if((val + Offset) == 7)
{
LCD_Orientation = Edit_Orientation(LCD_Orientation,0,4,DISPLAY8);
if (edit == 1)
if(!LCD_Change)
LCD_Change =1;
}
 
 
 
 
}
}
 
#if defined HWVERSION3_9 ||HWVERSION1_3W
////--------------------------------------------------------------
//void Wi_Use (void)
//{
// Pre = UseWi;
//
// lcd_cls ();
//
// lcd_cls ();
//// lcd_printp_at (0, 0, PSTR(" Wi.232 Setup "), 2);
//// lcd_printp_at (0, 2, PSTR("Ist ein Wi.232-Modul "), 0);
//// lcd_printp_at (0, 4, PSTR("eingebaut?"), 0);
// lcd_puts_at(0, 0, strGet(WI2321), 2);
// lcd_puts_at(0, 2, strGet(WI2322), 0);
// lcd_puts_at(0, 4, strGet(WI2323), 0);
//// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
// lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
//
// while(1)
// {
// if(UseWi == false)
//// lcd_printp_at (12, 4, PSTR("Nein"), 0);
// lcd_puts_at(12, 4, strGet(NOO), 0);
// else
// //lcd_printp_at (12, 4, PSTR("Ja "), 0);
// lcd_puts_at(12, 4, strGet(YES), 0);
//
// if(get_key_press (1 << KEY_MINUS))
// {
// UseWi = false;
// edit = 1;
// }
//
// if(get_key_press (1 << KEY_PLUS))
// {
// UseWi = true;
// edit = 1;
// }
//
// if(get_key_short (1 << KEY_ENTER))
// {
//// WiIsSet = false;
//// WriteParameter();
//// if(UseWi == true)
//// Wi_Setup();
// return;
// }
//
// if (get_key_press (1 << KEY_ESC))
// {
// get_key_press(KEY_ALL);
// UseWi = Pre;
// return;
// }
// }
//}
 
 
//--------------------------------------------------------------
void Wi_Setup (void)
{
uint8_t ii = 0;
uint8_t Offset = 0;
uint8_t size = 0;
size = ITEMS_WI;
uint8_t dmode = 0;
uint8_t target_pos = 1;
uint8_t val = 0;
 
mmode = 0;
edit = 0;
// WiIsSet = true;
 
lcd_cls ();
 
while(1)
{
lcd_cls ();
lcd_printp_at (0, 0, PSTR(" Wi.232 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_wi[ii+Offset][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 (UseWi==true) InitWi232();
// WriteParameter();
// }
 
return;
}
else
 
if (edit == 1)
{
if (UseWi==true) InitWi232();
WriteParameter();
}
 
 
 
 
break;
}
target_pos = val;
 
if((val + Offset) == 1)
{
UseWi = Edit_YesNo(UseWi,0,1,WI2321);
}
 
if((val + Offset) == 2)
{
WiTXRXChannel = Edit_Int_Value(WiTXRXChannel, 0, 5,WINETWG);
 
}
 
if((val + Offset) == 3)
{
WiNetworkGroup = Edit_Int_Value(WiNetworkGroup, 0, 127, WINETWG);
 
 
}
 
if((val + Offset) == 4)
{
WiNetworkMode = Edit_Wi_NetMode_Value(WiNetworkMode);
 
 
}
 
if((val + Offset) == 5)
{
WiTXTO = Edit_Int_Value(WiTXTO,0,127,WITIMEOUT);
 
 
}
 
if((val + Offset) == 6)
{
WiUartMTU = Edit_Int_Value(WiUartMTU,0,127,WIUART);
 
 
}
 
if((val + Offset) == 7)
InitWi232();
 
if((val + Offset) == 8)
Port_USB2CFG_Wi();
}
}
#endif
 
#ifdef HWVERSION3_9
//--------------------------------------------------------------
//
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]++;
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]--;
lcd_putc (x, 3, EditString[I], 0);
edit = 1;
}
}
 
if (get_key_long (1 << KEY_ESC))
{
EditString[I] = ' '; // Zeichen l�schen
lcd_putc (x, 3, EditString[I], 0);
edit = 1;
}
 
if (get_key_short (1 << KEY_ESC))
{
if ((x / 2) + 2 > bt_name_length)
{
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));
{
get_key_press(KEY_ALL);
return 1;
}
}
 
 
////--------------------------------------------------------------
//void BT_Use (void)
//{
// Pre = UseBT;
//
// lcd_cls ();
//
// lcd_cls ();
//// lcd_printp_at (0, 0, PSTR(" BTM-222 Setup "), 2);
//// lcd_printp_at (0, 2, PSTR("Ist ein BTM-222-Modul"), 0);
//// lcd_printp_at (0, 4, PSTR("eingebaut?"), 0);
// lcd_puts_at(0, 0, strGet(BT1), 2);
// lcd_puts_at(0, 2, strGet(BT2), 0);
// lcd_puts_at(0, 4, strGet(BT3), 0);
//// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
// lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
//
// while(1)
// {
// if(UseBT == false)
//// lcd_printp_at (12, 4, PSTR("Nein"), 0);
// lcd_puts_at(12, 4, strGet(NOO), 0);
// else
//// lcd_printp_at (12, 4, PSTR("Ja "), 0);
// lcd_puts_at(12, 4, strGet(YES), 0);
// if(get_key_press (1 << KEY_MINUS))
// UseBT = false;
//
// if(get_key_press (1 << KEY_PLUS))
// UseBT = true;
//
// if(get_key_short (1 << KEY_ENTER))
// {
//// BTIsSet = false;
// WriteParameter();
// if(UseBT == true)
// BT_Setup();
// return;
// }
//
// if (get_key_press (1 << KEY_ESC))
// {
// get_key_press(KEY_ALL);
// UseBT = Pre;
// return;
// }
// }
//}
 
 
//--------------------------------------------------------------
//
void BT_Setup (void)
{
uint8_t ii = 0;
uint8_t Offset = 0;
uint8_t size = 0;
size = ITEMS_BT;
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)
{
lcd_cls ();
// lcd_printp_at (0, 0, PSTR(" BTM-222 Setup "), 2);
lcd_puts_at(0, 0, strGet(BT1), 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_bt[ii+Offset][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 (UseBT == 1);
// if (bt_init()) BTIsSet = true; else BTIsSet = false;
// WriteParameter();
// return;
// }
return;
}
else
 
if (edit == 1)
{
if (UseBT == 1);
if (bt_init()) BTIsSet = true; else BTIsSet = false;
WriteParameter();
return;
}
 
 
 
 
break;
}
 
target_pos = val;
if((val + Offset) == 1)
// BT_Use();
UseBT = Edit_YesNo(UseBT,0,1,BT1);
 
if((val + Offset) == 2)
{
for (uint8_t i = 0; i < bt_name_length; i++)
{
string[i] = 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++)
{
bt_name[i] = EditString[i];
WriteParameter();
}
 
if (bt_name_len < 10)
{
for (uint8_t i = bt_name_len; i < 10; i++)
{
bt_name[i] = ' ';
WriteParameter();
}
}
}
}
 
if((val + Offset) == 3)
{
for (uint8_t i = 0; i < bt_pin_length; i++)
{
string[i] = 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++)
{
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);
BTIsSet = false;
BeepTime = 1000;
BeepMuster = 0x0040;
}
}
 
if((val + Offset) == 5)
Port_FC2CFG_BT();
 
 
}
}
 
//--------------------------------------------------------------
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_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
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;
 
PKT_Accutyp = Value;
// WriteParameter();
 
return Value;
}
}
 
while (!get_key_press (1 << KEY_ESC));
{
get_key_press(KEY_ALL);
edit = 0;
PKT_Accutyp = Pre;
return Pre;
}
 
}
 
//--------------------------------------------------------------
uint16_t Edit_LipoOffset(uint16_t Value, uint16_t min, uint16_t max)
{
lcd_cls();
// lcd_printp_at (0, 2, Text, 0);
lcd_puts_at(0, 2, strGet(LIPO3), 0);
lcd_puts_at(0, 5, strGet(LIPO5), 0);
lcd_puts_at(0, 6, strGet(LIPO6), 0);
// lcd_printp_at (0, 3, PSTR("Offset verstellen bis"), 0);
// lcd_printp_at (0, 4, PSTR("die Spannung passt"), 0);
Pre16 = Value;
write_ndigit_number_u (16, 2, Value, 4, 0);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 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;
Lipo_UOffset = Value;
write_ndigit_number_u (16, 2,Value, 4, 0);
 
}
 
if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 2)) && (Value > min))
{
edit = 1;
Value=Value -10;
Lipo_UOffset = Value;
write_ndigit_number_u (16, 2,Value, 4, 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;
Lipo_UOffset = Pre16;
return Pre16;
}
}
 
//--------------------------------------------------------------
 
 
void Accu_Setup (void)
{
uint8_t ii = 0;
uint8_t Offset = 0;
uint8_t size = 0;
size = ITEMS_Accu;
uint8_t dmode = 0;
uint8_t target_pos = 1;
uint8_t val;
 
mmode = 0;
edit = 0;
val = 0;
lcd_cls ();
 
while(1)
{
lcd_cls ();
// lcd_printp_at (0, 0, PSTR(" PKT Accu Setup "), 2);
lcd_puts_at(0, 0, strGet(LIPO1), 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_Accu[ii+Offset][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();
 
return;
}
return;
}
else
break;
}
 
target_pos = val;
if((val + Offset) == 1)
{
PKT_Accutyp= Edit_PKT_Accu(PKT_Accutyp,0,1);
if (edit == 1) WriteParameter();
}
 
if((val + Offset) == 2)
{
Lipo_UOffset = Edit_LipoOffset(Lipo_UOffset,0,9999);
if (edit == 1) WriteParameter();
}
 
}
}
 
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/setup.h
0,0 → 1,50
/*****************************************************************************
* 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
 
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);
uint8_t Edit_Language(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text);
 
extern uint8_t bt_name_len;
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/timer.c
0,0 → 1,519
/*****************************************************************************
* 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 <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <string.h>
#include <util/delay.h>
#include <inttypes.h>
 
 
#include "main.h"
#include "timer.h"
#include "eeprom.h"
#include "lcd.h"
#include "uart1.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 abo_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
 
uint16_t WarnCount = 0; // Zähler der LIPO Warnzeit
uint16_t WarnToggle = 0; // Togglezähler zum blinken
uint16_t WarnTime = 10; // Länge der LIPO Warnzeit 10 Sek.
uint16_t PoffTime = 30; // Länge der Wartezeit vor Abschalten 30 Sek.
//uint8_t servo = 0;
 
 
volatile uint8_t Display_on;// Flag Display on/off
 
unsigned int BeepTime = 0;
unsigned int BeepMuster = 0xffff;
 
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 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
}
 
 
//--------------------------------------------------------------
void Timer2_Init (void) // 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;
}
 
 
#if defined HWVERSION1_2 || defined HWVERSION1_2W
//--------------------------------------------------------------
ISR(TIMER2_COMPA_vect)
{
PORTD &= ~(1 << PD7);
PORTC &= ~(1 << PC0);
PORTC &= ~(1 << PC1);
}
ISR(TIMER2_COMPB_vect)
{
PORTD |= (1 << PD7);
PORTC |= (1 << PC0);
PORTC |= (1 << PC1);
}
#endif
#if defined HWVERSION1_3 || defined HWVERSION1_3W
//--------------------------------------------------------------
ISR(TIMER2_COMPA_vect)
{
PORTD &= ~(1 << PD7);
PORTD &= ~(1 << PD6);
PORTC &= ~(1 << PC2);
}
ISR(TIMER2_COMPB_vect)
{
PORTD |= (1 << PD7);
PORTD |= (1 << PD6);
PORTC |= (1 << PC2);
}
#endif
#ifdef HWVERSION3_9
//--------------------------------------------------------------
ISR(TIMER2_COMPA_vect)
{
PORTD |= (1 << PD7);
}
ISR(TIMER2_COMPB_vect)
{
PORTD &= ~(1 << PD7);
}
#endif
 
 
//--------------------------------------------------------------
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
}
 
 
//--------------------------------------------------------------
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
{
BeepTime = 200;
BeepMuster = 0x0080;
IdleTimer = 0;
}
}
 
if (!cnt--)
{
cnt = 9;
CountMilliseconds++;
cnt_1ms++;
}
 
if (i!=0)
{ // Displaylicht einschalten, und bzw. Timeoutzählerreset wenn Taste gedrückt wurde
if (Display_on == 0)
set_D_LIGHT();
 
 
Display_on = 1; // Flag Display on
DisplayTime = 0; // Timer Reset
IdleTimer = 0; // Idletimeout Reset
 
}
 
if (DisplayTimeout > 0)
{
if (Display_on == 1)
{
DisplayTime++;
if ((DisplayTime / 100) == 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 (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;
}
 
if (beeper_ein)
set_BEEP();
else
clr_BEEP();
 
 
//--------------------------------------------------------------
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 (abo_timer > 0)
abo_timer --;
 
 
}
 
 
//--------------------------------------------------------------
#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
{
BeepTime = 1000;
BeepMuster = 0x0020;
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;
}
 
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/timer.h
0,0 → 1,87
/*****************************************************************************
* 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 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 abo_timer;
extern 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
 
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.
 
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/GPL_PKT_V3_5_8b_FC086/tools.c
0,0 → 1,332
/*****************************************************************************
* 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 <stdbool.h>
#include <util/delay.h>
#include "main.h"
#include "setup.h"
#include "lcd.h"
#include "menu.h"
#include "servo.h"
#include "motortest.h"
#include "eeprom.h"
#include "timer.h"
#include "connect.h"
#ifdef HWVERSION3_9
#include "HAL_HW3_9.h"
#endif
#ifdef HWVERSION1_3
#include "HAL_HW1_3.h"
#endif
//#include "voltmeter.h"
#include "lipo.h"
#include "messages.h"
 
//--------------------------------------------------------------
#define ITEMS_PKT 6
 
prog_char tools_menuitems_pkt[ITEMS_PKT][NUM_LANG][18]= // zeilen,zeichen+1
// German, English, French, Netherlands
{
{"Motor Tester ","Motor Tester ","Motor Tester ","Motor Tester "},
{"Servo Tester ","Servo Tester ","Servo Tester ","Servo Tester "},
{"PC BT > Kopter ","PC BT > Kopter ","PC BT > Kopter ","PC BT > Kopter "},
{"PC USB > Kopter ","PC USB > Kopter ","PC USB > Kopter ","PC USB > Kopter "},
{"PKT Setup \x1d","PKT Setup \x1d","PKT Setup \x1d","PKT Setup \x1d"},
{"PKT Version ","PKT Version ","PKT Version ","PKT Version "},
};
 
 
//--------------------------------------------------------------
void PKT_Tools (void)
{
uint8_t ii = 0;
uint8_t Offset = 0;
uint8_t size = 0;
size = ITEMS_PKT ;
uint8_t dmode = 0;
uint8_t target_pos = 1;
uint8_t val;
 
val = 0;
 
while(1)
{
lcd_cls ();
lcd_printp_at (0, 0, PSTR(" PKT-Tools "), 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,tools_menuitems_pkt[ii+Offset][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)
{
return;
}
else
{
break;
}
 
}
target_pos = val;
 
if((val+Offset) == 1 )
motor_test(FC_Mode);
if((val+Offset) == 2 )
servo_test();
#ifdef HWVERSION3_9
if(U02SV2 == 0)
{
if((val+Offset) == 3 )
Port_BT2Wi();
if((val+Offset) == 4 )
Port_USB2Wi();
}
else if(U02SV2 == 1)
{
if((val+Offset) == 3 )
Port_BT2FC();
if((val+Offset) == 4 )
Port_USB2FC();
}
#else
if((val+Offset) == 3 )
Show_Error_HW();
if((val+Offset) == 4 )
Show_Error_HW();
#endif
if((val+Offset) == 5)
PKT_Setup();
if((val+Offset) == 6)
Show_Version();
}
}
 
 
//--------------------------------------------------------------
//
void PC_Fast_Connect (void)
{
uint8_t value = 1;
 
while(1)
{
lcd_cls();
// lcd_printp_at (0, 0, PSTR(" PC-Quick-Verbindung "), 2);
lcd_puts_at(0, 8, strGet(TOOLS1), 2);
lcd_printp_at (3, 3, PSTR("PC BT > Kopter"), 0);
lcd_printp_at (3, 4, PSTR("PC USB > Kopter"), 0);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
// lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
 
while(2)
{
if(value == 1)
{
lcd_printp_at (1, 3, PSTR("\x1d"), 0);
lcd_printp_at (1, 4, PSTR(" "), 0);
}
else
{
lcd_printp_at (1, 3, PSTR(" "), 0);
lcd_printp_at (1, 4, PSTR("\x1d"), 0);
}
 
if(get_key_press (1 << KEY_MINUS))
value = 1;
 
if(get_key_press (1 << KEY_PLUS))
value = 2;
 
 
if(get_key_short (1 << KEY_ENTER))
{
#ifdef HWVERSION3_9
if(U02SV2 == 0)
{
if(value == 1)
Port_BT2Wi();
if(value == 2)
Port_USB2Wi();
}
else if(U02SV2 == 1)
{
if(value == 1)
Port_BT2FC();
if(value == 2)
Port_USB2FC();
}
#else
if(value == 1)
Show_Error_HW();
if(value == 2)
Show_Error_HW();
#endif
break;
}
 
if(get_key_press (1 << KEY_ESC))
{
get_key_press(KEY_ALL);
return;
}
 
}
}
}
 
 
void Test_HB (void) // bleibt für Tests
{
// ADC_Init();
//
// uint16_t volt_avg = 0;
//// uint64_t volt_tmp = 0;
// uint16_t Balken = 0;
 
 
lcd_cls();
lcd_printp_at(12, 7, PSTR("Ende"), 0);
 
// lcd_rect(104, 0, 23, 8, 1); // Rahmen
 
do
{
//
//
if(samples>4095)
{
// write_ndigit_number_u(0, 4, accumulator, 5, 0);
oversampled();
volt_avg = Vin;
}
// // write_ndigit_number_u(0, 3, samples, 5, 0);
//
//// write_ndigit_number_u(0, 1, Vin, 5, 0);
// _delay_ms(50);
 
show_Lipo();
 
write_ndigit_number_u_100th(5, 5, volt_avg, 0, 0);
lcd_printp_at(10, 5, PSTR("Volt"), 0);
//
//
//
write_ndigit_number_u(0, 6, Lipo_UOffset, 5, 0);
// write_ndigit_number_u(15, 6, WarnCount, 4, 0);
//// write_ndigit_number_u(10, 5, Vcorr, 4, 0);
 
 
if (get_key_press (1 << KEY_PLUS) | get_key_long_rpt_sp ((1 << KEY_PLUS), 3))
{
Lipo_UOffset = Lipo_UOffset +10;
}
 
if (get_key_press (1 << KEY_MINUS) | get_key_long_rpt_sp ((1 << KEY_MINUS),3))
{
Lipo_UOffset = Lipo_UOffset -10;
}
//
}
 
 
while(!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
return;
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/tools.h
0,0 → 1,41
/*****************************************************************************
* 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 _tools_H
#define _tools_H
 
void PKT_Tools (void);
void Test_HB (void); // TestTool für Softwareentwicklung
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/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.h"
#include "twimaster.h"
#include "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/GPL_PKT_V3_5_8b_FC086/twimaster.h
0,0 → 1,100
#ifndef _I2C_MASTER_H
#define _I2C_MASTER_H
+
+#include <inttypes.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
+
+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
+ int8_t Temperature; // old BL-Ctrl will return a 255 here, the new version the temp. in �C
+} __attribute__((packed)) MotorData_t;
+
+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
+
+typedef struct
+{
+ uint8_t Revision; // must be BL_REVISION
+ uint8_t SetMask; // settings mask
+ uint8_t PwmScaling; // maximum value of control pwm, acts like a thrust limit
+ uint8_t CurrentLimit; // current limit in A
+ uint8_t TempLimit; // in �C
+ uint8_t CurrentScaling; // scaling factor for current measurement
+ uint8_t BitConfig; // see defines above
+ uint8_t crc; // checksum
+} __attribute__((packed)) BLConfig_t;
+
+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/GPL_PKT_V3_5_8b_FC086/uart1.c
0,0 → 1,303
/*************************************************************************
Title: Interrupt UART library with receive/transmit circular buffers
Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury
File: $Id: uart.c,v 1.6.2.2 2009/11/29 08:56:12 Peter Exp $
Software: AVR-GCC 4.1, AVR Libc 1.4.6 or higher
Hardware: any AVR with built-in UART,
License: GNU General Public License
 
DESCRIPTION:
An interrupt is generated when the UART has finished transmitting or
receiving a byte. The interrupt handling routines use circular buffers
for buffering received and transmitted data.
 
The UART_RX_BUFFER_SIZE and UART_TX_BUFFER_SIZE variables define
the buffer size in bytes. Note that these variables must be a
power of 2.
 
USAGE:
Refere to the header file uart.h for a description of the routines.
See also example test_uart.c.
 
NOTES:
Based on Atmel Application Note AVR306
 
LICENSE:
Copyright (C) 2006 Peter Fleury
 
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, or
any later version.
 
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.
 
*************************************************************************/
 
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "uart1.h"
#include "main.h"
 
//
// constants and macros
//
 
 
// size of RX/TX buffers
#define UART_RX_BUFFER_MASK ( UART_RX_BUFFER_SIZE - 1)
#define UART_TX_BUFFER_MASK ( UART_TX_BUFFER_SIZE - 1)
 
#if ( UART_RX_BUFFER_SIZE & UART_RX_BUFFER_MASK )
#error RX buffer size is not a power of 2
#endif
 
#if ( UART_TX_BUFFER_SIZE & UART_TX_BUFFER_MASK )
#error TX buffer size is not a power of 2
#endif
 
 
// ATmega with two USART
 
#define ATMEGA_USART1
 
#define UART1_STATUS UCSR1A
#define UART1_CONTROL UCSR1B
#define UART1_DATA UDR1
#define UART1_UDRIE UDRIE1
 
 
 
//
// module global variables
//
 
#if defined( ATMEGA_USART1 )
static volatile unsigned char UART1_TxBuf[UART_TX_BUFFER_SIZE];
static volatile unsigned char UART1_RxBuf[UART_RX_BUFFER_SIZE];
static volatile unsigned char UART1_TxHead;
static volatile unsigned char UART1_TxTail;
static volatile unsigned char UART1_RxHead;
static volatile unsigned char UART1_RxTail;
static volatile unsigned char UART1_LastRxError;
#endif
 
 
 
 
//
// these functions are only for ATmegas with two USART
//
 
 
#if defined( ATMEGA_USART1 )
 
//--------------------------------------------------------------
// Function: UART1 Receive Complete interrupt
// Purpose: called when the UART1 has received a character
//--------------------------------------------------------------
ISR(USART1_RX_vect)
{
unsigned char tmphead;
unsigned char data;
unsigned char usr;
unsigned char lastRxError;
 
 
// read UART status register and UART data register
usr = UART1_STATUS;
data = UART1_DATA;
 
lastRxError = (usr & (_BV(FE1)|_BV(DOR1)) );
 
// calculate buffer index
tmphead = ( UART1_RxHead + 1) & UART_RX_BUFFER_MASK;
 
if ( tmphead == UART1_RxTail )
{
// error: receive buffer overflow
lastRxError = UART_BUFFER_OVERFLOW >> 8;
}
else
{
// store new index
UART1_RxHead = tmphead;
// store received data in buffer
UART1_RxBuf[tmphead] = data;
}
UART1_LastRxError = lastRxError;
}
 
 
//--------------------------------------------------------------
// Function: UART1 Data Register Empty interrupt
// Purpose: called when the UART1 is ready to transmit the next byte
//--------------------------------------------------------------
ISR(USART1_UDRE_vect)
{
unsigned char tmptail;
 
 
if ( UART1_TxHead != UART1_TxTail)
{
// calculate and store new buffer index
tmptail = (UART1_TxTail + 1) & UART_TX_BUFFER_MASK;
UART1_TxTail = tmptail;
// get one byte from buffer and write it to UART
UART1_DATA = UART1_TxBuf[tmptail]; // start transmission
}
else
{
// tx buffer empty, disable UDRE interrupt
UART1_CONTROL &= ~_BV(UART1_UDRIE);
}
}
 
 
//--------------------------------------------------------------
// Function: uart1_init()
// Purpose: initialize UART1 and set baudrate
// Input: baudrate using macro UART_BAUD_SELECT()
// Returns: none
//--------------------------------------------------------------
void uart1_init(unsigned int baudrate)
{
UART1_TxHead = 0;
UART1_TxTail = 0;
UART1_RxHead = 0;
UART1_RxTail = 0;
 
 
// Set baud rate
if ( baudrate & 0x8000 )
{
UART1_STATUS = (1<<U2X1); //Enable 2x speed
baudrate &= ~0x8000;
}
UBRR1H = (unsigned char)(baudrate>>8);
UBRR1L = (unsigned char) baudrate;
 
// Enable USART receiver and transmitter and receive complete interrupt
UART1_CONTROL = _BV(RXCIE1)|(1<<RXEN1)|(1<<TXEN1);
 
// Set frame format: asynchronous, 8data, no parity, 1stop bit
#ifdef URSEL1
UCSR1C = (1<<URSEL1)|(3<<UCSZ10);
#else
UCSR1C = (3<<UCSZ10);
#endif
}
 
 
//--------------------------------------------------------------
// Function: uart1_getc()
// Purpose: return byte from ringbuffer
// Returns: lower byte: received byte from ringbuffer
// higher byte: last receive error
//--------------------------------------------------------------
unsigned int uart1_getc(void)
{
unsigned char tmptail;
unsigned char data;
 
 
if ( UART1_RxHead == UART1_RxTail )
{
return UART_NO_DATA; // no data available
}
 
// calculate /store buffer index
tmptail = (UART1_RxTail + 1) & UART_RX_BUFFER_MASK;
UART1_RxTail = tmptail;
 
// get data from receive buffer
data = UART1_RxBuf[tmptail];
 
return (UART1_LastRxError << 8) + data;
 
}
 
 
//--------------------------------------------------------------
// Function: uart1_putc()
// Purpose: write byte to ringbuffer for transmitting via UART
// Input: byte to be transmitted
// Returns: 1 on succes, 0 if remote not ready
//--------------------------------------------------------------
int uart1_putc(unsigned char data)
{
unsigned char tmphead;
 
 
tmphead = (UART1_TxHead + 1) & UART_TX_BUFFER_MASK;
 
while ( tmphead == UART1_TxTail )
{;} // wait for free space in buffer
 
UART1_TxBuf[tmphead] = data;
UART1_TxHead = tmphead;
 
// enable UDRE interrupt
UART1_CONTROL |= _BV(UART1_UDRIE);
return (UART1_LastRxError << 8) + data;
}
 
 
//--------------------------------------------------------------
// Function: uart1_puts()
// Purpose: transmit string to UART1
// Input: string to be transmitted
// Returns: none
//--------------------------------------------------------------
void uart1_puts(const char *s )
{
while (*s)
uart1_putc(*s++);
}
 
 
//--------------------------------------------------------------
// Function: uart1_puts_p()
// Purpose: transmit string from program memory to UART1
// Input: program memory string to be transmitted
// Returns: none
//--------------------------------------------------------------
void uart1_puts_p(const char *progmem_s )
{
register char c;
while ( (c = pgm_read_byte(progmem_s++)) )
uart1_putc(c);
}
 
 
//--------------------------------------------------------------
// Function: uart1_available()
// Purpose: Determine the number of bytes waiting in the receive buffer
// Input: None
// Returns: Integer number of bytes in the receive buffer
//--------------------------------------------------------------
int uart1_available(void)
{
return (UART_RX_BUFFER_MASK + UART1_RxHead - UART1_RxTail) % UART_RX_BUFFER_MASK;
}
 
 
 
//--------------------------------------------------------------
// Function: uart1_flush()
// Purpose: Flush bytes waiting the receive buffer. Acutally ignores them.
// Input: None
// Returns: None
//--------------------------------------------------------------
void uart1_flush(void)
{
UART1_RxHead = UART1_RxTail;
}
 
 
#endif
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/uart1.h
0,0 → 1,167
/************************************************************************
Title: Interrupt UART library with receive/transmit circular buffers
Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury
File: $Id: uart.h,v 1.8.2.1 2007/07/01 11:14:38 peter Exp $
Software: AVR-GCC 4.1, AVR Libc 1.4
Hardware: any AVR with built-in UART, tested on AT90S8515 & ATmega8 at 4 Mhz
License: GNU General Public License
Usage: see Doxygen manual
 
LICENSE:
Copyright (C) 2006 Peter Fleury
 
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, or
any later version.
 
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.
 
************************************************************************/
 
//
// @defgroup pfleury_uart UART Library
// @code #include <uart.h> @endcode
//
// @brief Interrupt UART library using the built-in UART with transmit and receive circular buffers.
//
// This library can be used to transmit and receive data through the built in UART.
//
// An interrupt is generated when the UART has finished transmitting or
// receiving a byte. The interrupt handling routines use circular buffers
// for buffering received and transmitted data.
//
// The UART_RX_BUFFER_SIZE and UART_TX_BUFFER_SIZE constants define
// the size of the circular buffers in bytes. Note that these constants must be a power of 2.
// You may need to adapt this constants to your target and your application by adding
// CDEFS += -DUART_RX_BUFFER_SIZE=nn -DUART_RX_BUFFER_SIZE=nn to your Makefile.
//
// @note Based on Atmel Application Note AVR306
// @author Peter Fleury pfleury@gmx.ch http://jump.to/fleury
//
 
#ifndef UART_H
#define UART_H
 
#if (__GNUC__ * 100 + __GNUC_MINOR__) < 304
#error "This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !"
#endif
 
 
// constants and macros
 
 
// @brief UART Baudrate Expression
// @param xtalcpu system clock in Mhz, e.g. 4000000L for 4Mhz
// @param baudrate baudrate in bps, e.g. 1200, 2400, 9600
//
#define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu)/((baudRate)*16l)-1)
 
// @brief UART Baudrate Expression for ATmega double speed mode
// @param xtalcpu system clock in Mhz, e.g. 4000000L for 4Mhz
// @param baudrate baudrate in bps, e.g. 1200, 2400, 9600
//
#define UART_BAUD_SELECT_DOUBLE_SPEED(baudRate,xtalCpu) (((xtalCpu)/((baudRate)*8l)-1)|0x8000)
 
 
// Size of the circular receive buffer, must be power of 2
#ifndef UART_RX_BUFFER_SIZE
#define UART_RX_BUFFER_SIZE 32
#endif
 
// Size of the circular transmit buffer, must be power of 2
#ifndef UART_TX_BUFFER_SIZE
#define UART_TX_BUFFER_SIZE 32
#endif
 
// test if the size of the circular buffers fits into SRAM
#if ( (UART_RX_BUFFER_SIZE+UART_TX_BUFFER_SIZE) >= (RAMEND-0x60 ) )
#error "size of UART_RX_BUFFER_SIZE + UART_TX_BUFFER_SIZE larger than size of SRAM"
#endif
 
 
// high byte error return code of uart_getc()
 
#define UART_FRAME_ERROR 0x0800 // Framing Error by UART
#define UART_OVERRUN_ERROR 0x0400 // Overrun condition by UART
#define UART_BUFFER_OVERFLOW 0x0200 // receive ringbuffer overflow
#define UART_NO_DATA 0x0100 // no receive data available
 
 
//
// function prototypes
//
 
//
// @brief Initialize UART and set baudrate
// @param baudrate Specify baudrate using macro UART_BAUD_SELECT()
// @return none
//
extern void uart_init(unsigned int baudrate);
 
 
//
// @brief Get received byte from ringbuffer
//
// Returns in the lower byte the received character and in the
// higher byte the last receive error.
// UART_NO_DATA is returned when no data is available.
//
// @param void
// @return lower byte: received byte from ringbuffer
// @return higher byte: last receive status
// - \b 0 successfully received data from UART
// - \b UART_NO_DATA
// <br>no receive data available
// - \b UART_BUFFER_OVERFLOW
// <br>Receive ringbuffer overflow.
// We are not reading the receive buffer fast enough,
// one or more received character have been dropped
// - \b UART_OVERRUN_ERROR
// <br>Overrun condition by UART.
// A character already present in the UART UDR register was
// not read by the interrupt handler before the next character arrived,
// one or more received characters have been dropped.
// - \b UART_FRAME_ERROR
// <br>Framing Error by UART
//
extern unsigned int uart_getc(void);
 
 
//
// @brief Put byte to ringbuffer for transmitting via UART
// @param data byte to be transmitted
// @return none
//
 
 
 
 
// @brief Initialize USART1 (only available on selected ATmegas) @see uart_init
extern void uart1_init(unsigned int baudrate);
 
// @brief Get received byte of USART1 from ringbuffer. (only available on selected ATmega) @see uart_getc
extern unsigned int uart1_getc(void);
 
// @brief Put byte to ringbuffer for transmitting via USART1 (only available on selected ATmega) @see uart_putc
//extern void uart1_putc(unsigned char data);
extern int uart1_putc(unsigned char data);
 
// @brief Put string to ringbuffer for transmitting via USART1 (only available on selected ATmega) @see uart_puts
extern void uart1_puts(const char *s );
 
// @brief Put string from program memory to ringbuffer for transmitting via USART1 (only available on selected ATmega) @see uart_puts_p
extern void uart1_puts_p(const char *s );
 
// @brief Macro to automatically put a string constant into program memory
#define uart1_puts_P(__s) uart1_puts_p(PSTR(__s))
 
extern char *utoa1(char* buffer, const unsigned int size, unsigned int value);
 
 
#endif // UART_H
 
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/usart.c
0,0 → 1,634
/*****************************************************************************
* 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 <avr/wdt.h>
#include <util/delay.h>
#include <stdarg.h>
 
#include "main.h"
#include "usart.h"
#include "lcd.h"
#include "timer.h"
 
uint8_t buffer[30];
 
volatile uint8_t txd_buffer[TXD_BUFFER_LEN];
volatile uint8_t txd_complete = TRUE;
 
volatile uint8_t rxd_buffer[RXD_BUFFER_LEN];
volatile uint8_t rxd_buffer_locked = FALSE;
volatile uint8_t ReceivedBytes = 0;
volatile uint8_t *pRxData = 0;
volatile uint8_t RxDataLen = 0;
 
volatile uint16_t stat_crc_error = 0;
volatile uint16_t stat_overflow_error = 0;
 
volatile uint8_t rx_byte;
volatile uint8_t rxFlag = 0;
 
 
#define UART_RXBUFSIZE 64
#define UART_NO_DATA 0x0100 /* no receive data available */
 
volatile static uint8_t rxbuf[UART_RXBUFSIZE];
volatile static uint8_t *volatile rxhead, *volatile rxtail;
 
 
/*
 
//-----------------------------------------------------------------------------
// USART1 transmitter ISR
ISR (USART1_TX_vect)
{
static uint16_t ptr_txd1_buffer = 0;
uint8_t tmp_tx1;
 
if(!txd1_complete) // transmission not completed
{
ptr_txd1_buffer++; // [0] was already sent
tmp_tx1 = txd1_buffer[ptr_txd1_buffer];
// if terminating character or end of txd buffer was reached
if((tmp_tx1 == '\r') || (ptr_txd1_buffer == TXD_BUFFER_LEN))
{
ptr_txd1_buffer = 0; // reset txd pointer
txd1_complete = TRUE; // stop transmission
}
UDR1 = tmp_tx1; // send current byte will trigger this ISR again
}
// transmission completed
else ptr_txd1_buffer = 0;
}
 
*/
 
 
#ifdef USART_INT
//-----------------------------------------------------------------------------
// USART0 transmitter ISR
ISR (USART_TX_vect)
{
static uint16_t ptr_txd_buffer = 0;
uint8_t tmp_tx;
 
if(!txd_complete) // transmission not completed
{
ptr_txd_buffer++; // [0] was already sent
tmp_tx = txd_buffer[ptr_txd_buffer];
// if terminating character or end of txd buffer was reached
if((tmp_tx == '\r') || (ptr_txd_buffer == TXD_BUFFER_LEN))
{
ptr_txd_buffer = 0; // reset txd pointer
txd_complete = TRUE; // stop transmission
}
UDR = tmp_tx; // send current byte will trigger this ISR again
}
// transmission completed
else ptr_txd_buffer = 0;
}
#endif
 
 
 
 
 
//-----------------------------------------------------------------------------
//
 
//
//uint8_t uart_getc_nb(uint8_t *c)
//{
// if (rxhead==rxtail) return 0;
// *c = *rxtail;
// if (++rxtail == (rxbuf + UART_RXBUFSIZE)) rxtail = rxbuf;
// return 1;
//}
 
 
 
 
ISR (USART0_RX_vect)
{
static uint16_t crc;
static uint8_t ptr_rxd_buffer = 0;
uint8_t crc1, crc2;
uint8_t c;
// IdleTimer = 0;
if (current_hardware == Wi232)
{
// rx_byte = c;
// rxFlag = 1;
int diff;
uint8_t c;
c=UDR;
diff = rxhead - rxtail;
if (diff < 0) diff += UART_RXBUFSIZE;
if (diff < UART_RXBUFSIZE -1)
{
*rxhead = c;
++rxhead;
if (rxhead == (rxbuf + UART_RXBUFSIZE)) rxhead = rxbuf;
};
// USART_putc (c);
return;
}
 
 
if (current_hardware == MKGPS)
{
// rx_byte = c;
// rxFlag = 1;
int diff;
uint8_t c;
c=UDR;
diff = rxhead - rxtail;
if (diff < 0) diff += UART_RXBUFSIZE;
if (diff < UART_RXBUFSIZE -1)
{
*rxhead = c;
++rxhead;
if (rxhead == (rxbuf + UART_RXBUFSIZE)) rxhead = rxbuf;
};
 
return;
}
 
c = UDR; // catch the received byte
 
 
if (rxd_buffer_locked)
return; // if rxd buffer is locked immediately return
 
// the rxd buffer is unlocked
if ((ptr_rxd_buffer == 0) && (c == '#')) // if rxd buffer is empty and syncronisation character is received
{
rxd_buffer[ptr_rxd_buffer++] = c; // copy 1st byte to buffer
crc = c; // init crc
}
else if (ptr_rxd_buffer < RXD_BUFFER_LEN) // collect incomming bytes
{
if(c != '\r') // no termination character
{
rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer
crc += c; // update crc
}
else // termination character was received
{
// the last 2 bytes are no subject for checksum calculation
// they are the checksum itself
crc -= rxd_buffer[ptr_rxd_buffer-2];
crc -= rxd_buffer[ptr_rxd_buffer-1];
// calculate checksum from transmitted data
crc %= 4096;
crc1 = '=' + crc / 64;
crc2 = '=' + crc % 64;
// compare checksum to transmitted checksum bytes
if((crc1 == rxd_buffer[ptr_rxd_buffer-2]) && (crc2 == rxd_buffer[ptr_rxd_buffer-1]))
{ // checksum valid
rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character
ReceivedBytes = ptr_rxd_buffer + 1;// store number of received bytes
if (mode == rxd_buffer[2])
{
rxd_buffer_locked = TRUE; // lock the rxd buffer
// if 2nd byte is an 'R' enable watchdog that will result in an reset
if(rxd_buffer[2] == 'R') {wdt_enable(WDTO_250MS);} // Reset-Commando
}
}
else
{ // checksum invalid
stat_crc_error++;
rxd_buffer_locked = FALSE; // unlock rxd buffer
}
ptr_rxd_buffer = 0; // reset rxd buffer pointer
}
}
else // rxd buffer overrun
{
stat_overflow_error++;
ptr_rxd_buffer = 0; // reset rxd buffer
rxd_buffer_locked = FALSE; // unlock rxd buffer
}
}
 
 
//-----------------------------------------------------------------------------
// Function: uart0_getc()
// Purpose: return byte from ringbuffer
// Returns: lower byte: received byte from ringbuffer
// higher byte: last receive error
//-----------------------------------------------------------------------------
char USART_getc(void)
{
char val;
 
// while(rxhead==rxtail) ;
if (rxhead==rxtail)
return val=0;
// IdleTimer = 0;
val = *rxtail;
if (++rxtail == (rxbuf + UART_RXBUFSIZE))
rxtail = rxbuf;
 
return val;
}
 
 
uint8_t uart_getc_nb(uint8_t *c)
{
if (rxhead==rxtail)
return 0;
// IdleTimer = 0;
*c = *rxtail;
if (++rxtail == (rxbuf + UART_RXBUFSIZE))
rxtail = rxbuf;
return 1;
}
//-----------------------------------------------------------------------------
//
 
 
 
 
 
//-----------------------------------------------------------------------------
//
void USART_Init (unsigned int baudrate)
{
// set clock divider
// #undef BAUD
// #define BAUD baudrate
// #include <util/setbaud.h>
// UBRRH = UBRRH_VALUE;
// UBRRL = UBRRL_VALUE;
 
UBRRH = (unsigned char)(baudrate>>8);
UBRRL = (unsigned char) baudrate;
 
#if USE_2X
UCSRA |= (1 << U2X); // enable double speed operation
#else
UCSRA &= ~(1 << U2X); // disable double speed operation
#endif
 
// set 8N1
#if defined (__AVR_ATmega8__) || defined (__AVR_ATmega32__)
UCSRC = (1 << URSEL) | (1 << UCSZ1) | (1 << UCSZ0);
#else
UCSRC = (1 << UCSZ1) | (1 << UCSZ0);
#endif
UCSRB &= ~(1 << UCSZ2);
 
// flush receive buffer
while ( UCSRA & (1 << RXC) ) UDR;
 
UCSRB |= (1 << RXEN) | (1 << TXEN);
#ifdef USART_INT
UCSRB |= (1 << RXCIE) | (1 << TXCIE);
#else
UCSRB |= (1 << RXCIE);
#endif
 
rxhead = rxtail = rxbuf;
 
}
 
 
 
 
 
//-----------------------------------------------------------------------------
// disable the txd pin of usart
void USART_DisableTXD (void)
{
#ifdef USART_INT
UCSRB &= ~(1 << TXCIE); // disable TX-Interrupt
#endif
UCSRB &= ~(1 << TXEN); // disable TX in USART
DDRB &= ~(1 << DDB3); // set TXD pin as input
PORTB &= ~(1 << PORTB3); // disable pullup on TXD pin
}
 
//-----------------------------------------------------------------------------
// enable the txd pin of usart
void USART_EnableTXD (void)
{
DDRB |= (1 << DDB3); // set TXD pin as output
PORTB &= ~(1 << PORTB3); // disable pullup on TXD pin
UCSRB |= (1 << TXEN); // enable TX in USART
#ifdef USART_INT
UCSRB |= (1 << TXCIE); // enable TX-Interrupt
#endif
}
 
//-----------------------------------------------------------------------------
// short script to directly send a request thorugh usart including en- and disabling it
// where <address> is the address of the receipient, <label> is which data set to request
// and <ms> represents the milliseconds delay between data
void USART_request_mk_data (uint8_t cmd, uint8_t addr, uint8_t ms)
{
USART_EnableTXD (); // re-enable TXD pin
 
unsigned char mstenth = ms/10;
SendOutData(cmd, addr, 1, &mstenth, 1);
// wait until command transmitted
while (txd_complete == FALSE);
 
USART_DisableTXD (); // disable TXD pin again
}
 
//-----------------------------------------------------------------------------
//
void USART_putc (char c)
{
#ifdef USART_INT
#else
loop_until_bit_is_set(UCSRA, UDRE);
UDR = c;
#endif
}
 
 
 
//-----------------------------------------------------------------------------
//
void USART_puts (char *s)
{
#ifdef USART_INT
#else
while (*s)
{
USART_putc (*s);
s++;
}
#endif
}
 
//-----------------------------------------------------------------------------
//
void USART_puts_p (const char *s)
{
#ifdef USART_INT
#else
while (pgm_read_byte(s))
{
USART_putc (pgm_read_byte(s));
s++;
}
#endif
}
 
//-----------------------------------------------------------------------------
//
void SendOutData(uint8_t cmd, uint8_t addr, uint8_t numofbuffers, ...) // uint8_t *pdata, uint8_t len, ...
{
va_list ap;
uint16_t pt = 0;
uint8_t a,b,c;
uint8_t ptr = 0;
uint16_t tmpCRC = 0;
 
uint8_t *pdata = 0;
int len = 0;
 
txd_buffer[pt++] = '#'; // Start character
txd_buffer[pt++] = 'a' + addr; // Address (a=0; b=1,...)
txd_buffer[pt++] = cmd; // Command
 
va_start(ap, numofbuffers);
if(numofbuffers)
{
pdata = va_arg (ap, uint8_t*);
len = va_arg (ap, int);
ptr = 0;
numofbuffers--;
}
 
while(len)
{
if(len)
{
a = pdata[ptr++];
len--;
if((!len) && numofbuffers)
{
pdata = va_arg(ap, uint8_t*);
len = va_arg(ap, int);
ptr = 0;
numofbuffers--;
}
}
else
a = 0;
 
if(len)
{
b = pdata[ptr++];
len--;
if((!len) && numofbuffers)
{
pdata = va_arg(ap, uint8_t*);
len = va_arg(ap, int);
ptr = 0;
numofbuffers--;
}
}
else
b = 0;
 
if(len)
{
c = pdata[ptr++];
len--;
if((!len) && numofbuffers)
{
pdata = va_arg(ap, uint8_t*);
len = va_arg(ap, int);
ptr = 0;
numofbuffers--;
}
}
else
c = 0;
 
txd_buffer[pt++] = '=' + (a >> 2);
txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
txd_buffer[pt++] = '=' + ( c & 0x3f);
}
va_end(ap);
 
for(a = 0; a < pt; a++)
{
tmpCRC += txd_buffer[a];
}
tmpCRC %= 4096;
txd_buffer[pt++] = '=' + tmpCRC / 64;
txd_buffer[pt++] = '=' + tmpCRC % 64;
txd_buffer[pt++] = '\r';
 
txd_complete = FALSE;
#ifdef USART_INT
UDR = txd_buffer[0]; // initiates the transmittion (continued in the TXD ISR)
#else
for(a = 0; a < pt; a++)
{
loop_until_bit_is_set(UCSRA, UDRE);
UDR = txd_buffer[a];
}
txd_complete = TRUE;
#endif
}
 
//-----------------------------------------------------------------------------
//
void Decode64 (void)
{
uint8_t a,b,c,d;
uint8_t ptrIn = 3;
uint8_t ptrOut = 3;
uint8_t len = ReceivedBytes - 6;
 
while (len)
{
a = rxd_buffer[ptrIn++] - '=';
b = rxd_buffer[ptrIn++] - '=';
c = rxd_buffer[ptrIn++] - '=';
d = rxd_buffer[ptrIn++] - '=';
//if(ptrIn > ReceivedBytes - 3) break;
 
if (len--)
rxd_buffer[ptrOut++] = (a << 2) | (b >> 4);
else
break;
 
if (len--)
rxd_buffer[ptrOut++] = ((b & 0x0f) << 4) | (c >> 2);
else
break;
 
if (len--)
rxd_buffer[ptrOut++] = ((c & 0x03) << 6) | d;
else
break;
}
pRxData = &rxd_buffer[3];
RxDataLen = ptrOut - 3;
}
 
 
//-----------------------------------------------------------------------------
//
void SwitchToNC (void)
{
 
if(hardware == NC)
{
// switch to NC
USART_putc (0x1b);
USART_putc (0x1b);
USART_putc (0x55);
USART_putc (0xaa);
USART_putc (0x00);
current_hardware = NC;
_delay_ms (50);
}
}
 
//-----------------------------------------------------------------------------
//
 
 
//-----------------------------------------------------------------------------
//
void SwitchToWi232 (void)
{
 
// if(hardware == NC)
{
// switch to Wi232
current_hardware = Wi232;
_delay_ms (50);
}
}
 
//-----------------------------------------------------------------------------
//
void SwitchToFC (void)
{
uint8_t cmd;
 
if (current_hardware == NC)
{
// switch to FC
cmd = 0x00; // 0 = FC, 1 = MK3MAG, 2 = MKGPS
SendOutData('u', ADDRESS_NC, 1, &cmd, 1);
current_hardware = FC;
_delay_ms (50);
}
}
 
//-----------------------------------------------------------------------------
//
void SwitchToMAG (void)
{
uint8_t cmd;
 
if (current_hardware == NC)
{
// switch to MK3MAG
cmd = 0x01; // 0 = FC, 1 = MK3MAG, 2 = MKGPS
SendOutData('u', ADDRESS_NC, 1, &cmd, 1);
current_hardware = MK3MAG;
_delay_ms (50);
}
}
 
//-----------------------------------------------------------------------------
//
void SwitchToGPS (void)
{
uint8_t cmd;
if (current_hardware == NC)
{
// switch to MKGPS
cmd = 0x02; // 0 = FC, 1 = MK3MAG, 2 = MKGPS
SendOutData('u', ADDRESS_NC, 1, &cmd, 1);
current_hardware = MKGPS;
_delay_ms (50);
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/usart.h
0,0 → 1,149
/*****************************************************************************
* 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 _USART_H
#define _USART_H
 
//--------------------------------------------------------------
//
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
 
// addresses
#define ADDRESS_ANY 0
#define ADDRESS_FC 1
#define ADDRESS_NC 2
#define ADDRESS_MAG 3
 
// must be at least 4('#'+Addr+'CmdID'+'\r')+ (80 * 4)/3 = 111 bytes
#define TXD_BUFFER_LEN 60
#define RXD_BUFFER_LEN 180
 
// Baud rate of the USART
#define USART_BAUD 57600
//#define USART_BAUD 125000
 
//--------------------------------------------------------------
//
extern uint8_t buffer[30];
 
extern volatile uint8_t txd_buffer[TXD_BUFFER_LEN];
extern volatile uint8_t txd_complete;
extern volatile uint8_t txd1_buffer[TXD_BUFFER_LEN];
extern volatile uint8_t txd1_complete;
extern volatile uint8_t rxd_buffer[RXD_BUFFER_LEN];
extern volatile uint8_t rxd_buffer_locked;
extern volatile uint8_t ReceivedBytes;
extern volatile uint8_t *pRxData;
extern volatile uint8_t RxDataLen;
 
extern volatile uint16_t stat_crc_error;
extern volatile uint16_t stat_overflow_error;
 
extern volatile uint8_t rxFlag;
extern volatile uint8_t rx_byte;
 
//--------------------------------------------------------------
//
void USART_Init (unsigned int baudrate);
void USART_DisableTXD (void);
void USART_EnableTXD (void);
void USART_request_mk_data (uint8_t cmd, uint8_t addr, uint8_t ms);
 
void USART_putc (char c);
void USART_puts (char *s);
void USART_puts_p (const char *s);
 
 
extern char USART_getc(void);
void SendOutData (uint8_t cmd, uint8_t addr, uint8_t numofbuffers, ...); // uint8_t *pdata, uint8_t len, ...
//void SendOutData(uint8_t cmd, uint8_t addr, uint8_t numofbuffers, uint8_t *pdata, uint8_t len); // uint8_t *pdata, uint8_t len, ...
void Decode64 (void);
 
void SwitchToNC (void);
void SwitchToFC (void);
void SwitchToMAG (void);
void SwitchToGPS (void);
void SwitchToWi232 (void);
void debug1(void);
 
uint8_t uart_getc_nb(uint8_t*);
 
//--------------------------------------------------------------
//Anpassen der seriellen Schnittstellen Register
#define USART_RXC_vect USART0_RX_vect
//--------------------------------------------------------------
#define UCSRA UCSR0A
#define UCSRB UCSR0B
#define UCSRC UCSR0C
#define UDR UDR0
#define UBRRL UBRR0L
#define UBRRH UBRR0H
 
// UCSRA
#define RXC RXC0
#define TXC TXC0
#define UDRE UDRE0
#define FE FE0
#define UPE UPE0
#define U2X U2X0
#define MPCM MPCM0
 
// UCSRB
#define RXCIE RXCIE0
#define TXCIE TXCIE0
#define UDRIE UDRIE0
#define TXEN TXEN0
#define RXEN RXEN0
#define UCSZ2 UCSZ02
#define RXB8 RXB80
#define TXB8 TXB80
 
// UCSRC
#define UMSEL1 UMSEL01
#define UMSEL0 UMSEL00
#define UPM1 UPM01
#define UPM0 UPM00
#define USBS USBS0
#define UCSZ1 UCSZ01
#define UCSZ0 UCSZ00
#define UCPOL UCPOL0
 
 
#endif
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/waypoints.c
0,0 → 1,347
/*#######################################################################################*/
/* !!! THIS IS NOT FREE SOFTWARE !!! */
/*#######################################################################################*/
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Copyright (c) 2008 Ingo Busker, Holger Buss
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
// + FOR NON COMMERCIAL USE ONLY
// + www.MikroKopter.com
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + 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 oder Nutzung 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 permitted
// + 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 the sources to other systems or using the software on other systems (except 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 <string.h>
#include "91x_lib.h"
#include "waypoints.h"
#include "uart1.h"
 
// the waypoints list
#define MAX_LIST_LEN 31
 
Point_t PointList[MAX_LIST_LEN];
u8 WPIndex = 0; // list index of GPS point representig the current WP, can be maximal WPCount
u8 POIIndex = 0; // list index of GPS Point representing the current POI, can be maximal WPCount
u8 WPCount = 0; // number of waypoints
u8 PointCount = 0; // number of wp in the list can be maximal equal to MAX_LIST_LEN
u8 POICount = 0;
 
u8 WPActive = FALSE;
 
u8 PointList_Init(void)
{
return PointList_Clear();
}
 
u8 PointList_Clear(void)
{
u8 i;
WPIndex = 0; // real list position are 1 ,2, 3 ...
POIIndex = 0; // real list position are 1 ,2, 3 ...
WPCount = 0; // no waypoints
POICount = 0;
PointCount = 0; // no contents
WPActive = FALSE;
NaviData.WaypointNumber = WPCount;
NaviData.WaypointIndex = 0;
 
for(i = 0; i < MAX_LIST_LEN; i++)
{
PointList[i].Position.Status = INVALID;
PointList[i].Position.Latitude = 0;
PointList[i].Position.Longitude = 0;
PointList[i].Position.Altitude = 0;
PointList[i].Heading = 361; // invalid value
PointList[i].ToleranceRadius = 0; // in meters, if the MK is within that range around the target, then the next target is triggered
PointList[i].HoldTime = 0; // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before the next WP is triggered
PointList[i].Type = POINT_TYPE_INVALID;
PointList[i].Event_Flag = 0; // future implementation
PointList[i].AltitudeRate = 0; // no change of setpoint
}
return TRUE;
}
 
u8 PointList_GetCount(void)
{
return PointCount; // number of points in the list
}
 
Point_t* PointList_GetAt(u8 index)
{
if((index > 0) && (index <= PointCount)) return(&(PointList[index-1])); // return pointer to this waypoint
else return(NULL);
}
 
u8 PointList_SetAt(Point_t* pPoint)
{
// if index is in range
if((pPoint->Index > 0) && (pPoint->Index <= MAX_LIST_LEN))
{
// check list entry before update
switch(PointList[pPoint->Index-1].Type)
{
case POINT_TYPE_INVALID: // was invalid
switch(pPoint->Type)
{
default:
case POINT_TYPE_INVALID:
// nothing to do
break;
 
case POINT_TYPE_WP:
WPCount++;
PointCount++;
break;
case POINT_TYPE_POI:
POICount++;
PointCount++;
break;
}
break;
case POINT_TYPE_WP: // was a waypoint
switch(pPoint->Type)
{
case POINT_TYPE_INVALID:
WPCount--;
PointCount--;
break;
 
default:
case POINT_TYPE_WP:
//nothing to do
break;
case POINT_TYPE_POI:
POICount++;
WPCount--;
break;
}
break;
case POINT_TYPE_POI: // was a poi
switch(pPoint->Type)
{
case POINT_TYPE_INVALID:
POICount--;
PointCount--;
break;
 
case POINT_TYPE_WP:
WPCount++;
POICount--;
break;
case POINT_TYPE_POI:
default:
// nothing to do
break;
}
break;
}
memcpy(&PointList[pPoint->Index-1], pPoint, sizeof(Point_t)); // copy data to list entry
NaviData.WaypointNumber = WPCount;
return pPoint->Index;
}
else return(0);
}
 
// returns the pointer to the first waypoint within the list
Point_t* PointList_WPBegin(void)
{
u8 i;
WPIndex = 0; // set list position invalid
 
if(WPActive == FALSE) return(NULL);
 
POIIndex = 0; // set invalid POI
if(PointCount > 0)
{
// search for first wp in list
for(i = 0; i <MAX_LIST_LEN; i++)
{
if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID))
{
WPIndex = i + 1;
break;
}
}
if(WPIndex) // found a WP in the list
{
NaviData.WaypointIndex = 1;
// update index to POI
if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading);
else POIIndex = 0;
}
else // some points in the list but no WP found
{
NaviData.WaypointIndex = 0;
//Check for an existing POI
for(i = 0; i < MAX_LIST_LEN; i++)
{
if((PointList[i].Type == POINT_TYPE_POI) && (PointList[i].Position.Status != INVALID))
{
POIIndex = i + 1;
break;
}
}
}
}
else // no point in the list
{
POIIndex = 0;
NaviData.WaypointIndex = 0;
}
 
if(WPIndex) return(&(PointList[WPIndex-1]));
else return(NULL);
}
 
// returns the last waypoint
Point_t* PointList_WPEnd(void)
{
u8 i;
WPIndex = 0; // set list position invalid
POIIndex = 0; // set invalid
 
if(WPActive == FALSE) return(NULL);
 
if(PointCount > 0)
{
// search backward!
for(i = 1; i <= MAX_LIST_LEN; i++)
{
if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_WP) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID))
{
WPIndex = MAX_LIST_LEN - i + 1;
break;
}
}
if(WPIndex) // found a WP within the list
{
NaviData.WaypointIndex = WPCount;
if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading);
else POIIndex = 0;
}
else // list contains some points but no WP in the list
{
// search backward for a POI!
for(i = 1; i <= MAX_LIST_LEN; i++)
{
if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_POI) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID))
{
POIIndex = MAX_LIST_LEN - i + 1;
break;
}
}
NaviData.WaypointIndex = 0;
}
}
else // no point in the list
{
POIIndex = 0;
NaviData.WaypointIndex = 0;
}
if(WPIndex) return(&(PointList[WPIndex-1]));
else return(NULL);
}
 
// returns a pointer to the next waypoint or NULL if the end of the list has been reached
Point_t* PointList_WPNext(void)
{
u8 wp_found = 0;
if(WPActive == FALSE) return(NULL);
if(WPIndex < MAX_LIST_LEN) // if there is a next entry in the list
{
u8 i;
for(i = WPIndex; i < MAX_LIST_LEN; i++) // start search for next at next list entry
{
if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) // jump over POIs
{
wp_found = i+1;
break;
}
}
}
if(wp_found)
{
WPIndex = wp_found; // update list position
NaviData.WaypointIndex++;
if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading);
else POIIndex = 0;
return(&(PointList[WPIndex-1])); // return pointer to this waypoint
}
else
{ // no next wp found
NaviData.WaypointIndex = 0;
POIIndex = 0;
return(NULL);
}
}
 
void PointList_WPActive(u8 set)
{
if(set)
{
WPActive = TRUE;
PointList_WPBegin(); // uopdates POI index
}
else
{
WPActive = FALSE;
POIIndex = 0; // disable POI also
}
}
Point_t* PointList_GetPOI(void)
{
return PointList_GetAt(POIIndex);
}
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8b_FC086/waypoints.h
0,0 → 1,56
#ifndef _WAYPOINTS_H
#define _WAYPOINTS_H
 
//#include "ubx.h"
 
#define POINT_TYPE_INVALID 255
#define POINT_TYPE_WP 0
#define POINT_TYPE_POI 1
 
 
typedef struct
{
s32 Longitude; // in 1E-7 deg
s32 Latitude; // in 1E-7 deg
s32 Altitude; // in mm
u8 Status;// validity of data
} __attribute__((packed)) GPS_Pos_t;
 
 
typedef struct
{
GPS_Pos_t Position; // the gps position of the waypoint, see ubx.h for details
s16 Heading; // orientation, 0 no action, 1...360 fix heading, neg. = Index to POI in WP List
u8 ToleranceRadius; // in meters, if the MK is within that range around the target, then the next target is triggered
u8 HoldTime; // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before the next WP is triggered
u8 Event_Flag; // future implementation
u8 Index; // to indentify different waypoints, workaround for bad communications PC <-> NC
u8 Type; // typeof Waypoint
u8 WP_EventChannelValue; //
u8 AltitudeRate; // rate to change the setpoint
u8 reserve[8]; // reserve
} __attribute__((packed)) Point_t;
 
// Init List, return TRUE on success
u8 PointList_Init(void);
// Clear List, return TRUE on success
u8 PointList_Clear(void);
// Returns number of points in the list
u8 PointList_GetCount(void);
// return pointer to point at position
Point_t* PointList_GetAt(u8 index);
// set a point in the list at index, returns its index on success, else 0
u8 PointList_SetAt(Point_t* pPoint);
// goto the first WP in the list and return pointer to it
Point_t* PointList_WPBegin(void);
// goto the last WP in the list and return pointer to it
Point_t* PointList_WPEnd(void);
// goto next WP in the list and return pointer to it
Point_t* PointList_WPNext(void);
// enables/disables waypoint function
void PointList_WPActive(u8 set);
// returns pointer to actual POI
Point_t* PointList_GetPOI(void);
 
 
#endif // _WAYPOINTS_H
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property