Subversion Repositories Projects

Rev

Rev 1307 | Blame | Last modification | View Log | RSS feed

/*****************************************************************************
 *   Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net                  *
 *   Copyright (C) 2011 Christian Brandtner brandtner@brandtner.net          *
 *                                                                           *
 *   This program is free software; you can redistribute it and/or modify    *
 *   it under the terms of the GNU General Public License as published by    *
 *   the Free Software Foundation; either version 2 of the License.          *
 *                                                                           *
 *   This program is distributed in the hope that it will be useful,         *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 *   GNU General Public License for more details.                            *
 *                                                                           *
 *   You should have received a copy of the GNU General Public License       *
 *   along with this program; if not, write to the                           *
 *   Free Software Foundation, Inc.,                                         *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
 *                                                                                                                                               *
 *   Einstellen der Variablen Parameter des P-MKTool                                     *
 *                                                                           *
 *****************************************************************************/


#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <string.h>

#include "main.h"
#include "setup.h"
#include "lcd.h"
#include "eeprom.h"
#include "timer.h"
#include "menu.h"
#include "Wi232.h"


uint8_t spalte;
uint8_t mmode;
uint8_t zeile;
uint8_t edit;
uint8_t MenuItems;
uint8_t LCD_Ausrichtung;
uint8_t edit =0;
uint8_t LCD_Change = 0;
uint8_t Wi_Change =0;

//

#define ITEMS_PKT 7

prog_char param_menuitems_pkt[ITEMS_PKT][15]= // zeilen,zeichen+1
{
        "LowBat Warn  ",
        "Displ.Timeout",
        "LCD Orient.  ",
        "Language     ",
        "Wi TX/RX Chan",
        "Wi NetW. Grp.",
        "Wi NetW. Mode",

};

/***********************************************************************************************//***********************************************************************************************/
uint8_t Edit_Int10th_Value(uint8_t Value, uint8_t min, uint8_t max,const char *Text)

{
        lcd_cls();
        lcd_printpns_at (0, 2, Text, 0);
        write_ndigit_number_u_10th (16, 2,Value, 3, 0);
        lcd_printpns_at (0, 7, PSTR(" \x18    \x19     Back   "), 0);
        do
                {
                        if ((get_key_press (1 << KEY_PLUS) || get_key_rpt (1 << KEY_PLUS)) && (Value < max))
                         {
                                edit=1;
                                Value++;
                                write_ndigit_number_u_10th (16, 2,Value, 3, 0);
                         }
                        if ((get_key_press (1 << KEY_MINUS) || get_key_rpt (1 << KEY_MINUS)) && (Value > min))
                         {
                                edit=1;
                                Value--;
                                write_ndigit_number_u_10th (16, 2,Value, 3, 0);
                         }
                }
                while (!get_key_press (1 << KEY_ESC));
        return Value;

}


/***********************************************************************************************//***********************************************************************************************/
uint8_t Edit_Int_Value(uint8_t Value, uint8_t min, uint8_t max,const char *Text)

{
        lcd_cls();
        lcd_printpns_at (0, 2, Text, 0);
        write_ndigit_number_u (16, 2, Value, 3, 0);
        lcd_printpns_at (0, 7, PSTR(" \x18    \x19     Back   "), 0);
        do
                {
                        if ((get_key_press (1 << KEY_PLUS) || get_key_rpt (1 << KEY_PLUS)) && (Value < max))
                         {
                                edit=1;
                                Value++;
                                write_ndigit_number_u (16, 2,Value, 3, 0);
                         }
                        if ((get_key_press (1 << KEY_MINUS) || get_key_rpt (1 << KEY_MINUS)) && (Value > min))
                         {
                                edit=1;
                                Value--;
                                write_ndigit_number_u (16, 2,Value, 3, 0);
                         }
                }
                while (!get_key_press (1 << KEY_ESC));
       return Value;

}

/***********************************************************************************************//***********************************************************************************************/
uint8_t Edit_Wi_NetMode_Value(uint8_t Value, uint8_t min, uint8_t max,const char *Text)

