Blame |
Last modification |
View Log
| RSS feed
/*****************************************************************************
* 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 <stdlib.h>
#include "lcd.h"
#include "timer.h"
#include "usart.h"
#include "mk-data-structs.h"
#include "parameter.h"
#include "menu.h"
#include "eeprom.h"
#include "parameter_names.h"
#include "messages.h"
#define TIMEOUT 500 // 5 sec
uint8_t display_settings_menu (void);
uint8_t display_param_menu (uint8_t);
uint8_t load_setting (uint8_t);
uint8_t write_setting (uint8_t);
uint8_t display_section_menu(void);
void edit_param(uint8_t);
void copy_setting(void);
mk_param_struct_t *mk_param_struct;
uint8_t ii;
volatile uint8_t offset = 0;
volatile uint8_t dmode = 0;
volatile uint8_t target_pos = 1;
volatile uint8_t offset2 = 0;
volatile uint8_t pmode = 0;
volatile uint8_t target_pos2 = 1;
volatile uint8_t setting = 0;
uint8_t changes = 0;
#define OFFSETOF(type, field) ((unsigned int) &(((type *) 0)->field))
#define MKOSO(field) (uint8_t)OFFSETOF(mk_param_struct_t, field)
//--------------------------------------------------------------
// Typ == (0 ohne Poti, 1 mit Poti, 2 bitfield, 3 serCh, 4 LEDmask, 5 Angle, 6 Empfaenger),
// |||
// Group, Typ, Min, Max, Struct-Name(Value), Default1, Default2, Default3+4+5,
// 0 1 2 3 4 5 6 7
// | | | | | | | |
// | | | / | | | /
// | | | / | | | /
// | | | / | | | /
// | | / / | | | /
// | | / / | | | /
// | / / / | | / /
// | / / / | | / /
// | / / / | | / /
// | / / / | | / /
// | / / / | | / /
// | | / / | | / /
// | | | | | | / /
// | | | | | | / /
// | | | | | | | /
// | | | | | | | /
// | | | | | | | |
// | | | | | | | |
// 0,0,1,12, MKOSO(Kanalbelegung)+2 , 1,1,1, // gas
prog_uchar param_config[8*PARAM_COUNT]=
{
// group 0 (kanaele) 1-15
0,0,1,12, MKOSO(Kanalbelegung)+2 , 1,1,1, // gas
0,0,1,12, MKOSO(Kanalbelegung)+3 , 4,4,4, // gier
0,0,1,12, MKOSO(Kanalbelegung)+0 , 3,3,3, // nick
0,0,1,12, MKOSO(Kanalbelegung)+1 , 2,2,2, // roll
0,3,1,25, MKOSO(Kanalbelegung)+4 , 5,5,5, // poti1
0,3,1,25, MKOSO(Kanalbelegung)+5 , 6,6,6, // poti2
0,3,1,25, MKOSO(Kanalbelegung)+6 , 7,7,7, // poti3
0,3,1,25, MKOSO(Kanalbelegung)+7 , 8,8,8, // poti4
0,3,1,25, MKOSO(Kanalbelegung)+8 , 9,9,9, // poti5
0,3,1,25, MKOSO(Kanalbelegung)+9 , 10,10,10, // poti6
0,3,1,25, MKOSO(Kanalbelegung)+10, 11,11,11, // poti7
0,3,1,25, MKOSO(Kanalbelegung)+11, 12,12,12, // poti8
0,0,0,12, MKOSO(MotorSafetySwitch), 0,0,0, // Motor Sicherungsswitch
0,2,0,CFG3_MOTOR_SWITCH_MODE , MKOSO(GlobalConfig3), 0,0,0, // kein Start ohne GPS Fix
0,2,0,CFG_SENSITIVE_RC, MKOSO(ExtraConfig), 0,0,0, // erweiterte signal pruefung
0,6,0,6, MKOSO(Receiver), 1,1,1,
// group 1 (main) 16-23
1,2,0,CFG_HOEHENREGELUNG, MKOSO(GlobalConfig), 0,0,0, // hoehenregler
1,2,0,CFG_GPS_AKTIV, MKOSO(GlobalConfig), 1,1,1, // gps
1,2,0,CFG_KOMPASS_AKTIV, MKOSO(GlobalConfig), 1,1,1, // kompass
1,2,0,CFG_KOMPASS_FIX, MKOSO(GlobalConfig), 0,0,0, // feste ausrichtung
1,2,0,CFG_SENSITIVE_RC, MKOSO(ExtraConfig), 0,0,0, // erweiterte signal pruefung
1,2,0,CFG_ACHSENKOPPLUNG_AKTIV, MKOSO(GlobalConfig), 1,1,1, // achsentkopplung
1,2,0,CFG_DREHRATEN_BEGRENZER, MKOSO(GlobalConfig), 0,0,0, // drehratenbregrenzung
1,2,0,CFG_HEADING_HOLD, MKOSO(GlobalConfig), 0,0,0, // heading hold
// group 2 (stick) 24-27
2,0,0,20, MKOSO(Stick_P), 10,8,6,
2,0,0,20, MKOSO(Stick_D), 16,16,10,
2,1,0,255, MKOSO(StickGier_P), 6,6,4,
2,1,0,255, MKOSO(ExternalControl), 0,0,0,
// group3 : looping 28-36
3,2,0,CFG_LOOP_OBEN, MKOSO(BitConfig), 0,0,0, // oben
3,2,0,CFG_LOOP_UNTEN, MKOSO(BitConfig), 0,0,0, // unten
3,2,0,CFG_LOOP_LINKS, MKOSO(BitConfig), 0,0,0, // links
3,2,0,CFG_LOOP_RECHTS, MKOSO(BitConfig), 0,0,0, // rechts
3,1,0,255, MKOSO(LoopGasLimit), 50,50,50,
3,0,0,247, MKOSO(LoopThreshold), 90,90,90,
3,0,0,247, MKOSO(LoopHysterese), 50,50,50,
3,0,0,247, MKOSO(WinkelUmschlagNick), 78,78,78,
3,0,0,247, MKOSO(WinkelUmschlagRoll), 78,78,78,
// group 4 (hoehe) 37-50
4,2,0,CFG_HOEHENREGELUNG, MKOSO(GlobalConfig), 0,0,0, // hoehenrelger
4,2,0,CFG2_HEIGHT_LIMIT, MKOSO(ExtraConfig), 0,0,0, // vario oder hoeenbergenzung
4,2,0,CFG_HOEHEN_SCHALTER, MKOSO(GlobalConfig), 1,1,1, // hoehenschalter
4,2,0,CFG2_VARIO_BEEP, MKOSO(ExtraConfig), 1,1,1, // variobeep
4,1,0,255, MKOSO(MaxHoehe), 255,255,255,
4,0,0,247, MKOSO(Hoehe_MinGas), 30,30,30,
4,1,0,255, MKOSO(Hoehe_P), 15,15,15,
4,1,0,255, MKOSO(Luftdruck_D), 30,30,30,
4,1,0,255, MKOSO(Hoehe_ACC_Wirkung), 0,0,0,
4,1,0,255, MKOSO(MaxAltitude), 150,150,150,
4,0,0,247, MKOSO(Hoehe_Verstaerkung), 15,15,15,
4,0,0,247, MKOSO(Hoehe_HoverBand), 8,8,8,
4,1,0,255, MKOSO(Hoehe_GPS_Z), 64,64,64,
4,0,0,160, MKOSO(Hoehe_StickNeutralPoint), 0,0,0,
// group 5 : kamera 51-68
5,1,0,255, MKOSO(ServoNickControl), 128,128,128,
5,0,0,247, MKOSO(ServoNickComp), 50,50,50,
5,2,0,0x01, MKOSO(ServoCompInvert), 0,0,0, // nick
5,0,0,247, MKOSO(ServoNickMin), 15,15,15,
5,0,0,247, MKOSO(ServoNickMax), 230,230,230,
5,0,0,25, MKOSO(ServoFilterNick), 0,0,0, //FC0.87
5,1,0,255, MKOSO(ServoRollControl), 128,128,128,
5,0,0,247, MKOSO(ServoRollComp), 85,85,85,
5,2,0,0x02, MKOSO(ServoCompInvert), 0,0,0, // roll
5,0,0,247, MKOSO(ServoRollMin), 70,70,70,
5,0,0,247, MKOSO(ServoRollMax), 220,220,220,
5,0,0,25, MKOSO(ServoFilterRoll), 0,0,0, //FC0.87
5,0,2,8, MKOSO(ServoNickRefresh), 4,4,4,
5,0,0,247, MKOSO(ServoManualControlSpeed), 60,60,60,
5,5,0,247, MKOSO(CamOrientation), 0,0,0,
5,1,0,255, MKOSO(Servo3), 125,125,125,
5,1,0,255, MKOSO(Servo4), 125,125,125,
5,1,0,255, MKOSO(Servo5), 125,125,125,
// group 6 : navictrl 67-85
6,2,0,0x20, MKOSO(GlobalConfig), 1,1,1, // gps
6,1,0,255, MKOSO(NaviGpsModeControl), 254,254,254,
6,1,0,255, MKOSO(NaviGpsGain), 100,100,100,
6,0,0,247, MKOSO(NaviStickThreshold), 8,8,8,
6,0,0,247, MKOSO(NaviGpsMinSat), 6,6,6,
6,1,0,255, MKOSO(NaviGpsP), 90,90,90,
6,1,0,255, MKOSO(NaviGpsI), 90,90,90,
6,1,0,255, MKOSO(NaviGpsD), 90,90,90,
6,1,0,255, MKOSO(NaviGpsPLimit), 75,75,75,
6,1,0,255, MKOSO(NaviGpsILimit), 85,85,85,
6,1,0,255, MKOSO(NaviGpsDLimit), 75,75,75,
6,1,0,255, MKOSO(NaviGpsACC), 0,0,0,
6,1,0,255, MKOSO(NaviWindCorrection), 90,90,90,
6,1,0,255, MKOSO(NaviAccCompensation), 42,42,42,
6,1,0,255, MKOSO(NaviOperatingRadius), 245,245,245,
6,1,0,255, MKOSO(NaviAngleLimitation), 140,140,140,
6,0,0,247, MKOSO(NaviPH_LoginTime), 5,5,5,
6,2,0,CFG_GPS_AID, MKOSO(ExtraConfig), 0,0,0, // FC0.87dynamic ph
6,2,0,CFG3_DPH_MAX_RADIUS , MKOSO(GlobalConfig3), 0,0,0, // FC0.87
6,0,0,247, MKOSO(ComingHomeAltitude), 0,0,0,
// group 7 : ausgaenge 86-95
7,4,0,255, MKOSO(J16Bitmask), 95,95,95,
7,1,0,255, MKOSO(J16Timing), 20,20,20,
7,2,0,CFG_MOTOR_OFF_LED1, MKOSO(BitConfig), 0,0,0, // Motor_Off_Led1
7,2,0,CFG_MOTOR_BLINK1, MKOSO(BitConfig), 1,1,1, // Motor_Blink1
7,4,0,255, MKOSO(J17Bitmask), 243,243,243,
7,1,0,255, MKOSO(J17Timing), 20,20,20,
7,2,0,CFG_MOTOR_OFF_LED2, MKOSO(BitConfig), 0,0,0, // Motor_Off_Led2
7,2,0,CFG_MOTOR_BLINK2, MKOSO(BitConfig), 1,1,1, // Motor_Blink2
7,4,0,255, MKOSO(WARN_J16_Bitmask), 170,170,170,
7,4,0,255, MKOSO(WARN_J17_Bitmask), 170,170,170,
// group 8 : versch. 96-107
8,0,0,247, MKOSO(Gas_Min), 8,8,8,
8,0,0,247, MKOSO(Gas_Max), 230,230,230,
8,1,0,255, MKOSO(KompassWirkung), 64,64,64,
8,1,0,255, MKOSO(CareFreeModeControl), 0,0,0, // Carefree
8,2,0,CFG_LEARNABLE_CAREFREE, MKOSO(ExtraConfig), 0,0,0, // teachable Carefree
8,0,0,247, MKOSO(UnterspannungsWarnung), 33,33,33,
8,2,0,CFG_3_3V_REFERENCE, MKOSO(ExtraConfig), 0,0,0, // Voltage referenz
8,0,0,247, MKOSO(NotGasZeit), 90,90,90,
8,0,0,247, MKOSO(NotGas), 45,45,45,
8,0,0,247, MKOSO(FailSafeTime), 0,0,0, // Failsavetime
8,0,0,12, MKOSO(FailsafeChannel), 0,0,0, // FC0.87 Failsave Channel
8,2,0,CFG_NO_RCOFF_BEEPING, MKOSO(ExtraConfig), 0,0,0, // Kein Summer ohne Sender beim Start
8,2,0,CFG3_VARIO_FAILSAFE, MKOSO(GlobalConfig3), 0,0,0, //use vario Control for failsafe altitude
8,2,0,CFG_IGNORE_MAG_ERR_AT_STARTUP, MKOSO(ExtraConfig), 0,0,0, // Ignore Compass Error
8,2,0,CFG3_NO_SDCARD_NO_START , MKOSO(GlobalConfig3), 0,0,0, // nicht starten ohne SD Karte
8,2,0,CFG3_NO_GPSFIX_NO_START , MKOSO(GlobalConfig3), 0,0,0, // kein Start ohne GPS Fix
// group 9 : gyro 108-120
9,1,0,255, MKOSO(Gyro_P), 90,100,100,
9,1,0,255, MKOSO(Gyro_I), 120,120,120,
9,1,0,255, MKOSO(Gyro_D), 10,10,10,
9,1,0,255, MKOSO(Gyro_Gier_P), 90,100,100,
9,1,0,255, MKOSO(Gyro_Gier_I), 120,120,120,
9,1,0,255, MKOSO(DynamicStability), 70,70,70,
9,2,0,CFG_DREHRATEN_BEGRENZER, MKOSO(GlobalConfig), 0,0,0, // drehratenbregrenzung
9,0,0,247, MKOSO(GyroAccFaktor), 27,27,27,
9,0,0,247, MKOSO(GyroAccAbgleich), 32,32,32,
9,1,0,255, MKOSO(I_Faktor), 16,16,16,
9,0,0,247, MKOSO(Driftkomp), 0,0,0,
9,0,0,16, MKOSO(Gyro_Stability), 6,6,6,
9,0,0,247, MKOSO(MotorSmooth), 0,0,0,
// group 10: benutzer 121-128
10,1,0,255, MKOSO(UserParam1), 0,0,0,
10,1,0,255, MKOSO(UserParam2), 0,0,0,
10,1,0,255, MKOSO(UserParam3), 0,0,0,
10,1,0,255, MKOSO(UserParam4), 0,0,0,
10,1,0,255, MKOSO(UserParam5), 0,0,0,
10,1,0,255, MKOSO(UserParam6), 0,0,0,
10,1,0,255, MKOSO(UserParam7), 0,0,0,
10,1,0,255, MKOSO(UserParam8), 0,0,0,
// group 11: achskoppl 129-132
11,2,0,CFG_ACHSENKOPPLUNG_AKTIV, MKOSO(GlobalConfig), 0,0,0, // achsentkopplung
11,1,0,255, MKOSO(AchsKopplung1), 90,90,90,
11,1,0,255, MKOSO(AchsKopplung2), 55,55,55,
11,1,0,255, MKOSO(CouplingYawCorrection), 70,70,70,
// group 12: mixer 133
12,5,0,23,MKOSO(OrientationAngle), 0,0,0,
// group 13 (easy-setup) 134-144
13,2,0,0x01, MKOSO(GlobalConfig), 0,0,0, // hoehenrelger
13,1,0,255, MKOSO(MaxHoehe), 255,255,255,
13,0,0,160, MKOSO(Hoehe_StickNeutralPoint), 0,0,0,
13,2,0,0x20, MKOSO(GlobalConfig), 1,1,1, // gps
13,1,0,255, MKOSO(NaviGpsModeControl), 254,254,254,
13,2,0,0x20, MKOSO(ExtraConfig), 0,0,0, // dynamic ph
13,0,0,247, MKOSO(ComingHomeAltitude), 0,0,0,
13,1,0,255, MKOSO(CareFreeModeControl), 0,0,0, // Carefree
13,2,0,0x40, MKOSO(ExtraConfig), 0,0,0, // teachable Carefree
13,0,0,12, MKOSO(MotorSafetySwitch), 0,0,0, // Motor Sicherungsswitch
13,5,0,23, MKOSO(OrientationAngle), 0,0,0,
};
//--------------------------------------------------------------
#define ITEMS_RX 9
prog_char param_items_rx[ITEMS_RX][17]= // zeilen,zeichen+1
{
"PPM ",
"Spektrum ",
"Spektrum HiRes ",
"Spektrum LoRes ",
"Jeti ",
"ACT DSL ",
"HOTT ",
"Futuba SBUS ",
"User ",
};
//--------------------------------------------------------------
void edit_parameter(void)
{
SwitchToFC();
// uint8_t setting;
setting = display_settings_menu();
if(setting == 255)
return;
if(setting == 6)
{
copy_setting();
return;
}
lcd_cls();
// lcd_printp_at (0, 0, PSTR(" Setting x "), 2);
lcd_puts_at(0, 0, strGet(PARA_SETTINGS), 2);
lcd_putc (15, 0, (setting + 48), 2); // ASCII ab 48 (hex 30) beginnt 0 - 9
// lcd_printp_at (3, 2, PSTR("ändern"), 0);
// lcd_printp_at (3, 3, PSTR("aktivieren"), 0);
lcd_puts_at(3, 2, strGet(PARA_CHANGE), 0);
lcd_puts_at(3, 3, strGet(PARA_AKTIVI), 0);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
uint8_t val = menu_choose2 (2, 3, 2, 0, 0);
if (val == 255)
return;
if(val == 3)
{
load_setting(setting);
uint8_t setting_written = write_setting(setting);
if(setting_written == setting)
{
lcd_cls_line (0,2,21);
lcd_cls_line (0,3,21);
// lcd_printp_at (11, 0, PSTR("aktiviert"), 0);
lcd_puts_at(5, 2, strGet(PARA_AKTIV), 0);
}
else
{
lcd_cls_line (0,2,21);
lcd_cls_line (0,3,21);
// lcd_printp_at (0, 4, PSTR("Error"), 0);
lcd_puts_at(0, 4, strGet(FEHLER), 0);
}
_delay_ms(2000);
return;
}
if(setting == 255)
return;
uint8_t setting_loaded = load_setting(setting);
if(setting_loaded == 255)
return;
offset = 0;
dmode = 0;
target_pos = 1;
changes =0;
uint8_t group =0;
do
{
group = display_section_menu();
if(group != 255)
{
offset2 = 0;
pmode = 0;
target_pos2 = 1;
uint8_t param;
do
{
param = display_param_menu(group);
if(param != 255)
{
edit_param(param);
}
}
while(param != 255);
}
}
while(group != 255);
if(changes == 1)
{
lcd_cls();
// lcd_printp_at (0, 0, PSTR(" Setting x speichern?"), 2);
lcd_puts_at(0, 0, strGet(PARA_SAVESETT), 2);
lcd_putc (9, 0, (setting + 48), 2); // ASCII ab 48 (hex 30) beginnt 0 - 9
write_ndigit_number_u(9, 0, setting, 1, 0,0);
// lcd_printp_at (3, 2, PSTR("Ja"), 0);
// lcd_printp_at (3, 3, PSTR("Nein"), 0);
lcd_puts_at(3, 2, strGet(YES), 0);
lcd_puts_at(3, 3, strGet(NOO), 0);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
uint8_t val = menu_choose2 (2, 3, 2, 0, 0);
if(val == 2)
{
uint8_t setting_written = write_setting(setting);
if(setting_written == setting)
{
// lcd_printp_at (3, 4, PSTR("Gespeichert und"), 0);
lcd_puts_at(3, 4, strGet(PARA_SETTSAVED), 0);
// lcd_printp_at (3, 5, PSTR("Aktiviert"), 0);
lcd_puts_at(3, 5, strGet(PARA_AKTIV), 0);
}
else
{
// lcd_printp_at (0, 4, PSTR("Error"), 0);
lcd_puts_at(0, 4, strGet(FEHLER), 0);
}
timer = 100;
while (timer > 0);
}
}
}
//--------------------------------------------------------------
void copy_setting(void)
{
uint8_t fromsetting = 3;
uint8_t tosetting = 5;
lcd_cls();
// lcd_printp_at (0, 1, PSTR("Kopiere Setting"), 0);
// lcd_printp_at (0, 3, PSTR("von x nach y"), 0);
// lcd_printp_at (0, 7, PSTR("von nach Ende OK"), 0);
lcd_puts_at(0, 1, strGet(PARA_COPY), 0);
lcd_puts_at(0, 3, strGet(PARA_FROMTO), 0);
lcd_puts_at(0, 7, strGet(PARA_ENDE), 0);
do
{
write_ndigit_number_u(5,3,fromsetting, 1,0,0);
write_ndigit_number_u(14,3,tosetting, 1,0,0);
if(get_key_press (1 << KEY_MINUS))
{
fromsetting++;
if(fromsetting == 6) fromsetting = 1;
}
if(get_key_press (1 << KEY_PLUS))
{
tosetting++;
if(tosetting == 6) tosetting = 1;
}
if(get_key_press (1 << KEY_ENTER))
{
lcd_printp_at (0, 5, PSTR("Wirklich Kopieren?"), 0);
lcd_puts_at(0, 5, strGet(PARA_COPYQ), 0);
// lcd_printp_at (0, 7, PSTR(" Ende OK"), 0);
lcd_puts_at(12, 7, strGet(KEYLINE4), 0);
do
{
if(get_key_press (1 << KEY_ENTER))
{
uint8_t loaded = load_setting(fromsetting);
if(loaded == fromsetting)
{
uint8_t written = write_setting(tosetting);
if(written == tosetting)
{
lcd_printp_at (0, 5, PSTR("Kopiert und Aktiviert"), 0);
lcd_puts_at(0, 5, strGet(PARA_COPYACTIV), 0);
}
else
{
// lcd_printp_at (0, 5, PSTR("Fehler"), 0);
lcd_puts_at(0, 5, strGet(FEHLER), 0);
lcd_cls_line (6, 5, 14);
}
}
else
{
// lcd_printp_at (0, 5, PSTR("Fehler"), 0);
lcd_puts_at(0, 5, strGet(FEHLER), 0);
lcd_cls_line (6, 5, 14);
}
timer = 100;
while (timer > 0);
return;
}
}
while (!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
lcd_cls_line (0, 5, 21);
// lcd_printp_at (0, 7, PSTR("von nach Ende OK"), 0);
lcd_puts_at(0, 7, strGet(PARA_ENDE), 0);
}
}
while (!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
}
//--------------------------------------------------------------
void edit_param(uint8_t param)
{
lcd_cls();
uint8_t type = pgm_read_byte(param_config+(8*param)+1);
// lcd_printp_at (0, 0, PSTR(" Ändere Setting: "), 2);
lcd_puts_at(0, 0, strGet(PARA_CHANGESETT), 2);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
if(type != 6)
lcd_printp_at(0,2,param_names[param][DisplayLanguage], 0);
//-------------------------------------------------------
if(type == 0) // ohne poti
{
lcd_printp_at (4, 4, PSTR("( - ) (d: )"), 0);
lcd_printp_at (12, 6, PSTR("Std."), 0);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
uint8_t min = pgm_read_byte(param_config+(8*param)+2);
uint8_t max = pgm_read_byte(param_config+(8*param)+3);
uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4));
uint8_t defaultvalue = pgm_read_byte(param_config+(8*param)+4 + setting ); // 5 - 7
uint8_t newvalue = value;
write_ndigit_number_u (5, 4, min, 3, 0,0);
write_ndigit_number_u (9, 4, max, 3, 0,0);
write_ndigit_number_u (17, 4, defaultvalue, 3, 0,0);
do
{
write_ndigit_number_u (0, 4, newvalue, 3, 0,0);
lcd_frect ((8*0), (8*5), (newvalue * (16*8) / max), 6, 1);
if(max >= 50)
{
if(get_key_press (1 << KEY_PLUS) | get_key_long_rpt_sp ((1 << KEY_PLUS), 3))
{
if((newvalue+1) <= max)
newvalue++;
}
if(get_key_press (1 << KEY_MINUS) | get_key_long_rpt_sp ((1 << KEY_MINUS), 3))
{
if((newvalue-1) >= min)
{
lcd_frect (((newvalue - 1) * (16*8) / max), (8*5), (16*8), 6, 0);
// lcd_frect ((newvalue * (16*8) / max), (8*5), ((16*8) / max), 6, 0);
newvalue--;
}
}
}
else
{
if(get_key_press (1 << KEY_PLUS) | get_key_long_rpt_sp ((1 << KEY_PLUS), 2))
{
if((newvalue+1) <= max)
newvalue++;
}
if(get_key_press (1 << KEY_MINUS) | get_key_long_rpt_sp ((1 << KEY_MINUS), 2))
{
if((newvalue-1) >= min)
{
lcd_frect (((newvalue - 1) * (16*8) / max), (8*5), (16*8), 6, 0);
// lcd_frect ((newvalue * (16*8) / max), (8*5), ((16*8) / max), 6, 0);
newvalue--;
}
}
}
if(get_key_long (1 << KEY_ESC))
{
lcd_frect ((8*0), (8*5), (16*8), 6, 0);
newvalue = defaultvalue;
}
if(get_key_short (1 << KEY_ENTER))
{
if(newvalue != value)
{
*(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4)) = newvalue;
changes=1;
}
break;
}
}
while (!get_key_short (1 << KEY_ESC));
get_key_press(KEY_ALL);
}
//-------------------------------------------------------
if(type == 1) // mit poti
{
lcd_printp_at (4, 4, PSTR("(0-247-P8)(d:Po )"), 0);
lcd_printp_at (12, 6, PSTR("Std."), 0);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
uint8_t min = pgm_read_byte(param_config+(8*param)+2);
uint8_t max = pgm_read_byte(param_config+(8*param)+3);
uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4));
uint8_t defaultvalue = pgm_read_byte(param_config+(8*param)+4 + setting ); // 5 - 7
uint8_t newvalue = value;
uint8_t mode = 0;
if(defaultvalue > 247)
{
lcd_printp_at (17, 4, PSTR("Po )"), 0);
write_ndigit_number_u (19, 4, 256-defaultvalue, 1, 0,0);
}
else
write_ndigit_number_u (17, 4, defaultvalue, 3, 0,0);
if(value > 247)
mode = 1;
do
{
if(newvalue > 247)
mode = 1;
else
mode = 0;
if(mode == 0)
{
write_ndigit_number_u (0, 4, newvalue, 3, 0,0);
lcd_frect ((8*0), (8*5), (newvalue * (16*8) / max), 6, 1);
if(get_key_press (1 << KEY_PLUS) | get_key_long_rpt_sp ((1 << KEY_PLUS), 3))
{
if((newvalue+1) <= max)
newvalue++;
if(newvalue > 247)
{
lcd_frect ((8*0), (8*5), (16*8), 6, 0);
newvalue = 255;
}
}
if(get_key_press (1 << KEY_MINUS) | get_key_long_rpt_sp ((1 << KEY_MINUS), 3))
{
if((newvalue-1)>=min)
{
lcd_frect (((newvalue - 1) * (16*8) / max), (8*5), (16*8), 6, 0);
// lcd_frect ((newvalue * (16*8) / max), (8*5), ((16*8) / max), 6, 0);
newvalue--;
}
}
}
else
{
lcd_printp_at (0, 4, PSTR("Po"), 0);
write_ndigit_number_u (2, 4, 256 - newvalue, 1, 0,0);
lcd_frect ((8*0), (8*5), ((256 - newvalue) * (16*8) / 8), 6, 1);
if(get_key_press (1 << KEY_PLUS) | get_key_long_rpt_sp ((1 << KEY_PLUS), 1))
{
if(newvalue - 1 > 247)
{
newvalue--;
}
}
if(get_key_press (1 << KEY_MINUS) | get_key_long_rpt_sp ((1 << KEY_MINUS), 1))
{
lcd_frect (((255 - newvalue) * (16*8) / 8), (8*5), (16*8), 6, 0);
// lcd_frect (((255 - newvalue) * (16*8) / 8), (8*5), ((16*8) / 8), 6, 0);
newvalue++;
if(newvalue == 0)
{
lcd_frect ((8*0), (8*5), (16*8), 6, 0); // balken löschen
newvalue = 247;
}
}
}
if(get_key_long (1 << KEY_ESC))
{
lcd_frect ((8*0), (8*5), (16*8), 6, 0);
newvalue = defaultvalue;
}
if(get_key_short (1 << KEY_ENTER))
{
if(newvalue != value)
{
*(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4)) = newvalue;
changes=1;
}
break;
}
}
while (!get_key_short (1 << KEY_ESC));
get_key_press(KEY_ALL);
}
//-------------------------------------------------------
if(type == 2) // ja/nein
{
// lcd_printp_at (3, 4, PSTR("Ja"), 0);
// lcd_printp_at (3, 5, PSTR("Nein"), 0);
lcd_puts_at(3, 4, strGet(YES), 0);
lcd_puts_at(3, 5, strGet(NOO), 0);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
uint8_t bitmap = pgm_read_byte(param_config+(8*param)+3);
uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4));
uint8_t defaultvalue = pgm_read_byte(param_config+(8*param)+4 + setting ); // 5 - 7
uint8_t newvalue = value;
if(defaultvalue == 1)
lcd_printp_at (8, 4, PSTR("*"), 0);
if(defaultvalue == 0)
lcd_printp_at (8, 5, PSTR("*"), 0);
do
{
if(newvalue & bitmap)
{
lcd_printp_at (1, 4, PSTR("\x1d"), 0);
lcd_printp_at (1, 5, PSTR(" "), 0);
}
else
{
lcd_printp_at (1, 4, PSTR(" "), 0);
lcd_printp_at (1, 5, PSTR("\x1d"), 0);
}
if((get_key_press (1 << KEY_MINUS)) && (!(newvalue & bitmap)))
newvalue ^= bitmap;
if((get_key_press (1 << KEY_PLUS)) && (newvalue & bitmap))
newvalue ^= bitmap;
if(get_key_press (1 << KEY_ENTER))
{
if(newvalue != value)
{
*(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4)) = newvalue;
changes=1;
}
break;
}
}
while (!get_key_short (1 << KEY_ESC));
get_key_press(KEY_ALL);
}
//-------------------------------------------------------
if(type == 3) // serCH
{
lcd_printp_at (4, 4, PSTR("(1-S12/W) (d: )"), 0);
lcd_printp_at (12, 6, PSTR("Std."), 0);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
uint8_t min = pgm_read_byte(param_config+(8*param)+2);
uint8_t max = pgm_read_byte(param_config+(8*param)+3);
uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4));
uint8_t defaultvalue = pgm_read_byte(param_config+(8*param)+4 + setting ); // 5 - 7
uint8_t newvalue = value;
write_ndigit_number_u (17, 4, defaultvalue, 3, 0,0);
do
{
if (newvalue<=(max-13))
write_ndigit_number_u (0, 4, newvalue, 3, 0,0);
else
{
if (newvalue<=(max-1))
{
lcd_printp_at (0, 4, PSTR("S"), 0);
write_ndigit_number_u (1, 4, (newvalue-12), 2, 0,0);
}
}
if (newvalue==max)
lcd_printp_at (0, 4, PSTR("WPE"), 0);
lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 1);
if(get_key_press (1 << KEY_PLUS) | get_key_long_rpt_sp ((1 << KEY_PLUS), 2))
{
if((newvalue+1) <= max)
newvalue++;
}
if(get_key_press (1 << KEY_MINUS) | get_key_long_rpt_sp ((1 << KEY_MINUS), 2))
{
if((newvalue-1)>=min)
{
lcd_frect (((newvalue - 1) * (16*8) / max), (8*5), (16*8), 6, 0);
newvalue--;
}
}
if(get_key_long (1 << KEY_ESC))
{
lcd_frect ((8*0), (8*5), (16*8), 6, 0);
newvalue = defaultvalue;
}
if(get_key_short (1 << KEY_ENTER))
{
if(newvalue != value)
{
*(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4)) = newvalue;
changes=1;
}
break;
}
}
while (!get_key_short (1 << KEY_ESC));
get_key_press(KEY_ALL);
}
//-------------------------------------------------------
if(type == 4) // led bitfeld
{
// TODO: Übersetzung
lcd_printp_at (0, 7, PSTR(" \x19 0\x11I Ende OK"), 0);
if (param == 93 || param == 94)
// lcd_printp_at (5, 6, PSTR("aktiv"), 0);
lcd_puts_at(5, 6, strGet(AKTIV), 0);
uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4));
uint8_t newvalue = value;
uint8_t pos = 0;
do
{
for(ii = 0; ii < 8; ii++)
{
if(newvalue & (1 << ii))
lcd_printp_at (8-ii, 4,PSTR("1"),0);
else
lcd_printp_at (8-ii, 4,PSTR("0"),0);
}
lcd_printp_at (pos+1, 5,PSTR("\x12"),0);
if(get_key_press (1 << KEY_MINUS))
{
lcd_printp_at (pos+1, 5,PSTR(" "),0);
pos++;
if(pos == 8)
pos = 0;
}
if (param == 93 || param == 94)
{
if(get_key_long (1 << KEY_PLUS))
{
if (newvalue != 0)
newvalue = 0;
else
newvalue = 170;
}
}
if(get_key_short (1 << KEY_PLUS))
newvalue ^= (1<<(7-pos));
if(get_key_short (1 << KEY_ENTER))
{
if(newvalue != value)
{
*(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4)) = newvalue;
changes = 1;
}
break;
}
}
while (!get_key_short (1 << KEY_ESC));
get_key_press(KEY_ALL);
}
//-------------------------------------------------------
if(type == 5) // Angle
{
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4));
lcd_ecircle(102, 35, 16, 1);
uint8_t newvalue = value;
uint8_t oldvalue = newvalue;
do
{
if(oldvalue != newvalue) lcd_ecirc_line (102, 35, 15, oldvalue*15, 0);
oldvalue = newvalue;
lcd_ecirc_line (102, 35, 15, newvalue*15, 1);
if(get_key_press (1 << KEY_PLUS) | get_key_long_rpt_sp ((1 << KEY_PLUS), 1))
{
newvalue++;
if(newvalue == 24)
newvalue = 0;
}
if(get_key_press (1 << KEY_MINUS) | get_key_long_rpt_sp ((1 << KEY_MINUS), 1))
{
if(newvalue == 0)
newvalue = 24;
newvalue--;
}
if(get_key_short (1 << KEY_ENTER))
{
if(newvalue != value)
{
*(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4)) = newvalue;
changes=1;
}
break;
}
}
while (!get_key_short (1 << KEY_ESC));
get_key_press(KEY_ALL);
}
//-------------------------------------------------------
if(type == 6) // receiver
{
uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4));
uint8_t newvalue = value + 1;
uint8_t val =0;
uint8_t ii = 0;
uint8_t offset = 0;
uint8_t dmode = 0;
uint8_t target_pos = 1;
uint8_t size = ITEMS_RX;
// 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_items_rx[ii+offset], 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_choose3 (1, 5, target_pos,0,1); //menu_choose3 (min, max, start, return_at_start, return_at_end)
else
val = menu_choose3 (1, size, target_pos,0,0);
}
else
val = menu_choose3 (2, 5, target_pos,1,1);
}
if(dmode == 1)
{
if(offset+7 > size)
val = menu_choose3 (2, 6, target_pos,1,0);
else
val = menu_choose3 (2, 5, target_pos,1,1);
}
if(val == 254) // überlauf unten
{
offset++;
dmode = 1;
target_pos = 5;
}
else if(val == 253) // überlauf oben
{
offset--;
dmode = 0;
target_pos = 2;
}
else if(val == 252) // ESC
return;
else if(val <= size)
{
newvalue = val + offset - 1;
*(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4)) = newvalue;
changes=1;
return;
}
}
}
}
//--------------------------------------------------------------
uint8_t display_param_menu(uint8_t group)
{
uint8_t items[20];
uint8_t size=0;
for(ii = 0;ii < PARAM_COUNT; ii++)
{
if(pgm_read_byte(param_config+(8*ii)) == (group-1))
{
items[size] = ii;
size++;
}
}
uint8_t val =0 ;
while(1)
{
lcd_cls ();
// lcd_printp_at (0, 0, PSTR(" Wähle Parameter: "), 2);
lcd_puts_at(0, 0, strGet(PARA_SELECT), 2);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
ii = 0;
if(offset2 > 0)
lcd_printp_at(1,1, PSTR("\x12"), 0);
for(ii = 0;ii < 6 ; ii++)
{
if((ii+offset2) < size)
{
lcd_printp_at(3,ii+1,param_names[items[ii+offset2]][DisplayLanguage], 0);
// this reads the the offset in the struct from the pgm configuration table and then reads the value from the struct
uint8_t type = pgm_read_byte(param_config+(8*items[ii+offset2])+1);
if(type == 0)
{
write_ndigit_number_u (18, ii+1, *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4)), 3, 0,0);
if (group == 9) // % Anzeige für Notgas wenn Variohöhe für Notgas verwendet wird
{
if (ii+offset2 == 8)
{
uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[(ii+offset2)+4])+4)); // Abfrage Variohöhe Notgas
uint8_t bitmap = pgm_read_byte(param_config+(8*items[(ii+offset2)+4])+3); // Abfrage Variohöhe Notgas
if(value & bitmap)
lcd_printp_at(17,ii+1,PSTR("%"), 0);
else
lcd_printp_at(17,ii+1,PSTR(" "), 0);
}
}
}
if(type == 1)
{
uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4));
if(value < 248)
write_ndigit_number_u (18, ii+1, value, 3, 0,0);
if(value >= 248)
{
lcd_printp_at (18, ii+1, PSTR(" P"), 0);
write_ndigit_number_u (20, ii+1, 256-value, 1, 0,0);
}
}
if(type == 2)
{
uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4));
uint8_t bitmap = pgm_read_byte(param_config+(8*items[ii+offset2])+3);
if(value & bitmap)
lcd_printp_at (18, ii+1, PSTR(" J"), 0);
else
lcd_printp_at (18, ii+1, PSTR(" N"), 0);
}
if(type == 3)
{
uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4));
if (value<=12)
write_ndigit_number_u (18, ii+1, value, 3, 0,0);
else
if (value<=(24))
{
lcd_printp_at (18, ii+1, PSTR("S"), 0);
write_ndigit_number_u (19, ii+1, (value-12), 2, 0,0);
}
if (value==25)
lcd_printp_at (18, ii+1, PSTR("WPE"), 0);
}
if(type == 4)
write_ndigit_number_u (18, ii+1, *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4)), 3, 0,0);
if(type == 5)
write_ndigit_number_u (18, ii+1, (*(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4)))*15, 3, 0,0);
if(type == 6) // Empfänger Typ
{
uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4));
if(value == 0)
lcd_printp_at (18, ii+1, PSTR("PPM"), 0);
else if(value == 1)
lcd_printp_at (18, ii+1, PSTR("Spe"), 0);
else if(value == 2)
lcd_printp_at (18, ii+1, PSTR("SpH"), 0);
else if(value == 3)
lcd_printp_at (18, ii+1, PSTR("SpL"), 0);
else if(value == 4)
lcd_printp_at (18, ii+1, PSTR("Jet"), 0);
else if(value == 5)
lcd_printp_at (18, ii+1, PSTR("ACT"), 0);
else if(value == 6)
lcd_printp_at (18, ii+1, PSTR("HoT"), 0);
else if(value == 7)
lcd_printp_at (18, ii+1, PSTR("SBU"), 0);
else if(value == 8)
lcd_printp_at (18, ii+1, PSTR("USR"), 0);
else
write_ndigit_number_u (18, ii+1, *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4)), 3, 0,0);
}
}
if((ii == 5)&&(ii+offset2 < (size-1)))
lcd_printp_at(1,6, PSTR("\x13"), 0);
}
if(pmode == 0)
{
if(offset2 == 0)
{
if(size > 6)
val = menu_choose2 (1, 5, target_pos2,0,1);
else
val = menu_choose2 (1, size, target_pos2,0,0);
}
else
val = menu_choose2 (2, 5, target_pos2,1,1);
}
if(pmode == 1)
{
if(offset2+7 > size)
val = menu_choose2 (2, 6, target_pos2,1,0);
else
val = menu_choose2 (2, 5, target_pos2,1,1);
}
if(val == 254)
{
offset2++;
pmode = 1;
target_pos2 = 5;
}
else if(val == 253)
{
offset2--;
pmode = 0;
target_pos2 = 2;
}
else
break;
}
if(val != 255)
{
target_pos2=val;
return items[val+offset2-1];
}
else
return val;
}
//--------------------------------------------------------------
uint8_t display_section_menu(void)
{
uint8_t size = PAGES;
uint8_t val =0;
while(1)
{
lcd_cls ();
// lcd_printp_at (0, 0, PSTR(" Wähle Seite: "), 2);
lcd_puts_at(0, 0, strGet(PARA_SEITE),2);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
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_pages[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
break;
}
if(val != 255)
{
target_pos=val;
return val+offset;
}
else
return val;
}
//--------------------------------------------------------------
uint8_t display_settings_menu (void)
{
uint8_t status;
lcd_cls ();
// lcd_printp_at (0, 0, PSTR(" Wähle Setting: "), 2);
lcd_puts_at(0, 0, strGet(PARA_SELSETT), 2);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
for(setting=1;setting<6;setting++)
{
status = load_setting(setting);
if(status == 255)
return 255;
write_ndigit_number_u (3, setting, status, 1, 0,0);
lcd_print_at (5,setting,(uint8_t*)mk_param_struct->Name, 0);
}
// lcd_printp_at (3, 6, PSTR("Kopiere Setting"), 0);
lcd_puts_at(3, 6, strGet(PARA_COPY), 0);
status = load_setting(0xff);
if(status == 255)
return 255;
setting = menu_choose (1, 6, 1,status);
return setting;
}
//--------------------------------------------------------------
uint8_t load_setting(uint8_t setting)
{
mode = 'Q'; // Settings
uint8_t timeout = 50;
rxd_buffer_locked = FALSE;
while (!rxd_buffer_locked && timeout)
{
SendOutData ('q', ADDRESS_FC, 1, &setting, 1);
// _delay_ms(50);
timer = 20;
while (timer > 0);
timeout--;
}
if (timeout != 0)
{
Decode64 ();
setting = *pRxData;
mk_param_struct = (mk_param_struct_t *) (pRxData + 1) ;
}
else
{ // timeout occured
// lcd_printp_at (0, 2, PSTR("Fehler: keine Daten"), 0);
lcd_puts_at(0, 2, strGet(OSD_ERROR), 0);
timer = 100;
while (timer > 0);
setting = 255;
}
return setting;
}
//--------------------------------------------------------------
uint8_t write_setting(uint8_t setting)
{
mode = 'S'; // Settings
uint8_t timeout = 50;
rxd_buffer_locked = FALSE;
while (!rxd_buffer_locked && timeout)
{
SendOutData ('s', ADDRESS_FC, 2, &setting, 1, mk_param_struct, sizeof(mk_param_struct_t));
// _delay_ms(50);
timer = 20;
while (timer > 0);
timeout--;
}
if (timeout != 0)
{
Decode64 ();
setting = *pRxData;
}
else // timeout occured
{
// lcd_printp_at (0, 2, PSTR("Fehler: keine Daten"), 0);
lcd_puts_at(0, 2, strGet(OSD_ERROR), 0);
timer = 100;
while (timer > 0);
setting = 255;
}
return setting;
}