#include "usr.h" int usrGetOnOff( char *txt, int current ) { int val; unsigned char KEY; char tmp1[20]; val = current; lcd_clear(); sprintf(tmp1,"%s",txt); lcd_puts(0,0,tmp1); sprintf(tmp1,"USE 1=ON, 0=OFF"); lcd_puts(1,0,tmp1); sprintf(tmp1,"E=SET, C=CANCEL"); lcd_puts(2,0,tmp1); KEY = NOKEY; while( KEY != KEY_E ){ if( val ){ sprintf(tmp1,"ON "); } else { sprintf(tmp1,"OFF"); } lcd_puts(3,0,tmp1); if( KEY == KEY_C ){ return( current ); } KEY = 0; while(! KEY ) { KEY = readkey(); } if( KEY == KEY_0 ){ val = 0; continue; } if( KEY == KEY_1 ){ val = 1; continue; } } return(val); } int usrGetDateTime( void ) { char tmp1[20]; char tmp2[20]; unsigned char KEY,x,y; int ret,newday,newmonth,newyear,newhour,newminute,newsecond; ret = 0; lcd_on(2); lcd_clear(); lcd_puts(0,0,"Date"); lcd_puts(2,0,"Time"); sprintf(tmp1,"%02d.%02d.%04d",(int)DAY,(int)MONTH,(int)YEAR); sprintf(tmp2,"%02d:%02d:%02d",(int)HOUR,(int)MINUTE,(int)SECOND); KEY = 0; x = 0; y = 1; while(KEY != KEY_E ){ if(KEY == KEY_C ){ lcd_on(0); lcd_clear(); return(ret); } KEY = 0; lcd_puts(1,0,tmp1); lcd_puts(3,0,tmp2); lcd_setcursor(y,x); while(! KEY ) { KEY = readkey(); } if(KEY == KEY_UP ){ if(y == 3){ y = 1; x = 0; } continue; } if(KEY == KEY_DOWN ){ if(y == 1){ y = 3; x = 0; } continue; } if(KEY == KEY_LEFT ){ if(x > 0 ){ x--; } if(x == 5 ){ x--; } if(x == 2){ x--; } continue; } if( ( KEY >= KEY_0 ) && ( KEY <= KEY_9 ) ){ if( y == 1 ) { tmp1[x] = KEY; } else { tmp2[x] = KEY; } KEY = 'R'; } if(KEY == KEY_RIGHT );{ x++; if(x == 5 ){ x++; } if(x == 2){ x++; } if(x > 9){ x--; } if( y == 3 ) { if(x > 7){ x--; } } continue; } } tmp1[2] = 0; tmp1[5] = 0; tmp2[2] = 0; tmp2[5] = 0; newday = atoi(&tmp1[0]); newmonth = atoi(&tmp1[3]); newyear = atoi(&tmp1[6]); newhour = atoi(&tmp2[0]); newminute = atoi(&tmp2[3]); newsecond = atoi(&tmp2[6]); if( ( newday > 0 ) && ( newday < 32 ) ){ if( ( newmonth > 0 ) && ( newmonth < 13 ) ) { if( newhour < 24 ) { if( newminute < 60 ) { if( newsecond < 60 ) { DAY = newday; MONTH = newmonth; YEAR = newyear; HOUR = newhour; MINUTE = newminute; SECOND = newsecond; ret = 1; } } } } } lcd_on(0); lcd_clear(); return( ret ); } int usrGetKoor( int azalt, double defho, double defve ) { char tmp1[20]; char tmp2[20]; unsigned char KEY,x,y; int ret; long l1,l2,l3,l4,l5,l6; ret = 0; lcd_on(2); lcd_clear(); if(azalt){ lcd_puts(0,0,"AZ"); lcd_puts(2,0,"ALT"); } else { lcd_puts(0,0,"RA"); lcd_puts(2,0,"DEC"); } sprintDegrees( tmp1, defho ); sprintDegrees( tmp2, defve ); KEY = 0; x = 1; y = 1; while(KEY != KEY_E ){ if(KEY == KEY_C ){ lcd_on(0); lcd_clear(); return(ret); } KEY = 0; lcd_puts(1,0,tmp1); lcd_puts(3,0,tmp2); lcd_setcursor(y,x); while(! KEY ) { KEY = readkey(); } if(KEY == KEY_UP ){ if(y == 3){ y = 1; } continue; } if(KEY == KEY_DOWN ){ if(y == 1){ y = 3; } continue; } if(KEY == KEY_LEFT){ if(x > 0 ){ x--; } if(x == 4 ){ x--; } if(x == 7){ x--; } continue; } if(x == 0){ if( ( KEY >= KEY_0 ) || ( KEY <= KEY_9 ) ){ if( y == 1 ) { if(tmp1[x] == '+'){ tmp1[x] = '-'; } else { tmp1[x] = '+'; } } else { if(tmp2[x] == '+'){ tmp2[x] = '-'; } else { tmp2[x] = '+'; } } KEY = KEY_RIGHT; } } else { if( ( KEY >= KEY_0 ) && ( KEY <= KEY_9) ){ if( y == 1 ) { tmp1[x] = (unsigned char)KEY; } else { tmp2[x] = (unsigned char)KEY; } KEY = KEY_RIGHT; } } if(KEY == KEY_RIGHT);{ x++; if(x == 4 ){ x++; } if(x == 7){ x++; } if(x > 9){ x--; } continue; } } ret = 1; tmp1[4] = 0; tmp1[7] = 0; tmp2[4] = 0; tmp2[7] = 0; l1 = atol(&tmp1[1]); l2 = atol(&tmp1[5]); l3 = atol(&tmp1[8]); l4 = atol(&tmp2[1]); l5 = atol(&tmp2[5]); l6 = atol(&tmp2[8]); l1 = l1 * 3600; if(! azalt){ l1 = l1 * 15; } l2 = l2 * 60; l1 = l1 + l2 + l3; l1 = l1 * 10; if(tmp1[0] == '-'){ l1 = l1 * -1; } l4 = l4 * 3600; l5 = l5 * 60; l4 = l4 + l5 + l6; l4 = l4 * 10; if(tmp2[0] == '-'){ l4 = l4 * -1; } OBJ_ARC10_HO = l1; OBJ_ARC10_VE = l4; if(azalt){ OBJ_DEG_AZ = lArc10dDegrees( l1 ); OBJ_DEG_ALT = lArc10dDegrees( l4 ); } else { OBJ_DEG_RA = lArc10dHours( l1 ); OBJ_DEG_DEC = lArc10dDegrees( l4 ); } lcd_on(0); lcd_clear(); return( ret ); } double usrGetDouble( unsigned char row, double defval ) { char tmp1[20]; unsigned char KEY,x; double d; lcd_on(2); lcd_clear(); sprintf(tmp1,"%016.6f",defval); if(defval >= 0.0){ tmp1[0] = '+'; } else { tmp1[0] = '-'; } KEY = 0; x = 1; while(KEY != KEY_E ){ KEY = 0; lcd_puts(row,0,tmp1); lcd_setcursor(row,x); while(! KEY ) { KEY = readkey(); } if(KEY == KEY_LEFT){ if(x > 0 ){ x--; } if(x == 9 ){ x--; } continue; } if(x == 0){ if( ( KEY >= KEY_0 ) || ( KEY <= KEY_9 ) ){ if(tmp1[x] == '+'){ tmp1[x] = '-'; } else { tmp1[x] = '+'; } KEY = KEY_RIGHT; } } else { if( ( KEY >= KEY_0 ) && ( KEY <= KEY_9 ) ){ tmp1[x] = (unsigned char)KEY; KEY = KEY_RIGHT; } } if(KEY == KEY_RIGHT);{ x++; if(x == 9 ){ x++; } if(x > 15){ x--; } continue; } } d = atof(tmp1); lcd_on(0); lcd_clear(); return( d ); } long usrGetLong( unsigned char row, long deflong ) { char tmp1[20]; unsigned char KEY,x; long l; lcd_on(2); lcd_clear(); sprintf(tmp1,"%010ld",deflong); if(deflong >= 0){ tmp1[0] = '+'; } else { tmp1[0] = '-'; } KEY = 0; x = 1; while(KEY != KEY_E){ KEY = 0; lcd_puts(row,0,tmp1); lcd_setcursor(row,x); while(! KEY ) { KEY = readkey(); } if(KEY == KEY_LEFT){ if(x > 0 ){ x--; } continue; } if(x == 0){ if( ( KEY >= KEY_0 ) || ( KEY <= KEY_9) ){ if(tmp1[x] == '+'){ tmp1[x] = '-'; } else { tmp1[x] = '+'; } KEY = KEY_RIGHT; } } else { if( ( KEY >= KEY_0 ) && ( KEY <= KEY_9) ){ tmp1[x] = (unsigned char)KEY; KEY = KEY_RIGHT; } } if(KEY == KEY_RIGHT);{ x++; if(x > 9){ x--; } continue; } } l = atol(tmp1); lcd_on(0); lcd_clear(); return( l ); } int usrGetInt( unsigned char row, int defint ) { char tmp1[20]; unsigned char KEY,x; int i; lcd_on(2); lcd_clear(); sprintf(tmp1,"%06d",defint); if(defint >= 0){ tmp1[0] = '+'; } else { tmp1[0] = '-'; } KEY = 0; x = 1; while(KEY != KEY_E){ KEY = 0; lcd_puts(row,0,tmp1); lcd_setcursor(row,x); while(! KEY ) { KEY = readkey(); } if(KEY == KEY_LEFT){ if(x > 0 ){ x--; } continue; } if(x == 0){ if( ( KEY >= KEY_0 ) || ( KEY <= KEY_9) ){ if(tmp1[x] == '+'){ tmp1[x] = '-'; } else { tmp1[x] = '+'; } KEY = KEY_RIGHT; } } else { if( ( KEY >= KEY_0 ) && ( KEY <= KEY_9) ){ tmp1[x] = (unsigned char)KEY; KEY = KEY_RIGHT; } } if(KEY == KEY_RIGHT);{ x++; if(x > 5){ x--; } continue; } } i = atoi(tmp1); lcd_on(0); lcd_clear(); return( i ); } void printArc10Degrees(unsigned char row, long val ) { char tmp1[20]; long l1,l2,l3,tmp,rest; int sign; sign = 0; rest = val / 10; if(rest < 0 ){ sign = 1; rest = rest * -1; } l1 = rest / 3600; tmp = l1 * 3600; rest = rest - tmp; l2 = rest / 60; tmp = l2 * 60; rest = rest - tmp; l3 = rest; sprintf(tmp1," %03ld:%02ld:%02ld",l1,l2,l3); if(sign){ tmp1[0] = '-'; } else { tmp1[0] = '+'; } lcd_puts(row,0,tmp1); } void printDegrees(unsigned char row, double val ) { long lo; lo = dDegreeslArc10( val ); printArc10Degrees(row, lo ); } void sprintArc10Degrees( char *ptr, long val ) { long l1,l2,l3,tmp,rest; int sign; sign = 0; rest = val / 10; if(rest < 0 ){ sign = 1; rest = rest * -1; } l1 = rest / 3600; tmp = l1 * 3600; rest = rest - tmp; l2 = rest / 60; tmp = l2 * 60; rest = rest - tmp; l3 = rest; sprintf(ptr," %03ld:%02ld:%02ld",l1,l2,l3); if(sign){ ptr[0] = '-'; } else { ptr[0] = '+'; } } void sprintDegrees(char *ptr, double val ) { long lo; lo = dDegreeslArc10( val ); sprintArc10Degrees( ptr , lo ); } void printDouble( unsigned char row, double val ) { char tmp1[42]; sprintf(tmp1,"%016.6f",val); lcd_puts(row,0,tmp1); } void printLong( unsigned char row, long val ) { char tmp1[42]; sprintf(tmp1,"%010ld",val); lcd_puts(row,0,tmp1); } void printDateTime( unsigned char row ) { char tmp1[20]; sprintf(tmp1,"%02d.%02d.%04d %02d:%02d", (int)DAY, (int)MONTH, (int)YEAR, (int)HOUR, (int)MINUTE); lcd_puts(row,0,tmp1); } int usrGetAck( char *txt ) { unsigned char KEY; char tmp1[20]; lcd_clear(); sprintf(tmp1,"%s",txt); lcd_puts(0,0,tmp1); sprintf(tmp1,"USE 1 = YES"); lcd_puts(1,0,tmp1); sprintf(tmp1,"OTHERS = CANCEL"); lcd_puts(2,0,tmp1); KEY = 0; while( ! KEY ){ KEY = readkey(); } if( KEY == KEY_1 ){ return( 1 ); } return( 0 ); }