{
        lcd_cls();
        lcd_printpns_at (0, 2, Text, 0);
         switch (Value)
                    {
                       case     0x0 :lcd_printpns_at (15, 2, PSTR("Slave "), 0);break;
                       case     0x1 :lcd_printpns_at (15, 2, PSTR("Normal"), 0);break;
                       break;
                    }
        lcd_printpns_at (0, 7, PSTR(" \x18    \x19     Back   "), 0);
        do
                {
                if ((get_key_press (1 << KEY_PLUS) || get_key_rpt (1 << KEY_PLUS)) && (Value == 0))
                 {
                        edit=1;
                        Value=NetMode_Normal;
                    lcd_printpns_at (15, 2, PSTR("Normal"), 0);
                 }
                if ((get_key_press (1 << KEY_MINUS) || get_key_rpt (1 << KEY_MINUS)) && (Value == 1))
                 {
                        edit=1;
                        Value=NetMode_Slave;
                    lcd_printpns_at (15, 2, PSTR("Slave "), 0);
                 }
                }
                while (!get_key_press (1 << KEY_ESC));
       return Value;

}


/***********************************************************************************************//***********************************************************************************************/
uint8_t Edit_Language(uint8_t Value, uint8_t min, uint8_t max,const char *Text)

{
        lcd_cls();
        lcd_printpns_at (0, 2, Text, 0);
         switch (Value)
                    {
                       case     0x0 :lcd_printpns_at (14, 2, PSTR("Deutsch"), 0);break;
                       case     0x1 :lcd_printpns_at (14, 2, PSTR("France"), 0);break;
                       case     0x2 :lcd_printpns_at (14, 2, PSTR("English"), 0);break;
                       break;
                    }
        lcd_printpns_at (0, 7, PSTR(" \x18    \x19     Back   "), 0);
        do
                {
                        if ((get_key_press (1 << KEY_PLUS) || get_key_rpt (1 << KEY_PLUS)) && (Value < max))
                         {
                                edit=1;
                                Value++;
                                 switch (Value)
                                            {
                                               case     0x0 :lcd_printpns_at (14, 2, PSTR("Deutsch"), 0);break;
                                               case     0x1 :lcd_printpns_at (14, 2, PSTR("France "), 0);break;
                                               case     0x2 :lcd_printpns_at (14, 2, PSTR("English"), 0);break;
                                               break;
                                            }
                         }
                        if ((get_key_press (1 << KEY_MINUS) || get_key_rpt (1 << KEY_MINUS)) && (Value > min))
                         {
                                edit=1;
                                Value--;
                                 switch (Value)
                                            {
                                                   case 0x0 :lcd_printpns_at (14, 2, PSTR("Deutsch"), 0);break;
                                                   case 0x1 :lcd_printpns_at (14, 2, PSTR("France "), 0);break;
                                                   case 0x2 :lcd_printpns_at (14, 2, PSTR("English"), 0);break;
                                                   break;
                                            }
                         }
                }
                while (!get_key_press (1 << KEY_ESC));
       return Value;

}



/***********************************************************************************************/

uint8_t Edit_Orientation(uint8_t Value, uint8_t min, uint8_t max,const char *Text)

{
        lcd_cls();
        lcd_printpns_at (0, 2, Text, 0);
    switch (Value)
    {
       case     0x0 :lcd_printpns_at (14, 2, PSTR("Normal "), 0);break;
       case     0x4 :lcd_printpns_at (14, 2, PSTR("Reverse"), 0);break;
       break;
    }
        lcd_printpns_at (0, 7, PSTR(" \x18    \x19     Back   "), 0);
        do
                {
                        if ((get_key_press (1 << KEY_PLUS) || get_key_rpt (1 << KEY_PLUS)) && (Value == 0))
                         {
                                edit=1;
                                Value=4;
                            lcd_printpns_at (14, 2, PSTR("Reverse"), 0);
                         }
                        if ((get_key_press (1 << KEY_MINUS) || get_key_rpt (1 << KEY_MINUS)) && (Value == 4))
                         {
                                edit=1;
                                Value=0;
                            lcd_printpns_at (14, 2, PSTR("Normal "), 0);
                         }
                }
                while (!get_key_press (1 << KEY_ESC));
       return Value;

}





