Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 1471 → Rev 1472

/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_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 */
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_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
 
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_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
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_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
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_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
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_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();
}
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_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
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_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();
}
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_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
 
 
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/eeprom.c
0,0 → 1,353
/*****************************************************************************
* 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 = 254; // default ungesetzt
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
 
 
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("Neu Starten mit "), 0);
lcd_printp_at (18, 7, PSTR("OK"), 0);
BeepTime = 200;
BeepMuster = 0x0080;
 
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);
 
}
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_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
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_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
 
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_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
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_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
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_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__