#ifndef __koor_c #define __koor_c #include "usr.h" #include "koor.h" void rwDBEntry( int pos, struct RADECKOOR * koor, char write ) { int ct,ect; unsigned char *ptr; ptr = (unsigned char *)koor; ct = EEPROM_DBSTART + ( pos * sizeof(RADECKOOR) ); ect = ct + sizeof( RADECKOOR ); while( ct < ect ){ if( write ){ EEPROM_write( ct, ptr[0] ); } else { ptr[0] = EEPROM_read( ct ); } ct++; ptr++; } } void getInitEepromDatabase( struct RADECKOOR * koor ){ int ct; if( ( EEPROM_read( EEPROM_INITADDR ) == EEPROM_INITIALIZER1 ) && ( EEPROM_read( EEPROM_INITADDR + 1 ) == EEPROM_INITIALIZER2 ) ){ //ok, database is initialized. return; } //not initialized, //we fill it complete with default koor, and a number for names. ct = 0; while( ct < DBMAXKOORS ){ rwDBEntry( ct, (struct RADECKOOR *)koor, 1 ); sprintf(koor->name,"%02d",ct + 1); ct++; } //now, at least whe write the initializers EEPROM_write(EEPROM_INITADDR, EEPROM_INITIALIZER1); EEPROM_write(EEPROM_INITADDR + 1, EEPROM_INITIALIZER2); } int chooseDbKoor( int ipos, struct RADECKOOR * koor ) { RADECKOOR _koor; int pos,oldpos,mode,oldmode; unsigned char k; memcpy((void *)&_koor,( const void *)koor,sizeof( RADECKOOR )); pos = ipos; oldpos = ipos + 1; mode = 0; oldmode = 1; LCDCls(); while( ( k = readkey()) != KEY_ACK ){ if( oldpos != pos ){ oldpos = pos; rwDBEntry( pos, (struct RADECKOOR *)&_koor, 0 ); showRaDec( &_koor ); } if( oldmode != mode ){ oldmode = mode; LCDPos(0,0); LCDWriteP((char *)&row_usechange[mode][0]); } if( k == KEY_UP ){ if( pos > 0 ){pos--;} } if( k == KEY_LEFT ){ if( pos >= 5 ){pos = pos - 5;} } if( k == KEY_RIGHT ){ if( pos < (DBMAXKOORS - 6 )){pos = pos + 5;} } if( k == KEY_DOWN ){ if( pos < ( DBMAXKOORS - 1) ){ pos++;} } if( k == KEY_MENU_LEFT ){ mode--; if( mode < 0 ){mode = 2;} } if( k == KEY_MENU_RIGHT ){ mode++; if( mode > 2 ){mode = 0;} } } if( mode == 0 ){ memcpy((void *)koor,( const void *)&_koor,sizeof( RADECKOOR )); return(pos); } if( mode == 1 ){ return( -1 ); } if( setusrRaDec( &_koor ) ){ if( usr_choose_yesno(0,0) ){ //write to db rwDBEntry( pos, (struct RADECKOOR *)&_koor, 1 ); } if( usr_choose_usecancel(0,0) ){ memcpy((void *)koor,( const void *)&_koor,sizeof( RADECKOOR )); return( pos ); } } return( -1 ); } #endif