void PMK_Setup (void)
{
        uint8_t ii = 0;
        uint8_t offset = 0;
        uint8_t size = 0;
        size = ITEMS_PKT ;
        uint8_t dmode = 0;
        uint8_t target_pos = 1;
        uint8_t val;


        lcd_cls ();
        mmode = 0;
        edit=0;
        LCD_Change =0;
        Wi_Change =0;
        zeile = 1;
        MenuItems =2;
        LCD_Ausrichtung = LCD_ORIENTATION;
        val = 0;


                while(1)
        {
                lcd_cls ();
                lcd_printp_at (0, 0, PSTR("PMK-Tool Setup"), 0);
                lcd_printpns_at (0, 7, PSTR(" \x18    \x19     Back   \x0c "), 0);
                while(1)
                {
                        ii = 0;
                        if(offset > 0)
                        {
                                lcd_printp_at(1,1, PSTR("\x1a"), 0);
                        }
                        for(ii = 0;ii < 6 ; ii++)
                        {
                                if((ii+offset) < size)
                                {
                         lcd_printp_at(3,ii+1,param_menuitems_pkt[ii+offset], 0);
                                }
                                if((ii == 5)&&(ii+offset < (size-1)))
                                {
                                        lcd_printp_at(1,6, PSTR("\x1b"), 0);
                                }
                        }

                        if(dmode == 0)
                        {
                                if(offset == 0)
                                {
                                        if(size > 6)
                                        {
                                                val = menu_choose2 (1, 5, target_pos,0,1);
                                        }
                                        else
                                        {
                                                val = menu_choose2 (1, size, target_pos,0,0);
                                        }
                                }
                                else
                                {
                                        val = menu_choose2 (2, 5, target_pos,1,1);
                                }
                        }
                        if(dmode == 1)
                        {
                                if(offset+7 > size)
                                {
                                        val = menu_choose2 (2, 6, target_pos,1,0);
                                }
                                else
                                {
                                        val = menu_choose2 (2, 5, target_pos,1,1);
                                }
                        }

                        if(val == 254)
                        {
                                offset++;
                                dmode = 1;
                                target_pos = 5;
                        }else if(val == 253)
                        {
                                offset--;
                                dmode = 0;
                                target_pos = 2;
                        }else if(val == 255)
                        {       /* Ende mit BACK, speichern */
                                if  (edit==1)
                                {
                                 WriteParameter();
                                  if (LCD_Change)
                                        {
                                        LCD_ORIENTATION = LCD_Ausrichtung;
                                        cli();
                                        LCD_Init();
                                        sei();
                                        }
                                  if (Wi_Change) InitWi232();
                                }
                                return;
                        }
                        else
                        {
                                break;
                        }
                }

                target_pos = val;

                if((val+offset) == 1 )  MK_LowBat = Edit_Int10th_Value(MK_LowBat,33,170,PSTR("LowBat Warn V:"));
                if((val+offset) == 2 )  DisplayTimeout = Edit_Int_Value(DisplayTimeout,0,254,PSTR("Disp.Timeout :"));
                if((val+offset) == 3 )  {
                                                                 LCD_Ausrichtung = Edit_Orientation(LCD_Ausrichtung,0,4,PSTR("LCD Orient.: "));
                                                                 if (edit) if(!LCD_Change) LCD_Change =1;
                                                                }
                if((val+offset) == 4 )  DisplayLanguage = Edit_Language(DisplayLanguage,0,2,PSTR("Language   : "));
                if((val+offset) == 5 )  {
                                                                 WiTXRXChannel =  Edit_Int_Value(WiTXRXChannel,0,0x79,PSTR("Wi TX/RX Chan:"));
                                                                 if (edit) if(!Wi_Change) Wi_Change =1;
                                                                }
                if((val+offset) == 6 )  {
                                                                 WiNetworkGroup = Edit_Int_Value(WiNetworkGroup,0,0x79,PSTR("Wi NetW. Grp.:"));
                                                                 if (edit) if(!Wi_Change) Wi_Change =1;
                                                                }
                if((val+offset) == 7 )  {
                                                                 WiNetworkMode =  Edit_Wi_NetMode_Value(WiNetworkMode,0,1,PSTR("Wi NetW. Mode:"));
                                                                 if (edit) if(!Wi_Change) Wi_Change =1;
                                                                }

        }
}